From 111270df037596a04df97f787ca8b9199dd99866 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 20 七月 2026 17:28:31 +0800
Subject: [PATCH] feat(crm): 增加商机客户团队权限校验功能

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java |  109 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 90 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 5188ab8..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
@@ -5,11 +5,13 @@
 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.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;
@@ -18,12 +20,16 @@
 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;
 import org.springframework.validation.annotation.Validated;
 
 import java.util.*;
+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;
@@ -49,9 +55,14 @@
     private MdmBrandService brandService;
 
     @Resource
+    @Lazy
     private MesMdItemApi mesMdItemApi;
     @Resource
+    private MdmItemBatchConfigMapper itemBatchConfigMapper;
+
+    @Resource
     private MesMdItemTypeApi mesMdItemTypeApi;
+
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -63,7 +74,11 @@
         MdmItemDO item = BeanUtils.toBean(createReqVO, MdmItemDO.class);
         itemMapper.insert(item);
 
+        // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
+        saveBatchConfig(item.getId(), createReqVO);
+
         // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
+        createReqVO.setId(item.getId());
         if (Boolean.TRUE.equals(createReqVO.getSyncMes())) {
             syncItemToMes(createReqVO);
         }
@@ -81,6 +96,9 @@
         // 鏇存柊 MDM 鐗╂枡
         MdmItemDO updateObj = BeanUtils.toBean(updateReqVO, MdmItemDO.class);
         itemMapper.updateById(updateObj);
+
+        // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
+        saveBatchConfig(updateReqVO.getId(), updateReqVO);
 
         // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
         if (Boolean.TRUE.equals(updateReqVO.getSyncMes())) {
@@ -110,29 +128,16 @@
             }
             unitCode = unitMeasure.getCode();
         }
-        // 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MES 鐗╂枡鍒嗙被 API锛�
+        // 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MDM 鏈湴鍒嗙被鏈嶅姟锛�
         String itemTypeCode = null;
         if (reqVO.getCategoryId() != null) {
-            CommonResult<MesMdItemTypeRespDTO> result = mesMdItemTypeApi.getItemType(reqVO.getCategoryId());
-            if (result != null && result.isSuccess() && result.getData() != null) {
-                itemTypeCode = result.getData().getCode();
-            }
-        } else if (reqVO.getItemType() != null) {
-            // 鏍规嵁 itemType 鏌ユ壘瀵瑰簲鍒嗙被缂栫爜
-            // itemType: 1鍘熸枡, 2鍗婃垚鍝�, 3鎴愬搧, 4杈呮枡
-            String itemTypeName = convertItemTypeToName(reqVO.getItemType());
-            CommonResult<List<MesMdItemTypeRespDTO>> listResult = mesMdItemTypeApi.getItemTypeList(null);
-            if (listResult != null && listResult.isSuccess() && listResult.getData() != null) {
-                itemTypeCode = listResult.getData().stream()
-                        .filter(c -> c.getName() != null && c.getName().equals(itemTypeName))
-                        .findFirst()
-                        .map(MesMdItemTypeRespDTO::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);
@@ -143,6 +148,14 @@
         syncReqDTO.setHighValue(reqVO.getIsHighValue());
         syncReqDTO.setBatchFlag(reqVO.getIsBatchManaged());
         syncReqDTO.setRemark(reqVO.getRemark());
+        // 鎵规閰嶇疆瀛楁
+        syncReqDTO.setProduceDateFlag(reqVO.getProduceDateFlag());
+        syncReqDTO.setExpireDateFlag(reqVO.getExpireDateFlag());
+        syncReqDTO.setReceiptDateFlag(reqVO.getReceiptDateFlag());
+        syncReqDTO.setVendorFlag(reqVO.getVendorFlag());
+        syncReqDTO.setPurchaseOrderCodeFlag(reqVO.getPurchaseOrderCodeFlag());
+        syncReqDTO.setLotNumberFlag(reqVO.getLotNumberFlag());
+        syncReqDTO.setQualityStatusFlag(reqVO.getQualityStatusFlag());
         // create 璧� createItem锛寀pdate 璧� updateItem锛圡ES 渚ф寜 code upsert锛�
         if (reqVO.getId() == null) {
             mesMdItemApi.createItem(syncReqDTO);
@@ -171,6 +184,16 @@
 //        }
         // 杞垹闄ゅ綋鍓嶈褰�
         itemMapper.deleteById(id);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteItemList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return;
+        }
+        // 閫愪釜鍒犻櫎锛堝鐢ㄥ崟鏉″垹闄ら�昏緫锛屼繚鎸佹牎楠岋級
+        ids.forEach(this::deleteItem);
     }
 
     @Override
@@ -205,8 +228,9 @@
         if (categoryId == null) {
             return;
         }
-        CommonResult<MesMdItemTypeRespDTO> result = mesMdItemTypeApi.getItemType(categoryId);
-        if (result == null || !result.isSuccess() || result.getData() == null) {
+        // 浣跨敤 MDM 鏈湴鍒嗙被鏈嶅姟鏍¢獙
+        MdmItemCategoryDO category = itemCategoryService.getItemCategory(categoryId);
+        if (category == null) {
             throw exception(MDM_ITEM_CATEGORY_NOT_EXISTS);
         }
     }
@@ -295,4 +319,51 @@
         return itemMapper.selectByCode(code);
     }
 
+    /**
+     * 淇濆瓨鎵规閰嶇疆锛堝埌 MDM 鏈湴琛級
+     */
+    private void saveBatchConfig(Long itemId, MdmItemSaveReqVO reqVO) {
+        // 妫�鏌ユ槸鍚︽湁鎵规閰嶇疆鏁版嵁
+        if (reqVO.getProduceDateFlag() == null
+                && reqVO.getExpireDateFlag() == null
+                && reqVO.getReceiptDateFlag() == null
+                && reqVO.getVendorFlag() == null
+                && reqVO.getPurchaseOrderCodeFlag() == null
+                && reqVO.getLotNumberFlag() == null
+                && reqVO.getQualityStatusFlag() == null) {
+            return;
+        }
+
+        // 鏌ヨ宸叉湁閰嶇疆
+        cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO existing =
+                itemBatchConfigMapper.selectOne(
+                        cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO::getItemId, itemId);
+
+        cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO config =
+                new cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO();
+        config.setItemId(itemId);
+        config.setProduceDateFlag(Boolean.TRUE.equals(reqVO.getProduceDateFlag()));
+        config.setExpireDateFlag(Boolean.TRUE.equals(reqVO.getExpireDateFlag()));
+        config.setReceiptDateFlag(Boolean.TRUE.equals(reqVO.getReceiptDateFlag()));
+        config.setVendorFlag(Boolean.TRUE.equals(reqVO.getVendorFlag()));
+        config.setPurchaseOrderCodeFlag(Boolean.TRUE.equals(reqVO.getPurchaseOrderCodeFlag()));
+        config.setLotNumberFlag(Boolean.TRUE.equals(reqVO.getLotNumberFlag()));
+        config.setQualityStatusFlag(Boolean.TRUE.equals(reqVO.getQualityStatusFlag()));
+        // 娓呯┖涓嶉渶瑕佺殑瀛楁
+        config.setClientFlag(false);
+        config.setSalesOrderCodeFlag(false);
+        config.setWorkOrderFlag(false);
+        config.setTaskFlag(false);
+        config.setWorkstationFlag(false);
+        config.setToolFlag(false);
+        config.setMoldFlag(false);
+
+        if (existing != null) {
+            config.setId(existing.getId());
+            itemBatchConfigMapper.updateById(config);
+        } else {
+            itemBatchConfigMapper.insert(config);
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3