Эх сурвалжийг харах

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

YunaiV 1 жил өмнө
parent
commit
3f5724e978
9 өөрчлөгдсөн 69 нэмэгдсэн , 49 устгасан
  1. 12 10
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java
  2. 2 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java
  3. 3 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java
  4. 4 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java
  5. 4 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java
  6. 3 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java
  7. 4 4
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java
  8. 35 32
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java
  9. 2 0
      yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml

+ 12 - 10
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java

@@ -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));
     }
 
 }

+ 2 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java

@@ -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;
 

+ 3 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java

@@ -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;
 

+ 4 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java

@@ -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;
 

+ 4 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java

@@ -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;
 

+ 3 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java

@@ -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);

+ 4 - 4
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java

@@ -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);
 
 }

+ 35 - 32
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java

@@ -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,30 +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<CrmStatisticCustomerIndustryRespVO> industryRespVOList = portraitMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO);
-        if (CollUtil.isEmpty(industryRespVOList)) {
+        // 2. 获取客户地区统计数据
+        List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListByAreaId(reqVO);
+        if (CollUtil.isEmpty(list)) {
             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;
             }
-            item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId()));
+            findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName()));
             return item;
         });
+        return customerAreaRespVOList;
     }
 
     @Override
-    public List<CrmStatisticCustomerSourceRespVO> getCustomerSource(CrmStatisticsCustomerReqVO reqVO) {
+    public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO) {
         // 1. 获得用户编号数组
         List<Long> userIds = getUserIds(reqVO);
         if (CollUtil.isEmpty(userIds)) {
@@ -78,70 +86,65 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
         }
         reqVO.setUserIds(userIds);
         // 2. 获取客户行业统计数据
-        List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO);
-        if (CollUtil.isEmpty(sourceRespVOList)) {
+        List<CrmStatisticCustomerIndustryRespVO> industryRespVOList = portraitMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO);
+        if (CollUtil.isEmpty(industryRespVOList)) {
             return Collections.emptyList();
         }
 
-        return convertList(sourceRespVOList, item -> {
-            if (ObjUtil.isNull(item.getSource())) {
+        return convertList(industryRespVOList, item -> {
+            if (ObjUtil.isNull(item.getIndustryId())) {
                 return item;
             }
-            item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource()));
+            item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId()));
             return item;
         });
     }
 
     @Override
-    public List<CrmStatisticCustomerLevelRespVO> getCustomerLevel(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<CrmStatisticCustomerLevelRespVO> levelRespVOList = portraitMapper.selectCustomerLevelListGroupbyLevel(reqVO);
-        if (CollUtil.isEmpty(levelRespVOList)) {
+        List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO);
+        if (CollUtil.isEmpty(sourceRespVOList)) {
             return Collections.emptyList();
         }
 
-        return convertList(levelRespVOList, item -> {
-            if (ObjUtil.isNull(item.getLevel())) {
+        return convertList(sourceRespVOList, item -> {
+            if (ObjUtil.isNull(item.getSource())) {
                 return item;
             }
-            item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel()));
+            item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource()));
             return item;
         });
     }
 
     @Override
-    public List<CrmStatisticCustomerAreaRespVO> getCustomerArea(CrmStatisticsCustomerReqVO reqVO) {
+    public List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(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)) {
+        // 2. 获取客户行业统计数据
+        List<CrmStatisticCustomerLevelRespVO> levelRespVOList = portraitMapper.selectCustomerLevelListGroupbyLevel(reqVO);
+        if (CollUtil.isEmpty(levelRespVOList)) {
             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 convertList(levelRespVOList, item -> {
+            if (ObjUtil.isNull(item.getLevel())) {
                 return item;
             }
-            findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName()));
+            item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel()));
             return item;
         });
-        return customerAreaRespVOList;
     }
 
     /**

+ 2 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml

@@ -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