xiaoyi
3 天以前 abf1c0a35d85d38239ff5d2ed746a4e4b797c9d1
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package cn.iocoder.yudao.module.mes.service.pd.techconfirm;
 
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.pd.techconfirm.vo.ProductTechConfirmPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.techconfirm.vo.ProductTechConfirmSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.techconfirm.ProductTechConfirmDO;
import cn.iocoder.yudao.module.mes.dal.mysql.pd.techconfirm.ProductTechConfirmMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PD_TECH_CONFIRM_NOT_EXISTS;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PD_TECH_CONFIRM_NO_DUPLICATE;
 
/**
 * MES 产品技术确认函 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ProductTechConfirmServiceImpl implements ProductTechConfirmService {
 
    @Resource
    private ProductTechConfirmMapper techConfirmMapper;
 
    @Override
    public Long createTechConfirm(ProductTechConfirmSaveReqVO createReqVO) {
        // 校验确认函编号唯一
        validateConfirmNoUnique(createReqVO.getConfirmNo(), null);
        // 插入
        ProductTechConfirmDO techConfirm = BeanUtils.toBean(createReqVO, ProductTechConfirmDO.class);
        techConfirmMapper.insert(techConfirm);
        return techConfirm.getId();
    }
 
    @Override
    public void updateTechConfirm(ProductTechConfirmSaveReqVO updateReqVO) {
        // 校验存在
        validateTechConfirmExists(updateReqVO.getId());
        // 校验确认函编号唯一(排除自身)
        validateConfirmNoUnique(updateReqVO.getConfirmNo(), updateReqVO.getId());
        // 更新
        ProductTechConfirmDO updateObj = BeanUtils.toBean(updateReqVO, ProductTechConfirmDO.class);
        techConfirmMapper.updateById(updateObj);
    }
 
    @Override
    public void deleteTechConfirm(Long id) {
        // 校验存在
        validateTechConfirmExists(id);
        // 删除
        techConfirmMapper.deleteById(id);
    }
 
    @Override
    public ProductTechConfirmDO getTechConfirm(Long id) {
        return techConfirmMapper.selectById(id);
    }
 
    @Override
    public PageResult<ProductTechConfirmDO> getTechConfirmPage(ProductTechConfirmPageReqVO pageReqVO) {
        return techConfirmMapper.selectPage(pageReqVO);
    }
 
    private void validateConfirmNoUnique(String confirmNo, Long excludeId) {
        if (confirmNo == null) {
            return;
        }
        ProductTechConfirmDO techConfirm = techConfirmMapper.selectOne(
                ProductTechConfirmDO::getConfirmNo, confirmNo);
        if (techConfirm != null && !techConfirm.getId().equals(excludeId)) {
            throw exception(PD_TECH_CONFIRM_NO_DUPLICATE);
        }
    }
 
    private ProductTechConfirmDO validateTechConfirmExists(Long id) {
        ProductTechConfirmDO techConfirm = techConfirmMapper.selectById(id);
        if (techConfirm == null) {
            throw exception(PD_TECH_CONFIRM_NOT_EXISTS);
        }
        return techConfirm;
    }
 
}