云
16 小时以前 fec1341c1cb8e11cfbe3fa7dfabe447edb72b630
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
@@ -15,6 +15,7 @@
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
@@ -33,10 +34,12 @@
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -56,6 +59,8 @@
    private CrmCustomerService customerService;
    @Resource
    private CrmCustomerPoolConfigService customerPoolConfigService;
    @Resource
    private CrmContractService contractService;
    @Resource
    private DeptApi deptApi;
@@ -101,11 +106,19 @@
    @GetMapping("/get")
    @Operation(summary = "获得客户")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:customer:query')")
    public CommonResult<CrmCustomerRespVO> getCustomer(@RequestParam("id") Long id) {
        // 1. 获取客户
        CrmCustomerDO customer = customerService.getCustomer(id);
        // 2. 拼接数据
        return success(buildCustomerDetail(customer));
    }
    @GetMapping("/business-get")
    @Operation(summary = "获得业务模块关联客户详情")
    @PreAuthorize("isAuthenticated()")
    public CommonResult<CrmCustomerRespVO> getBusinessCustomer(@RequestParam("id") Long id) {
        CrmCustomerDO customer = customerService.getCustomerList(java.util.Collections.singleton(id))
                .stream().findFirst().orElse(null);
        return success(buildCustomerDetail(customer));
    }
@@ -118,7 +131,6 @@
    @GetMapping("/page")
    @Operation(summary = "获得客户分页")
    @PreAuthorize("@ss.hasPermission('crm:customer:query')")
    public CommonResult<PageResult<CrmCustomerRespVO>> getCustomerPage(@Valid CrmCustomerPageReqVO pageVO) {
        // 1. 查询客户分页
        PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(pageVO, getLoginUserId());
@@ -126,6 +138,18 @@
            return success(PageResult.empty(pageResult.getTotal()));
        }
        // 2. 拼接数据
        return success(new PageResult<>(buildCustomerDetailList(pageResult.getList()), pageResult.getTotal()));
    }
    @GetMapping("/business-page")
    @Operation(summary = "获得业务模块客户分页")
    @PreAuthorize("isAuthenticated()")
    public CommonResult<PageResult<CrmCustomerRespVO>> getBusinessCustomerPage(
            @Valid CrmCustomerPageReqVO pageVO) {
        PageResult<CrmCustomerDO> pageResult = customerService.getBusinessCustomerPage(pageVO);
        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        return success(new PageResult<>(buildCustomerDetailList(pageResult.getList()), pageResult.getTotal()));
    }
@@ -139,6 +163,10 @@
        Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
        // 1.2 获取距离进入公海的时间
        Map<Long, Long> poolDayMap = getPoolDayMap(list);
        // 1.3 获取「已签订合同」的数量与金额合计(按本页客户批量统计,审核通过的合同才算)
        Set<Long> customerIds = convertSet(list, CrmCustomerDO::getId);
        Map<Long, Long> contractCountMap = contractService.getContractCountMapByCustomerIds(customerIds);
        Map<Long, BigDecimal> contractPriceMap = contractService.getContractPriceMapByCustomerIds(customerIds);
        // 2. 转换成 VO
        return BeanUtils.toBean(list, CrmCustomerRespVO.class, customerVO -> {
            customerVO.setAreaName(AreaUtils.format(customerVO.getAreaId()));
@@ -153,12 +181,15 @@
            if (customerVO.getOwnerUserId() != null) {
                customerVO.setPoolDay(poolDayMap.get(customerVO.getId()));
            }
            // 2.3 设置已签订合同的数量与金额合计(没有合同的客户:数量 0、金额 null,前端显示「—」)
            customerVO.setContractCount(
                    contractCountMap.getOrDefault(customerVO.getId(), 0L).intValue());
            customerVO.setContractTotalPrice(contractPriceMap.get(customerVO.getId()));
        });
    }
    @GetMapping("/put-pool-remind-page")
    @Operation(summary = "获得待进入公海客户分页")
    @PreAuthorize("@ss.hasPermission('crm:customer:query')")
    public CommonResult<PageResult<CrmCustomerRespVO>> getPutPoolRemindCustomerPage(@Valid CrmCustomerPageReqVO pageVO) {
        // 1. 查询客户分页
        PageResult<CrmCustomerDO> pageResult = customerService.getPutPoolRemindCustomerPage(pageVO, getLoginUserId());
@@ -168,21 +199,18 @@
    @GetMapping("/put-pool-remind-count")
    @Operation(summary = "获得待进入公海客户数量")
    @PreAuthorize("@ss.hasPermission('crm:customer:query')")
    public CommonResult<Long> getPutPoolRemindCustomerCount() {
        return success(customerService.getPutPoolRemindCustomerCount(getLoginUserId()));
    }
    @GetMapping("/today-contact-count")
    @Operation(summary = "获得今日需联系客户数量")
    @PreAuthorize("@ss.hasPermission('crm:customer:query')")
    public CommonResult<Long> getTodayContactCustomerCount() {
        return success(customerService.getTodayContactCustomerCount(getLoginUserId()));
    }
    @GetMapping("/follow-count")
    @Operation(summary = "获得分配给我、待跟进的线索数量的客户数量")
    @PreAuthorize("@ss.hasPermission('crm:customer:query')")
    public CommonResult<Long> getFollowCustomerCount() {
        return success(customerService.getFollowCustomerCount(getLoginUserId()));
    }
@@ -200,7 +228,7 @@
        }
        list = CollectionUtils.filterList(list, customer -> {
            // 特殊:如果没负责人,则说明已经在公海,不用计算
            if (customer.getOwnerUserId() == null) {
            if (customer.getOwnerUserId() == null || Boolean.FALSE.equals(customer.getAutoPoolEnabled())) {
                return false;
            }
            // 已成交 or 已锁定,不进入公海
@@ -249,12 +277,12 @@
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<CrmCustomerImportExcelVO> list = Arrays.asList(
                CrmCustomerImportExcelVO.builder().name("芋道").industryId(1).level(1).source(1)
                CrmCustomerImportExcelVO.builder().name("超级管理员").industryId(1).level(1).source(1)
                        .mobile("15601691300").telephone("").qq("").wechat("").email("yunai@iocoder.cn")
                        .areaId(null).detailAddress("").remark("").build(),
                        .areaId(null).detailAddress("").remark("").autoPoolEnabled(true).build(),
                CrmCustomerImportExcelVO.builder().name("源码").industryId(1).level(1).source(1)
                        .mobile("15601691300").telephone("").qq("").wechat("").email("yunai@iocoder.cn")
                        .areaId(null).detailAddress("").remark("").build()
                        .areaId(null).detailAddress("").remark("").autoPoolEnabled(true).build()
        );
        // 输出
        ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list);