| | |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.qc.ncr.MesQcNcrMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesNcrStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.md.autocode.MesMdAutoCodeRuleCodeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.iqc.MesQcIqcService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.ipqc.MesQcIpqcService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.oqc.MesQcOqcService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.rqc.MesQcRqcService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.support.MesQcItemResolver; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collection; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @Slf4j |
| | | public class MesQcNcrServiceImpl implements MesQcNcrService { |
| | | |
| | | @Resource |
| | |
| | | |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | |
| | | @Resource |
| | | private MesQcItemResolver qcItemResolver; |
| | | |
| | | @Resource |
| | | private MesMdAutoCodeRecordService autoCodeRecordService; |
| | | |
| | | @Resource |
| | | @Lazy |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createNcr(MesQcNcrSaveReqVO createReqVO) { |
| | | if (StrUtil.isBlank(createReqVO.getCode())) { |
| | | createReqVO.setCode(generateNcrCode()); |
| | | } |
| | | // 1. 校验数据 |
| | | validateNcrCodeUnique(null, createReqVO.getCode()); |
| | | validateItemExists(createReqVO.getItemId()); |
| | |
| | | } |
| | | ncrMapper.insert(ncr); |
| | | return ncr.getId(); |
| | | } |
| | | |
| | | private String generateNcrCode() { |
| | | try { |
| | | return autoCodeRecordService.generateAutoCode(MesMdAutoCodeRuleCodeEnum.QC_NCR_CODE.getCode()); |
| | | } catch (Exception e) { |
| | | log.warn("NCR 编码规则 {} 不可用,降级使用时间戳编码", |
| | | MesMdAutoCodeRuleCodeEnum.QC_NCR_CODE.getCode(), e); |
| | | return "NCR" + LocalDateTime.now() |
| | | .format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | * 校验物料存在 |
| | | */ |
| | | private void validateItemExists(Long itemId) { |
| | | if (itemId != null) { |
| | | mdmItemApi.getItem(itemId).getCheckedData(); |
| | | } |
| | | // 不合格品单的物料可能来自 MDM 单据或 MES 工单,需兼容两套 ID |
| | | qcItemResolver.validateItemExists(itemId); |
| | | } |
| | | |
| | | /** |