mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-11-04 08:06:12 +08:00 
			
		
		
		
	@ -1,7 +1,7 @@
 | 
			
		||||
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.CrmStatisticsPortraitReqVO;
 | 
			
		||||
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;
 | 
			
		||||
@ -30,34 +30,32 @@ public class CrmStatisticsPortraitController {
 | 
			
		||||
    @Resource
 | 
			
		||||
    private CrmStatisticsPortraitService statisticsPortraitService;
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:搞个属于自己的 CrmStatisticsCustomerReqVO 类哈
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/get-customer-area-summary")
 | 
			
		||||
    @Operation(summary = "获取客户地区统计数据", description = "用于【城市分布分析】页面")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerAreaRespVO>> getCustomerAreaSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerAreaSummary(reqVO));
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerAreaRespVO>> getCustomerAreaSummary(@Valid CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerSummaryByArea(reqVO));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/get-customer-industry-summary")
 | 
			
		||||
    @Operation(summary = "获取客户行业统计数据", description = "用于【客户行业分析】页面")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustrySummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerIndustrySummary(reqVO));
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerIndustryRespVO>> getCustomerIndustrySummary(@Valid CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerSummaryByIndustry(reqVO));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/get-customer-level-summary")
 | 
			
		||||
    @Operation(summary = "获取客户级别统计数据", description = "用于【客户级别分析】页面")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevelSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerLevelSummary(reqVO));
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerLevelRespVO>> getCustomerLevelSummary(@Valid CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerSummaryByLevel(reqVO));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/get-customer-source-summary")
 | 
			
		||||
    @Operation(summary = "获取客户来源统计数据", description = "用于【客户来源分析】页面")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('crm:statistics-portrait:query')")
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSourceSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerSourceSummary(reqVO));
 | 
			
		||||
    public CommonResult<List<CrmStatisticCustomerSourceRespVO>> getCustomerSourceSummary(@Valid CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        return success(statisticsPortraitService.getCustomerSummaryBySource(reqVO));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -18,12 +18,4 @@ public class CrmStatisticCustomerAreaRespVO {
 | 
			
		||||
    @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer dealCount;
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "省份占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double areaPortion;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double dealPortion;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -9,9 +9,6 @@ public class CrmStatisticCustomerIndustryRespVO {
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "客户行业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
 | 
			
		||||
    private Integer industryId;
 | 
			
		||||
    // TODO @puhui999:这个前端字典翻译哈
 | 
			
		||||
    @Schema(description = "客户行业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
 | 
			
		||||
    private String industryName;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer customerCount;
 | 
			
		||||
@ -19,12 +16,4 @@ public class CrmStatisticCustomerIndustryRespVO {
 | 
			
		||||
    @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer dealCount;
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "行业占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double industryPortion;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double dealPortion;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -9,9 +9,6 @@ public class CrmStatisticCustomerLevelRespVO {
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "客户级别编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
 | 
			
		||||
    private Integer level;
 | 
			
		||||
    // TODO @puhui999:这个前端字典翻译哈
 | 
			
		||||
    @Schema(description = "客户级别名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
 | 
			
		||||
    private String levelName;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer customerCount;
 | 
			
		||||
@ -19,12 +16,4 @@ public class CrmStatisticCustomerLevelRespVO {
 | 
			
		||||
    @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer dealCount;
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "级别占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double levelPortion;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double dealPortion;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -9,9 +9,6 @@ public class CrmStatisticCustomerSourceRespVO {
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "客户来源编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
 | 
			
		||||
    private Integer source;
 | 
			
		||||
    // TODO @puhui999:这个前端字典翻译哈
 | 
			
		||||
    @Schema(description = "客户来源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
 | 
			
		||||
    private String sourceName;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "客户个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer customerCount;
 | 
			
		||||
@ -19,12 +16,4 @@ public class CrmStatisticCustomerSourceRespVO {
 | 
			
		||||
    @Schema(description = "成交个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Integer dealCount;
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:下面两个的计算,交给前端。后端只返回数据即可。
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "来源占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double sourcePortion;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "成交占比(%)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    private Double dealPortion;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,42 @@
 | 
			
		||||
package cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait;
 | 
			
		||||
 | 
			
		||||
import io.swagger.v3.oas.annotations.media.Schema;
 | 
			
		||||
import jakarta.validation.constraints.NotNull;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import org.springframework.format.annotation.DateTimeFormat;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 | 
			
		||||
 | 
			
		||||
@Schema(description = "管理后台 - CRM 客户画像 Request VO")
 | 
			
		||||
@Data
 | 
			
		||||
public class CrmStatisticsPortraitReqVO {
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "部门 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
 | 
			
		||||
    @NotNull(message = "部门 id 不能为空")
 | 
			
		||||
    private Long deptId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 负责人用户 id, 当用户为空, 则计算部门下用户
 | 
			
		||||
     */
 | 
			
		||||
    @Schema(description = "负责人用户 id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1")
 | 
			
		||||
    private Long userId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * userIds 目前不用前端传递,目前是方便后端通过 deptId 读取编号后,设置回来
 | 
			
		||||
     * 后续,可能会支持选择部分用户进行查询
 | 
			
		||||
     */
 | 
			
		||||
    @Schema(description = "负责人用户 id 集合", hidden = true, example = "2")
 | 
			
		||||
    private List<Long> userIds;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 前端如果选择自定义时间, 那么前端传递起始-终止时间, 如果选择其他时间间隔类型, 则由后台计算起始-终止时间
 | 
			
		||||
     * 并作为参数传递给Mapper
 | 
			
		||||
     */
 | 
			
		||||
    @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
 | 
			
		||||
    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
 | 
			
		||||
    private LocalDateTime[] times;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -1,10 +1,6 @@
 | 
			
		||||
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 cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.*;
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@ -17,14 +13,12 @@ import java.util.List;
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface CrmStatisticsPortraitMapper {
 | 
			
		||||
 | 
			
		||||
    // TODO @puuhui999:GroupBy
 | 
			
		||||
    List<CrmStatisticCustomerAreaRespVO> selectSummaryListGroupByAreaId(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    List<CrmStatisticCustomerIndustryRespVO> selectCustomerIndustryListGroupbyIndustryId(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerIndustryRespVO> selectCustomerIndustryListGroupByIndustryId(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    List<CrmStatisticCustomerSourceRespVO> selectCustomerSourceListGroupbySource(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerSourceRespVO> selectCustomerSourceListGroupBySource(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    List<CrmStatisticCustomerLevelRespVO> selectCustomerLevelListGroupbyLevel(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    List<CrmStatisticCustomerAreaRespVO> selectSummaryListByAreaId(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerLevelRespVO> selectCustomerLevelListGroupByLevel(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,6 @@
 | 
			
		||||
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 cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.*;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@ -21,7 +17,7 @@ public interface CrmStatisticsPortraitService {
 | 
			
		||||
     * @param reqVO 请求参数
 | 
			
		||||
     * @return 统计数据
 | 
			
		||||
     */
 | 
			
		||||
    List<CrmStatisticCustomerAreaRespVO> getCustomerAreaSummary(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerAreaRespVO> getCustomerSummaryByArea(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取客户行业统计数据
 | 
			
		||||
@ -29,7 +25,7 @@ public interface CrmStatisticsPortraitService {
 | 
			
		||||
     * @param reqVO 请求参数
 | 
			
		||||
     * @return 统计数据
 | 
			
		||||
     */
 | 
			
		||||
    List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerIndustryRespVO> getCustomerSummaryByIndustry(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取客户级别统计数据
 | 
			
		||||
@ -37,7 +33,7 @@ public interface CrmStatisticsPortraitService {
 | 
			
		||||
     * @param reqVO 请求参数
 | 
			
		||||
     * @return 统计数据
 | 
			
		||||
     */
 | 
			
		||||
    List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerLevelRespVO> getCustomerSummaryByLevel(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取客户来源统计数据
 | 
			
		||||
@ -45,6 +41,6 @@ public interface CrmStatisticsPortraitService {
 | 
			
		||||
     * @param reqVO 请求参数
 | 
			
		||||
     * @return 统计数据
 | 
			
		||||
     */
 | 
			
		||||
    List<CrmStatisticCustomerSourceRespVO> getCustomerSourceSummary(CrmStatisticsCustomerReqVO reqVO);
 | 
			
		||||
    List<CrmStatisticCustomerSourceRespVO> getCustomerSummaryBySource(CrmStatisticsPortraitReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,15 +5,10 @@ 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.controller.admin.statistics.vo.portrait.*;
 | 
			
		||||
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;
 | 
			
		||||
@ -26,9 +21,7 @@ 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.*;
 | 
			
		||||
 | 
			
		||||
// TODO @puhui999:参考 CrmStatisticsCustomerServiceImpl 代码风格,优化下这个类哈;包括命名、空行、注释等;
 | 
			
		||||
/**
 | 
			
		||||
 * CRM 客户画像 Service 实现类
 | 
			
		||||
 *
 | 
			
		||||
@ -44,64 +37,54 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
 | 
			
		||||
    private AdminUserApi adminUserApi;
 | 
			
		||||
    @Resource
 | 
			
		||||
    private DeptApi deptApi;
 | 
			
		||||
    @Resource
 | 
			
		||||
    private DictDataApi dictDataApi;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<CrmStatisticCustomerAreaRespVO> getCustomerAreaSummary(CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
        // 1. 获得用户编号数组
 | 
			
		||||
    public List<CrmStatisticCustomerAreaRespVO> getCustomerSummaryByArea(CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        // 1.1 获得用户编号数组
 | 
			
		||||
        List<Long> userIds = getUserIds(reqVO);
 | 
			
		||||
        if (CollUtil.isEmpty(userIds)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
        reqVO.setUserIds(userIds);
 | 
			
		||||
        // 2. 获取客户地区统计数据
 | 
			
		||||
        List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListByAreaId(reqVO);
 | 
			
		||||
        // 1.2 获取客户地区统计数据
 | 
			
		||||
        List<CrmStatisticCustomerAreaRespVO> list = portraitMapper.selectSummaryListGroupByAreaId(reqVO);
 | 
			
		||||
        if (CollUtil.isEmpty(list)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 拼接数据
 | 
			
		||||
        // 2. 拼接数据
 | 
			
		||||
        List<Area> areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area);
 | 
			
		||||
        areaList.add(new Area().setId(null).setName("未知"));
 | 
			
		||||
        Map<Integer, Area> areaMap = convertMap(areaList, Area::getId);
 | 
			
		||||
        List<CrmStatisticCustomerAreaRespVO> customerAreaRespVOList = convertList(list, item -> {
 | 
			
		||||
        return convertList(list, item -> {
 | 
			
		||||
            Integer parentId = AreaUtils.getParentIdByType(item.getAreaId(), AreaTypeEnum.PROVINCE);
 | 
			
		||||
            // TODO @puhui999:找不到,可以归到未知哈;
 | 
			
		||||
            if (parentId == null) {
 | 
			
		||||
                return item;
 | 
			
		||||
            if (parentId == null) { // 找不到,归到未知
 | 
			
		||||
                return item.setAreaId(null).setAreaName("未知");
 | 
			
		||||
            }
 | 
			
		||||
            findAndThen(areaMap, parentId, area -> item.setAreaId(parentId).setAreaName(area.getName()));
 | 
			
		||||
            return item;
 | 
			
		||||
        });
 | 
			
		||||
        return customerAreaRespVOList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<CrmStatisticCustomerIndustryRespVO> getCustomerIndustrySummary(CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
    public List<CrmStatisticCustomerIndustryRespVO> getCustomerSummaryByIndustry(CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        // 1. 获得用户编号数组
 | 
			
		||||
        List<Long> userIds = getUserIds(reqVO);
 | 
			
		||||
        if (CollUtil.isEmpty(userIds)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
        reqVO.setUserIds(userIds);
 | 
			
		||||
 | 
			
		||||
        // 2. 获取客户行业统计数据
 | 
			
		||||
        List<CrmStatisticCustomerIndustryRespVO> industryRespVOList = portraitMapper.selectCustomerIndustryListGroupbyIndustryId(reqVO);
 | 
			
		||||
        List<CrmStatisticCustomerIndustryRespVO> 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;
 | 
			
		||||
        });
 | 
			
		||||
        return industryRespVOList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<CrmStatisticCustomerSourceRespVO> getCustomerSourceSummary(CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
    public List<CrmStatisticCustomerSourceRespVO> getCustomerSummaryBySource(CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        // 1. 获得用户编号数组
 | 
			
		||||
        List<Long> userIds = getUserIds(reqVO);
 | 
			
		||||
        if (CollUtil.isEmpty(userIds)) {
 | 
			
		||||
@ -110,41 +93,28 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
 | 
			
		||||
        reqVO.setUserIds(userIds);
 | 
			
		||||
 | 
			
		||||
        // 2. 获取客户行业统计数据
 | 
			
		||||
        List<CrmStatisticCustomerSourceRespVO> sourceRespVOList = portraitMapper.selectCustomerSourceListGroupbySource(reqVO);
 | 
			
		||||
        List<CrmStatisticCustomerSourceRespVO> 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;
 | 
			
		||||
        });
 | 
			
		||||
        return sourceRespVOList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<CrmStatisticCustomerLevelRespVO> getCustomerLevelSummary(CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
    public List<CrmStatisticCustomerLevelRespVO> getCustomerSummaryByLevel(CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        // 1. 获得用户编号数组
 | 
			
		||||
        List<Long> userIds = getUserIds(reqVO);
 | 
			
		||||
        if (CollUtil.isEmpty(userIds)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
        reqVO.setUserIds(userIds);
 | 
			
		||||
        // 2. 获取客户行业统计数据
 | 
			
		||||
        List<CrmStatisticCustomerLevelRespVO> levelRespVOList = portraitMapper.selectCustomerLevelListGroupbyLevel(reqVO);
 | 
			
		||||
 | 
			
		||||
        // 2. 获取客户级别统计数据
 | 
			
		||||
        List<CrmStatisticCustomerLevelRespVO> 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;
 | 
			
		||||
        });
 | 
			
		||||
        return levelRespVOList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -153,7 +123,7 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
 | 
			
		||||
     * @param reqVO 请求参数
 | 
			
		||||
     * @return 用户编号数组
 | 
			
		||||
     */
 | 
			
		||||
    private List<Long> getUserIds(CrmStatisticsCustomerReqVO reqVO) {
 | 
			
		||||
    private List<Long> getUserIds(CrmStatisticsPortraitReqVO reqVO) {
 | 
			
		||||
        // 情况一:选中某个用户
 | 
			
		||||
        if (ObjUtil.isNotNull(reqVO.getUserId())) {
 | 
			
		||||
            return List.of(reqVO.getUserId());
 | 
			
		||||
 | 
			
		||||
@ -2,91 +2,60 @@
 | 
			
		||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
			
		||||
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.statistics.CrmStatisticsPortraitMapper">
 | 
			
		||||
 | 
			
		||||
    <!-- TODO @puhui999:参考 CrmStatisticsCustomerMapper.xml 优化下 SQL 的排版;sql 结尾不用 ; ;XML 之间有空行; -->
 | 
			
		||||
 | 
			
		||||
    <select id="selectCustomerIndustryListGroupbyIndustryId"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO">
 | 
			
		||||
        SELECT
 | 
			
		||||
            industry_id,
 | 
			
		||||
            COUNT(*) AS customerCount,
 | 
			
		||||
            SUM(deal_status) AS dealCount,
 | 
			
		||||
            ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS industryPortion,
 | 
			
		||||
            ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
 | 
			
		||||
        FROM
 | 
			
		||||
            crm_customer
 | 
			
		||||
        WHERE
 | 
			
		||||
            deleted = 0 AND industry_id IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
 | 
			
		||||
        #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY
 | 
			
		||||
            industry_id;
 | 
			
		||||
    </select>
 | 
			
		||||
    <select id="selectCustomerSourceListGroupbySource"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO">
 | 
			
		||||
        SELECT
 | 
			
		||||
            source,
 | 
			
		||||
            COUNT(*) AS customerCount,
 | 
			
		||||
            SUM(deal_status) AS dealCount,
 | 
			
		||||
            ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS sourcePortion,
 | 
			
		||||
            ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
 | 
			
		||||
        FROM
 | 
			
		||||
            crm_customer
 | 
			
		||||
        WHERE
 | 
			
		||||
            deleted = 0 AND source IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
 | 
			
		||||
        #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY
 | 
			
		||||
            source;
 | 
			
		||||
    </select>
 | 
			
		||||
    <select id="selectCustomerLevelListGroupbyLevel"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO">
 | 
			
		||||
        SELECT
 | 
			
		||||
            level,
 | 
			
		||||
            COUNT(*) AS customerCount,
 | 
			
		||||
            SUM(deal_status) AS dealCount,
 | 
			
		||||
            ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS levelPortion,
 | 
			
		||||
            ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
 | 
			
		||||
        FROM
 | 
			
		||||
            crm_customer
 | 
			
		||||
        WHERE
 | 
			
		||||
            deleted = 0 AND level IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
 | 
			
		||||
        #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY
 | 
			
		||||
            level;
 | 
			
		||||
    </select>
 | 
			
		||||
    <select id="selectSummaryListByAreaId"
 | 
			
		||||
    <select id="selectSummaryListGroupByAreaId"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerAreaRespVO">
 | 
			
		||||
        SELECT
 | 
			
		||||
            area_id,
 | 
			
		||||
            COUNT(*) AS customerCount,
 | 
			
		||||
            SUM(deal_status) AS dealCount,
 | 
			
		||||
            ROUND(COUNT(*) / (SELECT COUNT(*) FROM crm_customer WHERE deleted = 0) * 100, 2) AS areaPortion,
 | 
			
		||||
            ROUND(SUM(deal_status) / NULLIF(COUNT(*), 0) * 100, 2) AS dealPortion
 | 
			
		||||
        FROM
 | 
			
		||||
            crm_customer
 | 
			
		||||
        WHERE
 | 
			
		||||
            deleted = 0 AND area_id IS NOT NULL
 | 
			
		||||
        SELECT area_id, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
 | 
			
		||||
        FROM crm_customer
 | 
			
		||||
        WHERE deleted = 0 AND area_id IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND
 | 
			
		||||
        #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY
 | 
			
		||||
            area_id;
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime}
 | 
			
		||||
        AND #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY area_id
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <select id="selectCustomerIndustryListGroupByIndustryId"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO">
 | 
			
		||||
        SELECT industry_id, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
 | 
			
		||||
        FROM crm_customer
 | 
			
		||||
        WHERE deleted = 0 AND industry_id IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime}
 | 
			
		||||
        AND #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY industry_id
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <select id="selectCustomerSourceListGroupBySource"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO">
 | 
			
		||||
        SELECT source, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
 | 
			
		||||
        FROM crm_customer
 | 
			
		||||
        WHERE deleted = 0 AND source IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime}
 | 
			
		||||
        AND #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY source
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <select id="selectCustomerLevelListGroupByLevel"
 | 
			
		||||
            resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO">
 | 
			
		||||
        SELECT level, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
 | 
			
		||||
        FROM crm_customer
 | 
			
		||||
        WHERE deleted = 0 AND level IS NOT NULL
 | 
			
		||||
        AND owner_user_id IN
 | 
			
		||||
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
 | 
			
		||||
            #{userId}
 | 
			
		||||
        </foreach>
 | 
			
		||||
        AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime}
 | 
			
		||||
        AND #{times[1],javaType=java.time.LocalDateTime}
 | 
			
		||||
        GROUP BY level
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
</mapper>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user