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-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
index 9b32fc6..5acea4b 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
@@ -2,8 +2,10 @@
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
 import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
@@ -15,8 +17,12 @@
 import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService;
 import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService;
 import cn.iocoder.yudao.module.mes.api.item.MesMdItemApi;
+import cn.iocoder.yudao.module.mes.api.item.MesMdItemTypeApi;
 import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSyncReqDTO;
+import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemTypeRespDTO;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import jakarta.annotation.Resource;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -54,6 +60,10 @@
     @Resource
     private MdmItemBatchConfigMapper itemBatchConfigMapper;
 
+    @Resource
+    private MesMdItemTypeApi mesMdItemTypeApi;
+
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Long createItem(MdmItemSaveReqVO createReqVO) {
@@ -68,6 +78,7 @@
         saveBatchConfig(item.getId(), createReqVO);
 
         // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
+        createReqVO.setId(item.getId());
         if (Boolean.TRUE.equals(createReqVO.getSyncMes())) {
             syncItemToMes(createReqVO);
         }
@@ -120,25 +131,13 @@
         // 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MDM 鏈湴鍒嗙被鏈嶅姟锛�
         String itemTypeCode = null;
         if (reqVO.getCategoryId() != null) {
-            MdmItemCategoryDO category = itemCategoryService.getItemCategory(reqVO.getCategoryId());
-            if (category != null) {
-                itemTypeCode = category.getCode();
-            }
-        } else if (reqVO.getItemType() != null) {
-            // 鏍规嵁 itemType 鏌ユ壘瀵瑰簲鍒嗙被缂栫爜
-            // itemType: 1鍘熸枡, 2鍗婃垚鍝�, 3鎴愬搧, 4杈呮枡
-            String itemTypeName = convertItemTypeToName(reqVO.getItemType());
-            List<MdmItemCategoryDO> categories = itemCategoryService.getItemCategoryList(
-                    itemCategoryService.getItemCategoryChildrenList(null).stream().map(MdmItemCategoryDO::getId).collect(Collectors.toSet()));
-            itemTypeCode = categories.stream()
-                    .filter(c -> c.getName() != null && c.getName().equals(itemTypeName))
-                    .findFirst()
-                    .map(MdmItemCategoryDO::getCode)
-                    .orElse(null);
+            CommonResult<MesMdItemTypeRespDTO> itemType = mesMdItemTypeApi.getItemType(reqVO.getCategoryId());
+            itemTypeCode = itemType.getData().getCode();
         }
         // 缁勮鍚屾 DTO
         MesMdItemSyncReqDTO syncReqDTO = new MesMdItemSyncReqDTO();
         syncReqDTO.setCode(reqVO.getCode());
+        syncReqDTO.setMdmItemId(reqVO.getId());
         syncReqDTO.setName(reqVO.getName());
         syncReqDTO.setSpecification(reqVO.getSpecification());
         syncReqDTO.setUnitCode(unitCode);
@@ -179,15 +178,25 @@
         // 鏍¢獙瀛樺湪
         MdmItemDO item = validateItemExists(id);
         // 瑙e喅杞垹闄ゅ敮涓�閿啿绐侊細濡傛灉宸插瓨鍦ㄧ浉鍚� code 涓斿凡杞垹闄ょ殑璁板綍锛屽厛鐗╃悊鍒犻櫎瀹�
-        MdmItemDO existingDeleted = itemMapper.selectByCodeAndDeleted(item.getCode(), true);
-        if (existingDeleted != null && !existingDeleted.getId().equals(id)) {
-            itemMapper.physicalDeleteById(existingDeleted.getId());
-        }
+//        MdmItemDO existingDeleted = itemMapper.selectByCodeAndDeleted(item.getCode(), true);
+//        if (existingDeleted != null && !existingDeleted.getId().equals(id)) {
+//            itemMapper.physicalDeleteById(existingDeleted.getId());
+//        }
         // 杞垹闄ゅ綋鍓嶈褰�
         itemMapper.deleteById(id);
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteItemList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return;
+        }
+        // 閫愪釜鍒犻櫎锛堝鐢ㄥ崟鏉″垹闄ら�昏緫锛屼繚鎸佹牎楠岋級
+        ids.forEach(this::deleteItem);
+    }
+
+    @Override
     public MdmItemDO validateItemExists(Long id) {
         MdmItemDO item = itemMapper.selectById(id);
         if (item == null) {

--
Gitblit v1.9.3