CRM:code review【客户统计】的代码实现

This commit is contained in:
YunaiV 2024-03-30 11:00:15 +08:00
parent 90f82b157d
commit a8bec19196
5 changed files with 51 additions and 47 deletions

View File

@ -61,8 +61,10 @@ public class CrmStatisticsCustomerController {
return success(customerService.getFollowUpSummaryByType(reqVO));
}
// TODO @dhb52客户转化率应该少了一个接口给上面图标的
@GetMapping("/get-contract-summary")
@Operation(summary = "获取合同摘要信息(客户转化率页面)")
@Operation(summary = "获取客户的首次合同、回款信息列表", description = "用于【客户转化率】页面")
@PreAuthorize("@ss.hasPermission('crm:statistics-customer:query')")
public CommonResult<List<CrmStatisticsCustomerContractSummaryRespVO>> getContractSummary(@Valid CrmStatisticsCustomerReqVO reqVO) {
return success(customerService.getContractSummary(reqVO));
@ -82,4 +84,6 @@ public class CrmStatisticsCustomerController {
return success(customerService.getCustomerDealCycleByUser(reqVO));
}
// TODO dhb52成交周期分析有按照员工已实现地区未实现产品未实现需要在看看哈可以把 CustomerDealCycle 拆成 3 tab员工客户成交周期分析地区客户成交周期分析产品客户成交周期分析
}

View File

@ -39,6 +39,6 @@ public interface CrmStatisticsCustomerMapper {
List<CrmStatisticsCustomerDealCycleByDateRespVO> selectCustomerDealCycleGroupByDate(CrmStatisticsCustomerReqVO reqVO);
List<CrmStatisticsCustomerDealCycleByUserRespVO> selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO); // TODO
List<CrmStatisticsCustomerDealCycleByUserRespVO> selectCustomerDealCycleGroupByUser(CrmStatisticsCustomerReqVO reqVO);
}

View File

@ -52,16 +52,18 @@ public interface CrmStatisticsCustomerService {
List<CrmStatisticsFollowUpSummaryByTypeRespVO> getFollowUpSummaryByType(CrmStatisticsCustomerReqVO reqVO);
/**
* 获取合同摘要信息(客户转化率页面)
* 获取客户的首次合同回款信息列表用于客户转化率页面
*
* @param reqVO 请求参数
* @return 合同摘要列表
* @return 客户的首次合同回款信息列表
*/
List<CrmStatisticsCustomerContractSummaryRespVO> getContractSummary(CrmStatisticsCustomerReqVO reqVO);
/**
* 客户成交周期(按日期)
*
* 成交的定义客户 customer 在创建出来到合同 contract 第一次成交的时间差
*
* @param reqVO 请求参数
* @return 统计数据
*/

View File

@ -24,7 +24,7 @@
COUNT( DISTINCT customer_id ) AS customerDealCount
FROM crm_contract
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
@ -56,7 +56,7 @@
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
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
@ -72,7 +72,7 @@
IFNULL(SUM(total_price), 0) AS contract_price
FROM crm_contract
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
@ -88,7 +88,7 @@
IFNULL(SUM(price), 0) AS receivable_price
FROM crm_receivable
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
@ -175,28 +175,24 @@
<select id="selectContractSummary"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerContractSummaryRespVO">
SELECT
customer.name AS customer_name,
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.name AS customer_name, customer.industry_id, customer.source, customer.owner_user_id, customer.creator,
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
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
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<!-- TODO @dhb52应该是客户的创建时间因为它的定位是知道这个时间范围内创建的客户是否下合同了转化 -->
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
</select>
<!-- TIMESTAMPDIFF 用于求差值AVG 求平均TRUNCATE 去掉小数点、只保留整数 -->
<select id="selectCustomerDealCycleGroupByDate"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByDateRespVO">
SELECT
@ -205,11 +201,12 @@
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
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<!-- TODO @dhb52应该是客户的创建时间 -->
AND contract.create_time BETWEEN #{times[0],javaType=java.time.LocalDateTime} AND #{times[1],javaType=java.time.LocalDateTime}
GROUP BY time
</select>
@ -222,11 +219,12 @@
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
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<!-- TODO @dhb52应该是客户的创建时间 -->
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>

View File

@ -7,11 +7,11 @@
SELECT IFNULL(SUM(total_price), 0) AS count, owner_user_id
FROM crm_contract
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<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
@ -22,11 +22,11 @@
SELECT IFNULL(SUM(price), 0) AS count, owner_user_id
FROM crm_receivable
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<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
@ -37,11 +37,11 @@
SELECT COUNT(1) AS count, owner_user_id
FROM crm_contract
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
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<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
@ -55,9 +55,9 @@
WHERE deleted = 0
AND audit_status = 20
AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<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
@ -69,9 +69,9 @@
FROM crm_customer
WHERE deleted = 0
AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<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 owner_user_id
@ -83,9 +83,9 @@
FROM crm_contact
WHERE deleted = 0
AND owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<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 owner_user_id
@ -99,9 +99,9 @@
WHERE cfur.deleted = 0
AND cc.deleted = 0
AND cc.owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and
#{times[1],javaType=java.time.LocalDateTime}
GROUP BY cc.owner_user_id
@ -115,9 +115,9 @@
WHERE cfur.deleted = 0
AND cc.deleted = 0
AND cc.owner_user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
AND cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and
#{times[1],javaType=java.time.LocalDateTime}
GROUP BY cc.owner_user_id