From 5af23a1b205787b50abdfbb3835619efa3911d60 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 21 八月 2026 13:36:51 +0800
Subject: [PATCH] Merge branch 'dev_business' of http://114.132.189.42:9002/r/mom-pro2-after into dev_business

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java |   74 ++++++++++++++++++++++++++++++------
 1 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java
index 1e51193..97e1853 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java
@@ -3,31 +3,39 @@
 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.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemImportExcelVO;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemImportRespVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemRespVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemStatusUpdateReqVO;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSyncUpdateReqVO;
 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.dataobject.warehouse.MdmWarehouseDO;
 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.item.MdmItemBatchConfigService;
 import cn.iocoder.yudao.module.mdm.service.item.MdmItemService;
 import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService;
-import cn.iocoder.yudao.module.mdm.service.warehouse.MdmWarehouseService;
 import cn.iocoder.yudao.module.mes.api.item.MesMdItemApi;
+import cn.iocoder.yudao.module.mes.api.wm.warehouse.MesWmWarehouseApi;
+import cn.iocoder.yudao.module.mes.api.wm.warehouse.dto.MesWmWarehouseRespDTO;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.Valid;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -51,7 +59,7 @@
     @Resource
     private MdmUnitMeasureService unitMeasureService;
     @Resource
-    private MdmWarehouseService warehouseService;
+    private MesWmWarehouseApi mesWmWarehouseApi;
     @Resource
     private MdmBrandService brandService;
     @Resource
@@ -77,6 +85,14 @@
     @PreAuthorize("@ss.hasPermission('mdm:item:update')")
     public CommonResult<Boolean> updateItemStatus(@RequestBody MdmItemStatusUpdateReqVO reqVO) {
         itemService.updateItemStatus(reqVO.getId(), reqVO.getStatus());
+        return success(true);
+    }
+
+    @PutMapping("/update-sync")
+    @Operation(summary = "鏇存柊鐗╂枡鍚屾鐘舵��")
+    @PreAuthorize("@ss.hasPermission('mdm:item:update')")
+    public CommonResult<Boolean> updateItemSync(@Valid @RequestBody MdmItemSyncUpdateReqVO reqVO) {
+        itemService.updateItemSync(reqVO.getId(), reqVO.getSync());
         return success(true);
     }
 
@@ -139,14 +155,14 @@
         });
         Map<Long, MdmUnitMeasureDO> auxUnitMap = unitIds.isEmpty() ?
                 Collections.emptyMap() : unitMeasureService.getUnitMeasureMap(unitIds);
-        // 鎵归噺鍏宠仈鏌ヨ浠撳簱鍚嶇О
+        // 鎵归噺鍏宠仈鏌ヨ浠撳簱鍚嶇О锛堜娇鐢� MES 浠撳簱锛�
         Set<Long> warehouseIds = new HashSet<>();
         respList.forEach(resp -> {
             if (resp.getWarehouseId() != null) warehouseIds.add(resp.getWarehouseId());
         });
-        Map<Long, MdmWarehouseDO> warehouseMap = warehouseIds.isEmpty() ?
-                Collections.emptyMap() : warehouseService.getWarehouseList(warehouseIds).stream()
-                        .collect(Collectors.toMap(MdmWarehouseDO::getId, w -> w));
+        Map<Long, MesWmWarehouseRespDTO> warehouseMap = warehouseIds.isEmpty() ?
+                Collections.emptyMap() : mesWmWarehouseApi.getWarehouseList(warehouseIds).stream()
+                        .collect(Collectors.toMap(MesWmWarehouseRespDTO::getId, w -> w));
         // 璧嬪��
         respList.forEach(resp -> {
             // 鍒嗙被鍚嶇О
@@ -166,7 +182,7 @@
             if (auxUnit2 != null) {
                 resp.setUnitMeasureName3(auxUnit2.getName());
             }
-            MdmWarehouseDO warehouse = warehouseMap.get(resp.getWarehouseId());
+            MesWmWarehouseRespDTO warehouse = warehouseMap.get(resp.getWarehouseId());
             if (warehouse != null) {
                 resp.setWarehouseName(warehouse.getName());
             }
@@ -189,7 +205,17 @@
     @Operation(summary = "鑾峰彇鐗╂枡绮剧畝鍒楄〃锛堝惎鐢ㄧ姸鎬侊紝鐢ㄤ簬涓嬫媺閫夋嫨锛�")
     public CommonResult<List<MdmItemRespVO>> getItemSimpleList() {
         List<MdmItemDO> list = itemService.getItemSimpleList();
-        return success(BeanUtils.toBean(list, MdmItemRespVO.class));
+        List<MdmItemRespVO> respList = BeanUtils.toBean(list, MdmItemRespVO.class);
+        // 濉厖鍗曚綅鍚嶇О绛夊叧鑱斿瓧娈碉紝纭繚涓嬫媺閫夋嫨鍚庡彲甯﹀嚭鍗曚綅绛変俊鎭�
+        Map<Long, MdmUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap(
+                convertSet(respList, MdmItemRespVO::getUnitMeasureId));
+        respList.forEach(resp -> {
+            MdmUnitMeasureDO unit = unitMap.get(resp.getUnitMeasureId());
+            if (unit != null) {
+                resp.setUnitMeasureName(unit.getName());
+            }
+        });
+        return success(respList);
     }
 
     /**
@@ -224,11 +250,11 @@
                 resp.setUnitMeasureName3(unit3.getName());
             }
         }
-        // 榛樿浠撳簱鍚嶇О
+        // 榛樿浠撳簱鍚嶇О锛堜娇鐢� MES 浠撳簱锛�
         if (resp.getWarehouseId() != null) {
-            MdmWarehouseDO warehouse = warehouseService.getWarehouse(resp.getWarehouseId());
-            if (warehouse != null) {
-                resp.setWarehouseName(warehouse.getName());
+            List<MesWmWarehouseRespDTO> warehouses = mesWmWarehouseApi.getWarehouseList(List.of(resp.getWarehouseId()));
+            if (!warehouses.isEmpty()) {
+                resp.setWarehouseName(warehouses.get(0).getName());
             }
         }
     }
@@ -249,4 +275,26 @@
         }
     }
 
+    @GetMapping("/get-import-template")
+    @Operation(summary = "鑾峰緱瀵煎叆鐗╂枡妯℃澘")
+    public void importTemplate(HttpServletResponse response) throws IOException {
+        List<MdmItemImportExcelVO> list = Arrays.asList(
+                MdmItemImportExcelVO.builder().code("ITEM001").name("绀轰緥鐗╂枡").specification("瑙勬牸").status(0).isBatchManaged(false).build()
+        );
+        ExcelUtils.write(response, "鐗╂枡瀵煎叆妯℃澘.xls", "鐗╂枡", MdmItemImportExcelVO.class, list);
+    }
+
+    @PostMapping("/import")
+    @Operation(summary = "瀵煎叆鐗╂枡")
+    @Parameters({
+            @Parameter(name = "file", description = "Excel 鏂囦欢", required = true),
+            @Parameter(name = "updateSupport", description = "鏄惁鏀寔鏇存柊锛岄粯璁や负 false", example = "true")
+    })
+    @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+    public CommonResult<MdmItemImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
+                                                         @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
+        List<MdmItemImportExcelVO> list = ExcelUtils.read(file, MdmItemImportExcelVO.class);
+        return success(itemService.importItemList(list, updateSupport));
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3