CRM:code review【客户画像】的实现

plp
YunaiV 2 years ago
parent 924580f4a2
commit 3f5724e978

@ -30,32 +30,34 @@ public class CrmStatisticsPortraitController {
@Resource @Resource
private CrmStatisticsPortraitService statisticsPortraitService; private CrmStatisticsPortraitService statisticsPortraitService;
// TODO @puhui999搞个属于自己的 CrmStatisticsCustomerReqVO 类哈
@GetMapping("/get-customer-area-summary") @GetMapping("/get-customer-area-summary")
@Operation(summary = "获取客户地区统计数据", description = "用于【城市分布分析】页面") @Operation(summary = "获取客户地区统计数据", description = "用于【城市分布分析】页面")
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
public CommonResult<List<CrmStatisticCustomerAreaRespVO>> getCustomerAreaSummary(@Valid CrmStatisticsCustomerReqVO reqVO) { public CommonResult<List<CrmStatisticCustomerAreaRespVO>> getCustomerAreaSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(statisticsPortraitService.getCustomerArea(reqVO)); return success(statisticsPortraitService.getCustomerAreaSummary(reqVO));
} }
@GetMapping("/get-customer-industry-summary") @GetMapping("/get-customer-industry-summary")
@Operation(summary = "获取客户行业统计数据") @Operation(summary = "获取客户行业统计数据", description = "用于【客户行业分析】页面")
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustry(@Valid CrmStatisticsCustomerReqVO reqVO) { public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustrySummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(statisticsPortraitService.getCustomerIndustry(reqVO)); return success(statisticsPortraitService.getCustomerIndustrySummary(reqVO));
} }
@GetMapping("/get-customer-level-summary") @GetMapping("/get-customer-level-summary")
@Operation(summary = "获取客户级别统计数据") @Operation(summary = "获取客户级别统计数据", description = "用于【客户级别分析】页面")
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevel(@Valid CrmStatisticsCustomerReqVO reqVO) { public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevelSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(statisticsPortraitService.getCustomerLevel(reqVO)); return success(statisticsPortraitService.getCustomerLevelSummary(reqVO));
} }
@GetMapping("/get-customer-source-summary") @GetMapping("/get-customer-source-summary")
@Operation(summary = "获取客户来源统计数据") @Operation(summary = "获取客户来源统计数据", description = "用于【客户来源分析】页面")
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSource(@Valid CrmStatisticsCustomerReqVO reqVO) { public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSourceSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(statisticsPortraitService.getCustomerSource(reqVO)); return success(statisticsPortraitService.getCustomerSourceSummary(reqVO));
} }
} }

@ -18,6 +18,8 @@ public class CrmStatisticCustomerAreaRespVO {
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount; private Integer dealCount;
// TODO @puhui999下面两个的计算交给前端。后端只返回数据即可。
@Schema(description = "省份占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "省份占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double areaPortion; private Double areaPortion;

@ -9,6 +9,7 @@ public class CrmStatisticCustomerIndustryRespVO {
@Schema(description = "客户行业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户行业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer industryId; private Integer industryId;
// TODO @puhui999这个前端字典翻译哈
@Schema(description = "客户行业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户行业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String industryName; private String industryName;
@ -18,6 +19,8 @@ public class CrmStatisticCustomerIndustryRespVO {
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount; private Integer dealCount;
// TODO @puhui999下面两个的计算交给前端。后端只返回数据即可。
@Schema(description = "行业占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "行业占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double industryPortion; private Double industryPortion;

@ -7,8 +7,9 @@ import lombok.Data;
@Data @Data
public class CrmStatisticCustomerLevelRespVO { public class CrmStatisticCustomerLevelRespVO {
@Schema(description = "客户级别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户级别编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer level; private Integer level;
// TODO @puhui999这个前端字典翻译哈
@Schema(description = "客户级别名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户级别名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String levelName; private String levelName;
@ -18,6 +19,8 @@ public class CrmStatisticCustomerLevelRespVO {
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount; private Integer dealCount;
// TODO @puhui999下面两个的计算交给前端。后端只返回数据即可。
@Schema(description = "级别占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "级别占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double levelPortion; private Double levelPortion;

@ -7,8 +7,9 @@ import lombok.Data;
@Data @Data
public class CrmStatisticCustomerSourceRespVO { public class CrmStatisticCustomerSourceRespVO {
@Schema(description = "客户来源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户来源编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer source; private Integer source;
// TODO @puhui999这个前端字典翻译哈
@Schema(description = "客户来源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户来源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String sourceName; private String sourceName;
@ -18,6 +19,8 @@ public class CrmStatisticCustomerSourceRespVO {
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer dealCount; private Integer dealCount;
// TODO @puhui999下面两个的计算交给前端。后端只返回数据即可。
@Schema(description = "来源占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "来源占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Double sourcePortion; private Double sourcePortion;

@ -12,11 +12,13 @@ import java.util.List;
/** /**
* CRM Mapper * CRM Mapper
* *
* @author dhb52 * @author HUIHUI
*/ */
@Mapper @Mapper
public interface CrmStatisticsPortraitMapper { public interface CrmStatisticsPortraitMapper {
// TODO @puuhui999GroupBy
List<CrmStatisticCustomerIndustryRespVO> selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticCustomerIndustryRespVO> selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO);
List<CrmStatisticCustomerSourceRespVO> selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticCustomerSourceRespVO> selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO);

@ -21,7 +21,7 @@ public interface CrmStatisticsPortraitService {
* @param reqVO * @param reqVO
* @return * @return
*/ */
List<CrmStatisticCustomerAreaRespVO> getCustomerArea(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticCustomerAreaRespVO> getCustomerAreaSummary(CrmStatisticsCustomerReqVO reqVO);
/** /**
* *
@ -29,7 +29,7 @@ public interface CrmStatisticsPortraitService {
* @param reqVO * @param reqVO
* @return * @return
*/ */
List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO);
/** /**
* *
@ -37,7 +37,7 @@ public interface CrmStatisticsPortraitService {
* @param reqVO * @param reqVO
* @return * @return
*/ */
List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(CrmStatisticsCustomerReqVO reqVO);
/** /**
* *
@ -45,6 +45,6 @@ public interface CrmStatisticsPortraitService {
* @param reqVO * @param reqVO
* @return * @return
*/ */
List<CrmStatisticCustomerSourceRespVO> getCustomerSource(CrmStatisticsCustomerReqVO reqVO); List<CrmStatisticCustomerSourceRespVO> getCustomerSourceSummary(CrmStatisticsCustomerReqVO reqVO);
} }

@ -28,6 +28,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*; import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*;
// TODO @puhui999参考 CrmStatisticsCustomerServiceImpl 代码风格,优化下这个类哈;包括命名、空行、注释等;
/** /**
* CRM Service * CRM Service
* *
@ -47,30 +48,37 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
private DictDataApi dictDataApi; private DictDataApi dictDataApi;
@Override @Override
public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO) { public List<CrmStatisticCustomerAreaRespVO> getCustomerAreaSummary(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组 // 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO); List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) { if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
reqVO.setUserIds(userIds); reqVO.setUserIds(userIds);
// 2. 获取客户行业统计数据 // 2. 获取客户地区统计数据
List<CrmStatisticCustomerIndustryRespVO> industryRespVOList = portraitMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO); List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListByAreaId(reqVO);
if (CollUtil.isEmpty(industryRespVOList)) { if (CollUtil.isEmpty(list)) {
return Collections.emptyList(); return Collections.emptyList();
} }
return convertList(industryRespVOList, item -> { // 拼接数据
if (ObjUtil.isNull(item.getIndustryId())) { List<Area> areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area);
areaList.add(new Area().setId(null).setName("未知"));
Map<Integer, Area> areaMap = convertMap(areaList, Area::getId);
List<CrmStatisticCustomerAreaRespVO> customerAreaRespVOList = convertList(list, item -> {
Integer parentId = AreaUtils.getParentIdByType(item.getAreaId(), AreaTypeEnum.PROVINCE);
// TODO @puhui999找不到可以归到未知哈
if (parentId == null) {
return item; return item;
} }
item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId())); findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName()));
return item; return item;
}); });
return customerAreaRespVOList;
} }
@Override @Override
public List<CrmStatisticCustomerSourceRespVO> getCustomerSource(CrmStatisticsCustomerReqVO reqVO) { public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组 // 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO); List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) { if (CollUtil.isEmpty(userIds)) {
@ -78,70 +86,65 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
} }
reqVO.setUserIds(userIds); reqVO.setUserIds(userIds);
// 2. 获取客户行业统计数据 // 2. 获取客户行业统计数据
List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO); List<CrmStatisticCustomerIndustryRespVO> industryRespVOList = portraitMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO);
if (CollUtil.isEmpty(sourceRespVOList)) { if (CollUtil.isEmpty(industryRespVOList)) {
return Collections.emptyList(); return Collections.emptyList();
} }
return convertList(sourceRespVOList, item -> { return convertList(industryRespVOList, item -> {
if (ObjUtil.isNull(item.getSource())) { if (ObjUtil.isNull(item.getIndustryId())) {
return item; return item;
} }
item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource())); item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId()));
return item; return item;
}); });
} }
@Override @Override
public List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(CrmStatisticsCustomerReqVO reqVO) { public List<CrmStatisticCustomerSourceRespVO> getCustomerSourceSummary(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组 // 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO); List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) { if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
reqVO.setUserIds(userIds); reqVO.setUserIds(userIds);
// 2. 获取客户行业统计数据 // 2. 获取客户行业统计数据
List<CrmStatisticCustomerLevelRespVO> levelRespVOList = portraitMapper.selectCustomerLevelListGroupbyLevel(reqVO); List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO);
if (CollUtil.isEmpty(levelRespVOList)) { if (CollUtil.isEmpty(sourceRespVOList)) {
return Collections.emptyList(); return Collections.emptyList();
} }
return convertList(levelRespVOList, item -> { return convertList(sourceRespVOList, item -> {
if (ObjUtil.isNull(item.getLevel())) { if (ObjUtil.isNull(item.getSource())) {
return item; return item;
} }
item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel())); item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource()));
return item; return item;
}); });
} }
@Override @Override
public List<CrmStatisticCustomerAreaRespVO> getCustomerArea(CrmStatisticsCustomerReqVO reqVO) { public List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(CrmStatisticsCustomerReqVO reqVO) {
// 1. 获得用户编号数组 // 1. 获得用户编号数组
List<Long> userIds = getUserIds(reqVO); List<Long> userIds = getUserIds(reqVO);
if (CollUtil.isEmpty(userIds)) { if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
reqVO.setUserIds(userIds); reqVO.setUserIds(userIds);
// 2. 获取客户地区统计数据 // 2. 获取客户行业统计数据
List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListByAreaId(reqVO); List<CrmStatisticCustomerLevelRespVO> levelRespVOList = portraitMapper.selectCustomerLevelListGroupbyLevel(reqVO);
if (CollUtil.isEmpty(list)) { if (CollUtil.isEmpty(levelRespVOList)) {
return Collections.emptyList(); return Collections.emptyList();
} }
// 拼接数据 return convertList(levelRespVOList, item -> {
List<Area> areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area); if (ObjUtil.isNull(item.getLevel())) {
areaList.add(new Area().setId(null).setName("未知"));
Map<Integer, Area> areaMap = convertMap(areaList, Area::getId);
List<CrmStatisticCustomerAreaRespVO> customerAreaRespVOList = convertList(list, item -> {
Integer parentId = AreaUtils.getParentIdByType(item.getAreaId(), AreaTypeEnum.PROVINCE);
if (parentId == null) {
return item; return item;
} }
findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName())); item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel()));
return item; return item;
}); });
return customerAreaRespVOList;
} }
/** /**

@ -2,6 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPortraitMapper"> <mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPortraitMapper">
<!-- TODO @puhui999参考 CrmStatisticsCustomerMapper.xml 优化下 SQL 的排版sql 结尾不用 ; XML 之间有空行; -->
<select id="selectCustomerIndustryListGroupbyIndustryId" <select id="selectCustomerIndustryListGroupbyIndustryId"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO">
SELECT SELECT

Loading…
Cancel
Save