| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private CrmCustomerService customerService; |
| | | @Resource |
| | | private CrmCustomerPoolConfigService customerPoolConfigService; |
| | | @Resource |
| | | private CrmContractService contractService; |
| | | |
| | | @Resource |
| | | private DeptApi deptApi; |
| | |
| | | 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)); |
| | | } |
| | | |
| | | public CrmCustomerRespVO buildCustomerDetail(CrmCustomerDO customer) { |
| | | if (customer == null) { |
| | | return null; |
| | |
| | | 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())); |
| | | } |
| | | |
| | | public List<CrmCustomerRespVO> buildCustomerDetailList(List<CrmCustomerDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return java.util.Collections.emptyList(); |
| | |
| | | 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())); |
| | |
| | | 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())); |
| | | }); |
| | | } |
| | | |