From b3fe06c151dc8455649bf0a46e481ceb83e3ea2a Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期六, 07 十一月 2026 13:37:54 +0800
Subject: [PATCH] feat: 完成好水川 MOM 需求1/2/4/5/8(装箱、BOM成本、销售合同、劳动合同、留样)

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java |   64 +++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 6 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..e3f90be 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
@@ -7,16 +7,19 @@
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.line.MesWmProductSalesLinePageReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.line.MesWmProductSalesLineSaveReqVO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesLineDO;
 import cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesLineMapper;
 import cn.iocoder.yudao.module.mes.enums.qc.MesQcCheckResultEnum;
 import cn.iocoder.yudao.module.mes.enums.wm.MesWmQualityStatusEnum;
+import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
 import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService;
 import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService;
 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;
@@ -24,6 +27,8 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.List;
 import java.util.Objects;
 
@@ -34,7 +39,7 @@
 /**
  * MES 閿�鍞嚭搴撳崟琛� Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -49,6 +54,8 @@
     @Resource
     private MesMdmItemService mdmItemService;
     @Resource
+    private MesMdItemService mdItemService;
+    @Resource
     private MesWmBatchService batchService;
     @Resource
     @Lazy
@@ -56,6 +63,9 @@
     @Resource
     @Lazy
     private MesWmSalesNoticeLineService salesNoticeLineService;
+    @Resource
+    @Lazy
+    private MesQcOqcService oqcService;
 
     @Override
     public Long createProductSalesLine(MesWmProductSalesLineSaveReqVO createReqVO) {
@@ -64,6 +74,7 @@
 
         // 鏂板
         MesWmProductSalesLineDO line = BeanUtils.toBean(createReqVO, MesWmProductSalesLineDO.class);
+        line.setBoxCount(calculateBoxCount(line.getItemId(), line.getQuantity()));
         productSalesLineMapper.insert(line);
         return line.getId();
     }
@@ -78,7 +89,36 @@
 
         // 鏇存柊
         MesWmProductSalesLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmProductSalesLineDO.class);
+        updateObj.setBoxCount(calculateBoxCount(updateObj.getItemId(), updateObj.getQuantity()));
         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
@@ -135,6 +175,21 @@
     }
 
     /**
+     * 鎸� 鏁伴噺 / 鐗╂枡姣忕鏁伴噺 鍚戜笂鍙栨暣璁$畻绠辨暟锛涙湭缁存姢姣忕鏁伴噺鏃惰繑鍥� 0
+     */
+    private int calculateBoxCount(Long itemId, BigDecimal quantity) {
+        if (itemId == null || quantity == null) {
+            return 0;
+        }
+        MesMdItemDO item = mdItemService.getItem(itemId);
+        if (item == null || item.getBoxQuantity() == null
+                || item.getBoxQuantity().compareTo(BigDecimal.ZERO) <= 0) {
+            return 0;
+        }
+        return quantity.divide(item.getBoxQuantity(), 0, RoundingMode.CEILING).intValue();
+    }
+
+    /**
      * 鏍规嵁 batchCode 瑙f瀽 batchId
      */
     private void fillBatchId(MesWmProductSalesLineSaveReqVO reqVO) {
@@ -175,7 +230,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 +242,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