2024-02-28 21:41:10 +08:00
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<!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.CrmStatisticsCustomerMapper">
|
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectCustomerCreateCountGroupByDate"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO">
|
|
|
|
|
SELECT
|
2024-03-30 09:22:54 +08:00
|
|
|
|
DATE_FORMAT(create_time, '%Y-%m-%d') AS time,
|
2024-03-09 22:51:38 +08:00
|
|
|
|
COUNT(*) AS customerCreateCount
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_customer
|
|
|
|
|
WHERE deleted = 0
|
|
|
|
|
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 time
|
2024-03-04 23:51:25 +08:00
|
|
|
|
</select>
|
2024-02-28 21:41:10 +08:00
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectCustomerDealCountGroupByDate"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO">
|
2024-02-28 21:41:10 +08:00
|
|
|
|
SELECT
|
2024-03-30 09:22:54 +08:00
|
|
|
|
DATE_FORMAT( order_date, '%Y-%m-%d' ) AS time,
|
2024-03-09 22:51:38 +08:00
|
|
|
|
COUNT( DISTINCT customer_id ) AS customerDealCount
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_contract
|
2024-03-09 22:51:38 +08:00
|
|
|
|
WHERE deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
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}
|
2024-03-04 23:51:25 +08:00
|
|
|
|
GROUP BY time
|
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectCustomerCreateCountGroupByUser"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
|
|
|
|
owner_user_id,
|
|
|
|
|
COUNT(1) AS customer_create_count
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_customer
|
|
|
|
|
WHERE deleted = 0
|
|
|
|
|
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}
|
2024-03-04 23:51:25 +08:00
|
|
|
|
GROUP BY owner_user_id
|
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectCustomerDealCountGroupByUser"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
|
|
|
|
customer.owner_user_id,
|
|
|
|
|
COUNT( DISTINCT customer.id ) AS customer_deal_count
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_customer AS customer
|
|
|
|
|
LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id
|
|
|
|
|
WHERE customer.deleted = 0 AND contract.deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND customer.owner_user_id IN
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
|
|
#{userId}
|
|
|
|
|
</foreach>
|
|
|
|
|
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
|
|
|
|
|
GROUP BY customer.owner_user_id
|
2024-03-04 23:51:25 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectContractPriceGroupByUser"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
|
|
|
|
owner_user_id,
|
|
|
|
|
IFNULL(SUM(total_price), 0) AS contract_price
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_contract
|
|
|
|
|
WHERE deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND owner_user_id in
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
|
|
#{userId}
|
|
|
|
|
</foreach>
|
|
|
|
|
AND order_date BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
|
|
|
|
|
GROUP BY owner_user_id
|
2024-03-04 23:51:25 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectReceivablePriceGroupByUser"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
|
|
|
|
owner_user_id,
|
|
|
|
|
IFNULL(SUM(price), 0) AS receivable_price
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_receivable
|
|
|
|
|
WHERE deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND owner_user_id IN
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
|
|
#{userId}
|
|
|
|
|
</foreach>
|
|
|
|
|
AND return_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
|
|
|
|
|
GROUP BY owner_user_id
|
2024-02-28 21:41:10 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-30 09:22:54 +08:00
|
|
|
|
<select id="selectFollowUpRecordCountGroupByDate"
|
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
2024-03-30 09:22:54 +08:00
|
|
|
|
DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time,
|
|
|
|
|
COUNT(*) AS follow_up_record_count
|
|
|
|
|
FROM crm_follow_up_record
|
|
|
|
|
WHERE creator 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}
|
|
|
|
|
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
|
|
|
|
|
GROUP BY time
|
2024-03-04 23:51:25 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-30 09:22:54 +08:00
|
|
|
|
<select id="selectFollowUpCustomerCountGroupByDate"
|
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO">
|
2024-02-28 21:41:10 +08:00
|
|
|
|
SELECT
|
2024-03-30 09:22:54 +08:00
|
|
|
|
DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time,
|
|
|
|
|
COUNT(DISTINCT biz_id) AS follow_up_customer_count
|
|
|
|
|
FROM crm_follow_up_record
|
|
|
|
|
WHERE creator 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}
|
|
|
|
|
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
|
|
|
|
|
GROUP BY time
|
2024-02-28 21:41:10 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-30 09:22:54 +08:00
|
|
|
|
<select id="selectFollowUpRecordCountGroupByUser"
|
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByUserRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
|
|
|
|
creator as owner_user_id,
|
2024-03-30 09:22:54 +08:00
|
|
|
|
COUNT(*) AS follow_up_record_count
|
|
|
|
|
FROM crm_follow_up_record
|
|
|
|
|
WHERE creator 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}
|
|
|
|
|
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
|
|
|
|
|
GROUP BY creator
|
2024-03-04 23:51:25 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-30 09:22:54 +08:00
|
|
|
|
<select id="selectFollowUpCustomerCountGroupByUser"
|
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByUserRespVO">
|
2024-03-09 22:51:38 +08:00
|
|
|
|
SELECT
|
|
|
|
|
creator as owner_user_id,
|
2024-03-30 09:22:54 +08:00
|
|
|
|
COUNT(DISTINCT biz_id) AS follow_up_customer_count
|
|
|
|
|
FROM crm_follow_up_record
|
|
|
|
|
WHERE creator 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}
|
|
|
|
|
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
|
|
|
|
|
GROUP BY creator
|
2024-03-04 23:51:25 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-30 09:22:54 +08:00
|
|
|
|
<select id="selectFollowUpRecordCountGroupByType"
|
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByTypeRespVO">
|
2024-02-28 23:07:38 +08:00
|
|
|
|
SELECT
|
2024-03-30 09:22:54 +08:00
|
|
|
|
type AS follow_up_type,
|
|
|
|
|
COUNT(*) AS follow_up_record_count
|
|
|
|
|
FROM crm_follow_up_record
|
|
|
|
|
WHERE creator 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}
|
|
|
|
|
AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type}
|
|
|
|
|
GROUP BY follow_up_type
|
2024-02-28 23:07:38 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-04 23:51:25 +08:00
|
|
|
|
<select id="selectContractSummary"
|
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerContractSummaryRespVO">
|
2024-02-28 23:07:38 +08:00
|
|
|
|
SELECT
|
2024-03-30 11:00:15 +08:00
|
|
|
|
customer.name AS customer_name, customer.industry_id, customer.source, customer.owner_user_id, customer.creator,
|
2024-03-09 22:51:38 +08:00
|
|
|
|
customer.create_time,
|
2024-03-30 11:00:15 +08:00
|
|
|
|
contract.name AS contract_name, contract.total_price, contract.order_date,
|
|
|
|
|
IFNULL( receivable.price, 0 ) AS receivable_price
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_customer AS customer
|
|
|
|
|
INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id
|
|
|
|
|
LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id
|
|
|
|
|
WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND customer.owner_user_id IN
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
|
|
#{userId}
|
|
|
|
|
</foreach>
|
2024-03-30 11:00:15 +08:00
|
|
|
|
<!-- TODO @dhb52:应该是客户的创建时间;因为它的定位,是知道这个时间范围内创建的客户,是否下合同了(转化); -->
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
|
2024-03-01 00:10:23 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-30 11:00:15 +08:00
|
|
|
|
<!-- TIMESTAMPDIFF 用于求差值;AVG 求平均;TRUNCATE 去掉小数点、只保留整数 -->
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectCustomerDealCycleGroupByDate"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByDateRespVO">
|
2024-03-01 00:10:23 +08:00
|
|
|
|
SELECT
|
2024-03-30 09:22:54 +08:00
|
|
|
|
DATE_FORMAT( contract.order_date, '%Y-%m-%d' ) AS time,
|
2024-03-09 22:51:38 +08:00
|
|
|
|
IFNULL( TRUNCATE ( AVG( TIMESTAMPDIFF( DAY, customer.create_time, contract.order_date )), 1 ), 0 ) AS customer_deal_cycle
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_customer AS customer
|
|
|
|
|
LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id
|
|
|
|
|
WHERE customer.deleted = 0 AND contract.deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND customer.owner_user_id IN
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
|
|
#{userId}
|
|
|
|
|
</foreach>
|
2024-03-30 11:00:15 +08:00
|
|
|
|
<!-- TODO @dhb52:应该是客户的创建时间; -->
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
|
|
|
|
|
GROUP BY time
|
2024-03-01 00:10:23 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-03-09 22:51:38 +08:00
|
|
|
|
<select id="selectCustomerDealCycleGroupByUser"
|
2024-03-04 23:51:25 +08:00
|
|
|
|
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByUserRespVO">
|
2024-03-01 00:10:23 +08:00
|
|
|
|
SELECT
|
2024-03-09 22:51:38 +08:00
|
|
|
|
customer.owner_user_id,
|
|
|
|
|
IFNULL( TRUNCATE ( AVG( TIMESTAMPDIFF( DAY, customer.create_time, contract.order_date )), 1 ), 0 ) AS customer_deal_cycle
|
2024-03-30 09:22:54 +08:00
|
|
|
|
FROM crm_customer AS customer
|
|
|
|
|
LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id
|
|
|
|
|
WHERE customer.deleted = 0 AND contract.deleted = 0
|
2024-03-30 11:00:15 +08:00
|
|
|
|
AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status}
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND customer.owner_user_id IN
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
|
|
#{userId}
|
|
|
|
|
</foreach>
|
2024-03-30 11:00:15 +08:00
|
|
|
|
<!-- TODO @dhb52:应该是客户的创建时间; -->
|
2024-03-30 09:22:54 +08:00
|
|
|
|
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
|
|
|
|
|
GROUP BY customer.owner_user_id
|
2024-02-28 23:07:38 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
2024-02-28 21:41:10 +08:00
|
|
|
|
</mapper>
|