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;
|
}
|
|
}
|