|
|
|
|
@ -3,12 +3,14 @@ package cn.iocoder.yudao.module.crm.service.statistics;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerCountVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper;
|
|
|
|
|
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.dto.DeptRespDTO;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
@ -21,7 +23,8 @@ import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CRM 数据统计 员工客户分析 Service 实现类
|
|
|
|
|
@ -39,6 +42,8 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
|
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
@Resource
|
|
|
|
|
private DeptApi deptApi;
|
|
|
|
|
@Resource
|
|
|
|
|
private DictDataApi dictDataApi;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<CrmStatisticsCustomerCountVO> getTotalCustomerCount(CrmStatisticsCustomerReqVO reqVO) {
|
|
|
|
|
@ -62,6 +67,37 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
|
|
|
|
|
return getStat(reqVO, customerMapper::selectDistinctRecordCountGroupbyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<CrmStatisticsCustomerCountVO> getRecordTypeCount(CrmStatisticsCustomerReqVO reqVO) {
|
|
|
|
|
// 1. 获得用户编号数组: 如果用户编号为空, 则获得部门下的用户编号数组
|
|
|
|
|
if (ObjUtil.isNotNull(reqVO.getUserId())) {
|
|
|
|
|
reqVO.setUserIds(List.of(reqVO.getUserId()));
|
|
|
|
|
} else {
|
|
|
|
|
reqVO.setUserIds(getUserIds(reqVO.getDeptId()));
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isEmpty(reqVO.getUserIds())) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. 获得排行数据
|
|
|
|
|
reqVO.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType());
|
|
|
|
|
List<CrmStatisticsCustomerCountVO> stats = customerMapper.selectRecordCountGroupbyType(reqVO);
|
|
|
|
|
|
|
|
|
|
// 3. 获取字典数据
|
|
|
|
|
List<DictDataRespDTO> followUpTypes = dictDataApi.getDictDataList("crm_follow_up_type");
|
|
|
|
|
final Map<String, String> followUpTypeMap = convertMap(followUpTypes, DictDataRespDTO::getValue, DictDataRespDTO::getLabel);
|
|
|
|
|
stats.forEach(stat -> {
|
|
|
|
|
stat.setCategory(followUpTypeMap.get(stat.getCategory()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<CrmStatisticsCustomerCountVO> getCustomerCycle(CrmStatisticsCustomerReqVO reqVO) {
|
|
|
|
|
return getStat(reqVO, customerMapper::selectCustomerCycleGroupbyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获得统计数据
|
|
|
|
|
*
|
|
|
|
|
@ -98,9 +134,9 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
|
|
|
|
|
|
|
|
|
|
// 4. 生成时间序列
|
|
|
|
|
List<CrmStatisticsCustomerCountVO> result = CollUtil.newArrayList();
|
|
|
|
|
while (startTime.compareTo(endTime) <= 0) {
|
|
|
|
|
while (!startTime.isAfter(endTime)) {
|
|
|
|
|
final String category = LocalDateTimeUtil.format(startTime, byMonth ? "yyyyMM" : "yyyyMMdd");
|
|
|
|
|
result.add(new CrmStatisticsCustomerCountVO().setCategory(category).setCount(0));
|
|
|
|
|
result.add(new CrmStatisticsCustomerCountVO().setCategory(category));
|
|
|
|
|
if (byMonth)
|
|
|
|
|
startTime = startTime.plusMonths(1);
|
|
|
|
|
else
|
|
|
|
|
@ -108,12 +144,13 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5. 使用时间序列填充结果
|
|
|
|
|
final Map<String, Integer> statMap = convertMap(stats,
|
|
|
|
|
CrmStatisticsCustomerCountVO::getCategory,
|
|
|
|
|
CrmStatisticsCustomerCountVO::getCount);
|
|
|
|
|
final Map<String, CrmStatisticsCustomerCountVO> statMap = convertMap(stats,
|
|
|
|
|
CrmStatisticsCustomerCountVO::getCategory,
|
|
|
|
|
Function.identity());
|
|
|
|
|
result.forEach(r -> {
|
|
|
|
|
if (statMap.containsKey(r.getCategory())) {
|
|
|
|
|
r.setCount(statMap.get(r.getCategory()));
|
|
|
|
|
r.setCount(statMap.get(r.getCategory()).getCount())
|
|
|
|
|
.setCycle(statMap.get(r.getCategory()).getCycle());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|