!931 fix: 按Code-Review修改CrmStatisticsCustomerMapper.xml

Merge pull request !931 from dhb52/develop
This commit is contained in:
芋道源码 2024-04-05 05:22:59 +00:00 committed by Gitee
commit 5666121daf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 149 additions and 159 deletions

View File

@ -62,7 +62,7 @@ public interface CrmStatisticsCustomerService {
/** /**
* 客户成交周期(按日期) * 客户成交周期(按日期)
* *
* 成交的定义客户 customer 在创建出来到合同 contract 第一次成交的时间差 * 成交周期的定义客户 customer 在创建出来到合同 contract 第一次成交的时间差
* *
* @param reqVO 请求参数 * @param reqVO 请求参数
* @return 统计数据 * @return 统计数据

View File

@ -4,8 +4,7 @@
<select id="selectCustomerCreateCountGroupByDate" <select id="selectCustomerCreateCountGroupByDate"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO">
SELECT SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
COUNT(*) AS customerCreateCount COUNT(*) AS customerCreateCount
FROM crm_customer FROM crm_customer
WHERE deleted = 0 WHERE deleted = 0
@ -19,9 +18,8 @@
<select id="selectCustomerDealCountGroupByDate" <select id="selectCustomerDealCountGroupByDate"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO">
SELECT SELECT DATE_FORMAT(order_date, '%Y-%m-%d') AS time,
DATE_FORMAT( order_date, '%Y-%m-%d' ) AS time, COUNT(DISTINCT customer_id) AS customerDealCount
COUNT( DISTINCT customer_id ) AS customerDealCount
FROM crm_contract FROM crm_contract
WHERE deleted = 0 WHERE deleted = 0
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
@ -35,9 +33,8 @@
<select id="selectCustomerCreateCountGroupByUser" <select id="selectCustomerCreateCountGroupByUser"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
SELECT SELECT owner_user_id,
owner_user_id, COUNT(*) AS customer_create_count
COUNT(1) AS customer_create_count
FROM crm_customer FROM crm_customer
WHERE deleted = 0 WHERE deleted = 0
AND owner_user_id in AND owner_user_id in
@ -50,9 +47,8 @@
<select id="selectCustomerDealCountGroupByUser" <select id="selectCustomerDealCountGroupByUser"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
SELECT SELECT customer.owner_user_id,
customer.owner_user_id, COUNT(DISTINCT customer.id) AS customer_deal_count
COUNT( DISTINCT customer.id ) AS customer_deal_count
FROM crm_customer AS customer FROM crm_customer AS customer
LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id
WHERE customer.deleted = 0 AND contract.deleted = 0 WHERE customer.deleted = 0 AND contract.deleted = 0
@ -67,8 +63,7 @@
<select id="selectContractPriceGroupByUser" <select id="selectContractPriceGroupByUser"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
SELECT SELECT owner_user_id,
owner_user_id,
IFNULL(SUM(total_price), 0) AS contract_price IFNULL(SUM(total_price), 0) AS contract_price
FROM crm_contract FROM crm_contract
WHERE deleted = 0 WHERE deleted = 0
@ -83,8 +78,7 @@
<select id="selectReceivablePriceGroupByUser" <select id="selectReceivablePriceGroupByUser"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
SELECT SELECT owner_user_id,
owner_user_id,
IFNULL(SUM(price), 0) AS receivable_price IFNULL(SUM(price), 0) AS receivable_price
FROM crm_receivable FROM crm_receivable
WHERE deleted = 0 WHERE deleted = 0
@ -99,8 +93,7 @@
<select id="selectFollowUpRecordCountGroupByDate" <select id="selectFollowUpRecordCountGroupByDate"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO">
SELECT SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time,
COUNT(*) AS follow_up_record_count COUNT(*) AS follow_up_record_count
FROM crm_follow_up_record FROM crm_follow_up_record
WHERE creator IN WHERE creator IN
@ -114,8 +107,7 @@
<select id="selectFollowUpCustomerCountGroupByDate" <select id="selectFollowUpCustomerCountGroupByDate"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO">
SELECT SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time,
COUNT(DISTINCT biz_id) AS follow_up_customer_count COUNT(DISTINCT biz_id) AS follow_up_customer_count
FROM crm_follow_up_record FROM crm_follow_up_record
WHERE creator IN WHERE creator IN
@ -129,8 +121,7 @@
<select id="selectFollowUpRecordCountGroupByUser" <select id="selectFollowUpRecordCountGroupByUser"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByUserRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByUserRespVO">
SELECT SELECT creator as owner_user_id,
creator as owner_user_id,
COUNT(*) AS follow_up_record_count COUNT(*) AS follow_up_record_count
FROM crm_follow_up_record FROM crm_follow_up_record
WHERE creator IN WHERE creator IN
@ -159,8 +150,7 @@
<select id="selectFollowUpRecordCountGroupByType" <select id="selectFollowUpRecordCountGroupByType"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByTypeRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByTypeRespVO">
SELECT SELECT type AS follow_up_type,
type AS follow_up_type,
COUNT(*) AS follow_up_record_count COUNT(*) AS follow_up_record_count
FROM crm_follow_up_record FROM crm_follow_up_record
WHERE creator IN WHERE creator IN
@ -174,11 +164,16 @@
<select id="selectContractSummary" <select id="selectContractSummary"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerContractSummaryRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerContractSummaryRespVO">
SELECT SELECT customer.name AS customer_name,
customer.name AS customer_name, customer.industry_id, customer.source, customer.owner_user_id, customer.creator, customer.industry_id,
customer.source,
customer.owner_user_id,
customer.creator,
customer.create_time, customer.create_time,
contract.name AS contract_name, contract.total_price, contract.order_date, contract.name AS contract_name,
IFNULL( receivable.price, 0 ) AS receivable_price contract.total_price,
contract.order_date,
IFNULL(receivable.price, 0) AS receivable_price
FROM crm_customer AS customer FROM crm_customer AS customer
INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id
LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id
@ -188,16 +183,14 @@
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId} #{userId}
</foreach> </foreach>
<!-- TODO @dhb52应该是客户的创建时间因为它的定位是知道这个时间范围内创建的客户是否下合同了转化 --> AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
</select> </select>
<!-- TIMESTAMPDIFF 用于求差值AVG 求平均TRUNCATE 去掉小数点、只保留整数 --> <!-- TIMESTAMPDIFF 用于求差值AVG 求平均TRUNCATE 去掉小数点、只保留整数 -->
<select id="selectCustomerDealCycleGroupByDate" <select id="selectCustomerDealCycleGroupByDate"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByDateRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByDateRespVO">
SELECT SELECT DATE_FORMAT(contract.order_date, '%Y-%m-%d') AS time,
DATE_FORMAT( contract.order_date, '%Y-%m-%d' ) AS time, IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY, customer.create_time, contract.order_date)), 1), 0) AS customer_deal_cycle
IFNULL( TRUNCATE ( AVG( TIMESTAMPDIFF( DAY, customer.create_time, contract.order_date )), 1 ), 0 ) AS customer_deal_cycle
FROM crm_customer AS customer FROM crm_customer AS customer
LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id
WHERE customer.deleted = 0 AND contract.deleted = 0 WHERE customer.deleted = 0 AND contract.deleted = 0
@ -206,16 +199,14 @@
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId} #{userId}
</foreach> </foreach>
<!-- TODO @dhb52应该是客户的创建时间 --> AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
GROUP BY time GROUP BY time
</select> </select>
<select id="selectCustomerDealCycleGroupByUser" <select id="selectCustomerDealCycleGroupByUser"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByUserRespVO"> resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByUserRespVO">
SELECT SELECT customer.owner_user_id,
customer.owner_user_id, IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY, customer.create_time, contract.order_date)), 1), 0) AS customer_deal_cycle
IFNULL( TRUNCATE ( AVG( TIMESTAMPDIFF( DAY, customer.create_time, contract.order_date )), 1 ), 0 ) AS customer_deal_cycle
FROM crm_customer AS customer FROM crm_customer AS customer
LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id
WHERE customer.deleted = 0 AND contract.deleted = 0 WHERE customer.deleted = 0 AND contract.deleted = 0
@ -224,8 +215,7 @@
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId} #{userId}
</foreach> </foreach>
<!-- TODO @dhb52应该是客户的创建时间 --> AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
GROUP BY customer.owner_user_id GROUP BY customer.owner_user_id
</select> </select>