Merge remote-tracking branch 'refs/remotes/yudao/develop' into develop
This commit is contained in:
commit
9a2eb2d02c
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.service.statistics;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
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.CrmStatisticsPerformanceRespVO;
|
||||
@ -13,8 +14,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
@ -38,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 也会很简单,开发者理解起来也简单哈;
|
||||
@ -55,28 +57,99 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
|
||||
return getPerformance(performanceReqVO, performanceMapper::selectReceivablePricePerformance);
|
||||
}
|
||||
|
||||
// TODO @scholar:代码注释,应该有 3 个变量哈;
|
||||
/**
|
||||
* 获得员工业绩数据
|
||||
*
|
||||
* @param performanceReqVO 参数
|
||||
* @param performanceFunction 排行榜方法
|
||||
* @return 排行版数据
|
||||
* @param performanceFunction 员工业绩统计方法
|
||||
* @return 员工业绩数据
|
||||
*/
|
||||
// TODO @scholar:下面一行的变量,超过一行了,阅读不美观;可以考虑每一行一个变量;
|
||||
private List<CrmStatisticsPerformanceRespVO> getPerformance(CrmStatisticsPerformanceReqVO performanceReqVO, Function<CrmStatisticsPerformanceReqVO,
|
||||
List<CrmStatisticsPerformanceRespVO>> performanceFunction) {
|
||||
|
||||
// TODO @scholar:没使用到的变量,建议删除;
|
||||
List<CrmStatisticsPerformanceRespVO> performanceRespVOList;
|
||||
|
||||
// 1. 获得用户编号数组
|
||||
final List<Long> userIds = getUserIds(performanceReqVO);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
performanceReqVO.setUserIds(userIds);
|
||||
// 2. 获得排行数据
|
||||
// TODO @scholar:1. 和 2. 之间,可以考虑换一行;保证每一块逻辑的间隔;
|
||||
// 2. 获得业绩数据
|
||||
// TODO @scholar:复数变量,建议使用 s 或者 list 结果;这里用 performanceList 好列;
|
||||
List<CrmStatisticsPerformanceRespVO> performance = performanceFunction.apply(performanceReqVO);
|
||||
if (CollUtil.isEmpty(performance)) {
|
||||
return Collections.emptyList();
|
||||
|
||||
// 获取查询的年份
|
||||
// TODO @scholar:逻辑可以简化一下;
|
||||
// TODO 1)把 performance 转换成 map;key 是 time,value 是 count
|
||||
// TODO 2)当前年,遍历 1-12 月份,去 map 拿到 count;接着月份 -1,去 map 拿 count;再年份 -1,拿 count
|
||||
String currentYear = LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy");
|
||||
|
||||
// 构造查询当年和前一年,每年12个月的年月组合
|
||||
List<String> allMonths = new ArrayList<>();
|
||||
for (int year = Integer.parseInt(currentYear)-1; year <= Integer.parseInt(currentYear); year++) {
|
||||
for (int month = 1; month <= 12; month++) {
|
||||
allMonths.add(String.format("%d%02d", year, month));
|
||||
}
|
||||
}
|
||||
return performance;
|
||||
|
||||
List<CrmStatisticsPerformanceRespVO> computedList = new ArrayList<>();
|
||||
List<CrmStatisticsPerformanceRespVO> respVOList = new ArrayList<>();
|
||||
|
||||
// 生成computedList基础数据
|
||||
// 构造完整的2*12个月的数据,如果某月数据缺失,需要补上0,一年12个月不能有缺失
|
||||
for (String month : allMonths) {
|
||||
CrmStatisticsPerformanceRespVO foundData = performance.stream()
|
||||
.filter(data -> data.getTime().equals(month))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (foundData != null) {
|
||||
computedList.add(foundData);
|
||||
} else {
|
||||
CrmStatisticsPerformanceRespVO missingData = new CrmStatisticsPerformanceRespVO();
|
||||
missingData.setTime(month);
|
||||
missingData.setCurrentMonthCount(BigDecimal.ZERO);
|
||||
missingData.setLastMonthCount(BigDecimal.ZERO);
|
||||
missingData.setLastYearCount(BigDecimal.ZERO);
|
||||
computedList.add(missingData);
|
||||
}
|
||||
}
|
||||
//根据查询年份和前一年的数据,计算查询年份的同比环比数据
|
||||
for (CrmStatisticsPerformanceRespVO currentData : computedList) {
|
||||
String currentMonth = currentData.getTime();
|
||||
|
||||
// 根据当年和前一年的月销售数据,计算currentYear的完整数据
|
||||
if (currentMonth.startsWith(currentYear)) {
|
||||
// 计算 LastMonthCount
|
||||
int currentIndex = computedList.indexOf(currentData);
|
||||
if (currentIndex > 0) {
|
||||
CrmStatisticsPerformanceRespVO lastMonthData = computedList.get(currentIndex - 1);
|
||||
currentData.setLastMonthCount(lastMonthData.getCurrentMonthCount());
|
||||
} else {
|
||||
currentData.setLastMonthCount(BigDecimal.ZERO); // 第一个月的 LastMonthCount 设为0
|
||||
}
|
||||
|
||||
// 计算 LastYearCount
|
||||
String lastYearMonth = String.valueOf(Integer.parseInt(currentMonth) - 100);
|
||||
CrmStatisticsPerformanceRespVO lastYearData = computedList.stream()
|
||||
.filter(data -> data.getTime().equals(lastYearMonth))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (lastYearData != null) {
|
||||
currentData.setLastYearCount(lastYearData.getCurrentMonthCount());
|
||||
} else {
|
||||
currentData.setLastYearCount(BigDecimal.ZERO); // 如果去年同月数据不存在,设为0
|
||||
}
|
||||
respVOList.add(currentData);//给前端只需要返回查询当年的数据,不需要前一年数据
|
||||
}
|
||||
}
|
||||
return respVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,75 +5,28 @@
|
||||
<select id="selectContractCountPerformance"
|
||||
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
|
||||
SELECT
|
||||
t.time as time,
|
||||
COALESCE(t.currentMonthCount,0) as currentMonthCount,
|
||||
COALESCE(y.lastMonthCount,0) as lastMonthCount,
|
||||
COALESCE(z.lastYearCount,0) as lastYearCount
|
||||
FROM
|
||||
(SELECT
|
||||
COUNT(1) AS currentMonthCount,
|
||||
DATE_FORMAT(order_date, '%Y-%m') AS time
|
||||
FROM crm_contract
|
||||
DATE_FORMAT(order_date, '%Y%m') AS time,
|
||||
COUNT(1) AS currentMonthCount
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
<!-- TODO @scholar:20 改成静态类引入 -->
|
||||
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')
|
||||
GROUP BY time)t
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
COUNT(1) AS lastMonthCount,
|
||||
DATE_FORMAT(DATE_ADD(order_date,INTERVAL 1 MONTH), '%Y-%m') AS time
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
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)
|
||||
GROUP BY time)y ON t.time = y.time
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
COUNT(1) AS lastYearCount,
|
||||
DATE_FORMAT(DATE_ADD(order_date,INTERVAL 1 YEAR), '%Y-%m') AS time
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
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')-1
|
||||
GROUP BY time)z ON t.time = z.time
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
<!-- TODO @scholar:CrmStatisticsPerformanceReqVO 传递 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
|
||||
t.time as time,
|
||||
COALESCE(t.currentMonthCount,0) as currentMonthCount,
|
||||
COALESCE(y.lastMonthCount,0) as lastMonthCount,
|
||||
COALESCE(z.lastYearCount,0) as lastYearCount
|
||||
FROM
|
||||
(SELECT
|
||||
IFNULL(SUM(total_price), 0) AS currentMonthCount,
|
||||
DATE_FORMAT(order_date, '%Y-%m') AS time
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
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')
|
||||
GROUP BY time)t
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
IFNULL(SUM(total_price), 0) AS lastMonthCount,
|
||||
DATE_FORMAT(DATE_ADD(order_date,INTERVAL 1 MONTH), '%Y-%m') AS time
|
||||
DATE_FORMAT(order_date, '%Y%m') AS time,
|
||||
IFNULL(SUM(total_price), 0) AS currentMonthCount
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
AND audit_status = 20
|
||||
@ -83,46 +36,15 @@
|
||||
</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)
|
||||
GROUP BY time)y ON t.time = y.time
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
IFNULL(SUM(total_price), 0) AS lastYearCount,
|
||||
DATE_FORMAT(DATE_ADD(order_date,INTERVAL 1 YEAR), '%Y-%m') AS time
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
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')-1
|
||||
GROUP BY time)z ON t.time = z.time
|
||||
GROUP BY time
|
||||
</select>
|
||||
|
||||
<!-- TODO @scholar:参考上面,调整下这个 SQL 的排版、和代码建议哈 -->
|
||||
<select id="selectReceivablePricePerformance"
|
||||
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO">
|
||||
SELECT
|
||||
t.time as time,
|
||||
COALESCE(t.currentMonthCount,0) as currentMonthCount,
|
||||
COALESCE(y.lastMonthCount,0) as lastMonthCount,
|
||||
COALESCE(z.lastYearCount,0) as lastYearCount
|
||||
FROM
|
||||
(SELECT
|
||||
IFNULL(SUM(price), 0) AS currentMonthCount,
|
||||
DATE_FORMAT(return_time, '%Y-%m') AS time
|
||||
FROM crm_receivable
|
||||
WHERE deleted = 0
|
||||
AND audit_status = 20
|
||||
AND owner_user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
AND DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')
|
||||
GROUP BY time)t
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
IFNULL(SUM(price), 0) AS lastMonthCount,
|
||||
DATE_FORMAT(DATE_ADD(return_time,INTERVAL 1 MONTH), '%Y-%m') AS time
|
||||
DATE_FORMAT(return_time, '%Y%m') AS time,
|
||||
IFNULL(SUM(price), 0) AS currentMonthCount
|
||||
FROM crm_receivable
|
||||
WHERE deleted = 0
|
||||
AND audit_status = 20
|
||||
@ -132,21 +54,7 @@
|
||||
</foreach>
|
||||
AND (DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')
|
||||
or DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1)
|
||||
GROUP BY time)y ON t.time = y.time
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
IFNULL(SUM(price), 0) AS lastYearCount,
|
||||
DATE_FORMAT(DATE_ADD(return_time,INTERVAL 1 YEAR), '%Y-%m') AS time
|
||||
FROM crm_receivable
|
||||
WHERE deleted = 0
|
||||
AND audit_status = 20
|
||||
AND owner_user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
AND DATE_FORMAT(return_time, '%Y') = DATE_FORMAT(#{times[0],javaType=java.time.LocalDateTime},'%Y')-1
|
||||
GROUP BY time)z ON t.time = z.time
|
||||
GROUP BY time
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -88,7 +88,7 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla
|
||||
List<DeliveryExpressTemplateFreeDO> oldList = expressTemplateFreeMapper.selectListByTemplateId(templateId);
|
||||
List<DeliveryExpressTemplateFreeDO> newList = INSTANCE.convertTemplateFreeList(templateId, frees);
|
||||
List<List<DeliveryExpressTemplateFreeDO>> diffList = CollectionUtils.diffList(oldList, newList,
|
||||
(oldVal, newVal) -> ObjectUtil.equal(oldVal.getId(), newVal.getTemplateId()));
|
||||
(oldVal, newVal) -> ObjectUtil.equal(oldVal.getId(), newVal.getId()));
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
|
@ -36,13 +36,15 @@ public class PayWalletServiceImpl implements PayWalletService {
|
||||
|
||||
@Resource
|
||||
private PayWalletMapper walletMapper;
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private PayWalletTransactionService walletTransactionService;
|
||||
@Resource
|
||||
@Lazy
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private PayOrderService orderService;
|
||||
@Resource
|
||||
@Lazy
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private PayRefundService refundService;
|
||||
|
||||
@Override
|
||||
|
@ -198,6 +198,16 @@ justauth:
|
||||
client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw
|
||||
agent-id: 1000004
|
||||
ignore-check-redirect-uri: true
|
||||
# noinspection SpringBootApplicationYaml
|
||||
WECHAT_MINI_APP: # 微信小程序
|
||||
client-id: ${wx.miniapp.appid}
|
||||
client-secret: ${wx.miniapp.secret}
|
||||
ignore-check-redirect-uri: true
|
||||
ignore-check-state: true # 微信小程序,不会使用到 state,所以不进行校验
|
||||
WECHAT_MP: # 微信公众号
|
||||
client-id: ${wx.mp.app-id}
|
||||
client-secret: ${wx.mp.secret}
|
||||
ignore-check-redirect-uri: true
|
||||
cache:
|
||||
type: REDIS
|
||||
prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::
|
||||
|
@ -254,6 +254,7 @@ justauth:
|
||||
client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw
|
||||
agent-id: 1000004
|
||||
ignore-check-redirect-uri: true
|
||||
# noinspection SpringBootApplicationYaml
|
||||
WECHAT_MINI_APP: # 微信小程序
|
||||
client-id: ${wx.miniapp.appid}
|
||||
client-secret: ${wx.miniapp.secret}
|
||||
|
Loading…
Reference in New Issue
Block a user