From 52c86cd290d22bea92dcddf9ea6569b5c6c9d056 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 7 May 2024 23:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91CRM?= =?UTF-8?q?=EF=BC=9A=E5=91=98=E5=B7=A5=E4=B8=9A=E7=BB=A9=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +- .../CrmStatisticsPerformanceServiceImpl.java | 91 ++++++------------- yudao-server/pom.xml | 20 ++-- 3 files changed, 38 insertions(+), 77 deletions(-) diff --git a/pom.xml b/pom.xml index e770c0359..b1bc573e8 100644 --- a/pom.xml +++ b/pom.xml @@ -16,12 +16,12 @@ yudao-module-system yudao-module-infra - + yudao-module-bpm - + yudao-module-crm diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java index 6679a4500..77b14a268 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.crm.service.statistics; 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.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; @@ -11,16 +11,19 @@ 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.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; - import java.math.BigDecimal; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; 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.convertMap; /** * CRM 员工业绩分析 Service 实现类 @@ -56,9 +59,11 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform } /** - * 获得员工业绩数据,并通过如下方法拿到对应的lastYearCount,lastMonthCount - * 比如说,构造2024 年的CrmStatisticsPerformanceRespVO,获得 2023-01 到 2024-12的月统计数据即可 - * 可以数据 group by 年-月,2023-01 到 2024-12的,然后聚合出 CrmStatisticsPerformanceRespVO + * 获得员工业绩数据 + * + * 1. 获得今年 + 去年的数据 + * 2. 遍历今年的月份,逐个拼接去年的月份数据 + * * @param performanceReqVO 参数 * @param performanceFunction 员工业绩统计方法 * @return 员工业绩数据 @@ -67,7 +72,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform Function> performanceFunction) { // 1. 获得用户编号数组 - final List userIds = getUserIds(performanceReqVO); + List userIds = getUserIds(performanceReqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } @@ -75,66 +80,22 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform // 2. 获得业绩数据 List performanceList = performanceFunction.apply(performanceReqVO); + Map performanceMap = convertMap(performanceList, CrmStatisticsPerformanceRespVO::getTime, + CrmStatisticsPerformanceRespVO::getCurrentMonthCount); - // 获取查询的年份 - String currentYear = LocalDateTimeUtil.format(performanceReqVO.getTimes()[0],"yyyy"); - Map currentYearMap = new TreeMap<>();//查询当年的map数据 - Map lastYearMap = new TreeMap<>();//前一年的map数据 - + // 3. 组装数据返回 + List result = new ArrayList<>(); + int year = DateUtil.thisYear(); for (int month = 1; month <= 12; month++) { - //根据数据库的月销售数据查询结果,构造查询当年的map数据 - String currentYearKey = String.format("%d%02d", Integer.parseInt(currentYear), month); - buildYearMapData(performanceList, currentYearMap, currentYearKey); - - //根据数据库的月销售数据查询结果,构造查询前一年的map数据 - String lastYearKey = String.format("%d%02d", Integer.parseInt(currentYear)-1, month); - buildYearMapData(performanceList, lastYearMap, lastYearKey); - } - //根据构造好的map数据,计算查询当年的环比和同比数据,并构造好返回的respVOList - List respVOList = new ArrayList<>(); - for (int key : currentYearMap.keySet()) { - BigDecimal lastYearCount = lastYearMap.get(key-100).getCurrentMonthCount(); - BigDecimal lastMonthCount; - if (key % 100 > 1) {//2-12月份的前一个月数据 - lastMonthCount = currentYearMap.get(key-1).getCurrentMonthCount(); - } else {//1月份的前一个月数据 - lastMonthCount = lastYearMap.get(key-89).getCurrentMonthCount(); - } - - currentYearMap.get(key).setLastYearCount(lastYearCount); - currentYearMap.get(key).setLastMonthCount(lastMonthCount); - - respVOList.add(currentYearMap.get(key)); - } - - return respVOList; - } - - /** - * 根据mapKey,添加当年和前一年的月销售记录到对应的map结构中 - * @param performanceList 数据库中查询到的月销售记录 - * @param YearDataMap 将查询到的月销售记录put到对应的map中,如果月销售记录为null,置为0 - * @param mapKey 对应的mapKey - */ - private void buildYearMapData(List performanceList, - Map YearDataMap, - String mapKey) - { - CrmStatisticsPerformanceRespVO currentYearData = performanceList.stream() - .filter(data -> data.getTime().equals(mapKey)) - .findFirst() - .orElse(null); - - if(currentYearData != null) { - YearDataMap.put(Integer.parseInt(mapKey), currentYearData); - } else { - CrmStatisticsPerformanceRespVO defaultVO = new CrmStatisticsPerformanceRespVO(); - defaultVO.setTime(mapKey); - defaultVO.setCurrentMonthCount(BigDecimal.ZERO); - defaultVO.setLastMonthCount(BigDecimal.ZERO); - defaultVO.setLastYearCount(BigDecimal.ZERO); - YearDataMap.put(Integer.parseInt(mapKey), defaultVO); + 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 lastYear = String.format("%d%02d", year - 1, month); + result.add(new CrmStatisticsPerformanceRespVO().setTime(currentMonth) + .setCurrentMonthCount(performanceMap.getOrDefault(currentMonth, BigDecimal.ZERO)) + .setLastMonthCount(performanceMap.getOrDefault(lastMonth, BigDecimal.ZERO)) + .setLastYearCount(performanceMap.getOrDefault(lastYear, BigDecimal.ZERO))); } + return result; } /** diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index bc850b590..ade54c068 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -46,11 +46,11 @@ - - - - - + + cn.iocoder.boot + yudao-module-bpm-biz + ${revision} + @@ -88,11 +88,11 @@ - - - - - + + cn.iocoder.boot + yudao-module-crm-biz + ${revision} +