|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/**
|