Commit 4a0ad205ae13ba7ca104dc5b75723a4d6b1a37f9
1 parent
95a8aa9b
【代码评审】CRM:优化员工业绩统计的实现
Showing
3 changed files
with
10 additions
and
14 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/performance/CrmStatisticsPerformanceReqVO.java
| ... | ... | @@ -33,7 +33,6 @@ public class CrmStatisticsPerformanceReqVO { |
| 33 | 33 | @Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2") |
| 34 | 34 | private List<Long> userIds; |
| 35 | 35 | |
| 36 | - // TODO @scholar:应该传递的是 int year;年份 | |
| 37 | 36 | @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.REQUIRED) |
| 38 | 37 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 39 | 38 | @NotEmpty(message = "时间范围不能为空") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.statistics; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.date.LocalDateTimeUtil; | |
| 5 | 4 | import cn.hutool.core.util.ObjUtil; |
| 6 | 5 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; |
| 7 | 6 | 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; |
| 10 | 9 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| 11 | 10 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 12 | 11 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 12 | +import jakarta.annotation.Resource; | |
| 13 | 13 | import org.springframework.stereotype.Service; |
| 14 | 14 | import org.springframework.validation.annotation.Validated; |
| 15 | 15 | |
| 16 | -import jakarta.annotation.Resource; | |
| 17 | - | |
| 18 | 16 | import java.math.BigDecimal; |
| 19 | 17 | import java.time.LocalDateTime; |
| 20 | -import java.util.*; | |
| 18 | +import java.util.ArrayList; | |
| 19 | +import java.util.Collections; | |
| 20 | +import java.util.List; | |
| 21 | +import java.util.Map; | |
| 21 | 22 | import java.util.function.Function; |
| 22 | 23 | |
| 23 | 24 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| ... | ... | @@ -40,7 +41,6 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 40 | 41 | @Resource |
| 41 | 42 | private DeptApi deptApi; |
| 42 | 43 | |
| 43 | - | |
| 44 | 44 | @Override |
| 45 | 45 | public List<CrmStatisticsPerformanceRespVO> getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) { |
| 46 | 46 | return getPerformance(performanceReqVO, performanceMapper::selectContractCountPerformance); |
| ... | ... | @@ -77,11 +77,8 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 77 | 77 | performanceReqVO.setUserIds(userIds); |
| 78 | 78 | |
| 79 | 79 | // 2. 获得业绩数据 |
| 80 | - int year = Integer.parseInt(LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy"));//获取查询的年份 | |
| 81 | - LocalDateTime[] timesRange = performanceReqVO.getTimes();//以时间段形式去数据库查询,时间段为所查询年份和前一年,两年时间的数据,便于计算同比数据 | |
| 82 | - timesRange[0] = performanceReqVO.getTimes()[0].minusYears(1);//查询的起始时间往前推一年 | |
| 83 | - timesRange[1] = performanceReqVO.getTimes()[1];//查询的结束时间 | |
| 84 | - performanceReqVO.setTimes(timesRange); | |
| 80 | + int year = performanceReqVO.getTimes()[0].getYear(); // 获取查询的年份 | |
| 81 | + performanceReqVO.getTimes()[0] = performanceReqVO.getTimes()[0].minusYears(1); | |
| 85 | 82 | List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO); |
| 86 | 83 | Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime, |
| 87 | 84 | CrmStatisticsPerformanceRespVO::getCurrentMonthCount); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | SELECT |
| 8 | 8 | DATE_FORMAT(order_date, '%Y%m') AS time, |
| 9 | 9 | COUNT(1) AS currentMonthCount |
| 10 | - FROM crm_contract | |
| 10 | + FROM crm_contract | |
| 11 | 11 | WHERE deleted = 0 |
| 12 | 12 | AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} |
| 13 | 13 | AND owner_user_id in |
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | SELECT |
| 25 | 25 | DATE_FORMAT(order_date, '%Y%m') AS time, |
| 26 | 26 | IFNULL(SUM(total_price), 0) AS currentMonthCount |
| 27 | - FROM crm_contract | |
| 27 | + FROM crm_contract | |
| 28 | 28 | WHERE deleted = 0 |
| 29 | 29 | AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} |
| 30 | 30 | AND owner_user_id in |
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | SELECT |
| 42 | 42 | DATE_FORMAT(return_time, '%Y%m') AS time, |
| 43 | 43 | IFNULL(SUM(price), 0) AS currentMonthCount |
| 44 | - FROM crm_receivable | |
| 44 | + FROM crm_receivable | |
| 45 | 45 | WHERE deleted = 0 |
| 46 | 46 | AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} |
| 47 | 47 | AND owner_user_id in | ... | ... |