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
This commit is contained in:
YunaiV 2024-05-11 22:07:43 +08:00
commit 95a8aa9ba9
2 changed files with 32 additions and 34 deletions

View File

@ -1,8 +1,7 @@
package cn.iocoder.yudao.module.crm.service.statistics; package cn.iocoder.yudao.module.crm.service.statistics;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; 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;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.time.LocalDateTime;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@ -79,13 +77,17 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
performanceReqVO.setUserIds(userIds); performanceReqVO.setUserIds(userIds);
// 2. 获得业绩数据 // 2. 获得业绩数据
int year = Integer.parseInt(LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy"));//获取查询的年份
LocalDateTime[] timesRange = performanceReqVO.getTimes();//以时间段形式去数据库查询时间段为所查询年份和前一年两年时间的数据便于计算同比数据
timesRange[0] = performanceReqVO.getTimes()[0].minusYears(1);//查询的起始时间往前推一年
timesRange[1] = performanceReqVO.getTimes()[1];//查询的结束时间
performanceReqVO.setTimes(timesRange);
List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO); List<CrmStatisticsPerformanceRespVO> performanceList = performanceFunction.apply(performanceReqVO);
Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime, Map<String, BigDecimal> performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime,
CrmStatisticsPerformanceRespVO::getCurrentMonthCount); CrmStatisticsPerformanceRespVO::getCurrentMonthCount);
// 3. 组装数据返回 // 3. 组装数据返回
List<CrmStatisticsPerformanceRespVO> result = new ArrayList<>(); List<CrmStatisticsPerformanceRespVO> result = new ArrayList<>();
int year = DateUtil.thisYear();
for (int month = 1; month <= 12; month++) { for (int month = 1; month <= 12; month++) {
String currentMonth = String.format("%d%02d", year, month); String currentMonth = String.format("%d%02d", year, month);
String lastMonth = month == 1 ? String.format("%d%02d", year - 1, 12) : String.format("%d%02d", year, month - 1); 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
private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) { private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) {
// 情况一选中某个用户 // 情况一选中某个用户
if (ObjUtil.isNotNull(reqVO.getUserId())) { if (ObjUtil.isNotNull(reqVO.getUserId())) {
return ListUtil.of(reqVO.getUserId()); return List.of(reqVO.getUserId());
} }
// 情况二选中某个部门 // 情况二选中某个部门
// 2.1 获得部门列表 // 2.1 获得部门列表

View File

@ -9,19 +9,16 @@
COUNT(1) AS currentMonthCount COUNT(1) AS currentMonthCount
FROM crm_contract FROM crm_contract
WHERE deleted = 0 WHERE deleted = 0
<!-- TODO @scholar20 改成静态类引入 --> AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND audit_status = 20
AND owner_user_id in AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId} #{userId}
</foreach> </foreach>
<!-- TODO @scholarCrmStatisticsPerformanceReqVO 传递 year然后 java 代码里,转换出 times这样order_time 使用范围查询,避免使用函数 --> AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y') #{times[1],javaType=java.time.LocalDateTime}
or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime}, '%Y') - 1)
GROUP BY time GROUP BY time
</select> </select>
<!-- TODO @scholar参考上面调整下这个 SQL 的排版、和代码建议哈 -->
<select id="selectContractPricePerformance" <select id="selectContractPricePerformance"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
SELECT SELECT
@ -29,17 +26,16 @@
IFNULL(SUM(total_price), 0) AS currentMonthCount IFNULL(SUM(total_price), 0) AS currentMonthCount
FROM crm_contract FROM crm_contract
WHERE deleted = 0 WHERE deleted = 0
AND audit_status = 20 AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND owner_user_id in AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId} #{userId}
</foreach> </foreach>
AND (DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y') AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
or DATE_FORMAT(order_date, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1) #{times[1],javaType=java.time.LocalDateTime}
GROUP BY time GROUP BY time
</select> </select>
<!-- TODO @scholar参考上面调整下这个 SQL 的排版、和代码建议哈 -->
<select id="selectReceivablePricePerformance" <select id="selectReceivablePricePerformance"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
SELECT SELECT
@ -47,13 +43,13 @@
IFNULL(SUM(price), 0) AS currentMonthCount IFNULL(SUM(price), 0) AS currentMonthCount
FROM crm_receivable FROM crm_receivable
WHERE deleted = 0 WHERE deleted = 0
AND audit_status = 20 AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND owner_user_id in AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId} #{userId}
</foreach> </foreach>
AND (DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y') AND return_time between #{times[0],javaType=java.time.LocalDateTime} and
or DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1) #{times[1],javaType=java.time.LocalDateTime}
GROUP BY time GROUP BY time
</select> </select>