From 924580f4a29db98d7add392e516be8505d0ed61b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 30 Mar 2024 13:51:46 +0800 Subject: [PATCH] =?UTF-8?q?CRM=EF=BC=9A=E9=87=8D=E6=9E=84=E3=80=90?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=94=BB=E5=83=8F=E3=80=91=EF=BC=8C=E4=BB=8E?= =?UTF-8?q?=E3=80=90=E5=AE=A2=E6=88=B7=E7=BB=9F=E8=AE=A1=E3=80=91=E6=8B=86?= =?UTF-8?q?=E5=88=86=E5=87=BA=E5=8E=BB=E5=85=88~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CrmStatisticsCustomerController.java | 32 ---- .../CrmStatisticsPortraitController.java | 61 +++++++ .../CrmStatisticsRankController.java | 1 - .../customer/CrmStatisticsCustomerReqVO.java | 8 - .../CrmStatisticCustomerAreaRespVO.java | 2 +- .../CrmStatisticCustomerIndustryRespVO.java | 2 +- .../CrmStatisticCustomerLevelRespVO.java | 2 +- .../CrmStatisticCustomerSourceRespVO.java | 2 +- .../CrmStatisticsCustomerMapper.java | 14 +- .../CrmStatisticsPortraitMapper.java | 28 +++ .../CrmStatisticsCustomerService.java | 36 ---- .../CrmStatisticsCustomerServiceImpl.java | 107 ----------- .../CrmStatisticsPortraitService.java | 50 ++++++ .../CrmStatisticsPortraitServiceImpl.java | 166 ++++++++++++++++++ .../CrmStatisticsCustomerMapper.xml | 85 --------- .../CrmStatisticsPortraitMapper.xml | 90 ++++++++++ 16 files changed, 400 insertions(+), 286 deletions(-) create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java rename yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/{customer/analyze => portrait}/CrmStatisticCustomerAreaRespVO.java (98%) rename yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/{customer/analyze => portrait}/CrmStatisticCustomerIndustryRespVO.java (98%) rename yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/{customer/analyze => portrait}/CrmStatisticCustomerLevelRespVO.java (98%) rename yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/{customer/analyze => portrait}/CrmStatisticCustomerSourceRespVO.java (98%) create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java index 413bae8f8..450a9cd99 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsCustomerController.java @@ -2,10 +2,6 @@ package cn.iocoder.yudao.module.crm.controller.admin.statistics; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerAreaRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO; import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsCustomerService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -90,32 +86,4 @@ public class CrmStatisticsCustomerController { // TODO dhb52:【成交周期分析】里,有按照员工(已实现)、地区(未实现)、产品(未实现),需要在看看哈;可以把 CustomerDealCycle 拆成 3 个 tab,员工客户成交周期分析、地区客户成交周期分析、产品客户成交周期分析; - @GetMapping("/get-customer-industry-summary") - @Operation(summary = "获取客户行业统计数据") - @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") - public CommonResult> getCustomerIndustry(@Valid CrmStatisticsCustomerReqVO reqVO) { - return success(customerService.getCustomerIndustry(reqVO)); - } - - @GetMapping("/get-customer-source-summary") - @Operation(summary = "获取客户来源统计数据") - @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") - public CommonResult> getCustomerSource(@Valid CrmStatisticsCustomerReqVO reqVO) { - return success(customerService.getCustomerSource(reqVO)); - } - - @GetMapping("/get-customer-level-summary") - @Operation(summary = "获取客户级别统计数据") - @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") - public CommonResult> getCustomerLevel(@Valid CrmStatisticsCustomerReqVO reqVO) { - return success(customerService.getCustomerLevel(reqVO)); - } - - @GetMapping("/get-customer-area-summary") - @Operation(summary = "获取客户地区统计数据") - @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") - public CommonResult> getCustomerArea(@Valid CrmStatisticsCustomerReqVO reqVO) { - return success(customerService.getCustomerArea(reqVO)); - } - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java new file mode 100644 index 000000000..90ef26688 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsPortraitController.java @@ -0,0 +1,61 @@ +package cn.iocoder.yudao.module.crm.controller.admin.statistics; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerAreaRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO; +import cn.iocoder.yudao.module.crm.service.statistics.CrmStatisticsPortraitService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - CRM 客户画像") +@RestController +@RequestMapping("/crm/statistics-portrait") +@Validated +public class CrmStatisticsPortraitController { + + @Resource + private CrmStatisticsPortraitService statisticsPortraitService; + + @GetMapping("/get-customer-area-summary") + @Operation(summary = "获取客户地区统计数据", description = "用于【城市分布分析】页面") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerAreaSummary(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(statisticsPortraitService.getCustomerArea(reqVO)); + } + + @GetMapping("/get-customer-industry-summary") + @Operation(summary = "获取客户行业统计数据") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerIndustry(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(statisticsPortraitService.getCustomerIndustry(reqVO)); + } + + @GetMapping("/get-customer-level-summary") + @Operation(summary = "获取客户级别统计数据") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerLevel(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(statisticsPortraitService.getCustomerLevel(reqVO)); + } + + @GetMapping("/get-customer-source-summary") + @Operation(summary = "获取客户来源统计数据") + @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')") + public CommonResult> getCustomerSource(@Valid CrmStatisticsCustomerReqVO reqVO) { + return success(statisticsPortraitService.getCustomerSource(reqVO)); + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java index f3757ea28..974963d33 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/CrmStatisticsRankController.java @@ -18,7 +18,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - @Tag(name = "管理后台 - CRM 排行榜统计") @RestController @RequestMapping("/crm/statistics-rank") 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 0564c2679..5c887c6af 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 @@ -45,12 +45,4 @@ public class CrmStatisticsCustomerReqVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] times; - /** - * group by DATE_FORMAT(field, #{dateFormat}) - * 非前端传递, 由Service计算后传递给Mapper的参数 - */ - @Deprecated - @Schema(description = "Group By 日期格式", hidden = true, example = "%Y%m") - private String sqlDateFormat; - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerAreaRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java similarity index 98% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerAreaRespVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java index 5f6924d58..05220d47c 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerAreaRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerAreaRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze; +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerIndustryRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java similarity index 98% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerIndustryRespVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java index 481174092..8d368a306 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerIndustryRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerIndustryRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze; +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerLevelRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java similarity index 98% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerLevelRespVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java index 74e06918c..5d6e9793d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerLevelRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerLevelRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze; +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerSourceRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java similarity index 98% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerSourceRespVO.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java index 2edba39ed..60b938139 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/customer/analyze/CrmStatisticCustomerSourceRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/statistics/vo/portrait/CrmStatisticCustomerSourceRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze; +package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; 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 f2e9dc9f3..b7f495b61 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 @@ -1,16 +1,12 @@ package cn.iocoder.yudao.module.crm.dal.mysql.statistics; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerAreaRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO; import org.apache.ibatis.annotations.Mapper; import java.util.List; /** - * CRM 数据统计 员工客户分析 Mapper + * CRM 数据统计 Mapper * * @author dhb52 */ @@ -45,12 +41,4 @@ public interface CrmStatisticsCustomerMapper { List selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO); - List selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO); - - List selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO); - - List selectCustomerLevelListGroupbyLevel(CrmStatisticsCustomerReqVO reqVO); - - List selectSummaryListByAreaId(CrmStatisticsCustomerReqVO reqVO); - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java new file mode 100644 index 000000000..25b7cb2d2 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/statistics/CrmStatisticsPortraitMapper.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.statistics; + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerAreaRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * CRM 数据画像 Mapper + * + * @author dhb52 + */ +@Mapper +public interface CrmStatisticsPortraitMapper { + + List selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO); + + List selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO); + + List selectCustomerLevelListGroupbyLevel(CrmStatisticsCustomerReqVO reqVO); + + List selectSummaryListByAreaId(CrmStatisticsCustomerReqVO reqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java index a69e1b9a0..55317f4ae 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java @@ -1,10 +1,6 @@ package cn.iocoder.yudao.module.crm.service.statistics; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerAreaRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO; import java.util.List; @@ -81,36 +77,4 @@ public interface CrmStatisticsCustomerService { */ List getCustomerDealCycleByUser(CrmStatisticsCustomerReqVO reqVO); - /** - * 获取客户行业统计数据 - * - * @param reqVO 请求参数 - * @return 统计数据 - */ - List getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO); - - /** - * 获取客户来源统计数据 - * - * @param reqVO 请求参数 - * @return 统计数据 - */ - List getCustomerSource(CrmStatisticsCustomerReqVO reqVO); - - /** - * 获取客户级别统计数据 - * - * @param reqVO 请求参数 - * @return 统计数据 - */ - List getCustomerLevel(CrmStatisticsCustomerReqVO reqVO); - - /** - * 获取客户地区统计数据 - * - * @param reqVO 请求参数 - * @return 统计数据 - */ - List getCustomerArea(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 e20d3a963..250560ef2 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 @@ -4,14 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; -import cn.iocoder.yudao.framework.ip.core.Area; -import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; -import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.*; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerAreaRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerIndustryRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerLevelRespVO; -import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.CrmStatisticCustomerSourceRespVO; import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsCustomerMapper; import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; @@ -30,8 +23,6 @@ import java.util.stream.Stream; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; -import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*; /** * CRM 客户分析 Service 实现类 @@ -245,104 +236,6 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe return summaryList; } - @Override - public List getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO) { - // 1. 获得用户编号数组 - List userIds = getUserIds(reqVO); - if (CollUtil.isEmpty(userIds)) { - return Collections.emptyList(); - } - reqVO.setUserIds(userIds); - // 2. 获取客户行业统计数据 - List industryRespVOList = customerMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO); - if (CollUtil.isEmpty(industryRespVOList)) { - return Collections.emptyList(); - } - - return convertList(industryRespVOList, item -> { - if (ObjUtil.isNull(item.getIndustryId())) { - return item; - } - item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId())); - return item; - }); - } - - @Override - public List getCustomerSource(CrmStatisticsCustomerReqVO reqVO) { - // 1. 获得用户编号数组 - List userIds = getUserIds(reqVO); - if (CollUtil.isEmpty(userIds)) { - return Collections.emptyList(); - } - reqVO.setUserIds(userIds); - // 2. 获取客户行业统计数据 - List sourceRespVOList = customerMapper.selectCustomerSourceListGroupbySource(reqVO); - if (CollUtil.isEmpty(sourceRespVOList)) { - return Collections.emptyList(); - } - - return convertList(sourceRespVOList, item -> { - if (ObjUtil.isNull(item.getSource())) { - return item; - } - item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource())); - return item; - }); - } - - @Override - public List getCustomerLevel(CrmStatisticsCustomerReqVO reqVO) { - // 1. 获得用户编号数组 - List userIds = getUserIds(reqVO); - if (CollUtil.isEmpty(userIds)) { - return Collections.emptyList(); - } - reqVO.setUserIds(userIds); - // 2. 获取客户行业统计数据 - List levelRespVOList = customerMapper.selectCustomerLevelListGroupbyLevel(reqVO); - if (CollUtil.isEmpty(levelRespVOList)) { - return Collections.emptyList(); - } - - return convertList(levelRespVOList, item -> { - if (ObjUtil.isNull(item.getLevel())) { - return item; - } - item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel())); - return item; - }); - } - - @Override - public List getCustomerArea(CrmStatisticsCustomerReqVO reqVO) { - // 1. 获得用户编号数组 - List userIds = getUserIds(reqVO); - if (CollUtil.isEmpty(userIds)) { - return Collections.emptyList(); - } - reqVO.setUserIds(userIds); - // 2. 获取客户地区统计数据 - List list = customerMapper.selectSummaryListByAreaId(reqVO); - if (CollUtil.isEmpty(list)) { - return Collections.emptyList(); - } - - // 拼接数据 - List areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area); - areaList.add(new Area().setId(null).setName("未知")); - Map areaMap = convertMap(areaList, Area::getId); - List customerAreaRespVOList = convertList(list, item -> { - Integer parentId = AreaUtils.getParentIdByType(item.getAreaId(), AreaTypeEnum.PROVINCE); - if (parentId == null) { - return item; - } - findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName())); - return item; - }); - return customerAreaRespVOList; - } - /** * 拼接用户信息(昵称) * diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java new file mode 100644 index 000000000..33afe0eca --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitService.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerAreaRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO; + +import java.util.List; + +/** + * CRM 客户画像 Service 接口 + * + * @author HUIHUI + */ +public interface CrmStatisticsPortraitService { + + /** + * 获取客户地区统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerArea(CrmStatisticsCustomerReqVO reqVO); + + /** + * 获取客户行业统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO); + + /** + * 获取客户级别统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerLevel(CrmStatisticsCustomerReqVO reqVO); + + /** + * 获取客户来源统计数据 + * + * @param reqVO 请求参数 + * @return 统计数据 + */ + List getCustomerSource(CrmStatisticsCustomerReqVO reqVO); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java new file mode 100644 index 000000000..2e63d8786 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPortraitServiceImpl.java @@ -0,0 +1,166 @@ +package cn.iocoder.yudao.module.crm.service.statistics; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.framework.ip.core.Area; +import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerAreaRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO; +import cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPortraitMapper; +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; +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 java.util.Collections; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; +import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*; + +/** + * CRM 客户画像 Service 实现类 + * + * @author HUIHUI + */ +@Service +public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitService { + + @Resource + private CrmStatisticsPortraitMapper portraitMapper; + + @Resource + private AdminUserApi adminUserApi; + @Resource + private DeptApi deptApi; + @Resource + private DictDataApi dictDataApi; + + @Override + public List getCustomerIndustry(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + // 2. 获取客户行业统计数据 + List industryRespVOList = portraitMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO); + if (CollUtil.isEmpty(industryRespVOList)) { + return Collections.emptyList(); + } + + return convertList(industryRespVOList, item -> { + if (ObjUtil.isNull(item.getIndustryId())) { + return item; + } + item.setIndustryName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, item.getIndustryId())); + return item; + }); + } + + @Override + public List getCustomerSource(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + // 2. 获取客户行业统计数据 + List sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO); + if (CollUtil.isEmpty(sourceRespVOList)) { + return Collections.emptyList(); + } + + return convertList(sourceRespVOList, item -> { + if (ObjUtil.isNull(item.getSource())) { + return item; + } + item.setSourceName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_SOURCE, item.getSource())); + return item; + }); + } + + @Override + public List getCustomerLevel(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + // 2. 获取客户行业统计数据 + List levelRespVOList = portraitMapper.selectCustomerLevelListGroupbyLevel(reqVO); + if (CollUtil.isEmpty(levelRespVOList)) { + return Collections.emptyList(); + } + + return convertList(levelRespVOList, item -> { + if (ObjUtil.isNull(item.getLevel())) { + return item; + } + item.setLevelName(dictDataApi.getDictDataLabel(CRM_CUSTOMER_LEVEL, item.getLevel())); + return item; + }); + } + + @Override + public List getCustomerArea(CrmStatisticsCustomerReqVO reqVO) { + // 1. 获得用户编号数组 + List userIds = getUserIds(reqVO); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + reqVO.setUserIds(userIds); + // 2. 获取客户地区统计数据 + List list = portraitMapper.selectSummaryListByAreaId(reqVO); + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); + } + + // 拼接数据 + List areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area); + areaList.add(new Area().setId(null).setName("未知")); + Map areaMap = convertMap(areaList, Area::getId); + List customerAreaRespVOList = convertList(list, item -> { + Integer parentId = AreaUtils.getParentIdByType(item.getAreaId(), AreaTypeEnum.PROVINCE); + if (parentId == null) { + return item; + } + findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName())); + return item; + }); + return customerAreaRespVOList; + } + + /** + * 获取用户编号数组。如果用户编号为空, 则获得部门下的用户编号数组,包括子部门的所有用户编号 + * + * @param reqVO 请求参数 + * @return 用户编号数组 + */ + private List getUserIds(CrmStatisticsCustomerReqVO reqVO) { + // 情况一:选中某个用户 + if (ObjUtil.isNotNull(reqVO.getUserId())) { + return List.of(reqVO.getUserId()); + } + // 情况二:选中某个部门 + // 2.1 获得部门列表 + List deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()), DeptRespDTO::getId); + deptIds.add(reqVO.getDeptId()); + // 2.2 获得用户编号 + return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId); + } + +} 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 acf354505..0672d629e 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 @@ -229,89 +229,4 @@ GROUP BY customer.owner_user_id - - - - - diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml new file mode 100644 index 000000000..0364027c7 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml @@ -0,0 +1,90 @@ + + + + + + + + + +