From be5783c8a7e13bbc76d33c95643d75779cce21db Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期六, 18 七月 2026 15:39:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_business' into dev_business

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
index 2ba2348..590df99 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
@@ -17,6 +17,7 @@
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeLineDO;
 import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeLineService;
+import cn.iocoder.yudao.module.mes.service.qc.oqc.MesQcOqcService;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Lazy;
@@ -56,6 +57,9 @@
     @Resource
     @Lazy
     private MesWmSalesNoticeLineService salesNoticeLineService;
+    @Resource
+    @Lazy
+    private MesQcOqcService oqcService;
 
     @Override
     public Long createProductSalesLine(MesWmProductSalesLineSaveReqVO createReqVO) {
@@ -79,6 +83,34 @@
         // 鏇存柊
         MesWmProductSalesLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmProductSalesLineDO.class);
         productSalesLineMapper.updateById(updateObj);
+
+        // 妫�鏌ユ槸鍚﹂渶瑕佸垱寤� OQC 妫�楠屽崟锛氫粠涓嶉渶瑕佹楠屽彉涓洪渶瑕佹楠�
+        if (Boolean.TRUE.equals(updateReqVO.getOqcCheckFlag())
+                && !Boolean.TRUE.equals(oldLine.getOqcCheckFlag())) {
+            // 鑾峰彇鍑哄簱鍗曚俊鎭�
+            MesWmProductSalesDO sales = productSalesService.getProductSales(updateReqVO.getSalesId());
+            if (sales == null) {
+                log.warn("[updateProductSalesLine] 鍑哄簱鍗曚笉瀛樺湪锛宻alesId={}", updateReqVO.getSalesId());
+                return;
+            }
+
+            // 鏋勫缓鍑哄簱鏄庣粏 DO
+            MesWmProductSalesLineDO line = new MesWmProductSalesLineDO();
+            line.setId(updateReqVO.getId());
+            line.setItemId(updateReqVO.getItemId());
+            line.setBatchCode(updateReqVO.getBatchCode());
+            line.setQuantity(updateReqVO.getQuantity());
+
+            // 鍒涘缓 OQC 妫�楠屽崟锛岃寮傚父鎶涘嚭
+            Long oqcId = oqcService.createOqcFromProductSales(
+                    sales.getId(), line, sales.getCode(), sales.getClientId());
+
+            // 鏇存柊鍑哄簱鏄庣粏鐨� oqcId 鍜岃川閲忕姸鎬�
+            productSalesLineMapper.updateById(new MesWmProductSalesLineDO()
+                    .setId(updateReqVO.getId())
+                    .setOqcId(oqcId)
+                    .setQualityStatus(MesWmQualityStatusEnum.PENDING.getStatus()));
+        }
     }
 
     @Override
@@ -175,7 +207,8 @@
             }
             MesWmSalesNoticeLineDO noticeLine = salesNoticeLineService.validateSalesNoticeLineExists(
                     noticeLineId, sales.getNoticeId());
-            // 鏍¢獙鍏抽敭瀛楁涓�鑷存�э細鐗╂枡銆佹暟閲忋�佹壒娆″彿銆丱QC 妫�楠屾爣璇�
+            // 鏍¢獙鍏抽敭瀛楁涓�鑷存�э細鐗╂枡銆佹暟閲忋�佹壒娆″彿
+            // 娉細OQC 妫�楠屾爣璇嗗厑璁稿湪鍑哄簱鏃剁嫭绔嬭缃紝涓嶅己鍒朵笌閫氱煡鍗曚竴鑷�
             if (ObjUtil.notEqual(reqVO.getItemId(), noticeLine.getItemId())) {
                 throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_ITEM_MISMATCH);
             }
@@ -186,10 +219,6 @@
             if (StrUtil.isNotBlank(noticeLine.getBatchCode())
                     && ObjUtil.notEqual(reqVO.getBatchCode(), noticeLine.getBatchCode())) {
                 throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_BATCH_MISMATCH);
-            }
-            if (noticeLine.getOqcCheckFlag() != null
-                    && ObjUtil.notEqual(reqVO.getOqcCheckFlag(), noticeLine.getOqcCheckFlag())) {
-                throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_OQC_MISMATCH);
             }
             return;
         }

--
Gitblit v1.9.3