!947 fix: selectCustomerDealCycleGroupByProductId使用LEFT JOIN替换子查询

Merge pull request !947 from dhb52/develop
This commit is contained in:
芋道源码 2024-04-18 01:22:41 +00:00 committed by Gitee
commit 488c46073b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -243,14 +243,17 @@
<select id="selectCustomerDealCycleGroupByProductId"
resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByProductRespVO">
SELECT (SELECT name FROM crm_product WHERE id = product.id) AS product_name,
SELECT product.name AS product_name,
IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY, customer.create_time, contract.order_date)), 1), 0) AS customer_deal_cycle,
COUNT(DISTINCT customer.id) AS customer_deal_count
FROM crm_customer AS customer
LEFT JOIN crm_contract AS contract ON customer.id = contract.customer_id
LEFT JOIN crm_contract_product AS product ON product.contract_id = contract.id
LEFT JOIN crm_contract_product AS contract_product ON contract_product.contract_id = contract.id
LEFT JOIN crm_product AS product ON contract_product.product_id = product.id
WHERE customer.deleted = 0
AND contract.deleted = 0
AND contract_product.deleted = 0
AND product.deleted = 0
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=",">