Commit 5666121daf1daca1b7c4ea05e94d6562cf4ccd2c
Committed by
Gitee
!931 fix: 按Code-Review修改CrmStatisticsCustomerMapper.xml
Merge pull request !931 from dhb52/develop
Showing
2 changed files
with
149 additions
and
159 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsCustomerService.java
| @@ -62,7 +62,7 @@ public interface CrmStatisticsCustomerService { | @@ -62,7 +62,7 @@ public interface CrmStatisticsCustomerService { | ||
| 62 | /** | 62 | /** |
| 63 | * 客户成交周期(按日期) | 63 | * 客户成交周期(按日期) |
| 64 | * | 64 | * |
| 65 | - * 成交的定义:客户 customer 在创建出来,到合同 contract 第一次成交的时间差 | 65 | + * 成交周期的定义:客户 customer 在创建出来,到合同 contract 第一次成交的时间差 |
| 66 | * | 66 | * |
| 67 | * @param reqVO 请求参数 | 67 | * @param reqVO 请求参数 |
| 68 | * @return 统计数据 | 68 | * @return 统计数据 |
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml
| @@ -4,142 +4,133 @@ | @@ -4,142 +4,133 @@ | ||
| 4 | 4 | ||
| 5 | <select id="selectCustomerCreateCountGroupByDate" | 5 | <select id="selectCustomerCreateCountGroupByDate" |
| 6 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO"> | 6 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO"> |
| 7 | - SELECT | ||
| 8 | - DATE_FORMAT(create_time, '%Y-%m-%d') AS time, | ||
| 9 | - COUNT(*) AS customerCreateCount | ||
| 10 | - FROM crm_customer | ||
| 11 | - WHERE deleted = 0 | ||
| 12 | - AND owner_user_id IN | ||
| 13 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 14 | - #{userId} | ||
| 15 | - </foreach> | ||
| 16 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 17 | - GROUP BY time | 7 | + SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS time, |
| 8 | + COUNT(*) AS customerCreateCount | ||
| 9 | + FROM crm_customer | ||
| 10 | + WHERE deleted = 0 | ||
| 11 | + AND owner_user_id IN | ||
| 12 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 13 | + #{userId} | ||
| 14 | + </foreach> | ||
| 15 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 16 | + GROUP BY time | ||
| 18 | </select> | 17 | </select> |
| 19 | 18 | ||
| 20 | <select id="selectCustomerDealCountGroupByDate" | 19 | <select id="selectCustomerDealCountGroupByDate" |
| 21 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO"> | 20 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByDateRespVO"> |
| 22 | - SELECT | ||
| 23 | - DATE_FORMAT( order_date, '%Y-%m-%d' ) AS time, | ||
| 24 | - COUNT( DISTINCT customer_id ) AS customerDealCount | ||
| 25 | - FROM crm_contract | ||
| 26 | - WHERE deleted = 0 | ||
| 27 | - AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 28 | - AND owner_user_id IN | ||
| 29 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 30 | - #{userId} | ||
| 31 | - </foreach> | ||
| 32 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | 21 | + SELECT DATE_FORMAT(order_date, '%Y-%m-%d') AS time, |
| 22 | + COUNT(DISTINCT customer_id) AS customerDealCount | ||
| 23 | + FROM crm_contract | ||
| 24 | + WHERE deleted = 0 | ||
| 25 | + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 26 | + AND owner_user_id IN | ||
| 27 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 28 | + #{userId} | ||
| 29 | + </foreach> | ||
| 30 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 33 | GROUP BY time | 31 | GROUP BY time |
| 34 | </select> | 32 | </select> |
| 35 | 33 | ||
| 36 | <select id="selectCustomerCreateCountGroupByUser" | 34 | <select id="selectCustomerCreateCountGroupByUser" |
| 37 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> | 35 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> |
| 38 | - SELECT | ||
| 39 | - owner_user_id, | ||
| 40 | - COUNT(1) AS customer_create_count | ||
| 41 | - FROM crm_customer | ||
| 42 | - WHERE deleted = 0 | ||
| 43 | - AND owner_user_id in | ||
| 44 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 45 | - #{userId} | ||
| 46 | - </foreach> | ||
| 47 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 48 | - GROUP BY owner_user_id | 36 | + SELECT owner_user_id, |
| 37 | + COUNT(*) AS customer_create_count | ||
| 38 | + FROM crm_customer | ||
| 39 | + WHERE deleted = 0 | ||
| 40 | + AND owner_user_id in | ||
| 41 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 42 | + #{userId} | ||
| 43 | + </foreach> | ||
| 44 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 45 | + GROUP BY owner_user_id | ||
| 49 | </select> | 46 | </select> |
| 50 | 47 | ||
| 51 | <select id="selectCustomerDealCountGroupByUser" | 48 | <select id="selectCustomerDealCountGroupByUser" |
| 52 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> | 49 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> |
| 53 | - SELECT | ||
| 54 | - customer.owner_user_id, | ||
| 55 | - COUNT( DISTINCT customer.id ) AS customer_deal_count | ||
| 56 | - FROM crm_customer AS customer | ||
| 57 | - LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id | ||
| 58 | - WHERE customer.deleted = 0 AND contract.deleted = 0 | ||
| 59 | - AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 60 | - AND customer.owner_user_id IN | ||
| 61 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 62 | - #{userId} | ||
| 63 | - </foreach> | ||
| 64 | - AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 65 | - GROUP BY customer.owner_user_id | 50 | + SELECT customer.owner_user_id, |
| 51 | + COUNT(DISTINCT customer.id) AS customer_deal_count | ||
| 52 | + FROM crm_customer AS customer | ||
| 53 | + LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id | ||
| 54 | + WHERE customer.deleted = 0 AND contract.deleted = 0 | ||
| 55 | + AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 56 | + AND customer.owner_user_id IN | ||
| 57 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 58 | + #{userId} | ||
| 59 | + </foreach> | ||
| 60 | + AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 61 | + GROUP BY customer.owner_user_id | ||
| 66 | </select> | 62 | </select> |
| 67 | 63 | ||
| 68 | <select id="selectContractPriceGroupByUser" | 64 | <select id="selectContractPriceGroupByUser" |
| 69 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> | 65 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> |
| 70 | - SELECT | ||
| 71 | - owner_user_id, | ||
| 72 | - IFNULL(SUM(total_price), 0) AS contract_price | ||
| 73 | - FROM crm_contract | ||
| 74 | - WHERE deleted = 0 | ||
| 75 | - AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 76 | - AND owner_user_id in | ||
| 77 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 78 | - #{userId} | ||
| 79 | - </foreach> | ||
| 80 | - AND order_date BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 81 | - GROUP BY owner_user_id | 66 | + SELECT owner_user_id, |
| 67 | + IFNULL(SUM(total_price), 0) AS contract_price | ||
| 68 | + FROM crm_contract | ||
| 69 | + WHERE deleted = 0 | ||
| 70 | + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 71 | + AND owner_user_id in | ||
| 72 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 73 | + #{userId} | ||
| 74 | + </foreach> | ||
| 75 | + AND order_date BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 76 | + GROUP BY owner_user_id | ||
| 82 | </select> | 77 | </select> |
| 83 | 78 | ||
| 84 | <select id="selectReceivablePriceGroupByUser" | 79 | <select id="selectReceivablePriceGroupByUser" |
| 85 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> | 80 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerSummaryByUserRespVO"> |
| 86 | - SELECT | ||
| 87 | - owner_user_id, | ||
| 88 | - IFNULL(SUM(price), 0) AS receivable_price | ||
| 89 | - FROM crm_receivable | ||
| 90 | - WHERE deleted = 0 | ||
| 91 | - AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 92 | - AND owner_user_id IN | ||
| 93 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 94 | - #{userId} | ||
| 95 | - </foreach> | ||
| 96 | - AND return_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 97 | - GROUP BY owner_user_id | 81 | + SELECT owner_user_id, |
| 82 | + IFNULL(SUM(price), 0) AS receivable_price | ||
| 83 | + FROM crm_receivable | ||
| 84 | + WHERE deleted = 0 | ||
| 85 | + AND audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 86 | + AND owner_user_id IN | ||
| 87 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 88 | + #{userId} | ||
| 89 | + </foreach> | ||
| 90 | + AND return_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 91 | + GROUP BY owner_user_id | ||
| 98 | </select> | 92 | </select> |
| 99 | 93 | ||
| 100 | <select id="selectFollowUpRecordCountGroupByDate" | 94 | <select id="selectFollowUpRecordCountGroupByDate" |
| 101 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO"> | 95 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO"> |
| 102 | - SELECT | ||
| 103 | - DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time, | ||
| 104 | - COUNT(*) AS follow_up_record_count | ||
| 105 | - FROM crm_follow_up_record | ||
| 106 | - WHERE creator IN | ||
| 107 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 108 | - #{userId} | ||
| 109 | - </foreach> | ||
| 110 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 111 | - AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 112 | - GROUP BY time | 96 | + SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS time, |
| 97 | + COUNT(*) AS follow_up_record_count | ||
| 98 | + FROM crm_follow_up_record | ||
| 99 | + WHERE creator IN | ||
| 100 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 101 | + #{userId} | ||
| 102 | + </foreach> | ||
| 103 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 104 | + AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 105 | + GROUP BY time | ||
| 113 | </select> | 106 | </select> |
| 114 | 107 | ||
| 115 | <select id="selectFollowUpCustomerCountGroupByDate" | 108 | <select id="selectFollowUpCustomerCountGroupByDate" |
| 116 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO"> | 109 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByDateRespVO"> |
| 117 | - SELECT | ||
| 118 | - DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time, | ||
| 119 | - COUNT(DISTINCT biz_id) AS follow_up_customer_count | ||
| 120 | - FROM crm_follow_up_record | ||
| 121 | - WHERE creator IN | ||
| 122 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 123 | - #{userId} | ||
| 124 | - </foreach> | ||
| 125 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 126 | - AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 127 | - GROUP BY time | 110 | + SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS time, |
| 111 | + COUNT(DISTINCT biz_id) AS follow_up_customer_count | ||
| 112 | + FROM crm_follow_up_record | ||
| 113 | + WHERE creator IN | ||
| 114 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 115 | + #{userId} | ||
| 116 | + </foreach> | ||
| 117 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 118 | + AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 119 | + GROUP BY time | ||
| 128 | </select> | 120 | </select> |
| 129 | 121 | ||
| 130 | <select id="selectFollowUpRecordCountGroupByUser" | 122 | <select id="selectFollowUpRecordCountGroupByUser" |
| 131 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByUserRespVO"> | 123 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByUserRespVO"> |
| 132 | - SELECT | ||
| 133 | - creator as owner_user_id, | ||
| 134 | - COUNT(*) AS follow_up_record_count | ||
| 135 | - FROM crm_follow_up_record | ||
| 136 | - WHERE creator IN | ||
| 137 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 138 | - #{userId} | ||
| 139 | - </foreach> | ||
| 140 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 141 | - AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 142 | - GROUP BY creator | 124 | + SELECT creator as owner_user_id, |
| 125 | + COUNT(*) AS follow_up_record_count | ||
| 126 | + FROM crm_follow_up_record | ||
| 127 | + WHERE creator IN | ||
| 128 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 129 | + #{userId} | ||
| 130 | + </foreach> | ||
| 131 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 132 | + AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 133 | + GROUP BY creator | ||
| 143 | </select> | 134 | </select> |
| 144 | 135 | ||
| 145 | <select id="selectFollowUpCustomerCountGroupByUser" | 136 | <select id="selectFollowUpCustomerCountGroupByUser" |
| @@ -159,74 +150,73 @@ | @@ -159,74 +150,73 @@ | ||
| 159 | 150 | ||
| 160 | <select id="selectFollowUpRecordCountGroupByType" | 151 | <select id="selectFollowUpRecordCountGroupByType" |
| 161 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByTypeRespVO"> | 152 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsFollowUpSummaryByTypeRespVO"> |
| 162 | - SELECT | ||
| 163 | - type AS follow_up_type, | ||
| 164 | - COUNT(*) AS follow_up_record_count | ||
| 165 | - FROM crm_follow_up_record | ||
| 166 | - WHERE creator IN | ||
| 167 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 168 | - #{userId} | ||
| 169 | - </foreach> | ||
| 170 | - AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 171 | - AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 172 | - GROUP BY follow_up_type | 153 | + SELECT type AS follow_up_type, |
| 154 | + COUNT(*) AS follow_up_record_count | ||
| 155 | + FROM crm_follow_up_record | ||
| 156 | + WHERE creator IN | ||
| 157 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 158 | + #{userId} | ||
| 159 | + </foreach> | ||
| 160 | + AND create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 161 | + AND biz_type = ${@cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum@CRM_CUSTOMER.type} | ||
| 162 | + GROUP BY follow_up_type | ||
| 173 | </select> | 163 | </select> |
| 174 | 164 | ||
| 175 | <select id="selectContractSummary" | 165 | <select id="selectContractSummary" |
| 176 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerContractSummaryRespVO"> | 166 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerContractSummaryRespVO"> |
| 177 | - SELECT | ||
| 178 | - customer.name AS customer_name, customer.industry_id, customer.source, customer.owner_user_id, customer.creator, | ||
| 179 | - customer.create_time, | ||
| 180 | - contract.name AS contract_name, contract.total_price, contract.order_date, | ||
| 181 | - IFNULL( receivable.price, 0 ) AS receivable_price | ||
| 182 | - FROM crm_customer AS customer | ||
| 183 | - INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id | ||
| 184 | - LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id | ||
| 185 | - WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0 | ||
| 186 | - AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 187 | - AND customer.owner_user_id IN | ||
| 188 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 189 | - #{userId} | ||
| 190 | - </foreach> | ||
| 191 | - <!-- TODO @dhb52:应该是客户的创建时间;因为它的定位,是知道这个时间范围内创建的客户,是否下合同了(转化); --> | ||
| 192 | - AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | 167 | + SELECT customer.name AS customer_name, |
| 168 | + customer.industry_id, | ||
| 169 | + customer.source, | ||
| 170 | + customer.owner_user_id, | ||
| 171 | + customer.creator, | ||
| 172 | + customer.create_time, | ||
| 173 | + contract.name AS contract_name, | ||
| 174 | + contract.total_price, | ||
| 175 | + contract.order_date, | ||
| 176 | + IFNULL(receivable.price, 0) AS receivable_price | ||
| 177 | + FROM crm_customer AS customer | ||
| 178 | + INNER JOIN crm_contract AS contract ON customer.id = contract.customer_id | ||
| 179 | + LEFT JOIN crm_receivable AS receivable ON contract.id = receivable.contract_id | ||
| 180 | + WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0 | ||
| 181 | + AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 182 | + AND customer.owner_user_id IN | ||
| 183 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 184 | + #{userId} | ||
| 185 | + </foreach> | ||
| 186 | + AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 193 | </select> | 187 | </select> |
| 194 | 188 | ||
| 195 | <!-- TIMESTAMPDIFF 用于求差值;AVG 求平均;TRUNCATE 去掉小数点、只保留整数 --> | 189 | <!-- TIMESTAMPDIFF 用于求差值;AVG 求平均;TRUNCATE 去掉小数点、只保留整数 --> |
| 196 | <select id="selectCustomerDealCycleGroupByDate" | 190 | <select id="selectCustomerDealCycleGroupByDate" |
| 197 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByDateRespVO"> | 191 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByDateRespVO"> |
| 198 | - SELECT | ||
| 199 | - DATE_FORMAT( contract.order_date, '%Y-%m-%d' ) AS time, | ||
| 200 | - IFNULL( TRUNCATE ( AVG( TIMESTAMPDIFF( DAY, customer.create_time, contract.order_date )), 1 ), 0 ) AS customer_deal_cycle | ||
| 201 | - FROM crm_customer AS customer | ||
| 202 | - LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id | ||
| 203 | - WHERE customer.deleted = 0 AND contract.deleted = 0 | ||
| 204 | - AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 205 | - AND customer.owner_user_id IN | ||
| 206 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 207 | - #{userId} | ||
| 208 | - </foreach> | ||
| 209 | - <!-- TODO @dhb52:应该是客户的创建时间; --> | ||
| 210 | - AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 211 | - GROUP BY time | 192 | + SELECT DATE_FORMAT(contract.order_date, '%Y-%m-%d') AS time, |
| 193 | + IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY, customer.create_time, contract.order_date)), 1), 0) AS customer_deal_cycle | ||
| 194 | + FROM crm_customer AS customer | ||
| 195 | + LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id | ||
| 196 | + WHERE customer.deleted = 0 AND contract.deleted = 0 | ||
| 197 | + AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 198 | + AND customer.owner_user_id IN | ||
| 199 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 200 | + #{userId} | ||
| 201 | + </foreach> | ||
| 202 | + AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 203 | + GROUP BY time | ||
| 212 | </select> | 204 | </select> |
| 213 | 205 | ||
| 214 | <select id="selectCustomerDealCycleGroupByUser" | 206 | <select id="selectCustomerDealCycleGroupByUser" |
| 215 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByUserRespVO"> | 207 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByUserRespVO"> |
| 216 | - SELECT | ||
| 217 | - customer.owner_user_id, | ||
| 218 | - IFNULL( TRUNCATE ( AVG( TIMESTAMPDIFF( DAY, customer.create_time, contract.order_date )), 1 ), 0 ) AS customer_deal_cycle | ||
| 219 | - FROM crm_customer AS customer | ||
| 220 | - LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id | ||
| 221 | - WHERE customer.deleted = 0 AND contract.deleted = 0 | ||
| 222 | - AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 223 | - AND customer.owner_user_id IN | ||
| 224 | - <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 225 | - #{userId} | ||
| 226 | - </foreach> | ||
| 227 | - <!-- TODO @dhb52:应该是客户的创建时间; --> | ||
| 228 | - AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 229 | - GROUP BY customer.owner_user_id | 208 | + SELECT customer.owner_user_id, |
| 209 | + IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY, customer.create_time, contract.order_date)), 1), 0) AS customer_deal_cycle | ||
| 210 | + FROM crm_customer AS customer | ||
| 211 | + LEFT JOIN crm_contract AS contract ON contract.customer_id = customer.id | ||
| 212 | + WHERE customer.deleted = 0 AND contract.deleted = 0 | ||
| 213 | + AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} | ||
| 214 | + AND customer.owner_user_id IN | ||
| 215 | + <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ||
| 216 | + #{userId} | ||
| 217 | + </foreach> | ||
| 218 | + AND customer.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime} | ||
| 219 | + GROUP BY customer.owner_user_id | ||
| 230 | </select> | 220 | </select> |
| 231 | 221 | ||
| 232 | </mapper> | 222 | </mapper> |