xiaoyi
5 天以前 481d8165f26fc7e37f0e87f6444ac0340bb563a3
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
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.CrmCreditRatingImportExcelVO;
import cn.iocoder.yudao.module.crm.controller.admin.credit.vo.CrmCreditRatingImportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.credit.vo.CrmCreditRatingImportRespVO;
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.Arrays;
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)
    public CommonResult<CrmCreditRatingRespVO> getCreditRating(@RequestParam("id") Long id) {
        return success(creditRatingService.getCreditRating(id));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得客户信用评级分页")
    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)
    public CommonResult<CrmCreditRatingRespVO> getLatestByCustomer(@RequestParam("customerId") Long customerId) {
        return success(creditRatingService.getLatestByCustomerId(customerId));
    }
 
    @GetMapping("/get-import-template")
    @Operation(summary = "获得导入客户信用评级模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        List<CrmCreditRatingImportExcelVO> list = Arrays.asList(
                CrmCreditRatingImportExcelVO.builder().customerName("示例客户").level(null)
                        .score(null).evalType("").evalReason("").operatorName("")
                        .operateTime(null).validUntil(null).remark("").build()
        );
        ExcelUtils.writeTemplate(response, "客户信用评级导入模板.xls", "客户信用评级列表", CrmCreditRatingImportExcelVO.class, list);
    }
 
    @PostMapping("/import")
    @Operation(summary = "导入客户信用评级")
    @PreAuthorize("@ss.hasPermission('crm:credit-rating:import')")
    public CommonResult<CrmCreditRatingImportRespVO> importExcel(@Valid CrmCreditRatingImportReqVO importReqVO)
            throws Exception {
        List<CrmCreditRatingImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), CrmCreditRatingImportExcelVO.class);
        return success(creditRatingService.importCreditRatingList(list, importReqVO));
    }
 
}