云
4 天以前 f02d0df2f1dfc7a8b775cf50d45375e57628a5ef
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
package cn.iocoder.yudao.module.crm.controller.admin.customer;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.progress.CrmCustomerProgressRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.progress.CrmCustomerProgressSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerProgressDO;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerProgressService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@Tag(name = "管理后台 - CRM 客户洽谈进度")
@RestController
@RequestMapping("/crm/customer-progress")
@Validated
public class CrmCustomerProgressController {
 
    @Resource
    private CrmCustomerProgressService customerProgressService;
 
    @Resource
    private AdminUserApi adminUserApi;
 
    @PostMapping("/create")
    @Operation(summary = "创建客户洽谈进度")
    @PreAuthorize("@ss.hasPermission('crm:customer:update')")
    public CommonResult<Long> createProgress(@Valid @RequestBody CrmCustomerProgressSaveReqVO createReqVO) {
        return success(customerProgressService.createProgress(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新客户洽谈进度")
    @PreAuthorize("@ss.hasPermission('crm:customer:update')")
    public CommonResult<Boolean> updateProgress(@Valid @RequestBody CrmCustomerProgressSaveReqVO updateReqVO) {
        customerProgressService.updateProgress(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除客户洽谈进度")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:customer:update')")
    public CommonResult<Boolean> deleteProgress(@RequestParam("id") Long id) {
        customerProgressService.deleteProgress(id);
        return success(true);
    }
 
    @GetMapping("/list")
    @Operation(summary = "获得客户洽谈进度列表", description = "按洽谈时间倒序")
    @Parameter(name = "customerId", description = "客户编号", required = true, example = "1024")
    public CommonResult<List<CrmCustomerProgressRespVO>> getProgressList(@RequestParam("customerId") Long customerId) {
        List<CrmCustomerProgressDO> list = customerProgressService.getProgressListByCustomerId(customerId);
        // 拼接记录人名称
        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
                convertSet(list, item -> NumberUtils.parseLong(item.getCreator())));
        return success(BeanUtils.toBean(list, CrmCustomerProgressRespVO.class, progress -> {
            MapUtils.findAndThen(userMap, NumberUtils.parseLong(progress.getCreator()),
                    user -> progress.setCreatorName(user.getNickname()));
        }));
    }
 
}