liu
2026-09-04 afd32af33acb4ab6f8e890c817d012cad75639c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package cn.iocoder.yudao.module.srm.controller.admin.supplier;
 
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.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;
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.ArrayList;
import java.util.Arrays;
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - SRM 供应商")
@RestController
@RequestMapping("/srm/supplier")
@Validated
public class SrmSupplierController {
 
    @Resource
    private SrmSupplierService supplierService;
 
    @PostMapping("/create")
    @Operation(summary = "创建供应商")
    @PreAuthorize("@ss.hasPermission('srm:supplier:create')")
    public CommonResult<Long> createSupplier(@Valid @RequestBody SrmSupplierSaveReqVO createReqVO) {
        return success(supplierService.createSupplier(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新供应商")
    @PreAuthorize("@ss.hasPermission('srm:supplier:update')")
    public CommonResult<Boolean> updateSupplier(@Valid @RequestBody SrmSupplierSaveReqVO updateReqVO) {
        supplierService.updateSupplier(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除供应商")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('srm:supplier:delete')")
    public CommonResult<Boolean> deleteSupplier(@RequestParam("id") Long id) {
        supplierService.deleteSupplier(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获取供应商详情")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('srm:supplier:query')")
    public CommonResult<SrmSupplierRespVO> getSupplier(@RequestParam("id") Long id) {
        SrmSupplierDO supplier = supplierService.getSupplier(id);
        return success(BeanUtils.toBean(supplier, SrmSupplierRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "供应商分页查询")
    @PreAuthorize("@ss.hasPermission('srm:supplier:query')")
    public CommonResult<PageResult<SrmSupplierRespVO>> getSupplierPage(@Valid SrmSupplierPageReqVO pageReqVO) {
        PageResult<SrmSupplierDO> pageResult = supplierService.getSupplierPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SrmSupplierRespVO.class));
    }
 
    @GetMapping("/simple-list")
    @Operation(summary = "获取供应商精简列表(仅返回已通过准入审批的供应商)")
    public CommonResult<List<SrmSupplierRespVO>> getSupplierSimpleList() {
        List<SrmSupplierDO> list = supplierService.getSupplierSimpleList();
        return success(BeanUtils.toBean(list, SrmSupplierRespVO.class));
    }
 
    @GetMapping("/list")
    @Operation(summary = "获取供应商档案列表(不过滤准入状态)")
    public CommonResult<List<SrmSupplierRespVO>> getSupplierAllList() {
        List<SrmSupplierDO> list = supplierService.getSupplierAllList();
        return success(BeanUtils.toBean(list, SrmSupplierRespVO.class));
    }
 
    @GetMapping("/export-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();
        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 ? "启用" : "禁用";
    }
 
}