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
package cn.iocoder.yudao.module.srm.controller.admin.evaluation;
 
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.evaluation.vo.*;
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierEvaluationDO;
import cn.iocoder.yudao.module.srm.service.evaluation.SrmSupplierEvaluationService;
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-evaluation")
@Validated
public class SrmSupplierEvaluationController {
 
    @Resource
    private SrmSupplierEvaluationService evaluationService;
 
    @Resource
    private SrmSupplierService supplierService;
 
    @PostMapping("/create")
    @Operation(summary = "创建绩效评价")
    @PreAuthorize("@ss.hasPermission('srm:supplier-evaluation:create')")
    public CommonResult<Long> createEvaluation(@Valid @RequestBody SrmSupplierEvaluationSaveReqVO createReqVO) {
        return success(evaluationService.createEvaluation(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新绩效评价")
    @PreAuthorize("@ss.hasPermission('srm:supplier-evaluation:update')")
    public CommonResult<Boolean> updateEvaluation(@Valid @RequestBody SrmSupplierEvaluationSaveReqVO updateReqVO) {
        evaluationService.updateEvaluation(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除绩效评价")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('srm:supplier-evaluation:delete')")
    public CommonResult<Boolean> deleteEvaluation(@RequestParam("id") Long id) {
        evaluationService.deleteEvaluation(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获取绩效评价详情")
    @PreAuthorize("@ss.hasPermission('srm:supplier-evaluation:query')")
    public CommonResult<SrmSupplierEvaluationRespVO> getEvaluation(@RequestParam("id") Long id) {
        SrmSupplierEvaluationDO evaluation = evaluationService.getEvaluation(id);
        SrmSupplierEvaluationRespVO resp = BeanUtils.toBean(evaluation, SrmSupplierEvaluationRespVO.class);
        enrichSupplierName(resp);
        resp.setGrade(evaluation.getEvaluationLevel());
        return success(resp);
    }
 
    @GetMapping("/page")
    @Operation(summary = "获取绩效评价分页")
    @PreAuthorize("@ss.hasPermission('srm:supplier-evaluation:query')")
    public CommonResult<PageResult<SrmSupplierEvaluationRespVO>> getEvaluationPage(@Valid SrmSupplierEvaluationPageReqVO pageReqVO) {
        PageResult<SrmSupplierEvaluationDO> pageResult = evaluationService.getEvaluationPage(pageReqVO);
        List<SrmSupplierEvaluationRespVO> respList = BeanUtils.toBean(pageResult.getList(), SrmSupplierEvaluationRespVO.class);
        respList.forEach(vo -> vo.setGrade(vo.getEvaluationLevel()));
        enrichSupplierNames(respList);
        return success(new PageResult<>(respList, pageResult.getTotal()));
    }
 
    // ========== 关联数据填充 ==========
 
    private void enrichSupplierNames(List<SrmSupplierEvaluationRespVO> list) {
        if (list == null || list.isEmpty()) return;
        Set<Long> supplierIds = convertSet(list, SrmSupplierEvaluationRespVO::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(SrmSupplierEvaluationRespVO vo) {
        if (vo == null || vo.getSupplierId() == null) return;
        SrmSupplierDO supplier = supplierService.getSupplier(vo.getSupplierId());
        if (supplier != null) {
            vo.setSupplierName(supplier.getName());
        }
    }
 
}