From abf1c0a35d85d38239ff5d2ed746a4e4b797c9d1 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 20 八月 2026 14:05:02 +0800
Subject: [PATCH] feat 功能修正

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java |   66 ++++++++++++++++++++++++++++++--
 1 files changed, 61 insertions(+), 5 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 8ff44ef..abc6f59 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
@@ -1,12 +1,15 @@
 package cn.iocoder.yudao.module.mes.api.item;
 
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSafetyStockRespDTO;
 import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSyncReqDTO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.MesMdItemSaveReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig.MesMdItemBatchConfigSaveReqVO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
+import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemMapper;
 import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemBatchConfigService;
 import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
 import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemTypeService;
@@ -15,6 +18,10 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
@@ -25,7 +32,7 @@
  * 渚� MDM 绛夋ā鍧楀悓姝ョ墿鏂欎富鏁版嵁鍒� MES 浣跨敤銆�
  * 鍗曚綅銆佸垎绫绘寜 code 鍦� MES 渚цВ鏋愪负瀵瑰簲 id銆�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -35,6 +42,8 @@
     @Resource
     private MesMdItemService itemService;
     @Resource
+    private MesMdItemMapper itemMapper;
+    @Resource
     private MesMdItemTypeService itemTypeService;
     @Resource
     private MesMdUnitMeasureService unitMeasureService;
@@ -43,8 +52,12 @@
 
     @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);
@@ -53,10 +66,22 @@
 
     @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);
@@ -90,6 +115,37 @@
         return saveReqVO;
     }
 
+    @Override
+    public void deleteItem(Long mdmItemId) {
+        log.info("[deleteItem] 鍚屾鍒犻櫎 MES 鐗╂枡浜у搧锛宮dmItemId={}", mdmItemId);
+        MesMdItemDO existItem = itemService.getItemByMdmItemId(mdmItemId);
+        if (existItem != null) {
+            itemService.deleteItem(existItem.getId());
+        }
+    }
+
+    @Override
+    public void updateItemStatus(Long mdmItemId, Integer status) {
+        log.info("[updateItemStatus] 鍚屾鏇存柊 MES 鐗╂枡浜у搧鐘舵�侊紝mdmItemId={}, status={}", mdmItemId, status);
+        MesMdItemDO existItem = itemService.getItemByMdmItemId(mdmItemId);
+        if (existItem != null) {
+            itemService.updateItemStatus(existItem.getId(), status);
+        }
+    }
+
+    @Override
+    public Set<Long> getSyncedMdmItemIds(Collection<Long> mdmItemIds) {
+        return itemMapper.selectMdmItemIdsByMdmItemIds(mdmItemIds);
+    }
+
+    @Override
+    public List<MesMdItemSafetyStockRespDTO> getSafetyStockItemList() {
+        List<MesMdItemDO> items = itemMapper.selectList(new LambdaQueryWrapperX<MesMdItemDO>()
+                .eq(MesMdItemDO::getSafeStockFlag, true)
+                .isNotNull(MesMdItemDO::getMinStock));
+        return BeanUtils.toBean(items, MesMdItemSafetyStockRespDTO.class);
+    }
+
     /**
      * 淇濆瓨鎵规閰嶇疆
      */

--
Gitblit v1.9.3