package cn.iocoder.yudao.module.srm.controller.admin.tender; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.srm.controller.admin.tender.vo.*; import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO; import cn.iocoder.yudao.module.srm.dal.dataobject.SrmTenderMaterialDO; import cn.iocoder.yudao.module.srm.dal.mysql.SrmTenderMaterialMapper; import cn.iocoder.yudao.module.srm.service.supplier.SrmSupplierService; import cn.iocoder.yudao.module.srm.service.tender.SrmTenderBidService; 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; @Tag(name = "管理后台 - SRM 投标管理") @RestController @RequestMapping("/srm/tender-bid") @Validated public class SrmTenderBidController { @Resource private SrmTenderBidService tenderBidService; @Resource private SrmSupplierService supplierService; @Resource private SrmTenderMaterialMapper tenderMaterialMapper; // ========== 投标管理 ========== @PostMapping("/create") @Operation(summary = "创建投标") @PreAuthorize("@ss.hasPermission('srm:tender-bid:create')") public CommonResult createBid(@Valid @RequestBody SrmTenderBidSaveReqVO createReqVO) { return success(tenderBidService.createBid(createReqVO)); } @GetMapping("/get") @Operation(summary = "获取投标详情") @PreAuthorize("@ss.hasPermission('srm:tender-bid:query')") public CommonResult getBid(@RequestParam("id") Long id) { SrmTenderBidRespVO resp = BeanUtils.toBean(tenderBidService.getBid(id), SrmTenderBidRespVO.class); enrichSupplierName(resp); return success(resp); } @GetMapping("/list-by-project") @Operation(summary = "按招标项目获取投标列表") @PreAuthorize("@ss.hasPermission('srm:tender-bid:query')") public CommonResult> getBidListByProject(@RequestParam("tenderProjectId") Long tenderProjectId) { List list = BeanUtils.toBean(tenderBidService.getBidListByProject(tenderProjectId), SrmTenderBidRespVO.class); enrichSupplierNames(list); return success(list); } @PutMapping("/withdraw") @Operation(summary = "撤标") @Parameter(name = "id", description = "投标ID", required = true) @PreAuthorize("@ss.hasPermission('srm:tender-bid:update')") public CommonResult withdrawBid(@RequestParam("id") Long id) { tenderBidService.withdrawBid(id); return success(true); } // ========== 供应商报价 ========== @PostMapping("/quote/create") @Operation(summary = "创建供应商报价") @PreAuthorize("@ss.hasPermission('srm:supplier-quote:create')") public CommonResult createQuote(@Valid @RequestBody SrmSupplierQuoteSaveReqVO createReqVO) { return success(tenderBidService.createQuote(createReqVO)); } @PutMapping("/quote/update") @Operation(summary = "更新供应商报价") @PreAuthorize("@ss.hasPermission('srm:supplier-quote:update')") public CommonResult updateQuote(@Valid @RequestBody SrmSupplierQuoteSaveReqVO updateReqVO) { tenderBidService.updateQuote(updateReqVO); return success(true); } @GetMapping("/quote/list-by-bid") @Operation(summary = "按投标获取报价列表") @PreAuthorize("@ss.hasPermission('srm:supplier-quote:query')") public CommonResult> getQuoteListByBid(@RequestParam("bidId") Long bidId) { List list = BeanUtils.toBean(tenderBidService.getQuoteList(bidId), SrmSupplierQuoteRespVO.class); enrichQuoteMaterialInfo(list); return success(list); } private void enrichQuoteMaterialInfo(List list) { if (list == null || list.isEmpty()) return; Set materialIds = CollectionUtils.convertSet(list, SrmSupplierQuoteRespVO::getTenderMaterialId); Map materialMap = tenderMaterialMapper.selectBatchIds(materialIds).stream() .collect(java.util.stream.Collectors.toMap(SrmTenderMaterialDO::getId, m -> m)); list.forEach(vo -> { SrmTenderMaterialDO material = materialMap.get(vo.getTenderMaterialId()); if (material != null) { vo.setTenderMaterialCode(material.getProductCode()); vo.setTenderMaterialName(material.getProductName()); vo.setTenderMaterialSpec(material.getProductSpec()); vo.setTenderMaterialUnit(material.getUnit()); } }); } // ========== 关联数据填充 ========== private void enrichSupplierNames(List list) { if (list == null || list.isEmpty()) return; Set supplierIds = CollectionUtils.convertSet(list, SrmTenderBidRespVO::getSupplierId); Map supplierMap = supplierService.getSupplierMap(supplierIds); list.forEach(vo -> { SrmSupplierDO supplier = supplierMap.get(vo.getSupplierId()); if (supplier != null) { vo.setSupplierName(supplier.getName()); } }); } private void enrichSupplierName(SrmTenderBidRespVO vo) { if (vo == null || vo.getSupplierId() == null) return; SrmSupplierDO supplier = supplierService.getSupplier(vo.getSupplierId()); if (supplier != null) { vo.setSupplierName(supplier.getName()); } } }