Commit 95a8aa9ba9b9a2ee21b2185d031995d4c3c97cd1

Authored by YunaiV
2 parents e1a5302b 99ab07de

Merge branch 'develop' of https://gitee.com/scholarli/ruoyi-vue-pro_1 into develop

# Conflicts:
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
#	yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
1 package cn.iocoder.yudao.module.crm.service.statistics; 1 package cn.iocoder.yudao.module.crm.service.statistics;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 -import cn.hutool.core.collection.ListUtil;  
5 -import cn.hutool.core.date.DateUtil; 4 +import cn.hutool.core.date.LocalDateTimeUtil;
6 import cn.hutool.core.util.ObjUtil; 5 import cn.hutool.core.util.ObjUtil;
7 import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; 6 import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO;
8 import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; 7 import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO;
@@ -11,15 +10,14 @@ import cn.iocoder.yudao.module.system.api.dept.DeptApi; @@ -11,15 +10,14 @@ import cn.iocoder.yudao.module.system.api.dept.DeptApi;
11 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; 10 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
12 import cn.iocoder.yudao.module.system.api.user.AdminUserApi; 11 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
13 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; 12 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
14 -import jakarta.annotation.Resource;  
15 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
16 import org.springframework.validation.annotation.Validated; 14 import org.springframework.validation.annotation.Validated;
17 15
  16 +import jakarta.annotation.Resource;
  17 +
18 import java.math.BigDecimal; 18 import java.math.BigDecimal;
19 -import java.util.ArrayList;  
20 -import java.util.Collections;  
21 -import java.util.List;  
22 -import java.util.Map; 19 +import java.time.LocalDateTime;
  20 +import java.util.*;
23 import java.util.function.Function; 21 import java.util.function.Function;
24 22
25 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; 23 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@@ -69,7 +67,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform @@ -69,7 +67,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
69 * @return 员工业绩数据 67 * @return 员工业绩数据
70 */ 68 */
71 private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO, 69 private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO,
72 - Function<CrmStatisticsPerformanceReqVO, List<CrmStatisticsPerformanceRespVO>> performanceFunction) { 70 + Function<CrmStatisticsPerformanceReqVO, List<CrmStatisticsPerformanceRespVO>> performanceFunction) {
73 71
74 // 1. 获得用户编号数组 72 // 1. 获得用户编号数组
75 List<Long> userIds = getUserIds(performanceReqVO); 73 List<Long> userIds = getUserIds(performanceReqVO);
@@ -79,13 +77,17 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform @@ -79,13 +77,17 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
79 performanceReqVO.setUserIds(userIds); 77 performanceReqVO.setUserIds(userIds);
80 78
81 // 2. 获得业绩数据 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);
82 List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO); 85 List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO);
83 Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime, 86 Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime,
84 CrmStatisticsPerformanceRespVO::getCurrentMonthCount); 87 CrmStatisticsPerformanceRespVO::getCurrentMonthCount);
85 88
86 // 3. 组装数据返回 89 // 3. 组装数据返回
87 List<CrmStatisticsPerformanceRespVO> result = new ArrayList<>(); 90 List<CrmStatisticsPerformanceRespVO> result = new ArrayList<>();
88 - int year = DateUtil.thisYear();  
89 for (int month = 1; month <= 12; month++) { 91 for (int month = 1; month <= 12; month++) {
90 String currentMonth = String.format("%d%02d", year, month); 92 String currentMonth = String.format("%d%02d", year, month);
91 String lastMonth = month == 1 ? String.format("%d%02d", year - 1, 12) : String.format("%d%02d", year, month - 1); 93 String lastMonth = month == 1 ? String.format("%d%02d", year - 1, 12) : String.format("%d%02d", year, month - 1);
@@ -107,7 +109,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform @@ -107,7 +109,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
107 private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) { 109 private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) {
108 // 情况一:选中某个用户 110 // 情况一:选中某个用户
109 if (ObjUtil.isNotNull(reqVO.getUserId())) { 111 if (ObjUtil.isNotNull(reqVO.getUserId())) {
110 - return ListUtil.of(reqVO.getUserId()); 112 + return List.of(reqVO.getUserId());
111 } 113 }
112 // 情况二:选中某个部门 114 // 情况二:选中某个部门
113 // 2.1 获得部门列表 115 // 2.1 获得部门列表
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml
@@ -7,53 +7,49 @@ @@ -7,53 +7,49 @@
7 SELECT 7 SELECT
8 DATE_FORMAT(order_date, '%Y%m') AS time, 8 DATE_FORMAT(order_date, '%Y%m') AS time,
9 COUNT(1) AS currentMonthCount 9 COUNT(1) AS currentMonthCount
10 - FROM crm_contract 10 + FROM crm_contract
11 WHERE deleted = 0 11 WHERE deleted = 0
12 - <!-- TODO @scholar:20 改成静态类引入 -->  
13 - AND audit_status = 20 12 + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
14 AND owner_user_id in 13 AND owner_user_id in
15 <foreach collection="userIds" item="userId" open="(" close=")" separator=","> 14 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
16 #{userId} 15 #{userId}
17 </foreach> 16 </foreach>
18 - <!-- TODO @scholar:CrmStatisticsPerformanceReqVO 传递 year,然后 java 代码里,转换出 times;这样,order_time 使用范围查询,避免使用函数 -->  
19 - AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y')  
20 - or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y') - 1) 17 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  18 + #{times[1],javaType=java.time.LocalDateTime}
21 GROUP BY time 19 GROUP BY time
22 </select> 20 </select>
23 21
24 - <!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 -->  
25 <select id="selectContractPricePerformance" 22 <select id="selectContractPricePerformance"
26 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> 23 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
27 SELECT 24 SELECT
28 - DATE_FORMAT(order_date, '%Y%m') AS time,  
29 - IFNULL(SUM(total_price), 0) AS currentMonthCount 25 + DATE_FORMAT(order_date, '%Y%m') AS time,
  26 + IFNULL(SUM(total_price), 0) AS currentMonthCount
30 FROM crm_contract 27 FROM crm_contract
31 WHERE deleted = 0 28 WHERE deleted = 0
32 - AND audit_status = 20 29 + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
33 AND owner_user_id in 30 AND owner_user_id in
34 - <foreach collection="userIds" item="userId" open="(" close=")" separator=",">  
35 - #{userId}  
36 - </foreach>  
37 - AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')  
38 - or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1) 31 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  32 + #{userId}
  33 + </foreach>
  34 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  35 + #{times[1],javaType=java.time.LocalDateTime}
39 GROUP BY time 36 GROUP BY time
40 </select> 37 </select>
41 38
42 - <!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 -->  
43 <select id="selectReceivablePricePerformance" 39 <select id="selectReceivablePricePerformance"
44 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> 40 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
45 SELECT 41 SELECT
46 - DATE_FORMAT(return_time, '%Y%m') AS time,  
47 - IFNULL(SUM(price), 0) AS currentMonthCount 42 + DATE_FORMAT(return_time, '%Y%m') AS time,
  43 + IFNULL(SUM(price), 0) AS currentMonthCount
48 FROM crm_receivable 44 FROM crm_receivable
49 WHERE deleted = 0 45 WHERE deleted = 0
50 - AND audit_status = 20 46 + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
51 AND owner_user_id in 47 AND owner_user_id in
52 - <foreach collection="userIds" item="userId" open="(" close=")" separator=",">  
53 - #{userId}  
54 - </foreach>  
55 - AND (DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')  
56 - or DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1) 48 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  49 + #{userId}
  50 + </foreach>
  51 + AND return_time between #{times[0],javaType=java.time.LocalDateTime} and
  52 + #{times[1],javaType=java.time.LocalDateTime}
57 GROUP BY time 53 GROUP BY time
58 </select> 54 </select>
59 55