xiaoyi
6 天以前 481d8165f26fc7e37f0e87f6444ac0340bb563a3
yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/supplier/SrmSupplierController.java
@@ -19,6 +19,7 @@
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -59,7 +60,6 @@
    @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));
@@ -67,7 +67,6 @@
    @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));
@@ -96,4 +95,28 @@
        ExcelUtils.write(response, "供应商数据.xlsx", "供应商", SrmSupplierRespVO.class, BeanUtils.toBean(list, SrmSupplierRespVO.class));
    }
    @GetMapping("/get-import-template")
    @Operation(summary = "获得导入供应商模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<SrmSupplierImportExcelVO> list = Collections.singletonList(
                SrmSupplierImportExcelVO.builder().code("SUP-001").name("示例供应商")
                        .shortName("示例").type("1").companyNature("").registeredCapital(null)
                        .businessLicenseNo("").taxNo("").legalPerson("").address("").website("")
                        .contactName("").contactMobile("").contactEmail("").bankName("").bankAccount("")
                        .status(0).remark("").build()
        );
        // 输出
        ExcelUtils.write(response, "供应商导入模板.xls", "供应商列表", SrmSupplierImportExcelVO.class, list);
    }
    @PostMapping("/import")
    @Operation(summary = "导入供应商")
    @PreAuthorize("@ss.hasPermission('srm:supplier:import')")
    public CommonResult<SrmSupplierImportRespVO> importExcel(@Valid SrmSupplierImportReqVO importReqVO)
            throws Exception {
        List<SrmSupplierImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), SrmSupplierImportExcelVO.class);
        return success(supplierService.importSupplierList(list, importReqVO));
    }
}