crm:code review 员工业绩统计

This commit is contained in:
YunaiV 2024-04-23 23:12:36 +08:00
parent af610c621f
commit 9ab53ee263
2 changed files with 21 additions and 9 deletions

View File

@ -40,7 +40,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
@Override
public List<CrmStatisticsPerformanceRespVO> getContractCountPerformance(CrmStatisticsPerformanceReqVO performanceReqVO) {
// TODO @scholar我们可以换个思路实现减少数据库的计算量
// TODO @scholar可以把下面这个注释你理解后重新整理下写到 getPerformance
// 比如说2024 年的合同数据是不是 2022-12 2024-12-31每个月的统计呢
// 理解之后我们可以数据 group by -20222-12 2024-12-31 然后内存在聚合出 CrmStatisticsPerformanceRespVO 这样
// 这样我们就可以减少数据库的计算量提升性能同时 SQL 也会很简单开发者理解起来也简单哈
@ -57,6 +57,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
return getPerformance(performanceReqVO, performanceMapper::selectReceivablePricePerformance);
}
// TODO @scholar代码注释应该有 3 个变量哈
/**
* 获得员工业绩数据
*
@ -64,9 +65,11 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
* @param performanceFunction 员工业绩统计方法
* @return 员工业绩数据
*/
// TODO @scholar下面一行的变量超过一行了阅读不美观可以考虑每一行一个变量
private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO, Function<CrmStatisticsPerformanceReqVO,
List<CrmStatisticsPerformanceRespVO>> performanceFunction) {
// TODO @scholar没使用到的变量建议删除
List<CrmStatisticsPerformanceRespVO> performanceRespVOList;
// 1. 获得用户编号数组
@ -75,10 +78,15 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
return Collections.emptyList();
}
performanceReqVO.setUserIds(userIds);
// TODO @scholar1. 2. 之间可以考虑换一行保证每一块逻辑的间隔
// 2. 获得业绩数据
// TODO @scholar复数变量建议使用 s 或者 list 结果这里用 performanceList 好列
List<CrmStatisticsPerformanceRespVO> performance = performanceFunction.apply(performanceReqVO);
// 获取查询的年份
// TODO @scholar逻辑可以简化一下
// TODO 1 performance 转换成 mapkey timevalue count
// TODO 2当前年遍历 1-12 月份 map 拿到 count接着月份 -1 map count再年份 -1 count
String currentYear = LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy");
// 构造查询当年和前一年每年12个月的年月组合

View File

@ -5,20 +5,23 @@
<select id="selectContractCountPerformance"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
SELECT
DATE_FORMAT(order_date, '%Y%m') AS time,
COUNT(1) AS currentMonthCount
FROM crm_contract
DATE_FORMAT(order_date, '%Y%m') AS time,
COUNT(1) AS currentMonthCount
FROM crm_contract
WHERE deleted = 0
<!-- TODO @scholar20 改成静态类引入 -->
AND audit_status = 20
AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')
or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1)
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<!-- TODO @scholarCrmStatisticsPerformanceReqVO 传递 year然后 java 代码里,转换出 times这样order_time 使用范围查询,避免使用函数 -->
AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y')
or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y') - 1)
GROUP BY time
</select>
<!-- TODO @scholar参考上面调整下这个 SQL 的排版、和代码建议哈 -->
<select id="selectContractPricePerformance"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
SELECT
@ -36,6 +39,7 @@
GROUP BY time
</select>
<!-- TODO @scholar参考上面调整下这个 SQL 的排版、和代码建议哈 -->
<select id="selectReceivablePricePerformance"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
SELECT