From eccad5a129106377a275be4f7cdc58e99e9b95d4 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 21 七月 2026 13:45:14 +0800
Subject: [PATCH] feat(mes): 实现库存移库功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
index 8be526a..fe63450 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
@@ -43,20 +43,36 @@
 
     @Override
     public Long createItem(MesMdItemSyncReqDTO syncReqDTO) {
-        log.info("[createItem] 鍚屾鍒涘缓 MES 鐗╂枡浜у搧锛宑ode={}", syncReqDTO.getCode());
+        log.info("[createItem] 鍚屾鍒涘缓 MES 鐗╂枡浜у搧锛宑ode={}, mdmItemId={}", syncReqDTO.getCode(), syncReqDTO.getMdmItemId());
         MesMdItemSaveReqVO saveReqVO = buildSaveReqVO(syncReqDTO);
+        // 浣跨敤 MDM 鐗╂枡 ID 浣滀负 MES 鐗╂枡 ID
+        if (syncReqDTO.getMdmItemId() != null) {
+            saveReqVO.setId(syncReqDTO.getMdmItemId());
+        }
         Long itemId = itemService.createItem(saveReqVO);
         // 鍚屾鎵规閰嶇疆
-        saveBatchConfig(itemId, syncReqDTO);
+//        saveBatchConfig(itemId, syncReqDTO);
         return itemId;
     }
 
     @Override
     public void updateItem(MesMdItemSyncReqDTO syncReqDTO) {
-        log.info("[updateItem] 鍚屾鏇存柊 MES 鐗╂枡浜у搧锛宑ode={}", syncReqDTO.getCode());
+        log.info("[updateItem] 鍚屾鏇存柊 MES 鐗╂枡浜у搧锛宑ode={}, mdmItemId={}", syncReqDTO.getCode(), syncReqDTO.getMdmItemId());
         MesMdItemSaveReqVO saveReqVO = buildSaveReqVO(syncReqDTO);
-        // 鎸� code 鍖归厤锛氬瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欏垱寤猴紙upsert锛�
-        MesMdItemDO existItem = itemService.getItemByCode(syncReqDTO.getCode());
+        // 浣跨敤 MDM 鐗╂枡 ID 浣滀负 MES 鐗╂枡 ID
+        if (syncReqDTO.getMdmItemId() != null) {
+            saveReqVO.setId(syncReqDTO.getMdmItemId());
+        }
+        // 鎸� ID 鎴� code 鍖归厤锛氬瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欏垱寤猴紙upsert锛�
+        MesMdItemDO existItem = null;
+        // 浼樺厛鎸� ID 鏌ユ壘
+        if (syncReqDTO.getMdmItemId() != null) {
+            existItem = itemService.getItem(syncReqDTO.getMdmItemId());
+        }
+        // 濡傛灉鎸� ID 鎵句笉鍒帮紝鍐嶆寜 code 鏌ユ壘
+        if (existItem == null) {
+            existItem = itemService.getItemByCode(syncReqDTO.getCode());
+        }
         Long itemId;
         if (existItem == null) {
             itemId = itemService.createItem(saveReqVO);
@@ -66,7 +82,7 @@
             itemId = existItem.getId();
         }
         // 鍚屾鎵规閰嶇疆
-        saveBatchConfig(itemId, syncReqDTO);
+//        saveBatchConfig(itemId, syncReqDTO);
     }
 
     /**

--
Gitblit v1.9.3