Browse Source

sql优化

zhouzeyu@c-top.com.cn 3 years ago
parent
commit
f8df324525

+ 11 - 5
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/MaterialReportOverViewV3Mapper.xml

@@ -638,17 +638,23 @@
         <if test="type == 3">t1.plan_name as userName, "编导" as roleName,</if>
         IFNULL(COUNT(DISTINCT t.material_id,IF(faddish_date BETWEEN #{startDate} and #{endDate} ,true,null)),0) as 'videoHotCount',
 
-        COUNT(DISTINCT t.material_id,IF(faddish_date BETWEEN #{startDate} and #{endDate} ,true,null))/
-        (SELECT COUNT(0) from application.app_bytedance_material_info where faddish_date BETWEEN #{startDate} and #{endDate} and t.company_id=#{companyId})*0.4+
-        SUM(t1.cost)/
+        ifnull( COUNT(DISTINCT t.material_id,IF(faddish_date BETWEEN #{startDate} and #{endDate} ,true,null))/
+        (SELECT COUNT(0) from application.app_bytedance_material_info where faddish_date BETWEEN #{startDate} and #{endDate} and company_id=#{companyId})*0.4,0)+
+         ifnull(SUM(t1.cost)/
         (SELECT SUM(cost) from application.bytedance_material_video_report_daily_dw where stat_datetime
         BETWEEN #{startDate} and #{endDate}
-        )*0.6  as sort
+        )*0.6 ,0) as sort
         from
         application.app_bytedance_material_info t
         LEFT JOIN application.bytedance_material_video_report_daily_dw t1 on t.material_id=t1.signature
+
+        left JOIN sys_user t2 on
+        <if test="type == 1"> t1.shot_id =t2.id</if>
+        <if test="type == 2"> t1.clip_id =t2.id</if>
+        <if test="type == 3"> t1.plan_id =t2.id</if>
+
         <where>
-            t1.stat_datetime BETWEEN #{startDate} and #{endDate} and t.company_id=#{companyId} and t1.company_id=#{companyId}
+            t1.stat_datetime BETWEEN #{startDate} and #{endDate} and t.company_id=#{companyId} and t1.company_id=#{companyId} and t2.del_flag=0
         </where>
         <if test="type == 1">AND t1.shot_id is not null and t1.shot_id != '' AND t1.shot_name is not null and t1.shot_name != ''  GROUP BY t1.shot_id</if>
         <if test="type == 2">AND t1.clip_id is not null and t1.clip_id != '' AND t1.clip_name is not null and t1.clip_name != '' GROUP BY t1.clip_id</if>