From d3e57f662fc00214c9d1b1caa9a4dd542a9d2e1e Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期五, 31 七月 2026 13:47:29 +0800
Subject: [PATCH] 采购订单入库批次关联

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java |  166 ++++++++++++++++++++++++++-----------------------------
 1 files changed, 78 insertions(+), 88 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
index 151f178..a84dda6 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
@@ -14,6 +14,7 @@
 import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService;
 import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService;
 import cn.iocoder.yudao.module.mes.service.wm.barcode.MesWmBarcodeService;
+import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
 import cn.iocoder.yudao.module.mdm.api.item.MdmItemBatchConfigApi;
 import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemBatchConfigRespDTO;
 import jakarta.annotation.Resource;
@@ -56,10 +57,14 @@
     private MesMdAutoCodeRecordService autoCodeRecordService;
     @Resource
     private MesWmBarcodeService barcodeService;
+    @Resource
+    private CrmCustomerApi customerApi;
 
     @Override
     public PageResult<MesWmBatchDO> getBatchPage(MesWmBatchPageReqVO pageReqVO) {
-        return batchMapper.selectPage(pageReqVO);
+        // 鑾峰彇鐢ㄦ埛鏈夋潈闄愮殑瀹㈡埛 ID 鍒楄〃
+        List<Long> permittedClientIds = customerApi.getPermittedCustomerIds();
+        return batchMapper.selectPage(pageReqVO, permittedClientIds);
     }
 
     @Override
@@ -92,122 +97,107 @@
         // 2. 鏍规嵁閰嶇疆鏍¢獙蹇呭~鍙傛暟骞舵竻绌轰笉闇�瑕佺殑鍙傛暟
         MesWmBatchDO batch = MesWmBatchDO.builder().itemId(reqVO.getItemId()).build();
         if (config != null) {
+            // ========== 蹇呭~鏍¢獙锛坒lag=true 琛ㄧず璇ュ瓧娈典负蹇呭~锛� ==========
             // 鐢熶骇鏃ユ湡
-            if (Boolean.TRUE.equals(config.getProduceDateFlag())) {
-                if (ObjUtil.isNull(reqVO.getProduceDate())) {
-                    throw exception(WM_BATCH_PRODUCE_DATE_REQUIRED);
-                }
-                batch.setProduceDate(reqVO.getProduceDate());
+            if (Boolean.TRUE.equals(config.getProduceDateFlag()) && ObjUtil.isNull(reqVO.getProduceDate())) {
+                throw exception(WM_BATCH_PRODUCE_DATE_REQUIRED);
             }
             // 鍏ュ簱鏃ユ湡
-            if (Boolean.TRUE.equals(config.getReceiptDateFlag())) {
-                if (ObjUtil.isNull(reqVO.getReceiptDate())) {
-                    throw exception(WM_BATCH_RECEIPT_DATE_REQUIRED);
-                }
-                batch.setReceiptDate(reqVO.getReceiptDate());
+            if (Boolean.TRUE.equals(config.getReceiptDateFlag()) && ObjUtil.isNull(reqVO.getReceiptDate())) {
+                throw exception(WM_BATCH_RECEIPT_DATE_REQUIRED);
             }
             // 鏈夋晥鏈�
-            if (Boolean.TRUE.equals(config.getExpireDateFlag())) {
-                if (ObjUtil.isNull(reqVO.getExpireDate())) {
-                    throw exception(WM_BATCH_EXPIRE_DATE_REQUIRED);
-                }
-                batch.setExpireDate(reqVO.getExpireDate());
+            if (Boolean.TRUE.equals(config.getExpireDateFlag()) && ObjUtil.isNull(reqVO.getExpireDate())) {
+                throw exception(WM_BATCH_EXPIRE_DATE_REQUIRED);
             }
             // 渚涘簲鍟�
-            if (Boolean.TRUE.equals(config.getVendorFlag())) {
-                if (ObjUtil.isNull(reqVO.getVendorId())) {
-                    throw exception(WM_BATCH_VENDOR_REQUIRED);
-                }
-                batch.setVendorId(reqVO.getVendorId());
+            if (Boolean.TRUE.equals(config.getVendorFlag()) && ObjUtil.isNull(reqVO.getVendorId())) {
+                throw exception(WM_BATCH_VENDOR_REQUIRED);
             }
             // 瀹㈡埛
-            if (Boolean.TRUE.equals(config.getClientFlag())) {
-                if (ObjUtil.isNull(reqVO.getClientId())) {
-                    throw exception(WM_BATCH_CLIENT_REQUIRED);
-                }
-                batch.setClientId(reqVO.getClientId());
+            if (Boolean.TRUE.equals(config.getClientFlag()) && ObjUtil.isNull(reqVO.getClientId())) {
+                throw exception(WM_BATCH_CLIENT_REQUIRED);
             }
             // 閲囪喘璁㈠崟缂栧彿
-            if (Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag())) {
-                if (ObjUtil.isNull(reqVO.getPurchaseOrderCode())) {
-                    throw exception(WM_BATCH_PURCHASE_ORDER_CODE_REQUIRED);
-                }
-                batch.setPurchaseOrderCode(reqVO.getPurchaseOrderCode());
+            if (Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag()) && ObjUtil.isNull(reqVO.getPurchaseOrderCode())) {
+                throw exception(WM_BATCH_PURCHASE_ORDER_CODE_REQUIRED);
             }
             // 閿�鍞鍗曠紪鍙�
-            if (Boolean.TRUE.equals(config.getSalesOrderCodeFlag())) {
-                if (ObjUtil.isNull(reqVO.getSalesOrderCode())) {
-                    throw exception(WM_BATCH_CUSTOMER_ORDER_CODE_REQUIRED);
-                }
-                batch.setSalesOrderCode(reqVO.getSalesOrderCode());
+            if (Boolean.TRUE.equals(config.getSalesOrderCodeFlag()) && ObjUtil.isNull(reqVO.getSalesOrderCode())) {
+                throw exception(WM_BATCH_CUSTOMER_ORDER_CODE_REQUIRED);
             }
             // 鐢熶骇宸ュ崟
-            if (Boolean.TRUE.equals(config.getWorkOrderFlag())) {
-                if (ObjUtil.isNull(reqVO.getWorkOrderId())) {
-                    throw exception(WM_BATCH_WORK_ORDER_REQUIRED);
-                }
-                batch.setWorkOrderId(reqVO.getWorkOrderId());
+            if (Boolean.TRUE.equals(config.getWorkOrderFlag()) && ObjUtil.isNull(reqVO.getWorkOrderId())) {
+                throw exception(WM_BATCH_WORK_ORDER_REQUIRED);
             }
             // 鐢熶骇浠诲姟
-            if (Boolean.TRUE.equals(config.getTaskFlag())) {
-                if (ObjUtil.isNull(reqVO.getTaskId())) {
-                    throw exception(WM_BATCH_TASK_REQUIRED);
-                }
-                batch.setTaskId(reqVO.getTaskId());
+            if (Boolean.TRUE.equals(config.getTaskFlag()) && ObjUtil.isNull(reqVO.getTaskId())) {
+                throw exception(WM_BATCH_TASK_REQUIRED);
             }
             // 宸ヤ綔绔�
-            if (Boolean.TRUE.equals(config.getWorkstationFlag())) {
-                if (ObjUtil.isNull(reqVO.getWorkstationId())) {
-                    throw exception(WM_BATCH_WORKSTATION_REQUIRED);
-                }
-                batch.setWorkstationId(reqVO.getWorkstationId());
+            if (Boolean.TRUE.equals(config.getWorkstationFlag()) && ObjUtil.isNull(reqVO.getWorkstationId())) {
+                throw exception(WM_BATCH_WORKSTATION_REQUIRED);
             }
             // 宸ュ叿
-            if (Boolean.TRUE.equals(config.getToolFlag())) {
-                if (ObjUtil.isNull(reqVO.getToolId())) {
-                    throw exception(WM_BATCH_TOOL_REQUIRED);
-                }
-                batch.setToolId(reqVO.getToolId());
+            if (Boolean.TRUE.equals(config.getToolFlag()) && ObjUtil.isNull(reqVO.getToolId())) {
+                throw exception(WM_BATCH_TOOL_REQUIRED);
             }
             // 妯″叿
-            if (Boolean.TRUE.equals(config.getMoldFlag())) {
-                if (ObjUtil.isNull(reqVO.getMoldId())) {
-                    throw exception(WM_BATCH_MOLD_REQUIRED);
-                }
-                batch.setMoldId(reqVO.getMoldId());
+            if (Boolean.TRUE.equals(config.getMoldFlag()) && ObjUtil.isNull(reqVO.getMoldId())) {
+                throw exception(WM_BATCH_MOLD_REQUIRED);
             }
             // 鐢熶骇鎵瑰彿
-            if (Boolean.TRUE.equals(config.getLotNumberFlag())) {
-                if (ObjUtil.isNull(reqVO.getLotNumber())) {
-                    throw exception(WM_BATCH_LOT_NUMBER_REQUIRED);
-                }
-                batch.setLotNumber(reqVO.getLotNumber());
+            if (Boolean.TRUE.equals(config.getLotNumberFlag()) && ObjUtil.isNull(reqVO.getLotNumber())) {
+                throw exception(WM_BATCH_LOT_NUMBER_REQUIRED);
             }
             // 璐ㄩ噺鐘舵��
-            if (Boolean.TRUE.equals(config.getQualityStatusFlag())) {
-                if (ObjUtil.isNull(reqVO.getQualityStatus())) {
-                    throw exception(WM_BATCH_QUALITY_STATUS_REQUIRED);
-                }
-                batch.setQualityStatus(reqVO.getQualityStatus());
+            if (Boolean.TRUE.equals(config.getQualityStatusFlag()) && ObjUtil.isNull(reqVO.getQualityStatus())) {
+                throw exception(WM_BATCH_QUALITY_STATUS_REQUIRED);
             }
         }
-        // 鏃犳壒娆¢厤缃椂锛屼娇鐢ㄤ紶鍏ョ殑鍙傛暟锛堝鏉炬ā寮忥紝閫傜敤浜庤嚜瀹氫箟鍏ュ簱绛夊満鏅級
-        else {
-            if (reqVO.getProduceDate() != null) {
-                batch.setProduceDate(reqVO.getProduceDate());
-            }
-            if (reqVO.getReceiptDate() != null) {
-                batch.setReceiptDate(reqVO.getReceiptDate());
-            }
-            if (reqVO.getExpireDate() != null) {
-                batch.setExpireDate(reqVO.getExpireDate());
-            }
-            if (reqVO.getVendorId() != null) {
-                batch.setVendorId(reqVO.getVendorId());
-            }
-            if (reqVO.getClientId() != null) {
-                batch.setClientId(reqVO.getClientId());
-            }
+
+        // ========== 淇濆瓨瀛楁锛堟棤璁烘湁鏃犻厤缃紝鍙璋冪敤鏂逛紶浜嗗氨淇濆瓨锛� ==========
+        if (reqVO.getProduceDate() != null) {
+            batch.setProduceDate(reqVO.getProduceDate());
+        }
+        if (reqVO.getReceiptDate() != null) {
+            batch.setReceiptDate(reqVO.getReceiptDate());
+        }
+        if (reqVO.getExpireDate() != null) {
+            batch.setExpireDate(reqVO.getExpireDate());
+        }
+        if (reqVO.getVendorId() != null) {
+            batch.setVendorId(reqVO.getVendorId());
+        }
+        if (reqVO.getClientId() != null) {
+            batch.setClientId(reqVO.getClientId());
+        }
+        if (reqVO.getPurchaseOrderCode() != null) {
+            batch.setPurchaseOrderCode(reqVO.getPurchaseOrderCode());
+        }
+        if (reqVO.getSalesOrderCode() != null) {
+            batch.setSalesOrderCode(reqVO.getSalesOrderCode());
+        }
+        if (reqVO.getWorkOrderId() != null) {
+            batch.setWorkOrderId(reqVO.getWorkOrderId());
+        }
+        if (reqVO.getTaskId() != null) {
+            batch.setTaskId(reqVO.getTaskId());
+        }
+        if (reqVO.getWorkstationId() != null) {
+            batch.setWorkstationId(reqVO.getWorkstationId());
+        }
+        if (reqVO.getToolId() != null) {
+            batch.setToolId(reqVO.getToolId());
+        }
+        if (reqVO.getMoldId() != null) {
+            batch.setMoldId(reqVO.getMoldId());
+        }
+        if (reqVO.getLotNumber() != null) {
+            batch.setLotNumber(reqVO.getLotNumber());
+        }
+        if (reqVO.getQualityStatus() != null) {
+            batch.setQualityStatus(reqVO.getQualityStatus());
         }
 
         // 3.1 鎯呭喌涓�锛氫紶鍏ヤ簡 batchCode锛屾煡璇㈡槸鍚﹀瓨鍦ㄨ鎵规鍙�

--
Gitblit v1.9.3