CRM:code review【客户画像】的实现
This commit is contained in:
parent
924580f4a2
commit
3f5724e978
@ -30,32 +30,34 @@ public class CrmStatisticsPortraitController {
|
||||
@Resource
|
||||
private CrmStatisticsPortraitService statisticsPortraitService;
|
||||
|
||||
// TODO @puhui999:搞个属于自己的 CrmStatisticsCustomerReqVO 类哈
|
||||
|
||||
@GetMapping("/get-customer-area-summary")
|
||||
@Operation(summary = "获取客户地区统计数据", description = "用于【城市分布分析】页面")
|
||||
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
|
||||
public CommonResult<List<CrmStatisticCustomerAreaRespVO>> getCustomerAreaSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerArea(reqVO));
|
||||
return success(statisticsPortraitService.getCustomerAreaSummary(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get-customer-industry-summary")
|
||||
@Operation(summary = "获取客户行业统计数据")
|
||||
@Operation(summary = "获取客户行业统计数据", description = "用于【客户行业分析】页面")
|
||||
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
|
||||
public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustry(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerIndustry(reqVO));
|
||||
public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustrySummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerIndustrySummary(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get-customer-level-summary")
|
||||
@Operation(summary = "获取客户级别统计数据")
|
||||
@Operation(summary = "获取客户级别统计数据", description = "用于【客户级别分析】页面")
|
||||
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
|
||||
public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevel(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerLevel(reqVO));
|
||||
public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevelSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerLevelSummary(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get-customer-source-summary")
|
||||
@Operation(summary = "获取客户来源统计数据")
|
||||
@Operation(summary = "获取客户来源统计数据", description = "用于【客户来源分析】页面")
|
||||
@PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
|
||||
public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSource(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerSource(reqVO));
|
||||
public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSourceSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
|
||||
return success(statisticsPortraitService.getCustomerSourceSummary(reqVO));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ public class CrmStatisticCustomerAreaRespVO {
|
||||
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer dealCount;
|
||||
|
||||
// TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
|
||||
|
||||
@Schema(description = "省份占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Double areaPortion;
|
||||
|
||||
|
@ -9,6 +9,7 @@ public class CrmStatisticCustomerIndustryRespVO {
|
||||
|
||||
@Schema(description = "客户行业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer industryId;
|
||||
// TODO @puhui999:这个前端字典翻译哈
|
||||
@Schema(description = "客户行业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private String industryName;
|
||||
|
||||
@ -18,6 +19,8 @@ public class CrmStatisticCustomerIndustryRespVO {
|
||||
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer dealCount;
|
||||
|
||||
// TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
|
||||
|
||||
@Schema(description = "行业占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Double industryPortion;
|
||||
|
||||
|
@ -7,8 +7,9 @@ import lombok.Data;
|
||||
@Data
|
||||
public class CrmStatisticCustomerLevelRespVO {
|
||||
|
||||
@Schema(description = "客户级别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@Schema(description = "客户级别编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer level;
|
||||
// TODO @puhui999:这个前端字典翻译哈
|
||||
@Schema(description = "客户级别名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private String levelName;
|
||||
|
||||
@ -18,6 +19,8 @@ public class CrmStatisticCustomerLevelRespVO {
|
||||
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer dealCount;
|
||||
|
||||
// TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
|
||||
|
||||
@Schema(description = "级别占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Double levelPortion;
|
||||
|
||||
|
@ -7,8 +7,9 @@ import lombok.Data;
|
||||
@Data
|
||||
public class CrmStatisticCustomerSourceRespVO {
|
||||
|
||||
@Schema(description = "客户来源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@Schema(description = "客户来源编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer source;
|
||||
// TODO @puhui999:这个前端字典翻译哈
|
||||
@Schema(description = "客户来源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private String sourceName;
|
||||
|
||||
@ -18,6 +19,8 @@ public class CrmStatisticCustomerSourceRespVO {
|
||||
@Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer dealCount;
|
||||
|
||||
// TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
|
||||
|
||||
@Schema(description = "来源占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Double sourcePortion;
|
||||
|
||||
|
@ -12,11 +12,13 @@ import java.util.List;
|
||||
/**
|
||||
* CRM 数据画像 Mapper
|
||||
*
|
||||
* @author dhb52
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Mapper
|
||||
public interface CrmStatisticsPortraitMapper {
|
||||
|
||||
// TODO @puuhui999:GroupBy
|
||||
|
||||
List<CrmStatisticCustomerIndustryRespVO> selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO);
|
||||
|
||||
List<CrmStatisticCustomerSourceRespVO> selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO);
|
||||
|
@ -21,7 +21,7 @@ public interface CrmStatisticsPortraitService {
|
||||
* @param reqVO 请求参数
|
||||
* @return 统计数据
|
||||
*/
|
||||
List<CrmStatisticCustomerAreaRespVO> getCustomerArea(CrmStatisticsCustomerReqVO reqVO);
|
||||
List<CrmStatisticCustomerAreaRespVO> getCustomerAreaSummary(CrmStatisticsCustomerReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获取客户行业统计数据
|
||||
@ -29,7 +29,7 @@ public interface CrmStatisticsPortraitService {
|
||||
* @param reqVO 请求参数
|
||||
* @return 统计数据
|
||||
*/
|
||||
List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO);
|
||||
List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获取客户级别统计数据
|
||||
@ -37,7 +37,7 @@ public interface CrmStatisticsPortraitService {
|
||||
* @param reqVO 请求参数
|
||||
* @return 统计数据
|
||||
*/
|
||||
List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(CrmStatisticsCustomerReqVO reqVO);
|
||||
List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(CrmStatisticsCustomerReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获取客户来源统计数据
|
||||
@ -45,6 +45,6 @@ public interface CrmStatisticsPortraitService {
|
||||
* @param reqVO 请求参数
|
||||
* @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.module.crm.enums.DictTypeConstants.*;
|
||||
|
||||
// TODO @puhui999:参考 CrmStatisticsCustomerServiceImpl 代码风格,优化下这个类哈;包括命名、空行、注释等;
|
||||
/**
|
||||
* CRM 客户画像 Service 实现类
|
||||
*
|
||||
@ -47,7 +48,37 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
|
||||
private DictDataApi dictDataApi;
|
||||
|
||||
@Override
|
||||
public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO) {
|
||||
public List<CrmStatisticCustomerAreaRespVO> getCustomerAreaSummary(CrmStatisticsCustomerReqVO reqVO) {
|
||||
// 1. 获得用户编号数组
|
||||
List<Long> userIds = getUserIds(reqVO);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
reqVO.setUserIds(userIds);
|
||||
// 2. 获取客户地区统计数据
|
||||
List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListByAreaId(reqVO);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 拼接数据
|
||||
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;
|
||||
}
|
||||
findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName()));
|
||||
return item;
|
||||
});
|
||||
return customerAreaRespVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO) {
|
||||
// 1. 获得用户编号数组
|
||||
List<Long> userIds = getUserIds(reqVO);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
@ -70,13 +101,14 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmStatisticCustomerSourceRespVO> getCustomerSource(CrmStatisticsCustomerReqVO reqVO) {
|
||||
public List<CrmStatisticCustomerSourceRespVO> getCustomerSourceSummary(CrmStatisticsCustomerReqVO reqVO) {
|
||||
// 1. 获得用户编号数组
|
||||
List<Long> userIds = getUserIds(reqVO);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
reqVO.setUserIds(userIds);
|
||||
|
||||
// 2. 获取客户行业统计数据
|
||||
List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO);
|
||||
if (CollUtil.isEmpty(sourceRespVOList)) {
|
||||
@ -93,7 +125,7 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(CrmStatisticsCustomerReqVO reqVO) {
|
||||
public List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(CrmStatisticsCustomerReqVO reqVO) {
|
||||
// 1. 获得用户编号数组
|
||||
List<Long> userIds = getUserIds(reqVO);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
@ -115,35 +147,6 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmStatisticCustomerAreaRespVO> getCustomerArea(CrmStatisticsCustomerReqVO reqVO) {
|
||||
// 1. 获得用户编号数组
|
||||
List<Long> userIds = getUserIds(reqVO);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
reqVO.setUserIds(userIds);
|
||||
// 2. 获取客户地区统计数据
|
||||
List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListByAreaId(reqVO);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 拼接数据
|
||||
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);
|
||||
if (parentId == null) {
|
||||
return item;
|
||||
}
|
||||
findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName()));
|
||||
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">
|
||||
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPortraitMapper">
|
||||
|
||||
<!-- TODO @puhui999:参考 CrmStatisticsCustomerMapper.xml 优化下 SQL 的排版;sql 结尾不用 ; ;XML 之间有空行; -->
|
||||
|
||||
<select id="selectCustomerIndustryListGroupbyIndustryId"
|
||||
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO">
|
||||
SELECT
|
||||
|
Loading…
Reference in New Issue
Block a user