fix: 按Code-Review修改CrmStatisticsCustomerMapper.xml

This commit is contained in:
dhb52 2024-04-02 23:44:17 +08:00
parent 5faa006dd0
commit 1944199f67
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,142 +4,133 @@
<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 AND owner_user_id IN
AND owner_user_id IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND 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="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} AND owner_user_id IN
AND owner_user_id IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND 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="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 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} GROUP BY owner_user_id
GROUP BY owner_user_id
</select> </select>
<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 AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND customer.owner_user_id IN
AND customer.owner_user_id IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND contract.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>
<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 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} AND owner_user_id in
AND owner_user_id in <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND order_date BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND order_date BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} GROUP BY owner_user_id
GROUP BY owner_user_id
</select> </select>
<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 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} AND owner_user_id IN
AND owner_user_id IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND return_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND return_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} GROUP BY owner_user_id
GROUP BY owner_user_id
</select> </select>
<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 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} GROUP BY time
GROUP BY time
</select> </select>
<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 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} GROUP BY time
GROUP BY time
</select> </select>
<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 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} GROUP BY creator
GROUP BY creator
</select> </select>
<select id="selectFollowUpCustomerCountGroupByUser" <select id="selectFollowUpCustomerCountGroupByUser"
@ -159,74 +150,73 @@
<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 <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} GROUP BY follow_up_type
GROUP BY follow_up_type
</select> </select>
<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.create_time, customer.source,
contract.name AS contract_name, contract.total_price, contract.order_date, customer.owner_user_id,
IFNULL( receivable.price, 0 ) AS receivable_price customer.creator,
FROM crm_customer AS customer customer.create_time,
INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id contract.name AS contract_name,
LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id contract.total_price,
WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0 contract.order_date,
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} IFNULL(receivable.price, 0) AS receivable_price
AND customer.owner_user_id IN FROM crm_customer AS customer
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id
#{userId} LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id
</foreach> WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0
<!-- TODO @dhb52应该是客户的创建时间因为它的定位是知道这个时间范围内创建的客户是否下合同了转化 --> AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} AND customer.owner_user_id IN
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND customer.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 AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND customer.owner_user_id IN
AND customer.owner_user_id IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
<!-- TODO @dhb52应该是客户的创建时间 --> GROUP BY time
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
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 AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} AND customer.owner_user_id IN
AND customer.owner_user_id IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="userIds" item="userId" open="(" close=")" separator=","> #{userId}
#{userId} </foreach>
</foreach> AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
<!-- TODO @dhb52应该是客户的创建时间 --> GROUP BY customer.owner_user_id
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
GROUP BY customer.owner_user_id
</select> </select>
</mapper> </mapper>