浏览代码

Merge branch 'zzy' into test

zhouzeyu@c-top.com.cn 3 年之前
父节点
当前提交
a5406dbdfb

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

@@ -303,7 +303,7 @@ public class MaterialReportOverViewController {
         result.setSuccess(true);
         return result;
     }
-    @PostMapping("/materialDetailPhotoShow")
+   /* @PostMapping("/materialDetailPhotoShow")
     public Result<Map<String,Object>> materialDetailPhotoShow(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
         Map<String,Object> map = new HashMap<>();
@@ -311,8 +311,8 @@ public class MaterialReportOverViewController {
         result.setResult(map);
         result.setSuccess(true);
         return result;
-    }
-    @PostMapping("/materialDetailPhotoClick")
+    }*/
+  /*  @PostMapping("/materialDetailPhotoClick")
     public Result<Map<String,Object>> materialDetailPhotoClick(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
         Map<String,Object> map = new HashMap<>();
@@ -320,7 +320,7 @@ public class MaterialReportOverViewController {
         result.setResult(map);
         result.setSuccess(true);
         return result;
-    }
+    }*/
     @PostMapping("/materialDetailAClick")
     public Result<Map<String,Object>> materialDetailAClick(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
@@ -330,7 +330,7 @@ public class MaterialReportOverViewController {
         result.setSuccess(true);
         return result;
     }
-    @PostMapping("/materialDetailBClick")
+   /* @PostMapping("/materialDetailBClick")
     public Result<Map<String,Object>> materialDetailBClick(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
         Map<String,Object> map = new HashMap<>();
@@ -338,7 +338,7 @@ public class MaterialReportOverViewController {
         result.setResult(map);
         result.setSuccess(true);
         return result;
-    }
+    }*/
     @PostMapping("/materialDetailActivation")
     public Result<Map<String,Object>> materialDetailActivation(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
@@ -366,4 +366,44 @@ public class MaterialReportOverViewController {
         result.setSuccess(true);
         return result;
     }
+    /**  查询人群分析数据列表
+     * @param
+     * @return
+     */
+    @GetMapping("/populationAnalysisList")
+    public Result  populationAnalysisList(@RequestParam String signature){
+        return materialReportOverViewService.populationAnalysisList(signature);
+
+    }
+
+    /**  查询人群分析数据图
+     * @param
+     * @return
+     */
+    @GetMapping("/populationAnalysisChart")
+    public Result  populationAnalysisChart(@RequestParam("signature") String signature){
+        return materialReportOverViewService.populationAnalysisChart(signature);
+
+    }
+
+    /**  最优定向组合
+     * @param
+     * @return
+     */
+    @GetMapping("/optimalCombination")
+    public Result  optimalCombination(@RequestParam("signature") String signature){
+        return materialReportOverViewService.optimalCombination(signature);
+
+    }
+
+    /**  相似素材
+     * @param
+     * @return
+     */
+    @GetMapping("/similarMaterial")
+    public Result  similarMaterial(@RequestParam("signature") String signature){
+        return materialReportOverViewService.similarMaterial(signature);
+
+    }
+
 }

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

@@ -138,4 +138,16 @@ public interface MaterialReportOverViewMapper {
     List<JSONObject> queryBytedanceVideoChat(String md5);
 
     List<JSONObject> queryKuaishouVideoChat(String md5);
+
+    List<Map> populationAnalysisList(@Param("signature") String signature);
+
+    String getActualProb(@Param("signature") String signature,@Param("targetType") String targetType);
+
+    List<Map> populationAnalysisChart(@Param("signature")String signature);
+
+    Map<String,String> optimalCombination(@Param("signature")String signature,@Param("targetType")String targetType);
+
+    Map<String,String> similarMaterialInfo(@Param("signature")String signature);
+
+    Map<String,String> getSimilarMaterialList(@Param("signature")String signature);
 }

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

@@ -148,7 +148,7 @@
         ORDER BY time
 
     </select>
-<!-- 查询素材 上新 数据  快手-->
+    <!-- 查询素材 上新 数据  快手-->
     <select id="queryMaterialCountListKs" resultType="java.util.HashMap">
         SELECT
         count(distinct code) as count ,
@@ -170,7 +170,7 @@
         ORDER BY time
     </select>
 
- <!-- 查询有消耗的素材 头条 -->
+    <!-- 查询有消耗的素材 头条 -->
     <select id="queryMaterialCostList" resultType="long">
         SELECT
         COUNT( distinct m.id) as count
@@ -178,7 +178,8 @@
         ctop_material_info m
         LEFT join ctop_project cp on cp.id = m.project_id
         LEFT JOIN ctop_bytedance_video_info v ON m.CODE = v.signature
-        LEFT JOIN ctop_bytedance_report_material_daily r ON v.account_id = r.account_id AND v.material_id = r.material_id
+        LEFT JOIN ctop_bytedance_report_material_daily r ON v.account_id = r.account_id AND v.material_id =
+        r.material_id
         WHERE
         1 = 1
         AND r.cost > 0
@@ -195,7 +196,7 @@
 
     </select>
 
- <!-- 查询有消耗的素材 快手 -->
+    <!-- 查询有消耗的素材 快手 -->
     <select id="queryMaterialCostListKs" resultType="long">
 
         SELECT
@@ -222,8 +223,8 @@
     <!-- 有效视频-头条 -->
     <select id="selectEffectiveMaterialVideoBytedance" resultType="java.util.HashMap">
         select
-               COUNT(m.id) count,
-               b.effect_date as time
+        COUNT(m.id) count,
+        b.effect_date as time
         from
         ctop_bytedance_video_etl_info b
         LEFT JOIN ctop_material_info m on m.code = b.video_code
@@ -246,8 +247,8 @@
     <!-- 有效视频-快手 -->
     <select id="selectEffectiveMaterialVideoKs" resultType="java.util.HashMap">
         select
-               COUNT(m.id) count,
-             b.effect_date as time
+        COUNT(m.id) count,
+        b.effect_date as time
         from
         ctop_kuaishou_video_etl_info b
         LEFT JOIN ctop_material_info m on m.code = b.video_code
@@ -270,7 +271,7 @@
     <!-- 爆款视频-头条 -->
     <select id="selectHotMaterialVideoBytedance" resultType="java.util.HashMap">
         select
-               COUNT(m.id) count,
+        COUNT(m.id) count,
         b.faddish_date as time
         from
         ctop_bytedance_video_etl_info b
@@ -294,8 +295,8 @@
     <!-- 爆款视频-快手 -->
     <select id="selectHotMaterialVideoKs" resultType="java.util.HashMap">
         select
-            COUNT(m.id) count,
-            b.faddish_date as time
+        COUNT(m.id) count,
+        b.faddish_date as time
         from
         ctop_kuaishou_video_etl_info b
         LEFT JOIN ctop_material_info m on m.code = b.video_code
@@ -315,7 +316,6 @@
     </select>
 
 
-
     <select id="queryNewMaterialCount" resultType="long">
         SELECT
         count(id) from ctop_material_info
@@ -333,6 +333,8 @@
     <select id="queryBytedanceChat" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(cost) as cost,
+        sum(material_show) as aclick,
+        sum(active) as active,
         stat_datetime as statDate
         FROM
         etl_report_bytedance_video
@@ -354,6 +356,8 @@
     <select id="queryBytedanceChatGroupMonth" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(cost) as cost,
+        sum(material_show) as aclick,
+        sum(active) as active,
         DATE_FORMAT(stat_datetime, '%Y-%m') as statDate
         FROM
         etl_report_bytedance_video
@@ -375,6 +379,8 @@
     <select id="queryKuaishouChat" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(charge) as cost,
+        sum(photo_show) as aclick,
+        sum(activation) as active,
         stat_date as statDate
         FROM
         ctop_etl_kuaishou_account_material_report_daily
@@ -396,6 +402,8 @@
     <select id="queryKuaishouChatGroupMonth" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(charge) as cost,
+        sum(photo_show) as aclick,
+        sum(activation) as active,
         DATE_FORMAT(stat_date, '%Y-%m') as statDate
         FROM
         ctop_etl_kuaishou_account_material_report_daily
@@ -445,12 +453,13 @@
     <select id="queryKuaishouTopDesign" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.charge as cost
-        <if test="type == 1"> ,t1.shot_name as userName, "摄像" as roleName </if>
-        <if test="type == 2"> ,t1.clip_name as userName, "剪辑" as roleName </if>
-        <if test="type == 3"> ,t1.plan_name as userName, "编导" as roleName </if>
+        <if test="type == 1">,t1.shot_name as userName, "摄像" as roleName</if>
+        <if test="type == 2">,t1.clip_name as userName, "剪辑" as roleName</if>
+        <if test="type == 3">,t1.plan_name as userName, "编导" as roleName</if>
         FROM
         (select sum(charge) as charge,t2.*
-        from ctop_etl_kuaishou_account_material_report_daily t1 LEFT JOIN ctop_etl_kuaishou_video_info t2 ON t1.signature = t2.video_code
+        from ctop_etl_kuaishou_account_material_report_daily t1 LEFT JOIN ctop_etl_kuaishou_video_info t2 ON
+        t1.signature = t2.video_code
         where
         1=1
         AND t1.stat_date &gt;= #{startDate}
@@ -462,30 +471,29 @@
                 #{item}
             </foreach>
         </if>
-        <if test="type == 1"> AND t2.shot_id is not null and t2.shot_id != '' GROUP BY t2.shot_id</if>
-        <if test="type == 2"> AND t2.clip_id is not null and t2.clip_id != '' GROUP BY t2.clip_id</if>
-        <if test="type == 3"> AND t2.plan_id is not null and t2.plan_id != '' GROUP BY t2.plan_id</if>
-        ORDER BY charge desc  LIMIT 10
+        <if test="type == 1">AND t2.shot_id is not null and t2.shot_id != '' GROUP BY t2.shot_id</if>
+        <if test="type == 2">AND t2.clip_id is not null and t2.clip_id != '' GROUP BY t2.clip_id</if>
+        <if test="type == 3">AND t2.plan_id is not null and t2.plan_id != '' GROUP BY t2.plan_id</if>
+        ORDER BY charge desc LIMIT 10
         ) t1
 
 
-
     </select>
 
     <select id="queryBytedanceTopDesign" resultType="com.alibaba.fastjson.JSONObject">
 
         SELECT
         t1.cost
-        <if test="type == 1"> ,t1.shot_name as userName, "摄像" as roleName </if>
-        <if test="type == 2"> ,t1.clip_name as userName, "剪辑" as roleName </if>
-        <if test="type == 3"> ,t1.plan_name as userName, "编导" as roleName </if>
+        <if test="type == 1">,t1.shot_name as userName, "摄像" as roleName</if>
+        <if test="type == 2">,t1.clip_name as userName, "剪辑" as roleName</if>
+        <if test="type == 3">,t1.plan_name as userName, "编导" as roleName</if>
         FROM
         (select sum(cost) as cost,clip_name,plan_name,shot_name
         from etl_report_bytedance_video t1
         where
         1=1
         AND t1.stat_datetime &gt;= #{startDate}
-        AND t1.stat_datetime &lt;=  #{endDate}
+        AND t1.stat_datetime &lt;= #{endDate}
         <if test="projects !=null">
             AND project_id IN
             <foreach collection="projects" item="item" separator=","
@@ -493,10 +501,10 @@
                 #{item}
             </foreach>
         </if>
-        <if test="type == 1"> AND t1.shot_id is not null and t1.shot_id != '' GROUP BY t1.shot_id</if>
-        <if test="type == 2"> AND t1.clip_id is not null and t1.clip_id != '' GROUP BY t1.clip_id</if>
-        <if test="type == 3"> AND t1.plan_id is not null and t1.plan_id != '' GROUP BY t1.plan_id</if>
-        ORDER BY cost desc  LIMIT 10
+        <if test="type == 1">AND t1.shot_id is not null and t1.shot_id != '' GROUP BY t1.shot_id</if>
+        <if test="type == 2">AND t1.clip_id is not null and t1.clip_id != '' GROUP BY t1.clip_id</if>
+        <if test="type == 3">AND t1.plan_id is not null and t1.plan_id != '' GROUP BY t1.plan_id</if>
+        ORDER BY cost desc LIMIT 10
         ) t1
 
     </select>
@@ -504,7 +512,8 @@
     <select id="queryBytedanceTopMaterialNew" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.*,
-        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=signature and status=1),"塑造") as  tag
+        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=signature and status=1),"塑造") as
+        tag
         FROM
         (SELECT md5 signature,
         case when toutiao_url = '' or toutiao_url is null then url end url,
@@ -582,7 +591,6 @@
     </select>
 
 
-
     <select id="queryKuaishouTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.*,
@@ -617,34 +625,34 @@
         </if>
         ORDER BY charge desc LIMIT 5
 
-<!--        SELECT-->
-<!--        t1.*,-->
-<!--        t2.video_name as materialName,-->
-<!--        t2.cover_url as coverUrl,-->
-<!--        t2.url as url ,-->
-<!--        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=t1.signature and status=1),"塑造") as-->
-<!--        tag-->
-<!--        FROM-->
-<!--        (select sum(charge) as charge,signature-->
-<!--        from ctop_etl_kuaishou_account_material_report_daily t1-->
-<!--        where-->
-<!--        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 &gt;= #{startDate}-->
-<!--        AND t1.stat_date &lt;= #{endDate}-->
-<!--        GROUP BY t1.signature-->
-<!--        ORDER BY charge desc-->
-<!--        limit 5-->
-<!--        ) t1-->
-<!--        LEFT JOIN ctop_etl_kuaishou_video_info t2-->
-<!--        ON t1.signature = t2.video_code-->
-<!--        ORDER BY charge desc-->
+        <!--        SELECT-->
+        <!--        t1.*,-->
+        <!--        t2.video_name as materialName,-->
+        <!--        t2.cover_url as coverUrl,-->
+        <!--        t2.url as url ,-->
+        <!--        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=t1.signature and status=1),"塑造") as-->
+        <!--        tag-->
+        <!--        FROM-->
+        <!--        (select sum(charge) as charge,signature-->
+        <!--        from ctop_etl_kuaishou_account_material_report_daily t1-->
+        <!--        where-->
+        <!--        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 &gt;= #{startDate}-->
+        <!--        AND t1.stat_date &lt;= #{endDate}-->
+        <!--        GROUP BY t1.signature-->
+        <!--        ORDER BY charge desc-->
+        <!--        limit 5-->
+        <!--        ) t1-->
+        <!--        LEFT JOIN ctop_etl_kuaishou_video_info t2-->
+        <!--        ON t1.signature = t2.video_code-->
+        <!--        ORDER BY charge desc-->
     </select>
 
     <select id="queryKuaishouMaterialReport" resultType="com.alibaba.fastjson.JSONObject">
@@ -825,6 +833,8 @@
 
     <select id="queryBytedanceVideoChat" resultType="com.alibaba.fastjson.JSONObject">
         SELECT sum(cost)                           AS cost,
+            					SUM(material_show) as aclick,
+	                        SUM(active) as activation,
                DATE_FORMAT(stat_datetime, '%Y-%m') AS statDate
         FROM etl_report_bytedance_video
         WHERE md5 = #{md5}
@@ -834,6 +844,8 @@
 
     <select id="queryKuaishouVideoChat" resultType="com.alibaba.fastjson.JSONObject">
         SELECT sum(charge)                     AS cost,
+        					SUM(aclick) as aclick,
+	                        SUM(activation) as activation,
                DATE_FORMAT(stat_date, '%Y-%m') AS statDate
         FROM ctop_etl_kuaishou_account_material_report_daily
         WHERE signature = #{md5}
@@ -1069,22 +1081,17 @@
         from (
                  SELECT ROUND(sum(charge), 2) charge,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  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
+                          FROM application.kuaishou_material_video_report_daily_dw
                           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>
@@ -1092,23 +1099,23 @@
     <select id="queryKuaishouPhotoShowByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select photoShow
         from (
-                 SELECT sum(photo_show) photoShow,
+                 SELECT sum(`show`) photoShow,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  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
+                          SELECT sum(`show`) photoShow
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
                  union all
-                 SELECT ROUND(AVG(photo_show), 0) average,
+                 SELECT ROUND(AVG(`show`), 0) average,
                         3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE project_id = #{project}
              ) t
         order by num
@@ -1144,22 +1151,17 @@
         from (
                  SELECT sum(aclick) aclick,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  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
+                          FROM application.kuaishou_material_video_report_daily_dw
                           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>
@@ -1194,22 +1196,17 @@
         from (
                  SELECT sum(activation) activation,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  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
+                          FROM application.kuaishou_material_video_report_daily_dw
                           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>
@@ -1217,26 +1214,115 @@
     <select id="queryKuaishouPlay3sRateByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select play3sRate
         from (
-                 SELECT round(sum(play_3s_count) / sum(aclick), 2) play3sRate,
+                 SELECT round(sum(play_3s_ratio*aclick) / sum(aclick), 2) play3sRate,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE signature = #{md5}
                  union all
                  SELECT ROUND(MAX(play3sRate), 2) top,
                         2 as num
                  FROM (
-                          SELECT sum(play_3s_count) / sum(aclick) play3sRate
-                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          SELECT sum(play_3s_ratio*aclick) / sum(aclick) play3sRate
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
-                 union all
-                 SELECT ROUND(sum(play_3s_count) / sum(aclick), 2) average,
-                        3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
 
+    <select id="populationAnalysisList" resultType="java.util.Map">
+	select 	t2.gender,
+		CASE t2.age WHEN '18-23岁|24-30岁|31-40岁' THEN '18-40'
+    WHEN '24-30岁|31-40岁|41-49岁' THEN '24-49'
+   WHEN '31-40岁|41-49岁|50+岁' THEN '大于等于31岁'
+    WHEN '不限' THEN '不限' ELSE null END as age,
+            case t2.target_type when 'convert_ratio' then CONCAT(IFNULL(ROUND(t2.combine_estimate_prob*100,2),0),'%') else 0 end 'convertRatio',
+            ( SELECT
+             case t.target_type when 'action_ratio' then CONCAT(IFNULL(ROUND(t.combine_estimate_prob*100,2),0),'%') else 0 end 'actionRatio'
+            from
+            ctop_ai_kuaishou_signature_recommended_target_combine t  where  t.signature=#{signature} and t.target_type='action_ratio' and t.age=t2.age and t.gender=t2.gender
+          ORDER BY t.stat_date DESC,t.gender DESC,t.age ASC LIMIT 0,1 ) as actionRatio
+                from
+            ctop_ai_kuaishou_signature_recommended_target_combine t2  where  t2.signature=#{signature} and  t2.target_type='convert_ratio'
+            ORDER BY t2.stat_date DESC,t2.gender DESC,t2.age ASC LIMIT 0,12
+    </select>
+
+    <select id="getActualProb" resultType="String">
+     SELECT  CONCAT(ROUND(max(actual_prob)*100,2),'%') from ctop_ai_kuaishou_signature_recommended_target_combine t
+      where t.signature=#{signature}  and target_type=#{targetType}
+    </select>
+
+    <select id="populationAnalysisChart" resultType="java.util.Map">
+
+        SELECT
+      t2.crowd_coverage_cnt as 'crowdCoverageCnt',
+		t2.gender,
+		CASE t2.age WHEN '18-23岁|24-30岁|31-40岁' THEN '18-40'
+            WHEN '24-30岁|31-40岁|41-49岁' THEN '24-49'
+        WHEN '31-40岁|41-49岁|50+岁' THEN '大于等于31岁'
+         WHEN '不限' THEN '不限' ELSE null END as age,
+            case t2.target_type when 'convert_ratio' then CONCAT(IFNULL(ROUND(t2.combine_estimate_prob*100,2),0),'%') else 0 end 'convertRatio',
+            ( SELECT
+             case t.target_type when 'action_ratio' then CONCAT(IFNULL(ROUND(t.combine_estimate_prob*100,2),0),'%') else 0 end 'actionRatio'
+            from
+            ctop_ai_kuaishou_signature_recommended_target_combine t  where  t.signature=#{signature} and t.target_type='action_ratio' and t.age=t2.age and t.gender=t2.gender
+          ORDER BY t.stat_date DESC,t.gender DESC,t.age ASC LIMIT 0,1 ) as actionRatio
+                from
+            ctop_ai_kuaishou_signature_recommended_target_combine t2  where  t2.signature=#{signature} and  t2.target_type='convert_ratio'
+            ORDER BY  t2.stat_date DESC,actionRatio ASC,convertRatio ASC  LIMIT 0,12
+    </select>
+
+    <select id="optimalCombination" resultType="java.util.Map">
+        SELECT * from (
+    select	t2.gender,
+		CASE t2.age WHEN '18-23岁|24-30岁|31-40岁' THEN '18-40'
+    WHEN '24-30岁|31-40岁|41-49岁' THEN '24-49'
+   WHEN '31-40岁|41-49岁|50+岁' THEN '大于等于31岁'
+    WHEN '不限' THEN '不限' ELSE null END as age,
+    <if test='targetType=="convert_ratio"'>
+        case t2.target_type when 'convert_ratio' then t2.combine_estimate_prob else 0 end 'convertRatio'
+    </if>
+        <if test='targetType=="action_ratio"'>
+            case t2.target_type when 'action_ratio' then t2.combine_estimate_prob else 0 end 'actionRatio'
+        </if>
+                from
+            ctop_ai_kuaishou_signature_recommended_target_combine t2  where  t2.signature=#{signature} and  t2.target_type=#{targetType}
+
+            ORDER BY t2.stat_date DESC,t2.gender DESC,t2.age ASC LIMIT 0,12 ) t3  where
+        <if test='targetType=="convert_ratio"'>
+            t3.convertRatio >
+        </if>
+        <if test='targetType=="action_ratio"'>
+            t3.actionRatio >
+        </if>
+   (
+        SELECT MAX(tt.actual_prob) FROM(
+        SELECT actual_prob FROM ctop_ai_kuaishou_signature_recommended_target_combine t
+        WHERE t.signature=#{signature} and target_type=#{targetType} ORDER BY stat_date DESC LIMIT 0,12
+        ) tt
+      )   ORDER BY
+        <if test='targetType=="convert_ratio"'>
+            convertRatio desc LIMIT 0,1
+        </if>
+        <if test='targetType=="action_ratio"'>
+           actionRatio desc LIMIT 0,1
+        </if>
+
+    </select>
+
+    <select id="similarMaterialInfo" resultType="java.util.Map">
+           SELECT IFNULL(t2.signature,'') as signature,IFNULL(t2.photo_name,'') as photoName,IFNULL(t2.url,'')  as url,IFNULL(SUM(t3.charge),'') as charge
+			 from
+         ctop_kuaishou_video_get t2
+        LEFT JOIN ctop_kuaishou_report_daily_material t3 on t2.signature=t3.signature
+        where t2.signature=#{signature} LIMIT 0,1
+    </select>
+
+    <select id="getSimilarMaterialList" resultType="java.util.Map">
+             SELECT IFNULL(t.similar_signature_1,'') as s1, IFNULL(t.similar_signature_2,'')  as s2,IFNULL(t.similar_signature_3,'')  as s3,IFNULL(t.similar_signature_4,'')  as s4,IFNULL(t.similar_signature_5,'')  as s5 from ctop_ai_kuaishou_signature_similar t
+        where t.signature=#{signature} ORDER BY t.stat_date desc LIMIT 0,1
+    </select>
+
+
 </mapper>

+ 15 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IMaterialReportOverViewService.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.ctop.service;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -53,4 +54,18 @@ public interface IMaterialReportOverViewService {
     Map<String,Object> materialDetailAnalyse(int mediaId, String md5);
 
     List<JSONObject> getMaterialDetailChat(int mediaId, String md5);
+    //查询人群分析数据列表
+    Result populationAnalysisList(String signature);
+    //查询人群分析数据图
+    Result populationAnalysisChart(String signature);
+    /**  最优定向组合
+     * @param
+     * @return
+     */
+    Result optimalCombination(String signature);
+    /**  相似素材
+     * @param
+     * @return
+     */
+    Result similarMaterial(String signature);
 }

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

@@ -11,6 +11,7 @@ import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.AccountReportConstants;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
@@ -93,39 +94,38 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
             //总消耗
             BigDecimal cost = materialReportOverViewMapper.queryBytedanceCost(startDate, endDate, projects);
             //上阶段消耗
-            BigDecimal lastCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
+            BigDecimal lastCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
             result.put("costTotal", cost);
             //同比 (本阶段截止昨天消耗-上一个阶段截止和昨天对应日期的消耗)/上一个阶段截止和昨天对应日期的消耗 X 100%
-            result.put("yearOnYearCompare", countLink(cost,lastCost));
+            result.put("yearOnYearCompare", countLink(cost, lastCost));
             //昨日消耗
             BigDecimal yesterdayCost = materialReportOverViewMapper.queryBytedanceCost(endDate, endDate, projects);
             //前天消耗
             BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
             result.put("yesterdayCost", yesterdayCost);
             //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
-            result.put("chainCompare", countLink(yesterdayCost,beforeYesterdayCost));
+            result.put("chainCompare", countLink(yesterdayCost, beforeYesterdayCost));
 
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
             //总消耗
             BigDecimal cost = materialReportOverViewMapper.queryKuaishouCost(startDate, endDate, projects);
             //上阶段
-            BigDecimal lastCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
+            BigDecimal lastCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
             result.put("costTotal", cost);
             //同比 (本阶段截止昨天消耗-上一个阶段截止和昨天对应日期的消耗)/上一个阶段截止和昨天对应日期的消耗 X 100%
-            result.put("yearOnYearCompare", countLink(cost,lastCost));
+            result.put("yearOnYearCompare", countLink(cost, lastCost));
             //昨日消耗
             BigDecimal yesterdayCost = materialReportOverViewMapper.queryKuaishouCost(endDate, endDate, projects);
             //前天消耗
             BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
             result.put("yesterdayCost", yesterdayCost);
             //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
-            result.put("chainCompare", countLink(yesterdayCost,beforeYesterdayCost));
+            result.put("chainCompare", countLink(yesterdayCost, beforeYesterdayCost));
         }
         return result;
     }
 
 
-
     @Override
     public Map<String, Object> sumDataVideoNewEffective(int mediaId, String startDate, String endDate, JSONArray projects) {
         Map<String, Object> result = new HashMap<>();
@@ -133,43 +133,43 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
             projects = getProjectsByCurrentUser(mediaId);
         }
         if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
-              //视频上新
-            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountList(startDate+" 00:00:00", endDate+" 23:59:59", projects);
+            //视频上新
+            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountList(startDate + " 00:00:00", endDate + " 23:59:59", projects);
             //总数
-            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("videoList",videoList);
-            result.put("videoTotal",videoTotal);
+            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("videoList", videoList);
+            result.put("videoTotal", videoTotal);
             //素材使用率 = 有消耗的素材 / 总数 * 100%
-            long videoCost = materialReportOverViewMapper.queryMaterialCostList(startDate+" 00:00:00", endDate+" 23:59:59", projects);
-            result.put("useCompare", Check.isNull(videoCost) ? 0: new BigDecimal(videoCost).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            long videoCost = materialReportOverViewMapper.queryMaterialCostList(startDate + " 00:00:00", endDate + " 23:59:59", projects);
+            result.put("useCompare", Check.isNull(videoCost) ? 0 : new BigDecimal(videoCost).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
             //有效视频
-            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoBytedance(startDate,endDate, projects);
+            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoBytedance(startDate, endDate, projects);
             //总数
-            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("effectiveList",effectiveList);
-            result.put("effectiveTotal",effectiveTotal);
+            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("effectiveList", effectiveList);
+            result.put("effectiveTotal", effectiveTotal);
             //素材有效率 = 有效视频数量 / 视频总数 X 100%
-            result.put("effectiveCompare",Check.isNull(videoCost) ? 0: new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            result.put("effectiveCompare", Check.isNull(videoCost) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
 
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
 
             //视频上新
-            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountListKs(startDate+" 00:00:00", endDate+" 23:59:59", projects);
+            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountListKs(startDate + " 00:00:00", endDate + " 23:59:59", projects);
             //总数
-            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("videoList",videoList);
-            result.put("videoTotal",videoTotal);
+            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("videoList", videoList);
+            result.put("videoTotal", videoTotal);
             //素材使用率 = 有消耗的素材 / 总数 * 100%
-            long videoCost = materialReportOverViewMapper.queryMaterialCostListKs(startDate+" 00:00:00", endDate+" 23:59:59", projects);
-            result.put("useCompare", Check.isNull(videoCost) ? 0: new BigDecimal(videoCost).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            long videoCost = materialReportOverViewMapper.queryMaterialCostListKs(startDate + " 00:00:00", endDate + " 23:59:59", projects);
+            result.put("useCompare", Check.isNull(videoCost) ? 0 : new BigDecimal(videoCost).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
             //有效视频
-            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoKs(startDate,endDate, projects);
+            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoKs(startDate, endDate, projects);
             //总数
-            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("effectiveList",effectiveList);
-            result.put("effectiveTotal",effectiveTotal);
+            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("effectiveList", effectiveList);
+            result.put("effectiveTotal", effectiveTotal);
             //素材有效率 = 有效视频数量 / 视频总数 X 100%
-            result.put("effectiveCompare",Check.isNull(videoTotal) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            result.put("effectiveCompare", Check.isNull(videoTotal) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
 
         }
         return result;
@@ -184,55 +184,50 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         }
         if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
             //爆款视频
-            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(startDate,endDate, projects);
+            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(startDate, endDate, projects);
             //总数
-            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("hotList",hotList);
-            result.put("hotTotal",hotTotal);
+            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("hotList", hotList);
+            result.put("hotTotal", hotTotal);
             //上阶段
-            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
-            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
+            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
             //同比 (本阶段截止昨天的爆款视频数量-上一个阶段截止和昨天对应日期的爆款视频数量)/上一个阶段截止和昨天对应日期的爆款视频数量X 100%
-            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal),new BigDecimal(lastHotTotal)));
+            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal), new BigDecimal(lastHotTotal)));
             //昨日消耗
-            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(endDate,endDate, projects);
+            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(endDate, endDate, projects);
             //前天消耗
             List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
-            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
             //环比 (昨日-前日)/前日消耗 X 100%
-            result.put("hostCompare", countLink(new BigDecimal(yesterday),new BigDecimal(before)));
+            result.put("hostCompare", countLink(new BigDecimal(yesterday), new BigDecimal(before)));
 
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
             //爆款视频
-            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoKs(startDate,endDate, projects);
+            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoKs(startDate, endDate, projects);
             //总数
-            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("hotList",hotList);
-            result.put("hotTotal",hotTotal);
+            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("hotList", hotList);
+            result.put("hotTotal", hotTotal);
             //上阶段
-            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
-            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
+            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
             //同比 (本阶段截止昨天的爆款视频数量-上一个阶段截止和昨天对应日期的爆款视频数量)/上一个阶段截止和昨天对应日期的爆款视频数量X 100%
-            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal),new BigDecimal(lastHotTotal)));
+            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal), new BigDecimal(lastHotTotal)));
             //昨日消耗
-            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(endDate,endDate, projects);
+            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(endDate, endDate, projects);
             //前天消耗
             List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
-            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
             //环比 (昨日-前日)/前日消耗 X 100%
-            result.put("hostCompare", countLink(new BigDecimal(yesterday),new BigDecimal(before)));
+            result.put("hostCompare", countLink(new BigDecimal(yesterday), new BigDecimal(before)));
         }
         return result;
     }
 
 
-
-
-
-
-
     @Override
     public List<JSONObject> getTotalChat(int mediaId, String startDate, String endDate, JSONArray projects) {
         List<JSONObject> result = new ArrayList<>();
@@ -306,7 +301,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     @Override
     public void exportBytedanceExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
-        JSONArray projects= requestBody.getJSONArray("projects");
+        JSONArray projects = requestBody.getJSONArray("projects");
         if (projects.isEmpty()) {
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
         }
@@ -328,8 +323,8 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         columns.add(3, "projectName");
 
         List<JSONObject> excelData = materialReportOverViewMapper.queryBytedanceMaterialReport(filed, requestBody.getString("startDate"), requestBody.getString("endDate"),
-                projects, requestBody.getString("md5"),requestBody.getString("target")==null?"cost":requestBody.getString("target")
-                , requestBody.getString("order")==null?"desc":requestBody.getString("order"));
+                projects, requestBody.getString("md5"), requestBody.getString("target") == null ? "cost" : requestBody.getString("target")
+                , requestBody.getString("order") == null ? "desc" : requestBody.getString("order"));
 
         if (null != excelData && excelData.isEmpty()) {
             return;
@@ -359,7 +354,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     @Override
     public void exportKuaishouExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
-        JSONArray projects= requestBody.getJSONArray("projects");
+        JSONArray projects = requestBody.getJSONArray("projects");
         if (projects.isEmpty()) {
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
         }
@@ -375,8 +370,8 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         List<String> titles = getfileIds(AccountReportConstants.getKuaishouVideoReportDict(), columns2);
         String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.getKuaishouVideoReportMap());
         List<JSONObject> excelData = materialReportOverViewMapper.queryKuaishouMaterialReport(filedAll, requestBody.getString("startDate"), requestBody.getString("endDate"),
-                projects, requestBody.getString("channelType"),requestBody.getString("md5"), requestBody.getString("target")==null?"cost":requestBody.getString("target")
-                , requestBody.getString("order")==null?"desc":requestBody.getString("order"));
+                projects, requestBody.getString("channelType"), requestBody.getString("md5"), requestBody.getString("target") == null ? "cost" : requestBody.getString("target")
+                , requestBody.getString("order") == null ? "desc" : requestBody.getString("order"));
         if (null != excelData && excelData.isEmpty()) {
             return;
         }
@@ -471,6 +466,140 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         return result;
     }
 
+    /**
+     * 查询人群分析数据列表
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result populationAnalysisList(String signature) {
+        Result result = new Result<>();
+        Map resultMap = new HashMap();
+        try {
+            List<Map> list = materialReportOverViewMapper.populationAnalysisList(signature);
+            //查询点击率
+            String actionRatio = materialReportOverViewMapper.getActualProb(signature, "action_ratio");
+            //查询转化率
+            String convertRatio = materialReportOverViewMapper.getActualProb(signature, "convert_ratio");
+            resultMap.put("dataList", list);
+            resultMap.put("actionRatio", actionRatio);
+            resultMap.put("convertRatio", convertRatio);
+            result.setSuccess(true);
+            result.setResult(resultMap);
+        } catch (Exception e) {
+            log.info("查询错误:{}", e.toString());
+            result.error500("查询错误");
+        }
+        return result;
+    }
+
+    /**
+     * 查询人群分析数据图
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result populationAnalysisChart(String signature) {
+        Result result = new Result<>();
+        try {
+            List<Map> list = materialReportOverViewMapper.populationAnalysisChart(signature);
+            result.setResult(list);
+        } catch (Exception e) {
+            log.info("查询错误:{}", e.toString());
+            result.error500("查询错误");
+        }
+        return result;
+    }
+
+    /**
+     * 最优定向组合
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result optimalCombination(String signature) {
+        Result result = new Result<>();
+        Map<String, String> map = new HashMap();
+        try {
+            //最优转化率组合
+            Map<String, String> convertRatio = materialReportOverViewMapper.optimalCombination(signature, "convert_ratio");
+            //最优点击率组合
+            Map<String, String> actionRatio = materialReportOverViewMapper.optimalCombination(signature, "action_ratio");
+            if (convertRatio != null) {
+                map.put("convertRatio", convertRatio.get("gender") + convertRatio.get("age"));
+            } else {
+                map.put("convertRatio", null);
+            }
+            if (actionRatio != null) {
+                map.put("actionRatio", actionRatio.get("gender") + convertRatio.get("age"));
+            } else {
+                map.put("actionRatio", null);
+            }
+
+            result.setResult(map);
+        } catch (Exception e) {
+            log.info("查询错误:{}", e.toString());
+            result.error500("查询错误");
+        }
+        return result;
+    }
+
+    /**
+     * 相似素材
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result similarMaterial(String signature) {
+        Result result = new Result<>();
+        List<Map> resultMap=new ArrayList<>();
+        Map<String,String> map = materialReportOverViewMapper.getSimilarMaterialList(signature);
+        if(map!=null){
+            String signature1 = map.get("s1");
+            String signature2 = map.get("s2");
+            String signature3 = map.get("s3");
+            String signature4 = map.get("s4");
+            String signature5 = map.get("s5");
+            if(signature1!=null&& !signature1.equals("")){
+                Map<String,String> info= materialReportOverViewMapper.similarMaterialInfo(signature1);
+                if(info.get("signature")!=null && !info.get("signature").equals("")){
+                    resultMap.add(info);
+                }
+            }
+            if(signature2!=null&& !signature2.equals("")){
+                Map<String,String> info= materialReportOverViewMapper.similarMaterialInfo(signature2);
+                if(info.get("signature")!=null && !info.get("signature").equals("")){
+                    resultMap.add(info);
+                }
+            }
+            if(signature3!=null&& !signature3.equals("")){
+                Map<String,String> info= materialReportOverViewMapper.similarMaterialInfo(signature3);
+                if(info.get("signature")!=null && !info.get("signature").equals("")){
+                    resultMap.add(info);
+                }
+            }
+            if(signature4!=null&& !signature4.equals("")){
+                Map<String,String> info= materialReportOverViewMapper.similarMaterialInfo(signature4);
+                if(info.get("signature")!=null && !info.get("signature").equals("")){
+                    resultMap.add(info);
+                }
+            }
+            if(signature5!=null&& !signature5.equals("")){
+                Map<String,String> info= materialReportOverViewMapper.similarMaterialInfo(signature5);
+                if(info.get("signature")!=null && !info.get("signature").equals("")){
+                    resultMap.add(info);
+                }
+            }
+        }
+        result.setResult(resultMap);
+        return result;
+    }
+
+
     //递归查询
     private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result) {
         if (leaderIds.isEmpty()) {
@@ -493,6 +622,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         }
         return Check.isNull(queryProjectIdBy(recursiveQuerySubordinate(currentUser), mediaId)) ? null : queryProjectIdBy(recursiveQuerySubordinate(currentUser), mediaId);
     }
+
     private List<String> getfileIds(Map<String, Map<String, Object>> kuaishouVideoReportMap, JSONArray columns) {
         List<String> titles = new ArrayList<>();
         for (int i = 0; i < columns.size(); i++) {
@@ -510,12 +640,12 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
     }
 
     //环比计算
-    private  BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
+    private BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
         BigDecimal link = new BigDecimal("0");
-        if (Check.isNull(numA) || Check.isNull(numB)){
+        if (Check.isNull(numA) || Check.isNull(numB)) {
             return link;
         }
-        if (numB.compareTo(BigDecimal.ZERO)!=0) {
+        if (numB.compareTo(BigDecimal.ZERO) != 0) {
             link = (numA.subtract(numB)).divide(numB, 4, RoundingMode.HALF_UP);
         }
         return link;
@@ -524,15 +654,16 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     /**
      * 同比 (当前 - 上阶段 ) / 上阶段
+     *
      * @param current 当前阶段数值
-     * @param last 上阶段数值
+     * @param last    上阶段数值
      * @return
      */
-    private BigDecimal yearOnYearCompare(BigDecimal current,BigDecimal last){
+    private BigDecimal yearOnYearCompare(BigDecimal current, BigDecimal last) {
         BigDecimal yearOnYear = new BigDecimal("0");
-        if (last.compareTo(BigDecimal.ZERO)!=0) {
+        if (last.compareTo(BigDecimal.ZERO) != 0) {
             // (当前 - 上阶段 ) / 上阶段
-            yearOnYear = (current.subtract(last)).divide(last,20,BigDecimal.ROUND_HALF_UP);
+            yearOnYear = (current.subtract(last)).divide(last, 20, BigDecimal.ROUND_HALF_UP);
         }
         return yearOnYear;
     }