5 小时以前 4d15fa8051884869c5b612d0641508874cc71811
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
        }
    }
 
}