From 0fdd0bf60b7d98d21c9b5ff95bb55f0fa6495007 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 14 八月 2026 14:20:03 +0800
Subject: [PATCH] Merge branch 'dev_business' of http://114.132.189.42:9002/r/mom-pro2-after into dev_business
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcServiceImpl.java | 81 +++++++++++++++++++++++++++++++---------
1 files changed, 63 insertions(+), 18 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcServiceImpl.java
index eb962d7..cf1ea78 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcServiceImpl.java
@@ -20,6 +20,7 @@
import cn.iocoder.yudao.module.mes.enums.qc.MesQcDefectLevelEnum;
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.enums.MesBizTypeConstants;
import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService;
@@ -31,9 +32,12 @@
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;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -50,10 +54,11 @@
/**
* MES 杩囩▼妫�楠屽崟锛圛PQC锛� Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
+@Slf4j
public class MesQcIpqcServiceImpl implements MesQcIpqcService {
/**
@@ -101,6 +106,10 @@
@Resource
@Lazy
private MesWmProductProduceLineService productProduceLineService;
+
+ @Resource
+ @Lazy
+ private MesQcNcrService ncrService;
@Resource
private AdminUserApi adminUserApi;
@@ -213,8 +222,35 @@
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());
}
/**
@@ -225,25 +261,34 @@
* @param ipqc 杩囩▼妫�楠屽崟
*/
private void writeBackSourceDoc(MesQcIpqcDO ipqc) {
- if (ipqc.getSourceDocType() == null) {
- return;
- }
- if (ipqc.getSourceDocId() == null) {
- throw new IllegalArgumentException(
- "IPQC 鍗昜" + ipqc.getId() + "] sourceDocType 闈炵┖浣� sourceDocId 涓虹┖");
+ // 1. 纭畾 sourceDocType/sourceDocId
+ Long sourceDocId = ipqc.getSourceDocId();
+ Long sourceLineId = ipqc.getSourceLineId();
+
+ // 濡傛灉 IPQC 鍗曟病鏈夎缃潵婧愶紝灏濊瘯閫氳繃 taskId 鏌ユ壘鍏宠仈鐨勫緟妫�楠屾姤宸�
+ if (sourceDocId == null && ipqc.getTaskId() != null) {
+ MesProFeedbackDO feedback = feedbackService.getFeedbackListByTaskId(ipqc.getTaskId()).stream()
+ .filter(f -> MesProFeedbackStatusEnum.UNCHECK.getStatus().equals(f.getStatus()))
+ .findFirst().orElse(null);
+ if (feedback != null) {
+ sourceDocId = feedback.getId();
+ log.info("[writeBackSourceDoc] IPQC({}) 鏈缃潵婧愬崟鎹紝閫氳繃 taskId({}) 鎵惧埌寰呮楠屾姤宸�({})",
+ ipqc.getId(), ipqc.getTaskId(), feedback.getId());
+ }
}
- if (Objects.equals(ipqc.getSourceDocType(), MesBizTypeConstants.PRO_FEEDBACK)) {
- feedbackService.updateProFeedbackWhenIpqcFinish(ipqc.getSourceDocId(), ipqc.getSourceLineId(),
- ObjectUtil.defaultIfNull(ipqc.getQualifiedQuantity(), BigDecimal.ZERO),
- ObjectUtil.defaultIfNull(ipqc.getUnqualifiedQuantity(), BigDecimal.ZERO),
- ObjectUtil.defaultIfNull(ipqc.getLaborScrapQuantity(), BigDecimal.ZERO),
- ObjectUtil.defaultIfNull(ipqc.getMaterialScrapQuantity(), BigDecimal.ZERO),
- ObjectUtil.defaultIfNull(ipqc.getOtherScrapQuantity(), BigDecimal.ZERO));
- } else {
- throw new IllegalArgumentException(
- "IPQC 鍗昜" + ipqc.getId() + "] sourceDocType=" + ipqc.getSourceDocType() + " 鏃犳硶璇嗗埆锛屾棤娉曞洖鍐欐潵婧愬崟鎹�");
+ if (sourceDocId == null) {
+ log.warn("[writeBackSourceDoc] IPQC({}) 鏃犳硶纭畾鏉ユ簮鎶ュ伐锛岃烦杩囧洖鍐�", ipqc.getId());
+ return;
}
+
+ // 2. 鍥炲啓鎶ュ伐
+ feedbackService.updateProFeedbackWhenIpqcFinish(sourceDocId, sourceLineId,
+ ObjectUtil.defaultIfNull(ipqc.getQualifiedQuantity(), BigDecimal.ZERO),
+ ObjectUtil.defaultIfNull(ipqc.getUnqualifiedQuantity(), BigDecimal.ZERO),
+ ObjectUtil.defaultIfNull(ipqc.getLaborScrapQuantity(), BigDecimal.ZERO),
+ ObjectUtil.defaultIfNull(ipqc.getMaterialScrapQuantity(), BigDecimal.ZERO),
+ ObjectUtil.defaultIfNull(ipqc.getOtherScrapQuantity(), BigDecimal.ZERO));
}
@Override
--
Gitblit v1.9.3