| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateItemDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.qc.ipqc.MesQcIpqcMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcDefectLevelEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcCheckResultEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProFeedbackStatusEnum; |
| | |
| | | import cn.iocoder.yudao.module.mes.service.qc.defectrecord.MesQcDefectRecordService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.indicatorresult.MesQcIndicatorResultService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.template.MesQcTemplateItemService; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.ncr.vo.MesQcNcrSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.service.qc.ncr.MesQcNcrService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.productproduce.MesWmProductProduceLineService; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import jakarta.annotation.Resource; |
| | |
| | | /** |
| | | * MES 过程检验单(IPQC) Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | @Resource |
| | | @Lazy |
| | | private MesWmProductProduceLineService productProduceLineService; |
| | | |
| | | @Resource |
| | | @Lazy |
| | | private MesQcNcrService ncrService; |
| | | |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | |
| | | if (ipqc.getCheckResult() == null) { |
| | | throw exception(QC_IPQC_CHECK_RESULT_EMPTY); |
| | | } |
| | | if (ipqc.getUnqualifiedQuantity() != null && ipqc.getUnqualifiedQuantity().compareTo(BigDecimal.ZERO) > 0 |
| | | && MesQcCheckResultEnum.QUALIFIED.getType().equals(ipqc.getCheckResult())) { |
| | | throw new IllegalArgumentException("存在不合格品时,过程检验结论不能为合格"); |
| | | } |
| | | if ((ipqc.getUnqualifiedQuantity() == null || ipqc.getUnqualifiedQuantity().compareTo(BigDecimal.ZERO) == 0) |
| | | && !MesQcCheckResultEnum.QUALIFIED.getType().equals(ipqc.getCheckResult())) { |
| | | throw new IllegalArgumentException("不合格数量为 0 时,过程检验结论必须为合格"); |
| | | } |
| | | // 1.3 校验至少存在一条检测结果 |
| | | indicatorResultService.validateIndicatorResultExistsByQcIdAndType(id, MesQcTypeEnum.IPQC.getType()); |
| | | |
| | |
| | | ipqcMapper.updateById(new MesQcIpqcDO() |
| | | .setId(id).setStatus(MesQcStatusEnum.FINISHED.getStatus())); |
| | | |
| | | // 3. 回写来源单据 |
| | | // 3. 不合格时自动创建 NCR |
| | | generateNcrIfNeeded(ipqc); |
| | | |
| | | // 4. 回写来源单据 |
| | | writeBackSourceDoc(ipqc); |
| | | } |
| | | |
| | | /** |
| | | * 不合格时自动创建 NCR(不合格品处理单) |
| | | * |
| | | * @param ipqc 过程检验单 |
| | | */ |
| | | private void generateNcrIfNeeded(MesQcIpqcDO ipqc) { |
| | | BigDecimal unqualifiedQty = ipqc.getUnqualifiedQuantity(); |
| | | if (unqualifiedQty == null || unqualifiedQty.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | String ncrCode = "NCR" + java.time.LocalDateTime.now() |
| | | .format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")); |
| | | MesQcNcrSaveReqVO saveReqVO = new MesQcNcrSaveReqVO(); |
| | | saveReqVO.setCode(ncrCode); |
| | | saveReqVO.setName("不合格品处理单"); |
| | | saveReqVO.setQcType(MesQcTypeEnum.IPQC.getType()); |
| | | saveReqVO.setQcId(ipqc.getId()); |
| | | saveReqVO.setItemId(ipqc.getItemId()); |
| | | saveReqVO.setUnqualifiedQuantity(unqualifiedQty); |
| | | saveReqVO.setDefectDescription("由过程检验(" + ipqc.getCode() + ")自动生成"); |
| | | ncrService.createNcr(saveReqVO); |
| | | log.info("[generateNcrIfNeeded] IPQC({}) 不合格,自动创建 NCR", ipqc.getId()); |
| | | } |
| | | |
| | | /** |
| | | * 回写来源单据(IPQC 完成后) |
| | | * |
| | | * <p>当来源为报工时,拆分待检产出行、完成产出入库、回写报工状态和任务/工单进度 |