xiaoyi
4 天以前 abf1c0a35d85d38239ff5d2ed746a4e4b797c9d1
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
package cn.iocoder.yudao.module.crm.controller.admin.credit;
 
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.crm.controller.admin.credit.vo.CrmCreditRatingPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.credit.vo.CrmCreditRatingRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.credit.vo.CrmCreditRatingSaveReqVO;
import cn.iocoder.yudao.module.crm.service.credit.CrmCreditRatingService;
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.List;
 
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
 
@Tag(name = "管理后台 - CRM 客户信用评级")
@RestController
@RequestMapping("/crm/credit-rating")
@Validated
public class CrmCreditRatingController {
 
    @Resource
    private CrmCreditRatingService creditRatingService;
 
    @PostMapping("/create")
    @Operation(summary = "创建客户信用评级")
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:create')")
    public CommonResult<Long> createCreditRating(@Valid @RequestBody CrmCreditRatingSaveReqVO createReqVO) {
        return success(creditRatingService.createCreditRating(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新客户信用评级")
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:update')")
    public CommonResult<Boolean> updateCreditRating(@Valid @RequestBody CrmCreditRatingSaveReqVO updateReqVO) {
        creditRatingService.updateCreditRating(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除客户信用评级")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:delete')")
    public CommonResult<Boolean> deleteCreditRating(@RequestParam("id") Long id) {
        creditRatingService.deleteCreditRating(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得客户信用评级")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:query')")
    public CommonResult<CrmCreditRatingRespVO> getCreditRating(@RequestParam("id") Long id) {
        return success(creditRatingService.getCreditRating(id));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得客户信用评级分页")
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:query')")
    public CommonResult<PageResult<CrmCreditRatingRespVO>> getCreditRatingPage(@Valid CrmCreditRatingPageReqVO pageReqVO) {
        return success(creditRatingService.getCreditRatingPage(pageReqVO));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出客户信用评级 Excel")
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportCreditRatingExcel(@Valid CrmCreditRatingPageReqVO exportReqVO,
                                       HttpServletResponse response) throws IOException {
        exportReqVO.setPageSize(PAGE_SIZE_NONE);
        List<CrmCreditRatingRespVO> list = creditRatingService.getCreditRatingList(exportReqVO);
        ExcelUtils.write(response, "客户信用评级.xls", "数据", CrmCreditRatingRespVO.class, list);
    }
 
    @GetMapping("/latest-by-customer")
    @Operation(summary = "获取客户最新信用评级")
    @Parameter(name = "customerId", description = "客户ID", required = true)
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:query')")
    public CommonResult<CrmCreditRatingRespVO> getLatestByCustomer(@RequestParam("customerId") Long customerId) {
        return success(creditRatingService.getLatestByCustomerId(customerId));
    }
 
}