浏览代码

素材大盘 优化sql

zhaoxian 2 年之前
父节点
当前提交
31e6923036

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

@@ -588,41 +588,57 @@
     </select>
     </select>
 
 
     <select id="queryBytedanceTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
     <select id="queryBytedanceTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT ROUND(SUM(t1.cost),2) as charge,tt.material_id,t1.cover_url as 'coverUrl',tt.video_url as
-        'url',tt.material_name as
-        'materialName',
-        tt.tag as 'tag'
-        from (
-        select t.material_id,t.material_name,GROUP_CONCAT(t2.tag_name) as tag,video_url,cover_url from
-        application.app_bytedance_material_info t left join
-        application.app_material_tag_busi_info t2 on t.material_id=t2.material_id where tag_category_id=1 and
-        t.company_id=#{companyId}
-
+        SELECT
+        t.material_id,
+        t.tag,
+        ROUND(t1.charge,2) as 'charge',
+        t1.video_name as        'materialName',
+        t1.video_url  as 'url',
+        t1.cover_url as 'coverUrl'
+        from
+        (
+        select
+        material_id,
+        GROUP_CONCAT(tag_name) as tag
+        from
+        application.app_material_tag_busi_info
+        where
+        tag_category_id=1
+        and company_id=#{companyId}
         <if test='dimension=="designTeam" and leaderId!=null'>
         <if test='dimension=="designTeam" and leaderId!=null'>
-            and t.leader_id=#{leaderId}
+            and leader_id=#{leaderId}
+        </if>
+        group by material_id
+        ) t
+        left join
+        (
+        select
+        signature,
+        sum(cost) as charge,
+        video_name,
+        video_url,
+        cover_url
+        from
+        application.bytedance_material_video_report_daily_dw
+        WHERE cost>0
+        <if test='dimension=="designTeam" and leaderId!=null'>
+            and leader_id=#{leaderId}
         </if>
         </if>
         <if test='dimension=="designer" and designerId!=null'>
         <if test='dimension=="designer" and designerId!=null'>
-            and (t.clip_id=#{designerId} or t.shot_id=#{designerId} or t.plan_id=#{designerId})
+            and (clip_id=#{designerId} or shot_id=#{designerId} or plan_id=#{designerId})
         </if>
         </if>
-        group by t.material_id
-        ) tt
-
-        left join
-        application.bytedance_material_video_report_daily_dw t1 on t1.signature=tt.material_id
+        <if test='dimension=="project" and projects!=null'>
+            AND project_id IN
+            <foreach collection="projects" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        AND stat_datetime >= #{startDate}
+        and stat_datetime &lt;= #{endDate}
+        GROUP BY signature
 
 
-        <where>
-            <if test='dimension=="project" and projects!=null'>
-                AND t1.project_id IN
-                <foreach collection="projects" item="item" separator=","
-                         open="(" close=")">
-                    #{item}
-                </foreach>
-            </if>
-            AND t1.stat_datetime >= #{startDate}
-            and t1.stat_datetime &lt;=#{endDate}
-        </where>
-        GROUP BY tt.material_id
-        ORDER BY SUM(t1.cost) DESC LIMIT 5
+        ) t1 on t1.signature=t.material_id
+        ORDER BY charge DESC LIMIT 5
     </select>
     </select>
 
 
     <select id="queryKuaishouTopDesign" resultType="com.alibaba.fastjson.JSONObject">
     <select id="queryKuaishouTopDesign" resultType="com.alibaba.fastjson.JSONObject">
@@ -815,40 +831,56 @@
 
 
 
 
     <select id="queryKuaishouTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
     <select id="queryKuaishouTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT ROUND(SUM(t1.charge),2) as charge,tt.material_id,t1.cover_url as 'coverUrl',tt.video_url as
-        'url',tt.material_name as
-        'materialName',
-        tt.tag as 'tag'
-        from (
-        select t.material_id,t.material_name,GROUP_CONCAT(t2.tag_name) as tag,video_url,cover_url from
-        application.app_kuaishou_material_info t left join
-        application.app_material_tag_busi_info t2 on t.material_id=t2.material_id where tag_category_id=1 and
-        t.company_id=#{companyId}
-
+        SELECT
+        t.material_id,
+        t.tag,
+        ROUND(t1.charge,2) as 'charge',
+        t1.video_name as        'materialName',
+        t1.photo_url  as 'url',
+        t1.cover_url as 'coverUrl'
+        from
+        (
+        select
+        material_id,
+        GROUP_CONCAT(tag_name) as tag
+        from
+        application.app_material_tag_busi_info
+        where
+        tag_category_id=1
+        and company_id=#{companyId}
         <if test='dimension=="designTeam" and leaderId!=null'>
         <if test='dimension=="designTeam" and leaderId!=null'>
-            and t.leader_id=#{leaderId}
+            and leader_id=#{leaderId}
+        </if>
+        group by material_id
+        ) t
+        left join
+        (
+        select
+        signature,
+        sum(charge) as charge,
+        video_name,
+        photo_url,
+        cover_url from
+        application.kuaishou_material_video_report_daily_dw
+        WHERE charge>0
+        <if test='dimension=="designTeam" and leaderId!=null'>
+            and leader_id=#{leaderId}
         </if>
         </if>
         <if test='dimension=="designer" and designerId!=null'>
         <if test='dimension=="designer" and designerId!=null'>
-            and (t.clip_id=#{designerId} or t.shot_id=#{designerId} or t.plan_id=#{designerId})
+            and (clip_id=#{designerId} or shot_id=#{designerId} or plan_id=#{designerId})
         </if>
         </if>
-        group by t.material_id
-        ) tt
-
-        left join
-        application.kuaishou_material_video_report_daily_dw t1 on t1.signature=tt.material_id
-
-        <where>
-            <if test='dimension=="project" and projects!=null'>
-                AND t1.project_id IN
-                <foreach collection="projects" item="item" separator=","
-                         open="(" close=")">
-                    #{item}
-                </foreach>
-            </if>
-            AND t1.stat_date >= #{startDate} and t1.stat_date &lt;= #{endDate}
-        </where>
-        GROUP BY tt.material_id
-        ORDER BY SUM(t1.charge) DESC LIMIT 5
+        <if test='dimension=="project" and projects!=null'>
+            AND project_id IN
+            <foreach collection="projects" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        AND stat_date >= #{startDate}
+        and stat_date &lt;= #{endDate}
+        GROUP BY signature
+        ) t1 on t1.signature=t.material_id
+        ORDER BY charge DESC
+        LIMIT 5
     </select>
     </select>
 
 
     <select id="queryKuaishouMaterialReport" resultType="com.alibaba.fastjson.JSONObject">
     <select id="queryKuaishouMaterialReport" resultType="com.alibaba.fastjson.JSONObject">