From e10c196ff7348a4461e8facee10a208779244ece Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期三, 30 九月 2026 15:33:30 +0800
Subject: [PATCH] 宁夏万通需求:出库单行支持主/辅单位录入;考勤节假日配置改为时间段;物料型号维护;设备批量删除;来料检验默认方案解析

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java |   72 ++++++++++++++++++++++++++++++++----
 1 files changed, 64 insertions(+), 8 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 a1ec2f7..373e12f 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,8 @@
 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 cn.iocoder.yudao.module.mes.service.wm.unitconvert.MesWmItemUnitConvertService;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Lazy;
@@ -24,6 +26,7 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Objects;
 
@@ -34,7 +37,7 @@
 /**
  * MES 閿�鍞嚭搴撳崟琛� Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -56,9 +59,16 @@
     @Resource
     @Lazy
     private MesWmSalesNoticeLineService salesNoticeLineService;
+    @Resource
+    @Lazy
+    private MesQcOqcService oqcService;
+    @Resource
+    private MesWmItemUnitConvertService itemUnitConvertService;
 
     @Override
     public Long createProductSalesLine(MesWmProductSalesLineSaveReqVO createReqVO) {
+        // 鍙屽崟浣嶆崲绠楋細鎸夊綍鍏ュ崟浣嶆崲绠椾负鐗╂枡涓诲崟浣嶆暟閲忥紙蹇呴』鍏堟崲绠楋紝鍐嶆牎楠屼笌鍙戣揣閫氱煡鍗曡鐨勬暟閲忎竴鑷存�э級
+        fillPrimaryQuantity(createReqVO);
         // 鏍¢獙鏁版嵁
         validateLineSaveData(createReqVO);
 
@@ -72,13 +82,43 @@
     public void updateProductSalesLine(MesWmProductSalesLineSaveReqVO updateReqVO) {
         // 鏍¢獙瀛樺湪
         MesWmProductSalesLineDO oldLine = validateProductSalesLineExists(updateReqVO.getId());
-        // 鏍¢獙鏁版嵁
         updateReqVO.setSalesId(oldLine.getSalesId());
+        // 鍙屽崟浣嶆崲绠楋細鎸夊綍鍏ュ崟浣嶆崲绠椾负鐗╂枡涓诲崟浣嶆暟閲忥紙蹇呴』鍏堟崲绠楋紝鍐嶆牎楠屼笌鍙戣揣閫氱煡鍗曡鐨勬暟閲忎竴鑷存�э級
+        fillPrimaryQuantity(updateReqVO);
+        // 鏍¢獙鏁版嵁
         validateLineSaveData(updateReqVO);
 
         // 鏇存柊
         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
@@ -135,6 +175,25 @@
     }
 
     /**
+     * 鍙屽崟浣嶆崲绠楋細閫夋嫨浜嗗綍鍏ュ崟浣嶆椂锛屾寜銆屽綍鍏ユ暟閲� 脳 鎹㈢畻姣旂巼銆嶅緱鍒扮墿鏂欎富鍗曚綅鍙e緞鐨勫嚭搴撴暟閲�
+     *
+     * 鏈寜杈呭崟浣嶅綍鍏ユ椂蹇呴』鐩存帴濉啓鍑哄簱鏁伴噺
+     */
+    private void fillPrimaryQuantity(MesWmProductSalesLineSaveReqVO reqVO) {
+        if (reqVO.getEnterUnitMeasureId() != null) {
+            BigDecimal primaryQuantity = itemUnitConvertService.convertToPrimaryUnit(
+                    reqVO.getItemId(), reqVO.getItemModelId(),
+                    reqVO.getEnterUnitMeasureId(), reqVO.getEnterQuantity());
+            if (primaryQuantity != null) {
+                reqVO.setQuantity(primaryQuantity);
+            }
+        }
+        if (reqVO.getQuantity() == null) {
+            throw exception(WM_PRODUCT_SALES_LINE_QUANTITY_REQUIRED);
+        }
+    }
+
+    /**
      * 鏍规嵁 batchCode 瑙f瀽 batchId
      */
     private void fillBatchId(MesWmProductSalesLineSaveReqVO reqVO) {
@@ -175,7 +234,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 +246,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;
         }
@@ -204,7 +260,7 @@
     @Transactional(rollbackFor = Exception.class)
     public void updateProductSalesLineWhenOqcFinish(Long id, Long oqcId, Integer checkResult) {
         // 1. 鏇存柊琛岀殑 oqcId + qualityStatus
-        Integer qualityStatus = Objects.equals(checkResult, MesQcCheckResultEnum.PASS.getType())
+        Integer qualityStatus = Objects.equals(checkResult, MesQcCheckResultEnum.QUALIFIED.getType())
                 ? MesWmQualityStatusEnum.PASS.getStatus() : MesWmQualityStatusEnum.FAIL.getStatus();
         productSalesLineMapper.updateById(new MesWmProductSalesLineDO()
                 .setId(id).setOqcId(oqcId).setQualityStatus(qualityStatus));

--
Gitblit v1.9.3