4 小时以前 4d15fa8051884869c5b612d0641508874cc71811
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
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.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;
 
    // ========== 投标管理 ==========
 
    @PostMapping("/create")
    @Operation(summary = "创建投标")
    @PreAuthorize("@ss.hasPermission('srm:tender-bid:create')")
    public CommonResult<Long> createBid(@Valid @RequestBody SrmTenderBidSaveReqVO createReqVO) {
        return success(tenderBidService.createBid(createReqVO));
    }
 
    @GetMapping("/get")
    @Operation(summary = "获取投标详情")
    @PreAuthorize("@ss.hasPermission('srm:tender-bid:query')")
    public CommonResult<SrmTenderBidRespVO> 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<List<SrmTenderBidRespVO>> getBidListByProject(@RequestParam("tenderProjectId") Long tenderProjectId) {
        List<SrmTenderBidRespVO> 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<Boolean> 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<Long> createQuote(@Valid @RequestBody SrmSupplierQuoteSaveReqVO createReqVO) {
        return success(tenderBidService.createQuote(createReqVO));
    }
 
    @PutMapping("/quote/update")
    @Operation(summary = "更新供应商报价")
    @PreAuthorize("@ss.hasPermission('srm:supplier-quote:update')")
    public CommonResult<Boolean> 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<List<SrmSupplierQuoteRespVO>> getQuoteListByBid(@RequestParam("bidId") Long bidId) {
        return success(BeanUtils.toBean(tenderBidService.getQuoteList(bidId), SrmSupplierQuoteRespVO.class));
    }
 
    // ========== 关联数据填充 ==========
 
    private void enrichSupplierNames(List<SrmTenderBidRespVO> list) {
        if (list == null || list.isEmpty()) return;
        Set<Long> supplierIds = CollectionUtils.convertSet(list, SrmTenderBidRespVO::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(SrmTenderBidRespVO vo) {
        if (vo == null || vo.getSupplierId() == null) return;
        SrmSupplierDO supplier = supplierService.getSupplier(vo.getSupplierId());
        if (supplier != null) {
            vo.setSupplierName(supplier.getName());
        }
    }
 
}