CRM: 新增客户行业、来源、级别统计数据统计

This commit is contained in:
puhui999
2024-03-24 17:15:56 +08:00
parent 0dd36f6c5c
commit ce013a2562
10 changed files with 345 additions and 51 deletions

View File

@@ -249,4 +249,68 @@
GROUP BY a.owner_user_id
</select>
<select id="selectCustomerIndustryListGroupbyIndustryId"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.analyze.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.customer.analyze.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.customer.analyze.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>
</mapper>