From 1fb5fc73e8df33b25337ab34f669ab03e0d9ce06 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期三, 02 九月 2026 17:18:43 +0800
Subject: [PATCH] feat(mdm/mes): 基础数据物料管理/物料分类/计量单位支持Excel导出

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/MdmUnitMeasureController.java        |   36 ++++++
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemTypeController.java      |   55 +++++++++
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/vo/MdmItemExcelVO.java               |   89 ++++++++++++++
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java                       |   14 +-
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/type/MesMdItemTypeExcelVO.java |   38 ++++++
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/vo/MdmUnitMeasureExcelVO.java        |   41 ++++++
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java               |   48 +++++++
 7 files changed, 309 insertions(+), 12 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 97e1853..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,9 +1,12 @@
 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;
@@ -15,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;
@@ -39,6 +43,7 @@
 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;
 
@@ -136,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);
@@ -189,7 +228,7 @@
             // 鍚屾鐘舵��
             resp.setSyncedMes(syncedIds.contains(resp.getId()));
         });
-        return success(new PageResult<>(respList, pageResult.getTotal()));
+        return respList;
     }
 
     @GetMapping("/list-by-ids")
@@ -277,6 +316,7 @@
 
     @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()
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/vo/MdmItemExcelVO.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/vo/MdmItemExcelVO.java
new file mode 100644
index 0000000..6273789
--- /dev/null
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/vo/MdmItemExcelVO.java
@@ -0,0 +1,89 @@
+package cn.iocoder.yudao.module.mdm.controller.admin.item.vo;
+
+import cn.idev.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * MDM 鐗╂枡瀵煎嚭 Excel VO
+ *
+ * @author 瓒呯骇绠$悊鍛�
+ */
+@Data
+public class MdmItemExcelVO {
+
+    @ExcelProperty("鐗╂枡缂栫爜")
+    private String code;
+
+    @ExcelProperty("鐗╂枡鍚嶇О")
+    private String name;
+
+    @ExcelProperty("鐗╂枡鏉$爜")
+    private String barCode;
+
+    @ExcelProperty("瑙勬牸鍨嬪彿")
+    private String specification;
+
+    @ExcelProperty("鐗╂枡绫诲瀷")
+    private String itemTypeName;
+
+    @ExcelProperty("鐗╂枡鍒嗙被")
+    private String categoryName;
+
+    @ExcelProperty("涓昏閲忓崟浣�")
+    private String unitMeasureName;
+
+    @ExcelProperty("杈呭崟浣�1")
+    private String unitMeasureName2;
+
+    @ExcelProperty("杈呭崟浣�1鎹㈢畻姣旂巼")
+    private BigDecimal unitMeasureRate1;
+
+    @ExcelProperty("杈呭崟浣�2")
+    private String unitMeasureName3;
+
+    @ExcelProperty("杈呭崟浣�2鎹㈢畻姣旂巼")
+    private BigDecimal unitMeasureRate2;
+
+    @ExcelProperty("榛樿浠撳簱")
+    private String warehouseName;
+
+    @ExcelProperty("鐘舵��")
+    private Integer status;
+
+    @ExcelProperty("鏄惁鎵规绠$悊")
+    private Boolean isBatchManaged;
+
+    @ExcelProperty("閲嶉噺(kg)")
+    private BigDecimal weight;
+
+    @ExcelProperty("閲囪喘浠�")
+    private BigDecimal purchasePrice;
+
+    @ExcelProperty("閿�鍞环")
+    private BigDecimal salesPrice;
+
+    @ExcelProperty("鎴愭湰浠�")
+    private BigDecimal costPrice;
+
+    @ExcelProperty("瀹夊叏搴撳瓨")
+    private BigDecimal safetyStock;
+
+    @ExcelProperty("鏈�浣庡簱瀛�")
+    private BigDecimal minStock;
+
+    @ExcelProperty("鏈�楂樺簱瀛�")
+    private BigDecimal maxStock;
+
+    @ExcelProperty("淇濊川鏈�(澶�)")
+    private Integer expiryDay;
+
+    @ExcelProperty("澶囨敞")
+    private String remark;
+
+    @ExcelProperty("鍒涘缓鏃堕棿")
+    private LocalDateTime createTime;
+
+}
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/MdmUnitMeasureController.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/MdmUnitMeasureController.java
index 072e4d0..2f5ec2c 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/MdmUnitMeasureController.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/MdmUnitMeasureController.java
@@ -1,9 +1,12 @@
 package cn.iocoder.yudao.module.mdm.controller.admin.unit;
 
+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.unit.vo.MdmUnitMeasureExcelVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.unit.vo.MdmUnitMeasureImportExcelVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.unit.vo.MdmUnitMeasureImportRespVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.unit.vo.MdmUnitMeasurePageReqVO;
@@ -23,9 +26,13 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
 @Tag(name = "绠$悊鍚庡彴 - MDM 璁¢噺鍗曚綅")
@@ -101,8 +108,37 @@
         return success(unitMeasureService.getUnitMeasureList(ids));
     }
 
+    @GetMapping("/export-excel")
+    @Operation(summary = "瀵煎嚭璁¢噺鍗曚綅 Excel")
+    @PreAuthorize("@ss.hasPermission('mdm:unit-measure:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportUnitMeasureExcel(@Valid MdmUnitMeasurePageReqVO pageReqVO,
+                                       HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<MdmUnitMeasureDO> list = unitMeasureService.getUnitMeasurePage(pageReqVO).getList();
+        // 涓诲崟浣嶇紪鐮佹槧灏勶細涓�娆℃煡璇㈠叏閮ㄨ閲忓崟浣嶏紝鐢ㄤ簬瑙f瀽 primaryId -> 缂栫爜
+        MdmUnitMeasurePageReqVO allReqVO = new MdmUnitMeasurePageReqVO();
+        allReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        Map<Long, String> unitCodeMap = new HashMap<>();
+        for (MdmUnitMeasureDO unit : unitMeasureService.getUnitMeasurePage(allReqVO).getList()) {
+            unitCodeMap.put(unit.getId(), unit.getCode());
+        }
+        // 缁勮瀵煎嚭 VO锛堜富鍗曚綅缂栫爜浠� DO.primaryId 瑙f瀽锛�
+        List<MdmUnitMeasureExcelVO> excelList = new ArrayList<>();
+        for (MdmUnitMeasureDO unit : list) {
+            MdmUnitMeasureExcelVO excelVO = BeanUtils.toBean(unit, MdmUnitMeasureExcelVO.class);
+            if (unit.getPrimaryId() != null) {
+                excelVO.setPrimaryCode(unitCodeMap.get(unit.getPrimaryId()));
+            }
+            excelList.add(excelVO);
+        }
+        // 瀵煎嚭 Excel
+        ExcelUtils.write(response, "璁¢噺鍗曚綅鏁版嵁.xls", "璁¢噺鍗曚綅", MdmUnitMeasureExcelVO.class, excelList);
+    }
+
     @GetMapping("/get-import-template")
     @Operation(summary = "鑾峰緱瀵煎叆璁¢噺鍗曚綅妯℃澘")
+    @PreAuthorize("@ss.hasPermission('mdm:unit-measure:import')")
     public void importTemplate(HttpServletResponse response) throws IOException {
         List<MdmUnitMeasureImportExcelVO> list = Arrays.asList(
                 MdmUnitMeasureImportExcelVO.builder().code("PC").name("鐗�").primaryFlag(true).changeRate(new java.math.BigDecimal("1")).status(0).remark("绀轰緥锛氫富鍗曚綅").build(),
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/vo/MdmUnitMeasureExcelVO.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/vo/MdmUnitMeasureExcelVO.java
new file mode 100644
index 0000000..d6d8de2
--- /dev/null
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/unit/vo/MdmUnitMeasureExcelVO.java
@@ -0,0 +1,41 @@
+package cn.iocoder.yudao.module.mdm.controller.admin.unit.vo;
+
+import cn.idev.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * MDM 璁¢噺鍗曚綅瀵煎嚭 Excel VO
+ *
+ * @author 瓒呯骇绠$悊鍛�
+ */
+@Data
+public class MdmUnitMeasureExcelVO {
+
+    @ExcelProperty("鍗曚綅缂栫爜")
+    private String code;
+
+    @ExcelProperty("鍗曚綅鍚嶇О")
+    private String name;
+
+    @ExcelProperty("鏄惁涓诲崟浣�")
+    private Boolean primaryFlag;
+
+    @ExcelProperty("涓诲崟浣嶇紪鐮�")
+    private String primaryCode;
+
+    @ExcelProperty("涓庝富鍗曚綅鎹㈢畻姣斾緥")
+    private BigDecimal changeRate;
+
+    @ExcelProperty("鐘舵��")
+    private Integer status;
+
+    @ExcelProperty("澶囨敞")
+    private String remark;
+
+    @ExcelProperty("鍒涘缓鏃堕棿")
+    private LocalDateTime createTime;
+
+}
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 d71bea1..cb23410 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
@@ -15,7 +15,6 @@
 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.category.MdmItemCategoryMapper;
 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.dal.mysql.unit.MdmUnitMeasureMapper;
@@ -65,9 +64,6 @@
     private MesMdItemApi mesMdItemApi;
     @Resource
     private MdmItemBatchConfigMapper itemBatchConfigMapper;
-
-    @Resource
-    private MdmItemCategoryMapper itemCategoryMapper;
 
     @Resource
     private MdmUnitMeasureMapper unitMeasureMapper;
@@ -443,11 +439,13 @@
                 .createList(new ArrayList<>()).updateList(new ArrayList<>())
                 .failureList(new LinkedHashMap<>()).build();
 
-        // 1. 棰勭儹锛氬垎绫荤紪鐮� -> ID銆佸崟浣嶇紪鐮� -> ID
+        // 1. 棰勭儹锛氬垎绫荤紪鐮� -> ID锛圡ES 鐗╂枡鍒嗙被锛屼笌鐗╂枡琛ㄥ崟涓嬫媺鏁版嵁婧愪竴鑷达級銆佸崟浣嶇紪鐮� -> ID
         Map<String, Long> categoryCodeIdMap = new HashMap<>();
-        for (MdmItemCategoryDO category : itemCategoryMapper.selectList()) {
-            if (category.getCode() != null) {
-                categoryCodeIdMap.put(category.getCode(), category.getId());
+        for (String categoryCode : importList.stream()
+                .map(MdmItemImportExcelVO::getCategoryCode).filter(StrUtil::isNotBlank).distinct().toList()) {
+            CommonResult<MesMdItemTypeRespDTO> categoryResult = mesMdItemTypeApi.getItemTypeByCode(categoryCode);
+            if (categoryResult != null && categoryResult.getData() != null) {
+                categoryCodeIdMap.put(categoryCode, categoryResult.getData().getId());
             }
         }
         Map<String, Long> unitCodeIdMap = new HashMap<>();
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemTypeController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemTypeController.java
index bd91d3f..ec014e0 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemTypeController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemTypeController.java
@@ -1,9 +1,11 @@
 package cn.iocoder.yudao.module.mes.controller.admin.md.item;
 
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeExcelVO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportExcelVO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeListReqVO;
@@ -24,9 +26,13 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+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.convertList;
 
@@ -91,8 +97,57 @@
                 .setItemOrProduct(itemType.getItemOrProduct())));
     }
 
+    @GetMapping("/export-excel")
+    @Operation(summary = "瀵煎嚭鐗╂枡浜у搧鍒嗙被 Excel")
+    @PreAuthorize("@ss.hasPermission('mes:md-item-type:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportItemTypeExcel(@Valid MesMdItemTypeListReqVO listReqVO,
+                                    HttpServletResponse response) throws IOException {
+        List<MesMdItemTypeDO> list = itemTypeService.getItemTypeList(listReqVO);
+        // 鍏ㄩ噺鍒嗙被锛岀敤浜庤В鏋愪笂绾у垎绫伙紙鐖跺垎绫诲彲鑳戒笉鍦ㄧ瓫閫夌粨鏋滃唴锛�
+        Map<Long, String> parentCodeMap = new HashMap<>();
+        Map<Long, String> parentNameMap = new HashMap<>();
+        for (MesMdItemTypeDO type : itemTypeService.getItemTypeList(new MesMdItemTypeListReqVO())) {
+            parentCodeMap.put(type.getId(), type.getCode());
+            parentNameMap.put(type.getId(), type.getName());
+        }
+        // 缁勮瀵煎嚭 VO锛堣ˉ榻愪笂绾у垎绫荤紪鐮�/鍚嶇О銆佺墿鏂欎骇鍝佷腑鏂囨爣璇嗭級
+        List<MesMdItemTypeExcelVO> excelList = new ArrayList<>();
+        for (MesMdItemTypeDO type : list) {
+            MesMdItemTypeExcelVO excelVO = BeanUtils.toBean(type, MesMdItemTypeExcelVO.class);
+            if (type.getParentId() != null && !MesMdItemTypeDO.PARENT_ID_ROOT.equals(type.getParentId())) {
+                excelVO.setParentCode(parentCodeMap.get(type.getParentId()));
+                excelVO.setParentName(parentNameMap.get(type.getParentId()));
+            }
+            excelVO.setItemOrProduct(convertItemOrProductToText(type.getItemOrProduct()));
+            excelList.add(excelVO);
+        }
+        // 瀵煎嚭 Excel
+        ExcelUtils.write(response, "鐗╂枡鍒嗙被鏁版嵁.xls", "鐗╂枡鍒嗙被", MesMdItemTypeExcelVO.class, excelList);
+    }
+
+    /**
+     * 灏嗙墿鏂�/浜у搧鏍囪瘑杞崲涓轰腑鏂囧悕绉�
+     *
+     * @param itemOrProduct 瀛楀吀鍊硷細ITEM=鐗╂枡锛孭RODUCT=浜у搧
+     * @return 涓枃鍚嶇О
+     */
+    private String convertItemOrProductToText(String itemOrProduct) {
+        if (itemOrProduct == null) {
+            return null;
+        }
+        if ("ITEM".equals(itemOrProduct)) {
+            return "鐗╂枡";
+        }
+        if ("PRODUCT".equals(itemOrProduct)) {
+            return "浜у搧";
+        }
+        return itemOrProduct;
+    }
+
     @GetMapping("/get-import-template")
     @Operation(summary = "鑾峰緱瀵煎叆鐗╂枡浜у搧鍒嗙被妯℃澘")
+    @PreAuthorize("@ss.hasPermission('mes:md-item-type:import')")
     public void importTemplate(HttpServletResponse response) throws IOException {
         List<MesMdItemTypeImportExcelVO> list = Arrays.asList(
                 MesMdItemTypeImportExcelVO.builder().code("RAW").name("鍘熸潗鏂�").itemOrProduct("ITEM").sort(1).status(0).remark("绀轰緥锛氶《绾у垎绫�").build(),
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/type/MesMdItemTypeExcelVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/type/MesMdItemTypeExcelVO.java
new file mode 100644
index 0000000..80a6b16
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/type/MesMdItemTypeExcelVO.java
@@ -0,0 +1,38 @@
+package cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type;
+
+import cn.idev.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+/**
+ * MES 鐗╂枡浜у搧鍒嗙被瀵煎嚭 Excel VO
+ *
+ * @author 瓒呯骇绠$悊鍛�
+ */
+@Data
+public class MesMdItemTypeExcelVO {
+
+    @ExcelProperty("鍒嗙被缂栫爜")
+    private String code;
+
+    @ExcelProperty("鍒嗙被鍚嶇О")
+    private String name;
+
+    @ExcelProperty("涓婄骇鍒嗙被缂栫爜")
+    private String parentCode;
+
+    @ExcelProperty("涓婄骇鍒嗙被鍚嶇О")
+    private String parentName;
+
+    @ExcelProperty("鐗╂枡/浜у搧")
+    private String itemOrProduct;
+
+    @ExcelProperty("鎺掑簭")
+    private Integer sort;
+
+    @ExcelProperty("鐘舵��")
+    private Integer status;
+
+    @ExcelProperty("澶囨敞")
+    private String remark;
+
+}

--
Gitblit v1.9.3