xiaoyi
7 天以前 481d8165f26fc7e37f0e87f6444ac0340bb563a3
yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/certificate/SrmSupplierCertificateController.java
@@ -3,19 +3,25 @@
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.certificate.vo.*;
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
import cn.iocoder.yudao.module.srm.service.certificate.SrmSupplierCertificateService;
import cn.iocoder.yudao.module.srm.service.certificate.SrmSupplierCertificateServiceImpl;
import cn.iocoder.yudao.module.srm.service.supplier.SrmSupplierService;
import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
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 java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -34,6 +40,9 @@
    @Resource
    private SrmSupplierService supplierService;
    @Resource
    private StorageAttachmentApi storageAttachmentApi;
    @PostMapping("/create")
    @Operation(summary = "创建资质证书")
@@ -61,26 +70,25 @@
    @GetMapping("/page")
    @Operation(summary = "获取资质证书分页")
    @PreAuthorize("@ss.hasPermission('srm:supplier-certificate:query')")
    public CommonResult<PageResult<SrmSupplierCertificateRespVO>> getCertificatePage(@Valid SrmSupplierCertificatePageReqVO pageReqVO) {
        var pageResult = certificateService.getCertificatePage(pageReqVO);
        var respList = BeanUtils.toBean(pageResult.getList(), SrmSupplierCertificateRespVO.class);
        enrichSupplierNames(respList);
        enrichAttachments(respList);
        return success(new PageResult<>(respList, pageResult.getTotal()));
    }
    @GetMapping("/list-by-supplier")
    @Operation(summary = "根据供应商ID获取资质列表")
    @PreAuthorize("@ss.hasPermission('srm:supplier-certificate:query')")
    public CommonResult<List<SrmSupplierCertificateRespVO>> getListBySupplier(@RequestParam("supplierId") Long supplierId) {
        var list = BeanUtils.toBean(certificateService.getCertificateListBySupplierId(supplierId), SrmSupplierCertificateRespVO.class);
        enrichSupplierNames(list);
        enrichAttachments(list);
        return success(list);
    }
    @GetMapping("/expiring-list")
    @Operation(summary = "获取即将到期的资质列表(30天内)")
    @PreAuthorize("@ss.hasPermission('srm:supplier-certificate:query')")
    public CommonResult<List<SrmSupplierCertificateRespVO>> getExpiringList() {
        var list = BeanUtils.toBean(certificateService.getExpiringCertificates(), SrmSupplierCertificateRespVO.class);
        enrichSupplierNames(list);
@@ -89,11 +97,36 @@
    @GetMapping("/get")
    @Operation(summary = "获取资质证书详情")
    @PreAuthorize("@ss.hasPermission('srm:supplier-certificate:query')")
    public CommonResult<SrmSupplierCertificateRespVO> getCertificate(@RequestParam("id") Long id) {
        var resp = BeanUtils.toBean(certificateService.getCertificate(id), SrmSupplierCertificateRespVO.class);
        enrichSupplierName(resp);
        enrichAttachments(List.of(resp));
        return success(resp);
    }
    @GetMapping("/get-import-template")
    @Operation(summary = "获得导入资质证书模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<SrmSupplierCertificateImportExcelVO> list = Collections.singletonList(
                SrmSupplierCertificateImportExcelVO.builder().supplierName("示例供应商")
                        .certificateName("ISO9001质量管理体系").certificateNo("ISO9001-2020-XXXX")
                        .certificateType(2).issuingAuthority("中国质量认证中心")
                        .validStartDate(java.time.LocalDate.of(2024, 1, 1))
                        .validEndDate(java.time.LocalDate.of(2027, 1, 1))
                        .remark("").build()
        );
        // 输出
        ExcelUtils.writeTemplate(response, "资质证书导入模板.xls", "资质证书列表", SrmSupplierCertificateImportExcelVO.class, list);
    }
    @PostMapping("/import")
    @Operation(summary = "导入资质证书")
    @PreAuthorize("@ss.hasPermission('srm:supplier-certificate:import')")
    public CommonResult<SrmSupplierCertificateImportRespVO> importExcel(@Valid SrmSupplierCertificateImportReqVO importReqVO)
            throws Exception {
        List<SrmSupplierCertificateImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), SrmSupplierCertificateImportExcelVO.class);
        return success(certificateService.importCertificateList(list, importReqVO));
    }
    // ========== 关联数据填充 ==========
@@ -118,4 +151,10 @@
        }
    }
    private void enrichAttachments(List<SrmSupplierCertificateRespVO> list) {
        if (list == null || list.isEmpty()) return;
        list.forEach(vo -> vo.setAttachmentList(storageAttachmentApi.listAttachments(
                SrmSupplierCertificateServiceImpl.CERTIFICATE_RECORD_TYPE, vo.getId())));
    }
}