From ee2be799875f0e4e415b5c551a2c171876d492c0 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Sat, 9 Mar 2024 22:51:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[CRM-=E5=AE=A2=E6=88=B7=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1]=E6=A0=B9=E6=8D=AECode-Review=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/CrmStatisticsCustomerReqVO.java | 8 - .../CrmStatisticsCustomerMapper.java | 27 +- .../CrmStatisticsCustomerServiceImpl.java | 161 ++++---- .../CrmStatisticsCustomerMapper.xml | 378 +++++++++--------- 4 files changed, 266 insertions(+), 308 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java index c5d5acbc3..13b3adda7 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/CrmStatisticsCustomerReqVO.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer; -import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -48,11 +47,4 @@ public class CrmStatisticsCustomerReqVO { @Schema(description = "Group By 日期格式", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "%Y%m") private String sqlDateFormat; - // TODO @dhb52:这个字段,目前是不是没啥用呀? - /** - * 数据类型 {@link CrmBizTypeEnum} - */ - @Schema(description = "数据类型", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2") - private Integer bizType; - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java index 19bd76fc3..7c8ed7e93 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsCustomerMapper.java @@ -13,33 +13,32 @@ import java.util.List; @Mapper public interface CrmStatisticsCustomerMapper { - // TODO @dhb52:拼写,GroupBy。一般 idea 如果出现绿色的警告,可能是单词拼写错误,建议是要修改的哈; - List selectCustomerCreateCountGroupbyDate(CrmStatisticsCustomerReqVO reqVO); // 已经 review + List selectCustomerCreateCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); // 已经 review - List selectCustomerDealCountGroupbyDate(CrmStatisticsCustomerReqVO reqVO); // 已经 review + List selectCustomerDealCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); // 已经 review - List selectCustomerCreateCountGroupbyUser(CrmStatisticsCustomerReqVO reqVO); // 已经 review + List selectCustomerCreateCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); // 已经 review - List selectCustomerDealCountGroupbyUser(CrmStatisticsCustomerReqVO crmStatisticsCustomerReqVO); // 已经 review + List selectCustomerDealCountGroupByUser(CrmStatisticsCustomerReqVO crmStatisticsCustomerReqVO); // 已经 review - List selectContractPriceGroupbyUser(CrmStatisticsCustomerReqVO crmStatisticsCustomerReqVO); // 已经 review + List selectContractPriceGroupByUser(CrmStatisticsCustomerReqVO crmStatisticsCustomerReqVO); // 已经 review - List selectReceivablePriceGroupbyUser(CrmStatisticsCustomerReqVO crmStatisticsCustomerReqVO); // 已经 review + List selectReceivablePriceGroupByUser(CrmStatisticsCustomerReqVO crmStatisticsCustomerReqVO); // 已经 review - List selectFollowupRecordCountGroupbyDate(CrmStatisticsCustomerReqVO reqVO); + List selectFollowupRecordCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); - List selectFollowupCustomerCountGroupbyDate(CrmStatisticsCustomerReqVO reqVO); + List selectFollowupCustomerCountGroupByDate(CrmStatisticsCustomerReqVO reqVO); - List selectFollowupRecordCountGroupbyUser(CrmStatisticsCustomerReqVO reqVO); + List selectFollowupRecordCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); - List selectFollowupCustomerCountGroupbyUser(CrmStatisticsCustomerReqVO reqVO); + List selectFollowupCustomerCountGroupByUser(CrmStatisticsCustomerReqVO reqVO); List selectContractSummary(CrmStatisticsCustomerReqVO reqVO); - List selectFollowupRecordCountGroupbyType(CrmStatisticsCustomerReqVO reqVO); + List selectFollowupRecordCountGroupByType(CrmStatisticsCustomerReqVO reqVO); - List selectCustomerDealCycleGroupbyDate(CrmStatisticsCustomerReqVO reqVO); + List selectCustomerDealCycleGroupByDate(CrmStatisticsCustomerReqVO reqVO); - List selectCustomerDealCycleGroupbyUser(CrmStatisticsCustomerReqVO reqVO); + List selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java index c9654a68e..a4c3f4ddf 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerServiceImpl.java @@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper; -import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; 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.dict.DictDataApi; @@ -20,7 +19,6 @@ import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -58,87 +56,83 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe @Override public List getCustomerSummaryByDate(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } reqVO.setUserIds(userIds); // 2. 获取分项统计数据 - // TODO @dhb52:如果是 list 变量,要么 List 要么 s 后缀 reqVO.setSqlDateFormat(getSqlDateFormat(reqVO.getTimes()[0], reqVO.getTimes()[1])); - final List customerCreateCount = customerMapper.selectCustomerCreateCountGroupbyDate(reqVO); - final List customerDealCount = customerMapper.selectCustomerDealCountGroupbyDate(reqVO); + List customerCreateCountVoList = customerMapper.selectCustomerCreateCountGroupByDate(reqVO); + List customerDealCountVoList = customerMapper.selectCustomerDealCountGroupByDate(reqVO); - // 3. 获取时间序列 - // TODO @dhb52:3 和 4 其实做的是一类事情,所以可以考虑 3.1 获取时间序列、3.2 合并统计数据 这样注释;然后中间就不空行了;就是说,一般空行的目的,是让逻辑分片,看着整体性更好,但是不能让逻辑感觉碎碎的; - final List times = generateTimeSeries(reqVO.getTimes()[0], reqVO.getTimes()[1]); - - // 4. 合并统计数据 - // TODO @dhb52:这个是不是要 add 到 respVoList 里?或者还可以 convertList(times, time -> new CrmStatisticsCustomerDealCycleByDateRespVO()...) - List respVoList = new ArrayList<>(times.size()); - final Map customerCreateCountMap = convertMap(customerCreateCount, + // 3. 合并数据 + List times = generateTimeSeries(reqVO.getTimes()[0], reqVO.getTimes()[1]); + Map customerCreateCountMap = convertMap(customerCreateCountVoList, CrmStatisticsCustomerSummaryByDateRespVO::getTime, CrmStatisticsCustomerSummaryByDateRespVO::getCustomerCreateCount); - final Map customerDealCountMap = convertMap(customerDealCount, + Map customerDealCountMap = convertMap(customerDealCountVoList, CrmStatisticsCustomerSummaryByDateRespVO::getTime, CrmStatisticsCustomerSummaryByDateRespVO::getCustomerDealCount); - times.forEach(time -> respVoList.add( - new CrmStatisticsCustomerSummaryByDateRespVO().setTime(time) + List respVoList = convertList(times, + time -> new CrmStatisticsCustomerSummaryByDateRespVO() + .setTime(time) .setCustomerCreateCount(customerCreateCountMap.getOrDefault(time, 0)) - .setCustomerDealCount(customerDealCountMap.getOrDefault(time, 0)) - )); + .setCustomerDealCount(customerDealCountMap.getOrDefault(time, 0))); + return respVoList; } @Override public List getCustomerSummaryByUser(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } reqVO.setUserIds(userIds); // 2. 获取分项统计数据 - final List customerCreateCount = customerMapper.selectCustomerCreateCountGroupbyUser(reqVO); - final List customerDealCount = customerMapper.selectCustomerDealCountGroupbyUser(reqVO); - final List contractPrice = customerMapper.selectContractPriceGroupbyUser(reqVO); - final List receivablePrice = customerMapper.selectReceivablePriceGroupbyUser(reqVO); + List customerCreateCount = customerMapper.selectCustomerCreateCountGroupByUser(reqVO); + List customerDealCount = customerMapper.selectCustomerDealCountGroupByUser(reqVO); + List contractPrice = customerMapper.selectContractPriceGroupByUser(reqVO); + List receivablePrice = customerMapper.selectReceivablePriceGroupByUser(reqVO); // 3. 合并统计数据 - final Map customerCreateCountMap = convertMap(customerCreateCount, + Map customerCreateCountMap = convertMap(customerCreateCount, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getCustomerCreateCount); - final Map customerDealCountMap = convertMap(customerDealCount, + Map customerDealCountMap = convertMap(customerDealCount, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount); - final Map contractPriceMap = convertMap(contractPrice, + Map contractPriceMap = convertMap(contractPrice, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getContractPrice); - final Map receivablePriceMap = convertMap(receivablePrice, + Map receivablePriceMap = convertMap(receivablePrice, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getReceivablePrice); - List respVoList = new ArrayList<>(userIds.size()); - userIds.forEach(userId -> { - final CrmStatisticsCustomerSummaryByUserRespVO vo = new CrmStatisticsCustomerSummaryByUserRespVO(); + List respVoList = convertList(userIds, userId -> { + CrmStatisticsCustomerSummaryByUserRespVO vo = new CrmStatisticsCustomerSummaryByUserRespVO(); + // ownerUserId 为基类属性 vo.setOwnerUserId(userId); vo.setCustomerCreateCount(customerCreateCountMap.getOrDefault(userId, 0)) .setCustomerDealCount(customerDealCountMap.getOrDefault(userId, 0)) .setContractPrice(contractPriceMap.getOrDefault(userId, BigDecimal.ZERO)) .setReceivablePrice(receivablePriceMap.getOrDefault(userId, BigDecimal.ZERO)); - respVoList.add(vo); + return vo; }); // 4. 拼接用户信息 appendUserInfo(respVoList); + return respVoList; } @Override public List getFollowupSummaryByDate(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } @@ -146,26 +140,22 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe // 2. 获取分项统计数据 reqVO.setSqlDateFormat(getSqlDateFormat(reqVO.getTimes()[0], reqVO.getTimes()[1])); - reqVO.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()); - final List followupRecordCount = customerMapper.selectFollowupRecordCountGroupbyDate(reqVO); - final List followupCustomerCount = customerMapper.selectFollowupCustomerCountGroupbyDate(reqVO); + List followupRecordCount = customerMapper.selectFollowupRecordCountGroupByDate(reqVO); + List followupCustomerCount = customerMapper.selectFollowupCustomerCountGroupByDate(reqVO); - // 3. 获取时间序列 - final List times = generateTimeSeries(reqVO.getTimes()[0], reqVO.getTimes()[1]); - - // 4. 合并统计数据 - List respVoList = new ArrayList<>(times.size()); - final Map followupRecordCountMap = convertMap(followupRecordCount, + // 3. 合并统计数据 + List times = generateTimeSeries(reqVO.getTimes()[0], reqVO.getTimes()[1]); + Map followupRecordCountMap = convertMap(followupRecordCount, CrmStatisticsFollowupSummaryByDateRespVO::getTime, CrmStatisticsFollowupSummaryByDateRespVO::getFollowupRecordCount); - final Map followupCustomerCountMap = convertMap(followupCustomerCount, + Map followupCustomerCountMap = convertMap(followupCustomerCount, CrmStatisticsFollowupSummaryByDateRespVO::getTime, CrmStatisticsFollowupSummaryByDateRespVO::getFollowupCustomerCount); - times.forEach(time -> respVoList.add( + List respVoList = convertList(times, time -> new CrmStatisticsFollowupSummaryByDateRespVO().setTime(time) .setFollowupRecordCount(followupRecordCountMap.getOrDefault(time, 0)) .setFollowupCustomerCount(followupCustomerCountMap.getOrDefault(time, 0)) - )); + ); return respVoList; } @@ -173,31 +163,30 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe @Override public List getFollowupSummaryByUser(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } reqVO.setUserIds(userIds); // 2. 获取分项统计数据 - reqVO.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()); - final List followupRecordCount = customerMapper.selectFollowupRecordCountGroupbyUser(reqVO); - final List followupCustomerCount = customerMapper.selectFollowupCustomerCountGroupbyUser(reqVO); + List followupRecordCount = customerMapper.selectFollowupRecordCountGroupByUser(reqVO); + List followupCustomerCount = customerMapper.selectFollowupCustomerCountGroupByUser(reqVO); // 3. 合并统计数据 - final Map followupRecordCountMap = convertMap(followupRecordCount, + Map followupRecordCountMap = convertMap(followupRecordCount, CrmStatisticsFollowupSummaryByUserRespVO::getOwnerUserId, CrmStatisticsFollowupSummaryByUserRespVO::getFollowupRecordCount); - final Map followupCustomerCountMap = convertMap(followupCustomerCount, + Map followupCustomerCountMap = convertMap(followupCustomerCount, CrmStatisticsFollowupSummaryByUserRespVO::getOwnerUserId, CrmStatisticsFollowupSummaryByUserRespVO::getFollowupCustomerCount); - List respVoList = new ArrayList<>(userIds.size()); - userIds.forEach(userId -> { - final CrmStatisticsFollowupSummaryByUserRespVO vo = new CrmStatisticsFollowupSummaryByUserRespVO() + List respVoList = convertList(userIds, userId -> { + CrmStatisticsFollowupSummaryByUserRespVO vo = new CrmStatisticsFollowupSummaryByUserRespVO() .setFollowupRecordCount(followupRecordCountMap.getOrDefault(userId, 0)) .setFollowupCustomerCount(followupCustomerCountMap.getOrDefault(userId, 0)); + // ownerUserId 为基类属性 vo.setOwnerUserId(userId); - respVoList.add(vo); + return vo; }); // 4. 拼接用户信息 @@ -208,19 +197,18 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe @Override public List getFollowupSummaryByType(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } reqVO.setUserIds(userIds); // 2. 获得排行数据 - reqVO.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()); - List respVoList = customerMapper.selectFollowupRecordCountGroupbyType(reqVO); + List respVoList = customerMapper.selectFollowupRecordCountGroupByType(reqVO); // 3. 获取字典数据 List followUpTypes = dictDataApi.getDictDataList(CRM_FOLLOW_UP_TYPE); - final Map followUpTypeMap = convertMap(followUpTypes, + Map followUpTypeMap = convertMap(followUpTypes, DictDataRespDTO::getValue, DictDataRespDTO::getLabel); respVoList.forEach(vo -> { vo.setFollowupType(followUpTypeMap.get(vo.getFollowupType())); @@ -232,7 +220,7 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe @Override public List getContractSummary(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } @@ -242,16 +230,16 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe List respVoList = customerMapper.selectContractSummary(reqVO); // 3. 设置 创建人、负责人、行业、来源 - // 获取客户所属行业 + // 3.1 获取客户所属行业 Map industryMap = convertMap(dictDataApi.getDictDataList(CRM_CUSTOMER_INDUSTRY), DictDataRespDTO::getValue, DictDataRespDTO::getLabel); - // 获取客户来源 + // 3.2 获取客户来源 Map sourceMap = convertMap(dictDataApi.getDictDataList(CRM_CUSTOMER_SOURCE), DictDataRespDTO::getValue, DictDataRespDTO::getLabel); - // 获取创建人、负责人列表 + // 3.3 获取创建人、负责人列表 Map userMap = adminUserApi.getUserMap(convertSetByFlatMap(respVoList, vo -> Stream.of(NumberUtils.parseLong(vo.getCreatorUserId()), vo.getOwnerUserId()))); - + // 3.4 设置 创建人、负责人、行业、来源 respVoList.forEach(vo -> { MapUtils.findAndThen(industryMap, vo.getIndustryId(), vo::setIndustryName); MapUtils.findAndThen(sourceMap, vo.getSource(), vo::setSourceName); @@ -266,7 +254,7 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe @Override public List getCustomerDealCycleByDate(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } @@ -274,52 +262,48 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe // 2. 获取分项统计数据 reqVO.setSqlDateFormat(getSqlDateFormat(reqVO.getTimes()[0], reqVO.getTimes()[1])); - reqVO.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()); - final List customerDealCycle = customerMapper.selectCustomerDealCycleGroupbyDate(reqVO); + List customerDealCycle = customerMapper.selectCustomerDealCycleGroupByDate(reqVO); - // 3. 获取时间序列 - final List times = generateTimeSeries(reqVO.getTimes()[0], reqVO.getTimes()[1]); - - // 4. 合并统计数据 - List respVoList = new ArrayList<>(times.size()); - final Map customerDealCycleMap = convertMap(customerDealCycle, + // 3. 合并统计数据 + List times = generateTimeSeries(reqVO.getTimes()[0], reqVO.getTimes()[1]); + Map customerDealCycleMap = convertMap(customerDealCycle, CrmStatisticsCustomerDealCycleByDateRespVO::getTime, CrmStatisticsCustomerDealCycleByDateRespVO::getCustomerDealCycle); - times.forEach(time -> respVoList.add( + List respVoList = convertList(times, time -> new CrmStatisticsCustomerDealCycleByDateRespVO().setTime(time) .setCustomerDealCycle(customerDealCycleMap.getOrDefault(time, 0D)) - )); + ); + return respVoList; } @Override public List getCustomerDealCycleByUser(CrmStatisticsCustomerReqVO reqVO) { // 1. 获得用户编号数组 - final List userIds = getUserIds(reqVO); + List userIds = getUserIds(reqVO); if (CollUtil.isEmpty(userIds)) { return Collections.emptyList(); } reqVO.setUserIds(userIds); // 2. 获取分项统计数据 - reqVO.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()); - final List customerDealCycle = customerMapper.selectCustomerDealCycleGroupbyUser(reqVO); - final List customerDealCount = customerMapper.selectCustomerDealCountGroupbyUser(reqVO); + List customerDealCycle = customerMapper.selectCustomerDealCycleGroupByUser(reqVO); + List customerDealCount = customerMapper.selectCustomerDealCountGroupByUser(reqVO); // 3. 合并统计数据 - final Map customerDealCycleMap = convertMap(customerDealCycle, + Map customerDealCycleMap = convertMap(customerDealCycle, CrmStatisticsCustomerDealCycleByUserRespVO::getOwnerUserId, CrmStatisticsCustomerDealCycleByUserRespVO::getCustomerDealCycle); - final Map customerDealCountMap = convertMap(customerDealCount, + Map customerDealCountMap = convertMap(customerDealCount, CrmStatisticsCustomerSummaryByUserRespVO::getOwnerUserId, CrmStatisticsCustomerSummaryByUserRespVO::getCustomerDealCount); - List respVoList = new ArrayList<>(userIds.size()); - userIds.forEach(userId -> { - final CrmStatisticsCustomerDealCycleByUserRespVO vo = new CrmStatisticsCustomerDealCycleByUserRespVO() + List respVoList = convertList(userIds, userId -> { + CrmStatisticsCustomerDealCycleByUserRespVO vo = new CrmStatisticsCustomerDealCycleByUserRespVO() .setCustomerDealCycle(customerDealCycleMap.getOrDefault(userId, 0.0)) .setCustomerDealCount(customerDealCountMap.getOrDefault(userId, 0)); + // ownerUserId 为基类属性 vo.setOwnerUserId(userId); - respVoList.add(vo); + return vo; }); // 4. 拼接用户信息 @@ -335,8 +319,9 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe */ private void appendUserInfo(List respVoList) { Map userMap = adminUserApi.getUserMap(convertSet(respVoList, - CrmStatisticsCustomerByUserBaseRespVO::getOwnerUserId)); - respVoList.forEach(vo -> MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()))); + CrmStatisticsCustomerByUserBaseRespVO::getOwnerUserId)); + respVoList.forEach(vo -> MapUtils.findAndThen(userMap, + vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()))); } /** @@ -352,7 +337,7 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe } // 情况二:选中某个部门 // 2.1 获得部门列表 - final Long deptId = reqVO.getDeptId(); + Long deptId = reqVO.getDeptId(); List deptIds = convertList(deptApi.getChildDeptList(deptId), DeptRespDTO::getId); deptIds.add(deptId); // 2.2 获得用户编号 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml index fce255651..32a1d425e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml @@ -2,251 +2,233 @@ - - - - - - - - - - - - - - - - - + + - - - -