Commit 9ab53ee2637a8e04a2134642b62421c879e5d779
1 parent
af610c62
crm:code review 员工业绩统计
Showing
2 changed files
with
21 additions
and
9 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
| ... | ... | @@ -40,7 +40,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 40 | 40 | |
| 41 | 41 | @Override |
| 42 | 42 | public List<CrmStatisticsPerformanceRespVO> getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) { |
| 43 | - // TODO @scholar:我们可以换个思路实现,减少数据库的计算量; | |
| 43 | + // TODO @scholar:可以把下面这个注释,你理解后,重新整理下,写到 getPerformance 里; | |
| 44 | 44 | // 比如说,2024 年的合同数据,是不是 2022-12 到 2024-12-31,每个月的统计呢? |
| 45 | 45 | // 理解之后,我们可以数据 group by 年-月,20222-12 到 2024-12-31 的,然后内存在聚合出 CrmStatisticsPerformanceRespVO 这样 |
| 46 | 46 | // 这样,我们就可以减少数据库的计算量,提升性能;同时 SQL 也会很简单,开发者理解起来也简单哈; |
| ... | ... | @@ -57,6 +57,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 57 | 57 | return getPerformance(performanceReqVO, performanceMapper::selectReceivablePricePerformance); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | + // TODO @scholar:代码注释,应该有 3 个变量哈; | |
| 60 | 61 | /** |
| 61 | 62 | * 获得员工业绩数据 |
| 62 | 63 | * |
| ... | ... | @@ -64,9 +65,11 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 64 | 65 | * @param performanceFunction 员工业绩统计方法 |
| 65 | 66 | * @return 员工业绩数据 |
| 66 | 67 | */ |
| 68 | + // TODO @scholar:下面一行的变量,超过一行了,阅读不美观;可以考虑每一行一个变量; | |
| 67 | 69 | private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO, Function<CrmStatisticsPerformanceReqVO, |
| 68 | 70 | List<CrmStatisticsPerformanceRespVO>> performanceFunction) { |
| 69 | 71 | |
| 72 | + // TODO @scholar:没使用到的变量,建议删除; | |
| 70 | 73 | List<CrmStatisticsPerformanceRespVO> performanceRespVOList; |
| 71 | 74 | |
| 72 | 75 | // 1. 获得用户编号数组 |
| ... | ... | @@ -75,10 +78,15 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform |
| 75 | 78 | return Collections.emptyList(); |
| 76 | 79 | } |
| 77 | 80 | performanceReqVO.setUserIds(userIds); |
| 81 | + // TODO @scholar:1. 和 2. 之间,可以考虑换一行;保证每一块逻辑的间隔; | |
| 78 | 82 | // 2. 获得业绩数据 |
| 83 | + // TODO @scholar:复数变量,建议使用 s 或者 list 结果;这里用 performanceList 好列; | |
| 79 | 84 | List<CrmStatisticsPerformanceRespVO> performance = performanceFunction.apply(performanceReqVO); |
| 80 | 85 | |
| 81 | 86 | // 获取查询的年份 |
| 87 | + // TODO @scholar:逻辑可以简化一下; | |
| 88 | + // TODO 1)把 performance 转换成 map;key 是 time,value 是 count | |
| 89 | + // TODO 2)当前年,遍历 1-12 月份,去 map 拿到 count;接着月份 -1,去 map 拿 count;再年份 -1,拿 count | |
| 82 | 90 | String currentYear = LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy"); |
| 83 | 91 | |
| 84 | 92 | // 构造查询当年和前一年,每年12个月的年月组合 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPerformanceMapper.xml
| ... | ... | @@ -5,20 +5,23 @@ |
| 5 | 5 | <select id="selectContractCountPerformance" |
| 6 | 6 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> |
| 7 | 7 | SELECT |
| 8 | - DATE_FORMAT(order_date, '%Y%m') AS time, | |
| 9 | - COUNT(1) AS currentMonthCount | |
| 10 | - FROM crm_contract | |
| 8 | + DATE_FORMAT(order_date, '%Y%m') AS time, | |
| 9 | + COUNT(1) AS currentMonthCount | |
| 10 | + FROM crm_contract | |
| 11 | 11 | WHERE deleted = 0 |
| 12 | + <!-- TODO @scholar:20 改成静态类引入 --> | |
| 12 | 13 | AND audit_status = 20 |
| 13 | 14 | AND owner_user_id in |
| 14 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | |
| 15 | - #{userId} | |
| 16 | - </foreach> | |
| 17 | - AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y') | |
| 18 | - or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1) | |
| 15 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | |
| 16 | + #{userId} | |
| 17 | + </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) | |
| 19 | 21 | GROUP BY time |
| 20 | 22 | </select> |
| 21 | 23 | |
| 24 | + <!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 --> | |
| 22 | 25 | <select id="selectContractPricePerformance" |
| 23 | 26 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> |
| 24 | 27 | SELECT |
| ... | ... | @@ -36,6 +39,7 @@ |
| 36 | 39 | GROUP BY time |
| 37 | 40 | </select> |
| 38 | 41 | |
| 42 | + <!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 --> | |
| 39 | 43 | <select id="selectReceivablePricePerformance" |
| 40 | 44 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> |
| 41 | 45 | SELECT | ... | ... |