Jelajahi Sumber

release of '素材大盘' on 2021.3.19

jiequan.bi 4 tahun lalu
induk
melakukan
bf948d0662

+ 121 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialReportOverViewController.java

@@ -1,13 +1,16 @@
 package org.jeecg.modules.ctop.controller;
 
+import cn.com.ctop.common.module.utils.CtopAdConstant;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.ctop.mapper.MaterialReportOverViewMapper;
 import org.jeecg.modules.ctop.service.IMaterialReportOverViewService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -21,7 +24,10 @@ import java.util.Set;
 public class MaterialReportOverViewController {
 
     @Autowired
-    IMaterialReportOverViewService materialReportOverViewService;
+    private IMaterialReportOverViewService materialReportOverViewService;
+
+    @Autowired
+    private MaterialReportOverViewMapper materialReportOverViewMapper;
 
     /**
      *  根据userId递归查询下属,默认到最后一级,返回人员参与项目集合
@@ -154,11 +160,120 @@ public class MaterialReportOverViewController {
 
     }
 
-    @PostMapping("/materialDetailAnalyse")
-    public Result<Map<String,Object>> materialDetailAnalyse(@RequestBody JSONObject params){
-        Result<Map<String,Object>> result= new Result<>();
-        result.setResult(materialReportOverViewService.materialDetailAnalyse(params.getInteger("mediaId"),
-                params.getString("md5")));
+    @PostMapping("/getProjectIdByMd5")
+    public Result<Long> getProjectIdByMd5(@RequestBody JSONObject params){
+        Result<Long> result= new Result<>();
+        if (params.getInteger("mediaId") == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
+            result.setResult(materialReportOverViewMapper.queryBytedanceProjectIdByMd5(params.getString("md5")));
+        } else if (params.getInteger("mediaId") == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
+            result.setResult(materialReportOverViewMapper.queryKuaishouProjectIdByMd5(params.getString("md5")));
+        }
+        result.setSuccess(true);
+        return result;
+    }
+
+    @PostMapping("/materialDetailCost")
+    public Result<List<JSONObject>> materialDetailCost(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceCostByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailClick")
+    public Result<List<JSONObject>> materialDetailClick(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceClickByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailMaterialShow")
+    public Result<List<JSONObject>> materialDetailMaterialShow(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceMaterialShowByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailPlay100Rate")
+    public Result<List<JSONObject>> materialDetailPlay100Rate(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedancePlay100RateByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailLikeMaterial")
+    public Result<List<JSONObject>> materialDetailLikeMaterial(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceLikeMaterialByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailCommentMaterial")
+    public Result<List<JSONObject>> materialDetailCommentMaterial(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceCommentMaterialByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailShareMaterial")
+    public Result<List<JSONObject>> materialDetailShareMaterial(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceShareMaterialByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailFollow")
+    public Result<List<JSONObject>> materialDetailFollow(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryBytedanceFollowByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailCharge")
+    public Result<List<JSONObject>> materialDetailCharge(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouChargeByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailPhotoShow")
+    public Result<List<JSONObject>> materialDetailPhotoShow(@RequestBody JSONObject params){
+        Result<List<JSONObject>>  result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouPhotoShowByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailPhotoClick")
+    public Result<List<JSONObject>> materialDetailPhotoClick(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouPhotoClickByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailAClick")
+    public Result<List<JSONObject>> materialDetailAClick(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouAClickByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailBClick")
+    public Result<List<JSONObject>> materialDetailBClick(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouBClickByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailActivation")
+    public Result<List<JSONObject>> materialDetailActivation(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouActivationByMd5(params.getString("md5"),params.getLong("projectId")));
+        result.setSuccess(true);
+        return result;
+    }
+    @PostMapping("/materialDetailPlay3sRate")
+    public Result<List<JSONObject>> materialDetailPlay3sRate(@RequestBody JSONObject params){
+        Result<List<JSONObject>> result= new Result<>();
+        result.setResult(materialReportOverViewMapper.queryKuaishouPlay3sRateByMd5(params.getString("md5"),params.getLong("projectId")));
         result.setSuccess(true);
         return result;
     }

+ 3 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/MaterialReportOverViewMapper.java

@@ -75,7 +75,9 @@ public interface MaterialReportOverViewMapper {
     JSONObject queryKuaishouVideoDetail(String md5);
 
     //数据概览
-    Long queryProjectIdByMd5(String md5);
+    Long queryBytedanceProjectIdByMd5(String md5);
+
+    Long queryKuaishouProjectIdByMd5(String md5);
 
     List<JSONObject> queryBytedanceCostByMd5(String md5, Long project);
 

+ 248 - 196
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/MaterialReportOverViewMapper.xml

@@ -80,11 +80,14 @@
         FROM
         etl_report_bytedance_video
         WHERE
-        project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
+        1=1
+        <if test="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}
     </select>
@@ -95,11 +98,14 @@
         FROM
         ctop_etl_kuaishou_account_material_report_daily
         WHERE
-        project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
+        1=1
+        <if test="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}
     </select>
@@ -108,13 +114,16 @@
         SELECT
         count(id) from ctop_material_info
         WHERE
-        DATE_FORMAT(create_time, '%Y-%m-%d')>= #{startDate}
+        1=1
+        <if test="projects !=null">
+            AND project_id IN
+            <foreach collection="projects" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        AND DATE_FORMAT(create_time, '%Y-%m-%d')>= #{startDate}
         AND DATE_FORMAT(create_time, '%Y-%m-%d')&lt;= #{endDate}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
     </select>
 
     <select id="queryNewMaterialCount" resultType="long">
@@ -122,11 +131,13 @@
         count(id) from ctop_material_info
         WHERE
         DATE_FORMAT(create_time, '%Y-%m-%d')= #{statDate}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
+        <if test="projects !=null">
+            AND project_id IN
+            <foreach collection="projects" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
     </select>
 
     <select id="queryBytedanceChat" resultType="com.alibaba.fastjson.JSONObject">
@@ -136,13 +147,16 @@
         FROM
         etl_report_bytedance_video
         WHERE
-        stat_datetime >= #{startDate}
+        1=1
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         group by stat_datetime
         order by stat_datetime
     </select>
@@ -154,13 +168,16 @@
         FROM
         etl_report_bytedance_video
         WHERE
-        stat_datetime >= #{startDate}
+        1=1
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         group by DATE_FORMAT(stat_datetime, '%Y-%m')
         order by stat_datetime asc
     </select>
@@ -172,13 +189,16 @@
         FROM
         ctop_etl_kuaishou_account_material_report_daily
         WHERE
-        stat_date >= #{startDate}
+        1=1
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         group by stat_date
         order by stat_date
     </select>
@@ -190,13 +210,16 @@
         FROM
         ctop_etl_kuaishou_account_material_report_daily
         WHERE
-        stat_date >= #{startDate}
+        1=1
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         group by DATE_FORMAT(stat_date, '%Y-%m')
         order by stat_date
     </select>
@@ -212,13 +235,16 @@
         FROM
         etl_report_bytedance_video t1
         WHERE
-        stat_datetime >= #{startDate}
+        1=1
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         GROUP BY t1.md5
         ORDER BY cost desc
         limit 5
@@ -240,13 +266,15 @@
         <if test="md5 !=null and md5 != ''">
             AND t1.md5= #{md5}
         </if>
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         GROUP BY t1.md5
         ORDER BY ${target} ${order}
     </select>
@@ -262,13 +290,15 @@
         <if test="md5 !=null and md5 != ''">
             AND t1.md5= #{md5}
         </if>
+        <if test="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}
-        AND project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         GROUP BY t1.md5) t
     </select>
 
@@ -284,13 +314,16 @@
         (select sum(charge) as charge,signature
         from ctop_etl_kuaishou_account_material_report_daily t1
         where
-        t1.stat_date >= #{startDate}
+        1=1
+        <if test="projects !=null">
+            AND 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}
-        AND t1.project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         GROUP BY t1.signature
         ORDER BY charge desc
         limit 5
@@ -316,13 +349,15 @@
         <if test="md5 !=null and md5 != ''">
             AND t1.signature= #{md5}
         </if>
+        <if test="projects !=null">
+            AND 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}
-        AND t1.project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         GROUP BY t1.signature
         ) t1
         LEFT JOIN ctop_etl_kuaishou_video_info t2
@@ -345,13 +380,15 @@
         <if test="md5 !=null and md5 != ''">
             AND t1.signature= #{md5}
         </if>
+        <if test="projects !=null">
+            AND 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}
-        AND t1.project_id IN
-        <foreach collection="projects" item="item" separator=","
-                 open="(" close=")">
-            #{item}
-        </foreach>
         GROUP BY t1.signature
         ) t1
         LEFT JOIN ctop_etl_kuaishou_video_info t2
@@ -426,7 +463,7 @@
                t2.size,
                '内部'                                                                                  as channelType,
                t.`code`,
-               ''                                                                                    as materialType,
+               ''                                                                                  as materialType,
                t2.height,
                t2.width,
                '北京汇创思拓数字科技有限公司'                                                                      as supplier,
@@ -461,7 +498,7 @@
                IFNULL(t1.clip_name, '')                                                                 clipName,
                IFNULL(t1.shot_name, '')                                                                 shotName,
                IFNULL(t1.plan_name, '')                                                                 planName
-        FROM ctop_material_info t
+        FROM ctop_material_info  t
                  LEFT JOIN ctop_etl_kuaishou_video_info t1 ON t.`code` = t1.video_code
                  LEFT JOIN ctop_material_parameter t2 on t.`code` = t2.material_id
         where t.code = #{md5}
@@ -486,11 +523,26 @@
         ORDER BY stat_date
     </select>
 
-    <select id="queryProjectIdByMd5" resultType="java.lang.Long">
-        select project_id
-        from ctop_material_info
-        where code = #{md5}
-        limit 1
+    <select id="queryBytedanceProjectIdByMd5" resultType="java.lang.Long">
+        SELECT
+            project_id
+        FROM
+            etl_report_bytedance_video
+        WHERE
+            md5 = #{md5}
+          AND project_id IS NOT NULL
+        LIMIT 1
+    </select>
+
+    <select id="queryKuaishouProjectIdByMd5" resultType="java.lang.Long">
+        SELECT
+            project_id
+        FROM
+            ctop_etl_kuaishou_account_material_report_daily
+        WHERE
+            signature = #{md5}
+          AND project_id IS NOT NULL
+        LIMIT 1
     </select>
 
     <select id="queryBytedanceCostByMd5" resultType="com.alibaba.fastjson.JSONObject">
@@ -697,24 +749,24 @@
     <select id="queryKuaishouChargeByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select charge
         from (
-        SELECT ROUND(sum(charge), 2) charge,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT ROUND(MAX(charge), 2) top,
-            2 as num
-        FROM (
-                 SELECT sum(charge) charge
+                 SELECT ROUND(sum(charge), 2) charge,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT ROUND(MAX(charge), 2) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(charge) charge
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(AVG(charge), 2) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(AVG(charge), 2) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -722,24 +774,24 @@
     <select id="queryKuaishouPhotoShowByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select photoShow
         from (
-        SELECT sum(photo_show) photoShow,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT MAX(photoShow) top,
-            2 as num
-        FROM (
-                 SELECT sum(photo_show) photoShow
+                 SELECT sum(photo_show) photoShow,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT MAX(photoShow) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(photo_show) photoShow
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(AVG(photo_show), 0) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(AVG(photo_show), 0) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -747,24 +799,24 @@
     <select id="queryKuaishouPhotoClickByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select photoClick
         from (
-        SELECT sum(photo_click) photoClick,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT MAX(photoClick) top,
-            2 as num
-        FROM (
-                 SELECT sum(photo_click) photoClick
+                 SELECT sum(photo_click) photoClick,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT MAX(photoClick) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(photo_click) photoClick
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(AVG(photo_click), 0) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(AVG(photo_click), 0) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -772,24 +824,24 @@
     <select id="queryKuaishouAClickByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select aclick
         from (
-        SELECT sum(aclick) aclick,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT MAX(aclick) top,
-            2 as num
-        FROM (
-                 SELECT sum(aclick) aclick
+                 SELECT sum(aclick) aclick,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT MAX(aclick) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(aclick) aclick
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(AVG(aclick), 0) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(AVG(aclick), 0) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -797,24 +849,24 @@
     <select id="queryKuaishouBClickByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select bclick
         from (
-        SELECT sum(bclick) bclick,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT MAX(bclick) top,
-            2 as num
-        FROM (
-                 SELECT sum(bclick) bclick
+                 SELECT sum(bclick) bclick,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT MAX(bclick) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(bclick) bclick
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(AVG(bclick), 0) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(AVG(bclick), 0) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -822,24 +874,24 @@
     <select id="queryKuaishouActivationByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select activation
         from (
-        SELECT sum(activation) activation,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT MAX(activation) top,
-            2 as num
-        FROM (
-                 SELECT sum(activation) activation
+                 SELECT sum(activation) activation,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT MAX(activation) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(activation) activation
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(AVG(activation), 0) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(AVG(activation), 0) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -847,24 +899,24 @@
     <select id="queryKuaishouPlay3sRateByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select play3sRate
         from (
-        SELECT round(sum(play_3s_count) / sum(photo_show), 2) play3sRate,
-            1 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE signature = #{md5}
-        union all
-        SELECT ROUND(MAX(play3sRate), 2) top,
-            2 as num
-        FROM (
-                 SELECT sum(play_3s_count) / sum(photo_show) play3sRate
+                 SELECT round(sum(play_3s_count) / sum(photo_show), 2) play3sRate,
+                        1 as num
+                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 WHERE signature = #{md5}
+                 union all
+                 SELECT ROUND(MAX(play3sRate), 2) top,
+                        2 as num
+                 FROM (
+                          SELECT sum(play_3s_count) / sum(photo_show) play3sRate
+                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          WHERE project_id = #{project}
+                          GROUP BY signature
+                      ) t
+                 union all
+                 SELECT ROUND(sum(play_3s_count) / sum(photo_show), 2) average,
+                        3 as num
                  FROM ctop_etl_kuaishou_account_material_report_daily
                  WHERE project_id = #{project}
-                 GROUP BY signature
-             ) t
-        union all
-        SELECT ROUND(sum(play_3s_count) / sum(photo_show), 2) average,
-            3 as num
-        FROM ctop_etl_kuaishou_account_material_report_daily
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>

+ 12 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/MaterialReportOverViewServiceImpl.java

@@ -13,6 +13,7 @@ import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.JsonResourceUtil;
 import org.jeecg.modules.ctop.mapper.MaterialReportOverViewMapper;
 import org.jeecg.modules.ctop.service.IMaterialReportOverViewService;
+import org.jeecg.modules.system.service.ISysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -24,7 +25,10 @@ import java.util.*;
 public class MaterialReportOverViewServiceImpl implements IMaterialReportOverViewService {
 
     @Autowired
-    MaterialReportOverViewMapper materialReportOverViewMapper;
+    private MaterialReportOverViewMapper materialReportOverViewMapper;
+
+    @Autowired
+    private ISysRoleService roleService;
 
     @Override
     public Set<String> recursiveQuerySubordinate(String userId) {
@@ -196,8 +200,8 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
     @Override
     public Map<String, Object> materialDetailAnalyse(int mediaId, String md5) {
         Map<String,Object> result = new HashMap<>();
-        Long projectId = materialReportOverViewMapper.queryProjectIdByMd5(md5)==null?0L:materialReportOverViewMapper.queryProjectIdByMd5(md5);
         if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
+            Long projectId= materialReportOverViewMapper.queryBytedanceProjectIdByMd5(md5);
             result.put("cost",materialReportOverViewMapper.queryBytedanceCostByMd5(md5,projectId));
             result.put("click",materialReportOverViewMapper.queryBytedanceClickByMd5(md5,projectId));
             result.put("materialShow",materialReportOverViewMapper.queryBytedanceMaterialShowByMd5(md5,projectId));
@@ -207,6 +211,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
             result.put("shareMaterial",materialReportOverViewMapper.queryBytedanceShareMaterialByMd5(md5,projectId));
             result.put("follow",materialReportOverViewMapper.queryBytedanceFollowByMd5(md5,projectId));
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
+            Long projectId= materialReportOverViewMapper.queryKuaishouProjectIdByMd5(md5);
             result.put("charge",materialReportOverViewMapper.queryKuaishouChargeByMd5(md5,projectId));
             result.put("photoShow",materialReportOverViewMapper.queryKuaishouPhotoShowByMd5(md5,projectId));
             result.put("photoClick",materialReportOverViewMapper.queryKuaishouPhotoClickByMd5(md5,projectId));
@@ -243,6 +248,11 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
     //当项目为空的时候,根据当前登录人查询可查看的所有项目集合
     private JSONArray getProjectsByCurrentUser(int mediaId) {
         String currentUser = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
+        //TODO 为了解决管理员等角色初始化查全部项目查询效率慢的问题判断角色,待优化
+        String roleCode= roleService.getRoleCodeByUserId(currentUser);
+        if(roleCode.equals("admin")){
+            return null;
+        }
         return queryProjectIdBy(recursiveQuerySubordinate(currentUser), mediaId);
     }
 }