!932 CRM: 完善用户画像数据统计

Merge pull request !932 from puhui999/develop
This commit is contained in:
芋道源码
2024-04-05 05:55:15 +00:00
committed by Gitee
10 changed files with 132 additions and 204 deletions

View File

@@ -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>