Bläddra i källkod

!947 fix: selectCustomerDealCycleGroupByProductId使用LEFT JOIN替换子查询
Merge pull request !947 from dhb52/develop

芋道源码 1 år sedan
förälder
incheckning
488c46073b

+ 5 - 2
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml

@@ -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=",">