package cn.iocoder.yudao.module.srm.service.supplier;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.SrmSupplierContactSaveReqVO;
|
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierContactDO;
|
import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierContactMapper;
|
import cn.iocoder.yudao.module.srm.enums.ErrorCodeConstants;
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
|
import java.util.List;
|
|
@Service
|
@Validated
|
public class SrmSupplierContactServiceImpl implements SrmSupplierContactService {
|
|
@Resource
|
private SrmSupplierContactMapper supplierContactMapper;
|
|
@Override
|
public Long createContact(SrmSupplierContactSaveReqVO createReqVO) {
|
SrmSupplierContactDO contact = BeanUtils.toBean(createReqVO, SrmSupplierContactDO.class);
|
supplierContactMapper.insert(contact);
|
return contact.getId();
|
}
|
|
@Override
|
public void updateContact(SrmSupplierContactSaveReqVO updateReqVO) {
|
validateContactExists(updateReqVO.getId());
|
SrmSupplierContactDO updateObj = BeanUtils.toBean(updateReqVO, SrmSupplierContactDO.class);
|
supplierContactMapper.updateById(updateObj);
|
}
|
|
@Override
|
public void deleteContact(Long id) {
|
validateContactExists(id);
|
supplierContactMapper.deleteById(id);
|
}
|
|
@Override
|
public List<SrmSupplierContactDO> getContactListBySupplierId(Long supplierId) {
|
return supplierContactMapper.selectListBySupplierId(supplierId);
|
}
|
|
private void validateContactExists(Long id) {
|
if (supplierContactMapper.selectById(id) == null) {
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_CONTACT_NOT_EXISTS);
|
}
|
}
|
|
}
|