From 34e14f4d8f4756f12ad90d0d478c4c2d575203b8 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期四, 03 九月 2026 13:17:59 +0800
Subject: [PATCH] feat(srm): 供应商档案支持 Excel 导入导出

---
 yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/supplier/SrmSupplierController.java |   78 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/supplier/SrmSupplierController.java b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/supplier/SrmSupplierController.java
index c0b71d8..85770d4 100644
--- a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/supplier/SrmSupplierController.java
+++ b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/supplier/SrmSupplierController.java
@@ -7,6 +7,7 @@
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
 import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.*;
 import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
+import cn.iocoder.yudao.module.srm.enums.SupplierTypeEnum;
 import cn.iocoder.yudao.module.srm.service.supplier.SrmSupplierService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -17,8 +18,11 @@
 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.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -88,12 +92,82 @@
     }
 
     @GetMapping("/export-excel")
-    @Operation(summary = "瀵煎嚭渚涘簲鍟� Excel")
+    @Operation(summary = "瀵煎嚭渚涘簲鍟嗘。妗� Excel")
     @PreAuthorize("@ss.hasPermission('srm:supplier:export')")
     public void exportSupplierExcel(@Valid SrmSupplierPageReqVO pageReqVO, HttpServletResponse response) throws IOException {
         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        // 澶嶇敤鍒嗛〉杩囨护鏉′欢锛屽鍑哄唴瀹逛笌鍒楄〃涓�鑷�
         List<SrmSupplierDO> list = supplierService.getSupplierPage(pageReqVO).getList();
-        ExcelUtils.write(response, "渚涘簲鍟嗘暟鎹�.xlsx", "渚涘簲鍟�", SrmSupplierRespVO.class, BeanUtils.toBean(list, SrmSupplierRespVO.class));
+        List<SrmSupplierExcelVO> excelList = new ArrayList<>();
+        for (SrmSupplierDO supplier : list) {
+            SrmSupplierExcelVO excelVO = BeanUtils.toBean(supplier, SrmSupplierExcelVO.class);
+            excelVO.setType(toTypeLabel(supplier.getType()));
+            excelVO.setStatus(toStatusLabel(supplier.getStatus()));
+            excelList.add(excelVO);
+        }
+        ExcelUtils.write(response, "渚涘簲鍟嗘暟鎹�.xlsx", "渚涘簲鍟�", SrmSupplierExcelVO.class, excelList);
+    }
+
+    @GetMapping("/get-import-template")
+    @Operation(summary = "鑾峰緱瀵煎叆渚涘簲鍟嗘。妗堟ā鏉�")
+    @PreAuthorize("@ss.hasPermission('srm:supplier:import')")
+    public void getImportTemplate(HttpServletResponse response) throws IOException {
+        SrmSupplierImportExcelVO sample = new SrmSupplierImportExcelVO();
+        sample.setCode("GYS0001");
+        sample.setName("绀轰緥渚涘簲鍟�");
+        sample.setShortName("绀轰緥");
+        sample.setType("鐢熶骇鍨�");
+        sample.setCompanyNature("姘戣惀");
+        sample.setRegisteredCapital(new java.math.BigDecimal("1000"));
+        sample.setBusinessLicenseNo("91320000XXXXXXXXXX");
+        sample.setTaxNo("91320000XXXXXXXXXX");
+        sample.setLegalPerson("寮犱笁");
+        sample.setAddress("绀轰緥甯傜ず渚嬪尯绀轰緥璺�1鍙�");
+        sample.setWebsite("http://www.example.com");
+        sample.setContactName("鏉庡洓");
+        sample.setContactMobile("13800000000");
+        sample.setContactEmail("contact@example.com");
+        sample.setBankName("绀轰緥閾惰绀轰緥鏀");
+        sample.setBankAccount("6222020000000000000");
+        sample.setStatus(0);
+        sample.setRemark("瀵煎叆妯℃澘绀轰緥琛岋紝鍙垹闄�");
+        ExcelUtils.write(response, "渚涘簲鍟嗗鍏ユā鏉�.xlsx", "渚涘簲鍟�", SrmSupplierImportExcelVO.class, Arrays.asList(sample));
+    }
+
+    @PostMapping("/import-excel")
+    @Operation(summary = "瀵煎叆渚涘簲鍟嗘。妗� Excel")
+    @PreAuthorize("@ss.hasPermission('srm:supplier:import')")
+    public CommonResult<SrmSupplierImportRespVO> importSupplierExcel(@RequestParam("file") MultipartFile file,
+                                                                     @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
+        List<SrmSupplierImportExcelVO> list = ExcelUtils.read(file, SrmSupplierImportExcelVO.class);
+        return success(supplierService.importSupplierList(list, updateSupport));
+    }
+
+    // ========== Excel 灞曠ず杈呭姪 ==========
+
+    /**
+     * 渚涘簲鍟嗙被鍨嬬紪鐮� -> 涓枃鍚嶇О锛堝 1 -> 鐢熶骇鍨嬶級锛涙棤娉曡瘑鍒椂鍘熸牱杩斿洖
+     */
+    private static String toTypeLabel(String typeCode) {
+        if (typeCode == null) {
+            return null;
+        }
+        for (SupplierTypeEnum e : SupplierTypeEnum.values()) {
+            if (typeCode.equals(String.valueOf(e.getCode()))) {
+                return e.getName();
+            }
+        }
+        return typeCode;
+    }
+
+    /**
+     * 鐘舵�� 0 鍚敤 / 1 绂佺敤 -> 涓枃鏂囨锛涚┖鍊艰繑鍥炵┖
+     */
+    private static String toStatusLabel(Integer status) {
+        if (status == null) {
+            return null;
+        }
+        return status == 0 ? "鍚敤" : "绂佺敤";
     }
 
 }

--
Gitblit v1.9.3