CRM: 新增客户行业、来源、级别统计数据统计

This commit is contained in:
puhui999 2024-03-24 17:15:56 +08:00
parent 0dd36f6c5c
commit ce013a2562
10 changed files with 345 additions and 51 deletions

View File

@ -2,6 +2,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.statistics;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO;
import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsCustomerService; import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsCustomerService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -82,4 +85,25 @@ public class CrmStatisticsCustomerController {
return success(customerService.getCustomerDealCycleByUser(reqVO)); return success(customerService.getCustomerDealCycleByUser(reqVO));
} }
@GetMapping("/get-customer-industry-summary")
@Operation(summary = "获取客户行业统计数据")
@PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')")
public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustry(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(customerService.getCustomerIndustry(reqVO));
}
@GetMapping("/get-customer-source-summary")
@Operation(summary = "获取客户来源统计数据")
@PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')")
public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSource(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(customerService.getCustomerSource(reqVO));
}
@GetMapping("/get-customer-level-summary")
@Operation(summary = "获取客户级别统计数据")
@PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')")
public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevel(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(customerService.getCustomerLevel(reqVO));
}
} }

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - CRM 客户行业分析 VO")
@Data
public class CrmStatisticCustomerIndustryRespVO {
@Schema(description = "客户行业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer industryId;
@Schema(description = "客户行业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String industryName;
@Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer customerCount;
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount;
@Schema(description = "行业占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double industryPortion;
@Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double dealPortion;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - CRM 客户级别分析 VO")
@Data
public class CrmStatisticCustomerLevelRespVO {
@Schema(description = "客户级别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer level;
@Schema(description = "客户级别名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String levelName;
@Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer customerCount;
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount;
@Schema(description = "级别占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double levelPortion;
@Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double dealPortion;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - CRM 客户来源分析 VO")
@Data
public class CrmStatisticCustomerSourceRespVO {
@Schema(description = "客户来源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer source;
@Schema(description = "客户来源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String sourceName;
@Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer customerCount;
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount;
@Schema(description = "来源占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double sourcePortion;
@Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double dealPortion;
}

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.crm.dal.mysql.statistics; package cn.iocoder.yudao.module.crm.dal.mysql.statistics;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -42,4 +45,10 @@ public interface CrmStatisticsCustomerMapper {
List<CrmStatisticsCustomerDealCycleByUserRespVO> selectCustomerDealCycleGroupbyUser(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticsCustomerDealCycleByUserRespVO> selectCustomerDealCycleGroupbyUser(CrmStatisticsCustomerReqVO reqVO);
List<CrmStatisticCustomerIndustryRespVO> selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO);
List<CrmStatisticCustomerSourceRespVO> selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO);
List<CrmStatisticCustomerLevelRespVO> selectCustomerLevelListGroupbyLevel(CrmStatisticsCustomerReqVO reqVO);
} }

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.crm.service.statistics; package cn.iocoder.yudao.module.crm.service.statistics;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO;
import java.util.List; import java.util.List;
@ -77,4 +80,28 @@ public interface CrmStatisticsCustomerService {
*/ */
List<CrmStatisticsCustomerDealCycleByUserRespVO> getCustomerDealCycleByUser(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticsCustomerDealCycleByUserRespVO> getCustomerDealCycleByUser(CrmStatisticsCustomerReqVO reqVO);
/**
* 获取客户行业统计数据
*
* @param reqVO 请求参数
* @return 统计数据
*/
List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO);
/**
* 获取客户来源统计数据
*
* @param reqVO 请求参数
* @return 统计数据
*/
List<CrmStatisticCustomerSourceRespVO> getCustomerSource(CrmStatisticsCustomerReqVO reqVO);
/**
* 获取客户级别统计数据
*
* @param reqVO 请求参数
* @return 统计数据
*/
List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(CrmStatisticsCustomerReqVO reqVO);
} }

View File

@ -6,6 +6,9 @@ import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; 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.number.NumberUtils;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO;
import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper; import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.DeptApi;
@ -78,15 +81,15 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// TODO @dhb52这个是不是要 add respVoList 或者还可以 convertList(times, time -> new CrmStatisticsCustomerDealCycleByDateRespVO()...) // TODO @dhb52这个是不是要 add respVoList 或者还可以 convertList(times, time -> new CrmStatisticsCustomerDealCycleByDateRespVO()...)
List<CrmStatisticsCustomerSummaryByDateRespVO> respVoList = new ArrayList<>(times.size()); List<CrmStatisticsCustomerSummaryByDateRespVO> respVoList = new ArrayList<>(times.size());
final Map<String, Integer> customerCreateCountMap = convertMap(customerCreateCount, final Map<String, Integer> customerCreateCountMap = convertMap(customerCreateCount,
CrmStatisticsCustomerSummaryByDateRespVO::getTime, CrmStatisticsCustomerSummaryByDateRespVO::getTime,
CrmStatisticsCustomerSummaryByDateRespVO::getCustomerCreateCount); CrmStatisticsCustomerSummaryByDateRespVO::getCustomerCreateCount);
final Map<String, Integer> customerDealCountMap = convertMap(customerDealCount, final Map<String, Integer> customerDealCountMap = convertMap(customerDealCount,
CrmStatisticsCustomerSummaryByDateRespVO::getTime, CrmStatisticsCustomerSummaryByDateRespVO::getTime,
CrmStatisticsCustomerSummaryByDateRespVO::getCustomerDealCount); CrmStatisticsCustomerSummaryByDateRespVO::getCustomerDealCount);
times.forEach(time -> respVoList.add( times.forEach(time -> respVoList.add(
new CrmStatisticsCustomerSummaryByDateRespVO().setTime(time) new CrmStatisticsCustomerSummaryByDateRespVO().setTime(time)
.setCustomerCreateCount(customerCreateCountMap.getOrDefault(time, 0)) .setCustomerCreateCount(customerCreateCountMap.getOrDefault(time, 0))
.setCustomerDealCount(customerDealCountMap.getOrDefault(time, 0)) .setCustomerDealCount(customerDealCountMap.getOrDefault(time, 0))
)); ));
return respVoList; return respVoList;
} }
@ -108,25 +111,25 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 3. 合并统计数据 // 3. 合并统计数据
final Map<Long, Integer> customerCreateCountMap = convertMap(customerCreateCount, final Map<Long, Integer> customerCreateCountMap = convertMap(customerCreateCount,
CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsCustomerSummaryByUserRespVO::getCustomerCreateCount); CrmStatisticsCustomerSummaryByUserRespVO::getCustomerCreateCount);
final Map<Long, Integer> customerDealCountMap = convertMap(customerDealCount, final Map<Long, Integer> customerDealCountMap = convertMap(customerDealCount,
CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount); CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount);
final Map<Long, BigDecimal> contractPriceMap = convertMap(contractPrice, final Map<Long, BigDecimal> contractPriceMap = convertMap(contractPrice,
CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsCustomerSummaryByUserRespVO::getContractPrice); CrmStatisticsCustomerSummaryByUserRespVO::getContractPrice);
final Map<Long, BigDecimal> receivablePriceMap = convertMap(receivablePrice, final Map<Long, BigDecimal> receivablePriceMap = convertMap(receivablePrice,
CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsCustomerSummaryByUserRespVO::getReceivablePrice); CrmStatisticsCustomerSummaryByUserRespVO::getReceivablePrice);
List<CrmStatisticsCustomerSummaryByUserRespVO> respVoList = new ArrayList<>(userIds.size()); List<CrmStatisticsCustomerSummaryByUserRespVO> respVoList = new ArrayList<>(userIds.size());
userIds.forEach(userId -> { userIds.forEach(userId -> {
final CrmStatisticsCustomerSummaryByUserRespVO vo = new CrmStatisticsCustomerSummaryByUserRespVO(); final CrmStatisticsCustomerSummaryByUserRespVO vo = new CrmStatisticsCustomerSummaryByUserRespVO();
vo.setOwnerUserId(userId); vo.setOwnerUserId(userId);
vo.setCustomerCreateCount(customerCreateCountMap.getOrDefault(userId, 0)) vo.setCustomerCreateCount(customerCreateCountMap.getOrDefault(userId, 0))
.setCustomerDealCount(customerDealCountMap.getOrDefault(userId, 0)) .setCustomerDealCount(customerDealCountMap.getOrDefault(userId, 0))
.setContractPrice(contractPriceMap.getOrDefault(userId, BigDecimal.ZERO)) .setContractPrice(contractPriceMap.getOrDefault(userId, BigDecimal.ZERO))
.setReceivablePrice(receivablePriceMap.getOrDefault(userId, BigDecimal.ZERO)); .setReceivablePrice(receivablePriceMap.getOrDefault(userId, BigDecimal.ZERO));
respVoList.add(vo); respVoList.add(vo);
}); });
@ -156,15 +159,15 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 4. 合并统计数据 // 4. 合并统计数据
List<CrmStatisticsFollowupSummaryByDateRespVO> respVoList = new ArrayList<>(times.size()); List<CrmStatisticsFollowupSummaryByDateRespVO> respVoList = new ArrayList<>(times.size());
final Map<String, Integer> followupRecordCountMap = convertMap(followupRecordCount, final Map<String, Integer> followupRecordCountMap = convertMap(followupRecordCount,
CrmStatisticsFollowupSummaryByDateRespVO::getTime, CrmStatisticsFollowupSummaryByDateRespVO::getTime,
CrmStatisticsFollowupSummaryByDateRespVO::getFollowupRecordCount); CrmStatisticsFollowupSummaryByDateRespVO::getFollowupRecordCount);
final Map<String, Integer> followupCustomerCountMap = convertMap(followupCustomerCount, final Map<String, Integer> followupCustomerCountMap = convertMap(followupCustomerCount,
CrmStatisticsFollowupSummaryByDateRespVO::getTime, CrmStatisticsFollowupSummaryByDateRespVO::getTime,
CrmStatisticsFollowupSummaryByDateRespVO::getFollowupCustomerCount); CrmStatisticsFollowupSummaryByDateRespVO::getFollowupCustomerCount);
times.forEach(time -> respVoList.add( times.forEach(time -> respVoList.add(
new CrmStatisticsFollowupSummaryByDateRespVO().setTime(time) new CrmStatisticsFollowupSummaryByDateRespVO().setTime(time)
.setFollowupRecordCount(followupRecordCountMap.getOrDefault(time, 0)) .setFollowupRecordCount(followupRecordCountMap.getOrDefault(time, 0))
.setFollowupCustomerCount(followupCustomerCountMap.getOrDefault(time, 0)) .setFollowupCustomerCount(followupCustomerCountMap.getOrDefault(time, 0))
)); ));
return respVoList; return respVoList;
@ -186,16 +189,16 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 3. 合并统计数据 // 3. 合并统计数据
final Map<Long, Integer> followupRecordCountMap = convertMap(followupRecordCount, final Map<Long, Integer> followupRecordCountMap = convertMap(followupRecordCount,
CrmStatisticsFollowupSummaryByUserRespVO::getOwnerUserId, CrmStatisticsFollowupSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsFollowupSummaryByUserRespVO::getFollowupRecordCount); CrmStatisticsFollowupSummaryByUserRespVO::getFollowupRecordCount);
final Map<Long, Integer> followupCustomerCountMap = convertMap(followupCustomerCount, final Map<Long, Integer> followupCustomerCountMap = convertMap(followupCustomerCount,
CrmStatisticsFollowupSummaryByUserRespVO::getOwnerUserId, CrmStatisticsFollowupSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsFollowupSummaryByUserRespVO::getFollowupCustomerCount); CrmStatisticsFollowupSummaryByUserRespVO::getFollowupCustomerCount);
List<CrmStatisticsFollowupSummaryByUserRespVO> respVoList = new ArrayList<>(userIds.size()); List<CrmStatisticsFollowupSummaryByUserRespVO> respVoList = new ArrayList<>(userIds.size());
userIds.forEach(userId -> { userIds.forEach(userId -> {
final CrmStatisticsFollowupSummaryByUserRespVO vo = new CrmStatisticsFollowupSummaryByUserRespVO() final CrmStatisticsFollowupSummaryByUserRespVO vo = new CrmStatisticsFollowupSummaryByUserRespVO()
.setFollowupRecordCount(followupRecordCountMap.getOrDefault(userId, 0)) .setFollowupRecordCount(followupRecordCountMap.getOrDefault(userId, 0))
.setFollowupCustomerCount(followupCustomerCountMap.getOrDefault(userId, 0)); .setFollowupCustomerCount(followupCustomerCountMap.getOrDefault(userId, 0));
vo.setOwnerUserId(userId); vo.setOwnerUserId(userId);
respVoList.add(vo); respVoList.add(vo);
}); });
@ -221,7 +224,7 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 3. 获取字典数据 // 3. 获取字典数据
List<DictDataRespDTO> followUpTypes = dictDataApi.getDictDataList(CRM_FOLLOW_UP_TYPE); List<DictDataRespDTO> followUpTypes = dictDataApi.getDictDataList(CRM_FOLLOW_UP_TYPE);
final Map<String, String> followUpTypeMap = convertMap(followUpTypes, final Map<String, String> followUpTypeMap = convertMap(followUpTypes,
DictDataRespDTO::getValue, DictDataRespDTO::getLabel); DictDataRespDTO::getValue, DictDataRespDTO::getLabel);
respVoList.forEach(vo -> { respVoList.forEach(vo -> {
vo.setFollowupType(followUpTypeMap.get(vo.getFollowupType())); vo.setFollowupType(followUpTypeMap.get(vo.getFollowupType()));
}); });
@ -244,19 +247,19 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 3. 设置 创建人负责人行业来源 // 3. 设置 创建人负责人行业来源
// 获取客户所属行业 // 获取客户所属行业
Map<String, String> industryMap = convertMap(dictDataApi.getDictDataList(CRM_CUSTOMER_INDUSTRY), Map<String, String> industryMap = convertMap(dictDataApi.getDictDataList(CRM_CUSTOMER_INDUSTRY),
DictDataRespDTO::getValue, DictDataRespDTO::getLabel); DictDataRespDTO::getValue, DictDataRespDTO::getLabel);
// 获取客户来源 // 获取客户来源
Map<String, String> sourceMap = convertMap(dictDataApi.getDictDataList(CRM_CUSTOMER_SOURCE), Map<String, String> sourceMap = convertMap(dictDataApi.getDictDataList(CRM_CUSTOMER_SOURCE),
DictDataRespDTO::getValue, DictDataRespDTO::getLabel); DictDataRespDTO::getValue, DictDataRespDTO::getLabel);
// 获取创建人负责人列表 // 获取创建人负责人列表
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSetByFlatMap(respVoList, Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSetByFlatMap(respVoList,
vo -> Stream.of(NumberUtils.parseLong(vo.getCreatorUserId()), vo.getOwnerUserId()))); vo -> Stream.of(NumberUtils.parseLong(vo.getCreatorUserId()), vo.getOwnerUserId())));
respVoList.forEach(vo -> { respVoList.forEach(vo -> {
MapUtils.findAndThen(industryMap, vo.getIndustryId(), vo::setIndustryName); MapUtils.findAndThen(industryMap, vo.getIndustryId(), vo::setIndustryName);
MapUtils.findAndThen(sourceMap, vo.getSource(), vo::setSourceName); MapUtils.findAndThen(sourceMap, vo.getSource(), vo::setSourceName);
MapUtils.findAndThen(userMap, NumberUtils.parseLong(vo.getCreatorUserId()), MapUtils.findAndThen(userMap, NumberUtils.parseLong(vo.getCreatorUserId()),
user -> vo.setCreatorUserName(user.getNickname())); user -> vo.setCreatorUserName(user.getNickname()));
MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname())); MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
}); });
@ -283,11 +286,11 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 4. 合并统计数据 // 4. 合并统计数据
List<CrmStatisticsCustomerDealCycleByDateRespVO> respVoList = new ArrayList<>(times.size()); List<CrmStatisticsCustomerDealCycleByDateRespVO> respVoList = new ArrayList<>(times.size());
final Map<String, Double> customerDealCycleMap = convertMap(customerDealCycle, final Map<String, Double> customerDealCycleMap = convertMap(customerDealCycle,
CrmStatisticsCustomerDealCycleByDateRespVO::getTime, CrmStatisticsCustomerDealCycleByDateRespVO::getTime,
CrmStatisticsCustomerDealCycleByDateRespVO::getCustomerDealCycle); CrmStatisticsCustomerDealCycleByDateRespVO::getCustomerDealCycle);
times.forEach(time -> respVoList.add( times.forEach(time -> respVoList.add(
new CrmStatisticsCustomerDealCycleByDateRespVO().setTime(time) new CrmStatisticsCustomerDealCycleByDateRespVO().setTime(time)
.setCustomerDealCycle(customerDealCycleMap.getOrDefault(time, 0D)) .setCustomerDealCycle(customerDealCycleMap.getOrDefault(time, 0D))
)); ));
return respVoList; return respVoList;
} }
@ -308,16 +311,16 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
// 3. 合并统计数据 // 3. 合并统计数据
final Map<Long, Double> customerDealCycleMap = convertMap(customerDealCycle, final Map<Long, Double> customerDealCycleMap = convertMap(customerDealCycle,
CrmStatisticsCustomerDealCycleByUserRespVO::getOwnerUserId, CrmStatisticsCustomerDealCycleByUserRespVO::getOwnerUserId,
CrmStatisticsCustomerDealCycleByUserRespVO::getCustomerDealCycle); CrmStatisticsCustomerDealCycleByUserRespVO::getCustomerDealCycle);
final Map<Long, Integer> customerDealCountMap = convertMap(customerDealCount, final Map<Long, Integer> customerDealCountMap = convertMap(customerDealCount,
CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId,
CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount); CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount);
List<CrmStatisticsCustomerDealCycleByUserRespVO> respVoList = new ArrayList<>(userIds.size()); List<CrmStatisticsCustomerDealCycleByUserRespVO> respVoList = new ArrayList<>(userIds.size());
userIds.forEach(userId -> { userIds.forEach(userId -> {
final CrmStatisticsCustomerDealCycleByUserRespVO vo = new CrmStatisticsCustomerDealCycleByUserRespVO() final CrmStatisticsCustomerDealCycleByUserRespVO vo = new CrmStatisticsCustomerDealCycleByUserRespVO()
.setCustomerDealCycle(customerDealCycleMap.getOrDefault(userId, 0.0)) .setCustomerDealCycle(customerDealCycleMap.getOrDefault(userId, 0.0))
.setCustomerDealCount(customerDealCountMap.getOrDefault(userId, 0)); .setCustomerDealCount(customerDealCountMap.getOrDefault(userId, 0));
vo.setOwnerUserId(userId); vo.setOwnerUserId(userId);
respVoList.add(vo); respVoList.add(vo);
}); });
@ -328,6 +331,75 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
return respVoList; return respVoList;
} }
@Override
public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList();
}
reqVO.setUserIds(userIds);
// 2. 获取客户行业统计数据
List<CrmStatisticCustomerIndustryRespVO> industryRespVOList = customerMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO);
if (CollUtil.isEmpty(industryRespVOList)) {
return Collections.emptyList();
}
return convertList(industryRespVOList, item -> {
if (ObjUtil.isNull(item.getIndustryId())) {
return item;
}
item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId()));
return item;
});
}
@Override
public List<CrmStatisticCustomerSourceRespVO> getCustomerSource(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList();
}
reqVO.setUserIds(userIds);
// 2. 获取客户行业统计数据
List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = customerMapper.selectCustomerSourceListGroupbySource(reqVO);
if (CollUtil.isEmpty(sourceRespVOList)) {
return Collections.emptyList();
}
return convertList(sourceRespVOList, item -> {
if (ObjUtil.isNull(item.getSource())) {
return item;
}
item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource()));
return item;
});
}
@Override
public List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList();
}
reqVO.setUserIds(userIds);
// 2. 获取客户行业统计数据
List<CrmStatisticCustomerLevelRespVO> levelRespVOList = customerMapper.selectCustomerLevelListGroupbyLevel(reqVO);
if (CollUtil.isEmpty(levelRespVOList)) {
return Collections.emptyList();
}
return convertList(levelRespVOList, item -> {
if (ObjUtil.isNull(item.getLevel())) {
return item;
}
item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel()));
return item;
});
}
/** /**
* 拼接用户信息昵称 * 拼接用户信息昵称
* *

View File

@ -249,4 +249,68 @@
GROUP BY a.owner_user_id GROUP BY a.owner_user_id
</select> </select>
<select id="selectCustomerIndustryListGroupbyIndustryId"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO">
SELECT
industry_id,
COUNT(*) AS customerCount,
SUM(deal_status) AS dealCount,
ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS industryPortion,
ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
FROM
crm_customer
WHERE
deleted = 0 AND industry_id IS NOT NULL
AND owner_user_id IN
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
#{times[1],javaType=java.time.LocalDateTime}
GROUP BY
industry_id;
</select>
<select id="selectCustomerSourceListGroupbySource"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO">
SELECT
source,
COUNT(*) AS customerCount,
SUM(deal_status) AS dealCount,
ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS sourcePortion,
ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
FROM
crm_customer
WHERE
deleted = 0 AND source IS NOT NULL
AND owner_user_id IN
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
#{times[1],javaType=java.time.LocalDateTime}
GROUP BY
source;
</select>
<select id="selectCustomerLevelListGroupbyLevel"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO">
SELECT
level,
COUNT(*) AS customerCount,
SUM(deal_status) AS dealCount,
ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS levelPortion,
ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
FROM
crm_customer
WHERE
deleted = 0 AND level IS NOT NULL
AND owner_user_id IN
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
#{times[1],javaType=java.time.LocalDateTime}
GROUP BY
level;
</select>
</mapper> </mapper>

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.system.api.dict; package cn.iocoder.yudao.module.system.api.dict;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import java.util.Collection; import java.util.Collection;
@ -33,6 +35,21 @@ public interface DictDataApi {
*/ */
DictDataRespDTO getDictData(String type, String value); DictDataRespDTO getDictData(String type, String value);
/**
* 获得指定的字典标签从缓存中
*
* @param type 字典类型
* @param value 字典数据值
* @return 字典标签
*/
default String getDictDataLabel(String type, Integer value) {
DictDataRespDTO dictData = getDictData(type, String.valueOf(value));
if (ObjUtil.isNull(dictData)) {
return StrUtil.EMPTY;
}
return dictData.getLabel();
}
/** /**
* 解析获得指定的字典数据从缓存中 * 解析获得指定的字典数据从缓存中
* *

View File

@ -95,11 +95,11 @@
</dependency> </dependency>
<!-- ERP 相关模块。默认注释,保证编译速度 --> <!-- ERP 相关模块。默认注释,保证编译速度 -->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-erp-biz</artifactId> <!-- <artifactId>yudao-module-erp-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<!-- spring boot 配置所需依赖 --> <!-- spring boot 配置所需依赖 -->
<dependency> <dependency>