From f4a412cebe9532833320bad81cc92e7930d7715a Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 03 九月 2026 17:27:06 +0800
Subject: [PATCH] feat(mes): 优化MES模块功能与配置

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java |   77 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 73 insertions(+), 4 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 664126c..4495e23 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
@@ -1,8 +1,14 @@
 package cn.iocoder.yudao.module.mdm.controller.admin.item;
 
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
 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.MdmItemExcelVO;
+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;
@@ -12,6 +18,7 @@
 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.enums.MdmItemTypeEnum;
 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;
@@ -22,16 +29,21 @@
 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;
 
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@@ -129,14 +141,48 @@
     @PreAuthorize("@ss.hasPermission('mdm:item:query')")
     public CommonResult<PageResult<MdmItemRespVO>> getItemPage(@Valid MdmItemPageReqVO pageReqVO) {
         PageResult<MdmItemDO> pageResult = itemService.getItemPage(pageReqVO);
+        // 杞崲骞惰ˉ榻愬叧鑱斿悕绉�
+        List<MdmItemRespVO> respList = convertAndEnrichItemList(pageResult.getList());
+        return success(new PageResult<>(respList, pageResult.getTotal()));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "瀵煎嚭鐗╂枡 Excel")
+    @PreAuthorize("@ss.hasPermission('mdm:item:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportItemExcel(@Valid MdmItemPageReqVO pageReqVO,
+                                HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        // 澶嶇敤鍒嗛〉鏌ヨ鐨勮繃婊や笌鍏宠仈濉厖閫昏緫锛屼繚璇佸鍑烘暟鎹笌鍒楄〃涓�鑷�
+        List<MdmItemRespVO> respList = convertAndEnrichItemList(itemService.getItemPage(pageReqVO).getList());
+        List<MdmItemExcelVO> excelList = new ArrayList<>();
+        for (MdmItemRespVO resp : respList) {
+            MdmItemExcelVO excelVO = BeanUtils.toBean(resp, MdmItemExcelVO.class);
+            MdmItemTypeEnum itemType = MdmItemTypeEnum.fromType(resp.getItemType());
+            excelVO.setItemTypeName(itemType != null ? itemType.getName() : null);
+            excelList.add(excelVO);
+        }
+        // 瀵煎嚭 Excel
+        ExcelUtils.write(response, "鐗╂枡鏁版嵁.xls", "鐗╂枡", MdmItemExcelVO.class, excelList);
+    }
+
+    /**
+     * 灏嗙墿鏂� DO 鍒楄〃杞崲涓哄凡琛ラ綈鍏宠仈鍚嶇О锛堝垎绫汇�佷富/杈呰閲忓崟浣嶃�侀粯璁や粨搴擄級鍙婂悓姝ョ姸鎬佺殑 RespVO 鍒楄〃
+     *
+     * 鍒嗛〉鏌ヨ涓� Excel 瀵煎嚭鍏辩敤锛屼繚璇佸鍑哄唴瀹逛笌鍒楄〃灞曠ず涓�鑷�
+     */
+    private List<MdmItemRespVO> convertAndEnrichItemList(List<MdmItemDO> itemList) {
+        if (itemList == null || itemList.isEmpty()) {
+            return Collections.emptyList();
+        }
         // 鍏宠仈鏌ヨ鍒嗙被鍚嶇О
         Map<Long, MdmItemCategoryDO> categoryMap = itemCategoryService.getItemCategoryMap(
-                convertSet(pageResult.getList(), MdmItemDO::getCategoryId));
+                convertSet(itemList, MdmItemDO::getCategoryId));
         // 鍏宠仈鏌ヨ璁¢噺鍗曚綅鍚嶇О
         Map<Long, MdmUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap(
-                convertSet(pageResult.getList(), MdmItemDO::getUnitMeasureId));
+                convertSet(itemList, MdmItemDO::getUnitMeasureId));
         // 杞崲
-        List<MdmItemRespVO> respList = BeanUtils.toBean(pageResult.getList(), MdmItemRespVO.class);
+        List<MdmItemRespVO> respList = BeanUtils.toBean(itemList, MdmItemRespVO.class);
         // 鎵归噺鏌ヨ鍚屾鐘舵��
         Set<Long> allIds = convertSet(respList, MdmItemRespVO::getId);
         Set<Long> syncedIds = mesMdItemApi.getSyncedMdmItemIds(allIds);
@@ -182,7 +228,7 @@
             // 鍚屾鐘舵��
             resp.setSyncedMes(syncedIds.contains(resp.getId()));
         });
-        return success(new PageResult<>(respList, pageResult.getTotal()));
+        return respList;
     }
 
     @GetMapping("/list-by-ids")
@@ -268,4 +314,27 @@
         }
     }
 
+    @GetMapping("/get-import-template")
+    @Operation(summary = "鑾峰緱瀵煎叆鐗╂枡妯℃澘")
+    @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+    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