package cn.iocoder.yudao.module.srm.controller.admin.certificate;
|
|
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.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.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.validation.Valid;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
@Tag(name = "管理后台 - SRM 供应商资质")
|
@RestController
|
@RequestMapping("/srm/supplier-certificate")
|
@Validated
|
public class SrmSupplierCertificateController {
|
|
@Resource
|
private SrmSupplierCertificateService certificateService;
|
|
@Resource
|
private SrmSupplierService supplierService;
|
|
@PostMapping("/create")
|
@Operation(summary = "创建资质证书")
|
@PreAuthorize("@ss.hasPermission('srm:supplier-certificate:create')")
|
public CommonResult<Long> createCertificate(@Valid @RequestBody SrmSupplierCertificateSaveReqVO createReqVO) {
|
return success(certificateService.createCertificate(createReqVO));
|
}
|
|
@PutMapping("/update")
|
@Operation(summary = "更新资质证书")
|
@PreAuthorize("@ss.hasPermission('srm:supplier-certificate:update')")
|
public CommonResult<Boolean> updateCertificate(@Valid @RequestBody SrmSupplierCertificateSaveReqVO updateReqVO) {
|
certificateService.updateCertificate(updateReqVO);
|
return success(true);
|
}
|
|
@DeleteMapping("/delete")
|
@Operation(summary = "删除资质证书")
|
@Parameter(name = "id", description = "编号", required = true)
|
@PreAuthorize("@ss.hasPermission('srm:supplier-certificate:delete')")
|
public CommonResult<Boolean> deleteCertificate(@RequestParam("id") Long id) {
|
certificateService.deleteCertificate(id);
|
return success(true);
|
}
|
|
@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);
|
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);
|
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);
|
return success(list);
|
}
|
|
@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);
|
return success(resp);
|
}
|
|
// ========== 关联数据填充 ==========
|
|
private void enrichSupplierNames(List<SrmSupplierCertificateRespVO> list) {
|
if (list == null || list.isEmpty()) return;
|
Set<Long> supplierIds = convertSet(list, SrmSupplierCertificateRespVO::getSupplierId);
|
Map<Long, SrmSupplierDO> supplierMap = supplierService.getSupplierMap(supplierIds);
|
list.forEach(vo -> {
|
SrmSupplierDO supplier = supplierMap.get(vo.getSupplierId());
|
if (supplier != null) {
|
vo.setSupplierName(supplier.getName());
|
}
|
});
|
}
|
|
private void enrichSupplierName(SrmSupplierCertificateRespVO vo) {
|
if (vo == null || vo.getSupplierId() == null) return;
|
SrmSupplierDO supplier = supplierService.getSupplier(vo.getSupplierId());
|
if (supplier != null) {
|
vo.setSupplierName(supplier.getName());
|
}
|
}
|
|
}
|