【代码评审】CRM:优化员工业绩统计的实现

This commit is contained in:
YunaiV 2024-05-11 22:30:37 +08:00
parent 95a8aa9ba9
commit 4a0ad205ae
3 changed files with 10 additions and 14 deletions

View File

@ -33,7 +33,6 @@ public class CrmStatisticsPerformanceReqVO {
@Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2") @Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2")
private List<Long> userIds; private List<Long> userIds;
// TODO @scholar应该传递的是 int year年份
@Schema(description = "时间范围", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.REQUIRED)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@NotEmpty(message = "时间范围不能为空") @NotEmpty(message = "时间范围不能为空")

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.crm.service.statistics; package cn.iocoder.yudao.module.crm.service.statistics;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO;
@ -10,14 +9,16 @@ 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.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@ -40,7 +41,6 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
@Resource @Resource
private DeptApi deptApi; private DeptApi deptApi;
@Override @Override
public List<CrmStatisticsPerformanceRespVO> getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) { public List<CrmStatisticsPerformanceRespVO> getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) {
return getPerformance(performanceReqVO, performanceMapper::selectContractCountPerformance); return getPerformance(performanceReqVO, performanceMapper::selectContractCountPerformance);
@ -77,11 +77,8 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
performanceReqVO.setUserIds(userIds); performanceReqVO.setUserIds(userIds);
// 2. 获得业绩数据 // 2. 获得业绩数据
int year = Integer.parseInt(LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy"));//获取查询的年份 int year = performanceReqVO.getTimes()[0].getYear(); // 获取查询的年份
LocalDateTime[] timesRange = performanceReqVO.getTimes();//以时间段形式去数据库查询时间段为所查询年份和前一年两年时间的数据便于计算同比数据 performanceReqVO.getTimes()[0] = performanceReqVO.getTimes()[0].minusYears(1);
timesRange[0] = performanceReqVO.getTimes()[0].minusYears(1);//查询的起始时间往前推一年
timesRange[1] = performanceReqVO.getTimes()[1];//查询的结束时间
performanceReqVO.setTimes(timesRange);
List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO); List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO);
Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime, Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime,
CrmStatisticsPerformanceRespVO::getCurrentMonthCount); CrmStatisticsPerformanceRespVO::getCurrentMonthCount);

View File

@ -7,7 +7,7 @@
SELECT SELECT
DATE_FORMAT(order_date, '%Y%m') AS time, DATE_FORMAT(order_date, '%Y%m') AS time,
COUNT(1) AS currentMonthCount COUNT(1) AS currentMonthCount
FROM crm_contract FROM crm_contract
WHERE deleted = 0 WHERE deleted = 0
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND owner_user_id in AND owner_user_id in
@ -24,7 +24,7 @@
SELECT SELECT
DATE_FORMAT(order_date, '%Y%m') AS time, DATE_FORMAT(order_date, '%Y%m') AS time,
IFNULL(SUM(total_price), 0) AS currentMonthCount IFNULL(SUM(total_price), 0) AS currentMonthCount
FROM crm_contract FROM crm_contract
WHERE deleted = 0 WHERE deleted = 0
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND owner_user_id in AND owner_user_id in
@ -41,7 +41,7 @@
SELECT SELECT
DATE_FORMAT(return_time, '%Y%m') AS time, DATE_FORMAT(return_time, '%Y%m') AS time,
IFNULL(SUM(price), 0) AS currentMonthCount IFNULL(SUM(price), 0) AS currentMonthCount
FROM crm_receivable FROM crm_receivable
WHERE deleted = 0 WHERE deleted = 0
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND owner_user_id in AND owner_user_id in