Browse Source

sql优化

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

+ 2 - 2
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/MaterialReportOverViewV3Mapper.java

@@ -174,9 +174,9 @@ public interface MaterialReportOverViewV3Mapper {
 
 
     BigDecimal getKuaishouDesignTeamAvgCost(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("leaderId") String leaderId, @Param("companyId") String companyId);
     BigDecimal getKuaishouDesignTeamAvgCost(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("leaderId") String leaderId, @Param("companyId") String companyId);
 
 
-    BigDecimal getBytedanceDesignTeamGroupWork(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("leaderId") String leaderId);
+    BigDecimal getBytedanceDesignTeamGroupWork(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("leaderId") String leaderId);
 
 
-    BigDecimal getKuaishouDesignTeamGroupWork(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("leaderId") String leaderId);
+    BigDecimal getKuaishouDesignTeamGroupWork(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("leaderId") String leaderId);
 
 
     int getBytedanceDesignTeaminnovativeVideoCount(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("leaderId") String leaderId);
     int getBytedanceDesignTeaminnovativeVideoCount(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("leaderId") String leaderId);
 
 

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

@@ -695,7 +695,7 @@
         application.bytedance_material_video_report_daily_dw t1
         application.bytedance_material_video_report_daily_dw t1
         LEFT JOIN
         LEFT JOIN
         application.app_bytedance_material_info t on t.material_id=t1.signature
         application.app_bytedance_material_info t on t.material_id=t1.signature
-        <if test='materialType!=null'>
+        <if test="materialType!=null and materialType!=''">
             LEFT JOIN
             LEFT JOIN
             (select material_id from application.app_material_tag_busi_info
             (select material_id from application.app_material_tag_busi_info
             <if test='materialType==1'>
             <if test='materialType==1'>
@@ -734,9 +734,12 @@
             <if test='innovative==1'>
             <if test='innovative==1'>
                 and t.material_innovate=1
                 and t.material_innovate=1
             </if>
             </if>
-            <if test='materialType!=null'>
+            <if test="materialType!=null and materialType!=''">
                 and t2.material_id is not null
                 and t2.material_id is not null
             </if>
             </if>
+            <if test="md5!=null and md5!=''">
+                and t1.material_id =#{md5}
+            </if>
 
 
             AND t1.company_id=#{companyId}
             AND t1.company_id=#{companyId}
         </where>
         </where>
@@ -814,7 +817,7 @@
         application.kuaishou_material_video_report_daily_dw t1
         application.kuaishou_material_video_report_daily_dw t1
         LEFT JOIN
         LEFT JOIN
         application.app_kuaishou_material_info t on  t1.signature=t.material_id
         application.app_kuaishou_material_info t on  t1.signature=t.material_id
-        <if test='materialType!=null'>
+        <if test="materialType!=null and materialType!=''">
             LEFT JOIN
             LEFT JOIN
             (select material_id from application.app_material_tag_busi_info
             (select material_id from application.app_material_tag_busi_info
             <if test='materialType==1'>
             <if test='materialType==1'>
@@ -856,9 +859,12 @@
             <if test='innovative==1'>
             <if test='innovative==1'>
                 and t.material_innovate=1
                 and t.material_innovate=1
             </if>
             </if>
-            <if test='materialType!=null'>
+            <if test="materialType!=null and materialType!=''">
                 and t2.material_id is not null
                 and t2.material_id is not null
             </if>
             </if>
+            <if test="md5!=null and md5!=''">
+                and t1.signature =#{md5}
+            </if>
             AND t1.company_id=#{companyId}
             AND t1.company_id=#{companyId}
         </where>
         </where>
         GROUP BY t1.signature
         GROUP BY t1.signature
@@ -1474,72 +1480,73 @@
     <!-- 头条组内人均消耗-->
     <!-- 头条组内人均消耗-->
     <select id="getBytedanceDesignTeamAvgCost" resultType="java.math.BigDecimal">
     <select id="getBytedanceDesignTeamAvgCost" resultType="java.math.BigDecimal">
         SELECT  IFNULL(ROUND( SUM(cost)/
         SELECT  IFNULL(ROUND( SUM(cost)/
-        (SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1),2),0)
+        ((SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1)+1),2),0)
         from  application.bytedance_material_video_report_daily_dw  t
         from  application.bytedance_material_video_report_daily_dw  t
         where  t.stat_datetime &gt;= #{startDate} and  t.stat_datetime &lt;=#{endDate} and t.leader_id=#{leaderId} and t.company_id=#{companyId}
         where  t.stat_datetime &gt;= #{startDate} and  t.stat_datetime &lt;=#{endDate} and t.leader_id=#{leaderId} and t.company_id=#{companyId}
     </select>
     </select>
     <!-- 快手组内人均消耗-->
     <!-- 快手组内人均消耗-->
     <select id="getKuaishouDesignTeamAvgCost" resultType="java.math.BigDecimal">
     <select id="getKuaishouDesignTeamAvgCost" resultType="java.math.BigDecimal">
         SELECT  IFNULL(ROUND( SUM(charge)/
         SELECT  IFNULL(ROUND( SUM(charge)/
-        (SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1),2),0)
+        ((SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1)+1),2),0)
         from  application.kuaishou_material_video_report_daily_dw  t
         from  application.kuaishou_material_video_report_daily_dw  t
         where  t.stat_date &gt;= #{startDate} and  t.stat_date &lt;=#{endDate} and t.leader_id=#{leaderId} and t.company_id=#{companyId}
         where  t.stat_date &gt;= #{startDate} and  t.stat_date &lt;=#{endDate} and t.leader_id=#{leaderId} and t.company_id=#{companyId}
     </select>
     </select>
 
 
     <!-- 头条组人效-->
     <!-- 头条组人效-->
     <select id="getBytedanceDesignTeamGroupWork" resultType="java.math.BigDecimal">
     <select id="getBytedanceDesignTeamGroupWork" resultType="java.math.BigDecimal">
-        SELECT  IFNULL(ROUND(COUNT(t.signature)/
+        SELECT  IFNULL(ROUND(COUNT(t.material_id)/
         (SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1),2),0)
         (SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1),2),0)
-        from  application.app_bytedance_file_video_get  t
-        where  t.create_time &gt;=#{startDate} and  t.create_time &lt;=#{endDate} and leader_id=#{leaderId}
+        from  application.app_bytedance_material_info  t
+        where  t.media_time between #{startDate} and #{endDate} and leader_id=#{leaderId}
     </select>
     </select>
 
 
     <!-- 快手组人效-->
     <!-- 快手组人效-->
     <select id="getKuaishouDesignTeamGroupWork" resultType="java.math.BigDecimal">
     <select id="getKuaishouDesignTeamGroupWork" resultType="java.math.BigDecimal">
-        SELECT  IFNULL(ROUND(COUNT(t.signature)/
+        SELECT  IFNULL(ROUND(COUNT(t.material_id)/
         (SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1),2),0)
         (SELECT COUNT(*) from sys_user where leader_id=#{leaderId} and status=1),2),0)
-        from  application.app_kuaishou_video_list  t
-        where  t.stat_date &gt;=#{startDate} and  t.stat_date &lt;=#{endDate} and leader_id=#{leaderId}
+        from  application.app_kuaishou_material_info  t
+        where  t.media_time between #{startDate} and #{endDate} and leader_id=#{leaderId}
     </select>
     </select>
 
 
     <!-- 头条创新视频数-->
     <!-- 头条创新视频数-->
     <select id="getBytedanceDesignTeaminnovativeVideoCount" resultType="int">
     <select id="getBytedanceDesignTeaminnovativeVideoCount" resultType="int">
          SELECT  ifnull(count(*),0)
          SELECT  ifnull(count(*),0)
-        from  application.app_bytedance_file_video_get  t
-        where  t.material_innovate &gt;=#{startDate} and  t.material_innovate &lt;=#{endDate} and leader_id=#{leaderId}
+        from  application.app_bytedance_material_info  t
+        where  t.media_time between #{startDate} and #{endDate} and t.material_innovate=2 and leader_id=#{leaderId}
     </select>
     </select>
 
 
     <!-- 快手创新视频数-->
     <!-- 快手创新视频数-->
     <select id="getKuaishouDesignTeaminnovativeVideoCount" resultType="int">
     <select id="getKuaishouDesignTeaminnovativeVideoCount" resultType="int">
          SELECT  ifnull(count(*),0)
          SELECT  ifnull(count(*),0)
-        from  application.app_kuaishou_video_list  t
-        where  t.material_innovate &gt;=#{startDate} and  t.material_innovate &lt;=#{endDate} and leader_id=#{leaderId}
+        from  application.app_kuaishou_material_info  t
+        where t.media_time between #{startDate} and #{endDate} and  t.material_innovate=2 and leader_id=#{leaderId}
     </select>
     </select>
 
 
     <!-- 头条素材平均消耗-->
     <!-- 头条素材平均消耗-->
     <select id="getBytedanceMaterialCost" resultType="java.math.BigDecimal">
     <select id="getBytedanceMaterialCost" resultType="java.math.BigDecimal">
-        SELECT
-        IFNULL(ROUND(
+           select
+            IFNULL(ROUND(
+                (SELECT  SUM(t1.cost)
+        from  application.app_bytedance_material_info  t
+		LEFT JOIN  application.bytedance_material_video_report_daily_dw t1 on t.material_id=t1.signature
+        where t.media_time between #{startDate} and #{endDate} and t.leader_id=#{leaderId} and t.company_id=#{companyId}
+		and t1.stat_datetime between #{startDate} and #{endDate})
+		/
+         (SELECT  ifnull(count(DISTINCT t.material_id),0)
+        from  application.app_bytedance_material_info  t
+        where t.media_time between #{startDate} and #{endDate}  and t.leader_id=#{leaderId} and t.company_id=#{companyId})
+            ,2),0)
 
 
-        (SELECT SUM(cost) from application.bytedance_material_video_report_daily_dw t2
-        where
-        t2.stat_datetime &gt;=#{startDate} and   t2.stat_datetime&lt;= #{endDate}  and t2.leader_id=#{leaderId} and company_id=#{companyId})/
-
-        (SELECT  DISTINCT COUNT(t.signature) from application.app_bytedance_file_video_get t
-        where
-        t.create_time &gt;=str_to_date(#{startDate}, '%Y-%m-%d') and  t.create_time &lt;=str_to_date(#{endDate}, '%Y-%m-%d')  and t.leader_id=#{leaderId})
-        ,2),0)
 
 
     </select>
     </select>
 
 
     <!-- 快手创新视频消耗-->
     <!-- 快手创新视频消耗-->
     <select id="getKuaishouDesignTeaminnovativeVideoCost" resultType="java.math.BigDecimal">
     <select id="getKuaishouDesignTeaminnovativeVideoCost" resultType="java.math.BigDecimal">
-        SELECT  ifnull(ROUND(sum(charge),2),0)
-        from  application.app_kuaishou_video_list  t
-        left join  application.kuaishou_material_video_report_daily_dw t1 on t.signature=t1.signature
-        where  t.material_innovate &gt;=#{startDate} and  t.material_innovate &lt;=#{endDate} and t.leader_id=#{leaderId}
-        and t1.stat_date &gt;=#{startDate} and   t1.stat_date &lt;=#{endDate} and  t1.leader_id=#{leaderId}
-
+        SELECT  SUM(t1.charge)
+        from  application.app_kuaishou_material_info  t
+		LEFT JOIN  application.kuaishou_material_video_report_daily_dw t1 on t.material_id=t1.signature
+        where t.media_time between #{startDate} and #{endDate} and  t.material_innovate=2 and t.leader_id=#{leaderId} and t.company_id=#{companyId}
+		and t1.stat_date between #{startDate} and #{endDate}
     </select>
     </select>
 
 
 
 

+ 4 - 4
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/MaterialReportOverViewV2ServiceImpl.java

@@ -349,7 +349,7 @@ public class MaterialReportOverViewV2ServiceImpl implements IMaterialReportOverV
     @Override
     @Override
     public void exportBytedanceExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
     public void exportBytedanceExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
         JSONArray projects = requestBody.getJSONArray("projects");
         JSONArray projects = requestBody.getJSONArray("projects");
-        if (projects.isEmpty()) {
+        if (projects!=null && projects.isEmpty()) {
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
         }
         }
         JSONArray columns = requestBody.getJSONArray("columns");
         JSONArray columns = requestBody.getJSONArray("columns");
@@ -413,7 +413,7 @@ public class MaterialReportOverViewV2ServiceImpl implements IMaterialReportOverV
     @Override
     @Override
     public void exportKuaishouExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
     public void exportKuaishouExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
         JSONArray projects = requestBody.getJSONArray("projects");
         JSONArray projects = requestBody.getJSONArray("projects");
-        if (projects.isEmpty()) {
+        if (projects!=null && projects.isEmpty()) {
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
         }
         }
         JSONArray columns2 = new JSONArray();
         JSONArray columns2 = new JSONArray();
@@ -757,7 +757,7 @@ public class MaterialReportOverViewV2ServiceImpl implements IMaterialReportOverV
             //组内人均消耗
             //组内人均消耗
             BigDecimal sumCost = materialReportOverViewV3Mapper.getBytedanceDesignTeamAvgCost(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId, companyId);
             BigDecimal sumCost = materialReportOverViewV3Mapper.getBytedanceDesignTeamAvgCost(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId, companyId);
             //组人效
             //组人效
-            BigDecimal groupWork = materialReportOverViewV3Mapper.getBytedanceDesignTeamGroupWork(startDate, endDate, leaderId);
+            BigDecimal groupWork = materialReportOverViewV3Mapper.getBytedanceDesignTeamGroupWork(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId);
             //创新视频数
             //创新视频数
             int innovativeVideoCount = materialReportOverViewV3Mapper.getBytedanceDesignTeaminnovativeVideoCount(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId);
             int innovativeVideoCount = materialReportOverViewV3Mapper.getBytedanceDesignTeaminnovativeVideoCount(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId);
             //素材平均消耗
             //素材平均消耗
@@ -772,7 +772,7 @@ public class MaterialReportOverViewV2ServiceImpl implements IMaterialReportOverV
             //组内人均消耗
             //组内人均消耗
             BigDecimal sumCost = materialReportOverViewV3Mapper.getKuaishouDesignTeamAvgCost(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId, companyId);
             BigDecimal sumCost = materialReportOverViewV3Mapper.getKuaishouDesignTeamAvgCost(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId, companyId);
             //组人效
             //组人效
-            BigDecimal groupWork = materialReportOverViewV3Mapper.getKuaishouDesignTeamGroupWork(startDate, endDate, leaderId);
+            BigDecimal groupWork = materialReportOverViewV3Mapper.getKuaishouDesignTeamGroupWork(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId);
             //创新视频数
             //创新视频数
             int innovativeVideoCount = materialReportOverViewV3Mapper.getKuaishouDesignTeaminnovativeVideoCount(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId);
             int innovativeVideoCount = materialReportOverViewV3Mapper.getKuaishouDesignTeaminnovativeVideoCount(Long.parseLong(startDate.replace("-", "")), Long.parseLong(endDate.replace("-", "")), leaderId);
             //创新视频消耗
             //创新视频消耗