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