From f7273277023f3497ac071bf98f556a569cb4dd25 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 17 九月 2026 16:24:10 +0800
Subject: [PATCH] feat(mes): 重构袋码生成与物料分类功能

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java |  103 ++++++++++++++++++++++++++-------------------------
 1 files changed, 52 insertions(+), 51 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 14990a0..3176e2f 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,27 +2,20 @@
 
 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;
+import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO;
 import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemDO;
 import cn.iocoder.yudao.module.mdm.dal.dataobject.unit.MdmUnitMeasureDO;
 import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemBatchConfigMapper;
 import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemMapper;
 import cn.iocoder.yudao.module.mdm.service.brand.MdmBrandService;
-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;
@@ -32,13 +25,12 @@
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.iocoder.yudao.module.mdm.enums.ErrorCodeConstants.*;
 
 /**
  * MDM 鐗╂枡涓绘暟鎹� Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -47,8 +39,6 @@
     @Resource
     private MdmItemMapper itemMapper;
 
-    @Resource
-    private MdmItemCategoryService itemCategoryService;
     @Resource
     private MdmUnitMeasureService unitMeasureService;
     @Resource
@@ -59,9 +49,6 @@
     private MesMdItemApi mesMdItemApi;
     @Resource
     private MdmItemBatchConfigMapper itemBatchConfigMapper;
-
-    @Resource
-    private MesMdItemTypeApi mesMdItemTypeApi;
 
 
     @Override
@@ -77,9 +64,11 @@
         // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
         saveBatchConfig(item.getId(), createReqVO);
 
-        // 濮嬬粓鍚屾鍒� MES
-        createReqVO.setId(item.getId());
-        syncItemToMes(createReqVO);
+        // 鍕鹃�夊悓姝ユ椂锛屽悓姝ュ埌 MES
+        if (Boolean.TRUE.equals(createReqVO.getSyncMes())) {
+            createReqVO.setId(item.getId());
+            syncItemToMes(createReqVO);
+        }
         return item.getId();
     }
 
@@ -98,8 +87,12 @@
         // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
         saveBatchConfig(updateReqVO.getId(), updateReqVO);
 
-        // 濮嬬粓鍚屾鍒� MES
-        syncItemToMes(updateReqVO);
+        // 鏍规嵁鍚屾寮�鍏冲喅瀹氾細鎵撳紑鍒欏悓姝ュ埌 MES锛屽叧闂垯鍙栨秷鍚屾锛堜粠 MES 鍒犻櫎锛�
+        if (Boolean.TRUE.equals(updateReqVO.getSyncMes())) {
+            syncItemToMes(updateReqVO);
+        } else {
+            mesMdItemApi.deleteItem(updateReqVO.getId());
+        }
     }
 
     private void validateItemSaveData(MdmItemSaveReqVO reqVO) {
@@ -108,10 +101,9 @@
     }
 
     /**
-     * 鍚屾鐗╂枡鍒� MES锛堝崟浣�/鍒嗙被鎸� code 鏄犲皠锛�
+     * 鍚屾鐗╂枡鍒� MES锛堝崟浣嶆寜 code 鏄犲皠锛�
      *
-     * MDM 鐨� unitMeasureId/categoryId 涓� MES 鐨� unitMeasureId/itemTypeId 鍒嗗睘涓ゅ涓绘暟鎹紝
-     * 杩欓噷鍏堝湪 MDM 渚цВ鏋愬嚭 code锛屽啀浜ょ敱 MesMdItemApi 鍦� MES 渚цВ鏋愪负瀵瑰簲 id銆�
+     * 鍝佺绠$悊宸插幓鎺夈�屽搧绉嶅垎绫汇�嶅瓧娈碉紝鍚屾涓嶅啀浼犻�� MES 鐗╂枡鍒嗙被锛坕tem_type_id 鐣欑┖锛屽彲鍦� MES 渚цˉ濉級銆�
      * 鍚屾澶辫触灏嗘姏鍑哄紓甯革紝瑙﹀彂澶栧眰 @Transactional 鏁翠綋鍥炴粴锛圡DM 鎿嶄綔涓�骞跺洖婊氾級銆�
      */
     private void syncItemToMes(MdmItemSaveReqVO reqVO) {
@@ -124,12 +116,6 @@
             }
             unitCode = unitMeasure.getCode();
         }
-        // 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MDM 鏈湴鍒嗙被鏈嶅姟锛�
-        String itemTypeCode = null;
-        if (reqVO.getCategoryId() != null) {
-            CommonResult<MesMdItemTypeRespDTO> itemType = mesMdItemTypeApi.getItemType(reqVO.getCategoryId());
-            itemTypeCode = itemType.getData().getCode();
-        }
         // 缁勮鍚屾 DTO
         MesMdItemSyncReqDTO syncReqDTO = new MesMdItemSyncReqDTO();
         syncReqDTO.setCode(reqVO.getCode());
@@ -137,12 +123,12 @@
         syncReqDTO.setName(reqVO.getName());
         syncReqDTO.setSpecification(reqVO.getSpecification());
         syncReqDTO.setUnitCode(unitCode);
-        syncReqDTO.setItemTypeCode(itemTypeCode);
         syncReqDTO.setSafeStockFlag(Boolean.TRUE); // 淇濈暀 MDM 鐨� minStock/maxStock锛岄伩鍏嶈 MES 娓呴浂
         syncReqDTO.setMinStock(reqVO.getMinStock());
         syncReqDTO.setMaxStock(reqVO.getMaxStock());
         syncReqDTO.setHighValue(reqVO.getIsHighValue());
         syncReqDTO.setBatchFlag(reqVO.getIsBatchManaged());
+        syncReqDTO.setStatus(reqVO.getStatus());
         syncReqDTO.setRemark(reqVO.getRemark());
         // 鎵规閰嶇疆瀛楁
         syncReqDTO.setProduceDateFlag(reqVO.getProduceDateFlag());
@@ -182,6 +168,35 @@
         itemMapper.deleteById(id);
         // 鍚屾鍒犻櫎鍒� MES
         mesMdItemApi.deleteItem(id);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateItemSync(Long id, Boolean sync) {
+        // 鏍¢獙瀛樺湪
+        MdmItemDO item = validateItemExists(id);
+        if (Boolean.TRUE.equals(sync)) {
+            // 鍚屾鍒� MES锛氫粠 DB 璇诲彇瀹屾暣鐗╂枡鏁版嵁缁勮鍚庤蛋 syncItemToMes
+            MdmItemSaveReqVO reqVO = BeanUtils.toBean(item, MdmItemSaveReqVO.class);
+            // DO 瀛楁鍚嶄负 highValue锛屼笌 VO 鐨� isHighValue 涓嶈嚜鍔ㄥ尮閰嶏紝鎵嬪姩琛ラ綈
+            reqVO.setIsHighValue(item.getHighValue());
+            // 琛ラ綈鎵规灞炴�ч厤缃�
+            MdmItemBatchConfigDO config = itemBatchConfigMapper.selectOne(
+                    MdmItemBatchConfigDO::getItemId, id);
+            if (config != null) {
+                reqVO.setProduceDateFlag(config.getProduceDateFlag());
+                reqVO.setExpireDateFlag(config.getExpireDateFlag());
+                reqVO.setReceiptDateFlag(config.getReceiptDateFlag());
+                reqVO.setVendorFlag(config.getVendorFlag());
+                reqVO.setPurchaseOrderCodeFlag(config.getPurchaseOrderCodeFlag());
+                reqVO.setLotNumberFlag(config.getLotNumberFlag());
+                reqVO.setQualityStatusFlag(config.getQualityStatusFlag());
+            }
+            syncItemToMes(reqVO);
+        } else {
+            // 鍙栨秷鍚屾锛氫粠 MES 鍒犻櫎璇ョ墿鏂欙紙MES 鏃犳鐗╂枡鏃跺唴閮ㄤ负绌烘搷浣滐級
+            mesMdItemApi.deleteItem(id);
+        }
     }
 
     /**
@@ -237,17 +252,6 @@
         }
     }
 
-    private void validateCategoryExists(Long categoryId) {
-        if (categoryId == null) {
-            return;
-        }
-        // 浣跨敤 MDM 鏈湴鍒嗙被鏈嶅姟鏍¢獙
-        MdmItemCategoryDO category = itemCategoryService.getItemCategory(categoryId);
-        if (category == null) {
-            throw exception(MDM_ITEM_CATEGORY_NOT_EXISTS);
-        }
-    }
-
     private void validateUnitMeasureExists(Long unitMeasureId) {
         if (unitMeasureService.getUnitMeasure(unitMeasureId) == null) {
             throw exception(MDM_UNIT_MEASURE_NOT_EXISTS);
@@ -291,17 +295,8 @@
 
     @Override
     public PageResult<MdmItemDO> getItemPage(MdmItemPageReqVO pageReqVO) {
-        // 鏌ユ壘鏃讹紝濡傛灉鏌ユ壘鏌愪釜鍒嗙被缂栧彿锛屽垯鍖呭惈瀹冪殑瀛愬垎绫�
-        Set<Long> categoryIds = null;
-        if (pageReqVO.getCategoryId() != null) {
-            categoryIds = new HashSet<>();
-            categoryIds.add(pageReqVO.getCategoryId());
-            List<cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO> children =
-                    itemCategoryService.getItemCategoryChildrenList(pageReqVO.getCategoryId());
-            categoryIds.addAll(convertSet(children, cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO::getId));
-        }
         // 鍒嗛〉鏌ヨ
-        return itemMapper.selectPage(pageReqVO, categoryIds);
+        return itemMapper.selectPage(pageReqVO, (Collection<Long>) null);
     }
 
     @Override
@@ -332,6 +327,12 @@
         return itemMapper.selectByCode(code);
     }
 
+    @Override
+    public List<MdmItemDO> getItemSimpleList() {
+        return itemMapper.selectList(MdmItemDO::getStatus,
+                cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE.getStatus());
+    }
+
     /**
      * 淇濆瓨鎵规閰嶇疆锛堝埌 MDM 鏈湴琛級
      */

--
Gitblit v1.9.3