mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	CRM:code review【客户统计】的代码实现
This commit is contained in:
		| @@ -61,8 +61,10 @@ public class CrmStatisticsCustomerController { | |||||||
|         return success(customerService.getFollowUpSummaryByType(reqVO)); |         return success(customerService.getFollowUpSummaryByType(reqVO)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // TODO @dhb52:【客户转化率】里,应该少了一个接口,给上面图标的; | ||||||
|  |  | ||||||
|     @GetMapping("/get-contract-summary") |     @GetMapping("/get-contract-summary") | ||||||
|     @Operation(summary = "获取合同摘要信息(客户转化率页面)") |     @Operation(summary = "获取客户的首次合同、回款信息列表", description = "用于【客户转化率】页面") | ||||||
|     @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") |     @PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')") | ||||||
|     public CommonResult<List<CrmStatisticsCustomerContractSummaryRespVO>> getContractSummary(@Valid CrmStatisticsCustomerReqVO reqVO) { |     public CommonResult<List<CrmStatisticsCustomerContractSummaryRespVO>> getContractSummary(@Valid CrmStatisticsCustomerReqVO reqVO) { | ||||||
|         return success(customerService.getContractSummary(reqVO)); |         return success(customerService.getContractSummary(reqVO)); | ||||||
| @@ -82,4 +84,6 @@ public class CrmStatisticsCustomerController { | |||||||
|         return success(customerService.getCustomerDealCycleByUser(reqVO)); |         return success(customerService.getCustomerDealCycleByUser(reqVO)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // TODO dhb52:【成交周期分析】里,有按照员工(已实现)、地区(未实现)、产品(未实现),需要在看看哈;可以把 CustomerDealCycle 拆成 3 个 tab,员工客户成交周期分析、地区客户成交周期分析、产品客户成交周期分析; | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -39,6 +39,6 @@ public interface CrmStatisticsCustomerMapper { | |||||||
|  |  | ||||||
|     List<CrmStatisticsCustomerDealCycleByDateRespVO> selectCustomerDealCycleGroupByDate(CrmStatisticsCustomerReqVO reqVO); |     List<CrmStatisticsCustomerDealCycleByDateRespVO> selectCustomerDealCycleGroupByDate(CrmStatisticsCustomerReqVO reqVO); | ||||||
|  |  | ||||||
|     List<CrmStatisticsCustomerDealCycleByUserRespVO> selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO); // TODO |     List<CrmStatisticsCustomerDealCycleByUserRespVO> selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO); | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -52,16 +52,18 @@ public interface CrmStatisticsCustomerService { | |||||||
|     List<CrmStatisticsFollowUpSummaryByTypeRespVO> getFollowUpSummaryByType(CrmStatisticsCustomerReqVO reqVO); |     List<CrmStatisticsFollowUpSummaryByTypeRespVO> getFollowUpSummaryByType(CrmStatisticsCustomerReqVO reqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 获取合同摘要信息(客户转化率页面) |      * 获取客户的首次合同、回款信息列表,用于【客户转化率】页面 | ||||||
|      * |      * | ||||||
|      * @param reqVO 请求参数 |      * @param reqVO 请求参数 | ||||||
|      * @return 合同摘要列表 |      * @return 客户的首次合同、回款信息列表 | ||||||
|      */ |      */ | ||||||
|     List<CrmStatisticsCustomerContractSummaryRespVO> getContractSummary(CrmStatisticsCustomerReqVO reqVO); |     List<CrmStatisticsCustomerContractSummaryRespVO> getContractSummary(CrmStatisticsCustomerReqVO reqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 客户成交周期(按日期) |      * 客户成交周期(按日期) | ||||||
|      * |      * | ||||||
|  |      * 成交的定义:客户 customer 在创建出来,到合同 contract 第一次成交的时间差 | ||||||
|  |      * | ||||||
|      * @param reqVO 请求参数 |      * @param reqVO 请求参数 | ||||||
|      * @return 统计数据 |      * @return 统计数据 | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ | |||||||
|             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 = 20 |         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} | ||||||
| @@ -56,7 +56,7 @@ | |||||||
|         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 = 20 |         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} | ||||||
| @@ -72,7 +72,7 @@ | |||||||
|             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 = 20 |         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} | ||||||
| @@ -88,7 +88,7 @@ | |||||||
|             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 = 20 |         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} | ||||||
| @@ -175,28 +175,24 @@ | |||||||
|     <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, | ||||||
|             contract.name AS contract_name, |  | ||||||
|             contract.total_price, |  | ||||||
|             IFNULL( receivable.price, 0 ) AS receivable_price, |  | ||||||
|             customer.industry_id, |  | ||||||
|             customer.source, |  | ||||||
|             customer.owner_user_id, |  | ||||||
|             customer.creator, |  | ||||||
|             customer.create_time, |             customer.create_time, | ||||||
|             contract.order_date |             contract.name AS contract_name, 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 | ||||||
|         WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0 |         WHERE customer.deleted = 0 AND contract.deleted = 0 AND receivable.deleted = 0 | ||||||
|         AND contract.audit_status = 20 |         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> | ||||||
|  |         <!-- TODO @dhb52:应该是客户的创建时间;因为它的定位,是知道这个时间范围内创建的客户,是否下合同了(转化); --> | ||||||
|         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} | ||||||
|     </select> |     </select> | ||||||
|  |  | ||||||
|  |     <!-- 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 | ||||||
| @@ -205,11 +201,12 @@ | |||||||
|         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 = 20 |         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> | ||||||
|  |         <!-- TODO @dhb52:应该是客户的创建时间; --> | ||||||
|         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 time |         GROUP BY time | ||||||
|     </select> |     </select> | ||||||
| @@ -222,11 +219,12 @@ | |||||||
|         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 = 20 |         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> | ||||||
|  |         <!-- TODO @dhb52:应该是客户的创建时间; --> | ||||||
|         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> | ||||||
|   | |||||||
| @@ -7,11 +7,11 @@ | |||||||
|         SELECT IFNULL(SUM(total_price), 0) AS count, owner_user_id |         SELECT IFNULL(SUM(total_price), 0) AS count, owner_user_id | ||||||
|         FROM crm_contract |         FROM crm_contract | ||||||
|         WHERE deleted = 0 |         WHERE deleted = 0 | ||||||
|         AND audit_status = 20 |         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 |         AND order_date between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY owner_user_id |         GROUP BY owner_user_id | ||||||
| @@ -22,11 +22,11 @@ | |||||||
|         SELECT IFNULL(SUM(price), 0) AS count, owner_user_id |         SELECT IFNULL(SUM(price), 0) AS count, owner_user_id | ||||||
|         FROM crm_receivable |         FROM crm_receivable | ||||||
|         WHERE deleted = 0 |         WHERE deleted = 0 | ||||||
|         AND audit_status = 20 |         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 |         AND return_time between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY owner_user_id |         GROUP BY owner_user_id | ||||||
| @@ -37,11 +37,11 @@ | |||||||
|         SELECT COUNT(1) AS count, owner_user_id |         SELECT COUNT(1) AS count, owner_user_id | ||||||
|         FROM crm_contract |         FROM crm_contract | ||||||
|         WHERE deleted = 0 |         WHERE deleted = 0 | ||||||
|         AND audit_status = 20 |         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 |         AND order_date between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY owner_user_id |         GROUP BY owner_user_id | ||||||
| @@ -55,9 +55,9 @@ | |||||||
|         WHERE deleted = 0 |         WHERE deleted = 0 | ||||||
|         AND audit_status = 20 |         AND audit_status = 20 | ||||||
|         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 |         AND order_date between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY owner_user_id |         GROUP BY owner_user_id | ||||||
| @@ -69,9 +69,9 @@ | |||||||
|         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 |         AND create_time between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY owner_user_id |         GROUP BY owner_user_id | ||||||
| @@ -83,9 +83,9 @@ | |||||||
|         FROM crm_contact |         FROM crm_contact | ||||||
|         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 |         AND create_time between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY owner_user_id |         GROUP BY owner_user_id | ||||||
| @@ -99,9 +99,9 @@ | |||||||
|         WHERE cfur.deleted = 0 |         WHERE cfur.deleted = 0 | ||||||
|         AND cc.deleted = 0 |         AND cc.deleted = 0 | ||||||
|         AND cc.owner_user_id in |         AND cc.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 cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and |         AND cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY cc.owner_user_id |         GROUP BY cc.owner_user_id | ||||||
| @@ -115,9 +115,9 @@ | |||||||
|         WHERE cfur.deleted = 0 |         WHERE cfur.deleted = 0 | ||||||
|         AND cc.deleted = 0 |         AND cc.deleted = 0 | ||||||
|         AND cc.owner_user_id in |         AND cc.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 cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and |         AND cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and | ||||||
|             #{times[1],javaType=java.time.LocalDateTime} |             #{times[1],javaType=java.time.LocalDateTime} | ||||||
|         GROUP BY cc.owner_user_id |         GROUP BY cc.owner_user_id | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV