ソースを参照

合并ai-adsp

jiequan.bi 4 年 前
コミット
79f006d8b1

+ 71 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/controller/AiKuaiShouReportAnalyzeCtrl.java

@@ -0,0 +1,71 @@
+package org.jeecg.modules.ads.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.ads.service.IAiKuaiShouReportAnalyzeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@RequestMapping("/ai/analyze")
+@RestController
+public class AiKuaiShouReportAnalyzeCtrl {
+
+    @Autowired
+    IAiKuaiShouReportAnalyzeService aiKuaiShouReportAnalyzeService;
+
+    @GetMapping("/getStrategyAndTarget")
+    public Result<List<JSONObject>> getStrategyAndTarget(@RequestParam("accountId") Long accountId){
+        Result<List<JSONObject>> result=new Result<>();
+        result.setResult(aiKuaiShouReportAnalyzeService.getStrategyAndTarget(accountId));
+        result.setSuccess(true);
+        return result;
+    }
+
+    @GetMapping("/getStrategyAndMaterial")
+    public Result<List<JSONObject>> getStrategyAndMaterial(@RequestParam("accountId") Long accountId){
+        Result<List<JSONObject>> result=new Result<>();
+        result.setResult(aiKuaiShouReportAnalyzeService.getStrategyAndMaterial(accountId));
+        result.setSuccess(true);
+        return result;
+    }
+
+    @PostMapping("/report/targetOrMaterial")
+    public Result<PageInfo<JSONObject>> targetOrMaterialReport(@RequestBody JSONObject params){
+        Result<PageInfo<JSONObject>> result=new Result<>();
+        if(params.isEmpty()){
+            result.error500("参数为空");
+        }else {
+            if(params.getString("type").equals("target")){
+                result.setResult(aiKuaiShouReportAnalyzeService.getTargetReportBy(params));
+            }
+            else if(params.getString("type").equals("material")){
+                result.setResult(aiKuaiShouReportAnalyzeService.getMaterialReportBy(params));
+            }
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    //TODO 先不加时间维度,现在是t-2
+    @PostMapping("/chart/targetOrMaterial")
+    public Result<Map<String,Object>> targetOrMaterialChart(@RequestBody JSONObject params){
+        Result<Map<String,Object>> result=new Result<>();
+        if(params.isEmpty()){
+            result.error500("参数为空");
+        }else {
+            if(params.getString("type").equals("target")){
+                result.setResult(aiKuaiShouReportAnalyzeService.getTargetChartBy(params));
+            }
+            else if(params.getString("type").equals("material")){
+                result.setResult(aiKuaiShouReportAnalyzeService.getMaterialChartBy(params));
+            }
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+}

+ 3 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/mapper/AiKuaiShouStrategyListPageMapper.java

@@ -14,10 +14,10 @@ import java.util.List;
 @Mapper
 public interface AiKuaiShouStrategyListPageMapper {
 
-    List<JSONObject> queryStrategyBy(@Param("accountIds") JSONArray accountIds,@Param("strategyName") String strategyName,@Param("strategyState") Integer strategyState,@Param("id") Long id);
+    List<JSONObject> queryStrategyBy(@Param("accountIds") JSONArray accountIds, @Param("strategyName") String strategyName, @Param("strategyState") Integer strategyState, @Param("id") Long id);
 
-    List<JSONObject> queryCampaignByStrategyId(@Param("strategyId") Long strategyId,@Param("campaignName") String campaignName,@Param("campaignId") Long campaignId,@Param("status") Integer status);
+    List<JSONObject> queryCampaignByStrategyId(@Param("strategyId") Long strategyId, @Param("campaignName") String campaignName, @Param("campaignId") Long campaignId, @Param("status") Integer status);
 
-    List<JSONObject> queryUnitByCampaignId(@Param("campaignId") Long campaignId,@Param("unitName") String unitName,@Param("unitId") Long unitId,@Param("status") Integer status);
+    List<JSONObject> queryUnitByCampaignId(@Param("campaignId") Long campaignId, @Param("unitName") String unitName, @Param("unitId") Long unitId, @Param("status") Integer status);
 
 }

+ 33 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/mapper/IAiKuaiShouReportAnalyzeMapper.java

@@ -0,0 +1,33 @@
+package org.jeecg.modules.ads.mapper;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface IAiKuaiShouReportAnalyzeMapper {
+
+    List<JSONObject> queryStrategyByAccountId(@Param("accountId") Long accountId);
+
+    List<JSONObject> queryTargetByStrategyId(@Param("strategyId") Long StrategyId);
+
+    List<JSONObject> queryMaterialByStrategyId(@Param("strategyId") Long strategyId);
+
+    List<JSONObject> queryTargetReportBy(@Param("accountId") Long accountId, @Param("strategyId") Long strategyId, @Param("codes") JSONArray codes, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryMaterialReportBy(@Param("accountId") Long accountId, @Param("strategyId") Long strategyId, @Param("targetIds") JSONArray targetIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryAgeChartByTarget(@Param("strategyId") Long strategyId, @Param("targetIds") JSONArray targetIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryAgeChartByMaterial(@Param("strategyId") Long strategyId, @Param("codes") JSONArray codes, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryGenderChartByTarget(@Param("strategyId") Long strategyId, @Param("targetIds") JSONArray targetIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryGenderChartByMaterial(@Param("strategyId") Long strategyId, @Param("codes") JSONArray codes, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryRegionChartByTarget(@Param("strategyId") Long strategyId, @Param("targetIds") JSONArray targetIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryRegionChartByMaterial(@Param("strategyId") Long strategyId, @Param("codes") JSONArray codes, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+}

+ 464 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/mapper/xml/AiKuaishouReportAnalyzeMapper.xml

@@ -0,0 +1,464 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.ads.mapper.IAiKuaiShouReportAnalyzeMapper">
+
+    <select id="queryStrategyByAccountId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT id,
+               strategy_name
+        FROM ctop_kuaishou_strategy
+        WHERE account_id = #{accountId}
+    </select>
+
+    <select id="queryTargetByStrategyId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t4.id,
+               t4.target_type,
+               t4.target_content
+        FROM ctop_kuaishou_strategy t1
+                 LEFT JOIN ctop_ai_kuaishou_strategy_middle t2 on t1.id = t2.strategy_id
+                 LEFT JOIN ctop_ai_kuaishou_strategy_target_union t3 on t2.id = t3.strategy_middle_id
+                 LEFT JOIN ctop_ai_kuaishou_strategy_target_base t4 on t3.strategy_target_id = t4.id
+        where t1.id = #{strategyId}
+    </select>
+
+    <select id="queryMaterialByStrategyId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT DISTINCT t2.code,
+                        t2.material_name,
+                        t2.cover_url
+        FROM ctop_ai_kuaishou_strategy_map_creative t1
+                 LEFT JOIN ctop_material_info t2 ON t1.video_signature = t2.CODE
+        WHERE t1.strategy_id = #{strategyId}
+        GROUP BY t2.code
+    </select>
+
+    <select id="queryTargetReportBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        r.target_type as targetType,
+        r.target_content as targetContent,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+        ctop_kuaishou_report_daily_group t LEFT JOIN (SELECT
+        unit_id,
+        t3.target_type,
+        t3.target_content
+        FROM
+        ctop_ai_kuaishou_strategy_map_creative t1
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_union t2 on t1.strategy_target_union_id=t2.id
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_base t3 on t2.strategy_target_id=t3.id
+        WHERE
+        t1.strategy_id= #{strategyId}
+        and t1.video_signature in
+        <foreach item="item" index="index" collection="codes"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY t1.unit_id,t3.id) r on t.unit_id=r.unit_id
+        where account_id=#{accountId}
+        <if test="startDate != null">
+            AND t.stat_date >=#{startDate}
+        </if>
+        <if test="endDate != null">
+            AND t.stat_date &lt;=#{endDate}
+        </if>
+        GROUP BY t.unit_id
+    </select>
+
+    <select id="queryMaterialReportBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT r.creativeCount,
+        r.scenes,
+        t.signature as code,
+        t.cover_url as coverUrl,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+        ctop_kuaishou_report_daily_material t LEFT JOIN (SELECT
+        t1.video_signature as code,
+        COUNT(t1.video_signature) as creativeCount,
+        t4.scenes
+        FROM
+        ctop_ai_kuaishou_strategy_map_creative t1
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_union t2 on t1.strategy_target_union_id=t2.id
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_base t3 on t2.strategy_target_id=t3.id
+        LEFT JOIN ctop_kuaishou_strategy t4 on t1.strategy_id=t4.id
+        WHERE
+        t1.strategy_id= #{strategyId}
+        and t3.id in
+        <foreach item="item" index="index" collection="targetIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY t1.video_signature) r on t.signature=r.`code`
+        where account_id=#{accountId}
+        <if test="startDate != null">
+            AND t.stat_date >=#{startDate}
+        </if>
+        <if test="endDate != null">
+            AND t.stat_date &lt;=#{endDate}
+        </if>
+        GROUP BY t.signature
+    </select>
+
+    <select id="queryAgeChartByTarget" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            t.age_segment as ageSegment,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+            ctop_kuaishou_audience_report_daily_age t
+        WHERE
+                unit_id IN (
+                SELECT
+                    t1.unit_id
+                FROM
+                    ctop_ai_kuaishou_strategy_map_creative t1
+                        LEFT JOIN ctop_ai_kuaishou_strategy_target_union t2 ON t1.strategy_target_union_id = t2.id
+                        LEFT JOIN ctop_ai_kuaishou_strategy_target_base t3 ON t2.strategy_target_id = t3.id
+                        LEFT JOIN ctop_kuaishou_strategy t4 ON t1.strategy_id = t4.id
+                WHERE
+                    t1.strategy_id = #{strategyId}
+                  AND t3.id in
+        <foreach item="item" index="index" collection="targetIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+                GROUP BY
+                    t1.unit_id
+            )
+        GROUP BY
+            t.age_segment
+    </select>
+
+    <select id="queryAgeChartByMaterial" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            t.age_segment as ageSegment,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+            ctop_kuaishou_audience_report_daily_age t
+        WHERE
+                unit_id IN (
+                SELECT
+                    unit_id
+                FROM
+                    ctop_ai_kuaishou_strategy_map_creative
+                WHERE
+                    strategy_id = #{strategyId}
+                  AND video_signature in
+        <foreach item="item" index="index" collection="codes"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+                GROUP BY
+                    unit_id
+            )
+        GROUP BY
+            t.age_segment
+    </select>
+
+    <select id="queryGenderChartByTarget" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.gender,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+        ctop_kuaishou_audience_report_daily_gender t
+        WHERE
+        unit_id IN (
+        SELECT
+        t1.unit_id
+        FROM
+        ctop_ai_kuaishou_strategy_map_creative t1
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_union t2 ON t1.strategy_target_union_id = t2.id
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_base t3 ON t2.strategy_target_id = t3.id
+        LEFT JOIN ctop_kuaishou_strategy t4 ON t1.strategy_id = t4.id
+        WHERE
+        t1.strategy_id = #{strategyId}
+        AND t3.id in
+        <foreach item="item" index="index" collection="targetIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY
+        t1.unit_id
+        )
+        GROUP BY
+        t.gender
+    </select>
+
+    <select id="queryGenderChartByMaterial" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.gender,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+        ctop_kuaishou_audience_report_daily_gender t
+        WHERE
+        unit_id IN (
+        SELECT
+        unit_id
+        FROM
+        ctop_ai_kuaishou_strategy_map_creative
+        WHERE
+        strategy_id = #{strategyId}
+        AND video_signature in
+        <foreach item="item" index="index" collection="codes"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY
+        unit_id
+        )
+        GROUP BY
+        t.gender
+    </select>
+
+    <select id="queryRegionChartByTarget" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.province,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+        ctop_kuaishou_audience_report_daily_province t
+        WHERE
+        unit_id IN (
+        SELECT
+        t1.unit_id
+        FROM
+        ctop_ai_kuaishou_strategy_map_creative t1
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_union t2 ON t1.strategy_target_union_id = t2.id
+        LEFT JOIN ctop_ai_kuaishou_strategy_target_base t3 ON t2.strategy_target_id = t3.id
+        LEFT JOIN ctop_kuaishou_strategy t4 ON t1.strategy_id = t4.id
+        WHERE
+        t1.strategy_id = #{strategyId}
+        AND t3.id in
+        <foreach item="item" index="index" collection="targetIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY
+        t1.unit_id
+        )
+        GROUP BY
+        t.province
+    </select>
+
+    <select id="queryRegionChartByMaterial" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.province,
+        IFNULL(sum(t.charge),0) as cost,
+        IFNULL(sum(t.photo_show),0) as photoShow,
+        IFNULL(sum(t.photo_click),0) as photoClick,
+        CASE WHEN sum(t.photo_click) / sum(t.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.photo_click) /
+        sum(t.photo_show)) * 100,2),'%') END AS clickRate,
+        IFNULL(sum(t.aclick),0) as aclick,
+        IFNULL(sum(t.bclick),0) as bclick,
+        CASE WHEN sum(t.bclick) / sum(t.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t.bclick) / sum(t.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t.charge) / sum(t.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t.charge) / sum(t.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t.charge) / sum(t.photo_click)), 2)
+        END AS cpc ,
+        IFNULL(sum(t.activation),0) as active,
+        CASE WHEN sum(t.charge) / sum(t.activation) IS NULL THEN 0 ELSE sum(t.charge) / sum(t.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t.activation) / sum(t.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t.activation) /
+        sum(t.download_completed)*100,2),'%') end as activeRate ,
+        IFNULL(sum(t.event_register),0) as register,
+        CASE WHEN sum(t.charge) / sum(t.event_register) IS NULL THEN 0 ELSE round(sum(t.charge)/sum(t.event_register),3)
+        end as activeRegisterCost ,
+        CASE WHEN sum(t.event_register) / sum(t.activation) IS NULL THEN 0 ELSE concat(round(sum(t.event_register) /
+        sum(t.activation)*100,2),'%') end as activeRegisterRate ,
+        IFNULL(sum(t.event_next_day_stay),0) as nextDayOpen,
+        CASE WHEN sum(t.event_next_day_stay) / sum(t.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t.event_next_day_stay) / sum(t.activation)*100,2),'%') end as nextDayOpenRate
+        FROM
+        ctop_kuaishou_audience_report_daily_province t
+        WHERE
+        unit_id IN (
+        SELECT
+        unit_id
+        FROM
+        ctop_ai_kuaishou_strategy_map_creative
+        WHERE
+        strategy_id = #{strategyId}
+        AND video_signature in
+        <foreach item="item" index="index" collection="codes"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY
+        unit_id
+        )
+        GROUP BY
+        t.province
+    </select>
+
+</mapper>

+ 58 - 31
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/mapper/xml/AiKuaishouStrategyListPageMapper.xml

@@ -9,26 +9,36 @@
         t1.strategy_name as strategyName,
         t1.create_time as createTime,
         t1.account_id as accountId,
+        (select auth_name from ctop_user_allocation where account_id=t1.account_id limit 1) as authName,
         '' as status,
         t1.scenes,
         t1.budget,
         IFNULL(sum(t3.charge),0) as cost,
         IFNULL(sum(t3.photo_show),0) as photoShow,
         IFNULL(sum(t3.photo_click),0) as photoClick,
-        CASE WHEN sum(t3.photo_click) / sum(t3.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t3.photo_click) / sum(t3.photo_show)) * 100,2),'%') END AS clickRate,
+        CASE WHEN sum(t3.photo_click) / sum(t3.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t3.photo_click) /
+        sum(t3.photo_show)) * 100,2),'%') END AS clickRate,
         IFNULL(sum(t3.aclick),0) as aclick,
         IFNULL(sum(t3.bclick),0) as bclick,
-        CASE WHEN sum(t3.bclick) / sum(t3.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t3.bclick) / sum(t3.aclick)) * 100,2),'%') END AS bClickRate,
-        CASE WHEN sum(t3.charge) / sum(t3.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t3.charge) / sum(t3.photo_show)) * 1000, 2 ) END AS cpm ,
-        CASE WHEN sum(t3.charge) / sum(t3.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t3.charge) / sum(t3.photo_click)), 2) END AS cpc ,
+        CASE WHEN sum(t3.bclick) / sum(t3.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t3.bclick) / sum(t3.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t3.charge) / sum(t3.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t3.charge) / sum(t3.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t3.charge) / sum(t3.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t3.charge) / sum(t3.photo_click)),
+        2) END AS cpc ,
         IFNULL(sum(t3.activation),0) as active,
-        CASE WHEN sum(t3.charge) / sum(t3.activation) IS NULL THEN 0 ELSE sum(t3.charge) / sum(t3.activation) end AS activeCost ,
-        CASE WHEN sum(t3.activation) / sum(t3.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t3.activation) / sum(t3.download_completed)*100,2),'%') end as activeRate ,
+        CASE WHEN sum(t3.charge) / sum(t3.activation) IS NULL THEN 0 ELSE sum(t3.charge) / sum(t3.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t3.activation) / sum(t3.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t3.activation) /
+        sum(t3.download_completed)*100,2),'%') end as activeRate ,
         IFNULL(sum(t3.event_register),0) as register,
-        CASE WHEN sum(t3.charge) / sum(t3.event_register) IS NULL THEN 0 ELSE round(sum(t3.charge)/sum(t3.event_register),3) end as activeRegisterCost ,
-        CASE WHEN sum(t3.event_register) / sum(t3.activation) IS NULL THEN 0 ELSE concat(round(sum(t3.event_register) / sum(t3.activation)*100,2),'%') end as activeRegisterRate ,
+        CASE WHEN sum(t3.charge) / sum(t3.event_register) IS NULL THEN 0 ELSE
+        round(sum(t3.charge)/sum(t3.event_register),3) end as activeRegisterCost ,
+        CASE WHEN sum(t3.event_register) / sum(t3.activation) IS NULL THEN 0 ELSE concat(round(sum(t3.event_register) /
+        sum(t3.activation)*100,2),'%') end as activeRegisterRate ,
         IFNULL(sum(t3.event_next_day_stay),0) as nextDayOpen,
-        CASE WHEN sum(t3.event_next_day_stay) / sum(t3.activation) IS NULL THEN 0 ELSE concat(round(sum(t3.event_next_day_stay) / sum(t3.activation)*100,2),'%') end as nextDayOpenRate
+        CASE WHEN sum(t3.event_next_day_stay) / sum(t3.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t3.event_next_day_stay) / sum(t3.activation)*100,2),'%') end as nextDayOpenRate
         FROM
         ctop_kuaishou_strategy t1
         LEFT JOIN ctop_ai_kuaishou_strategy_map_creative t2 on t1.id=t2.strategy_id
@@ -38,15 +48,14 @@
                  open="(" separator="," close=")">
             #{item}
         </foreach>
-        <if test="strategyName != null">
-            AND t1.strategy_name like '%${strategyName}%'
-        </if>
+        AND t1.strategy_name like '%${strategyName}%'
         <if test="strategyState != null">
-            AND t1.strategy_state=#{strategyState}
+            AND t1.strategy_state= #{strategyState}
         </if>
         <if test="id != null">
             AND t1.id=#{id}
         </if>
+        group by t1.id
         order by t1.create_time desc
     </select>
 
@@ -60,20 +69,29 @@
         IFNULL(sum(t1.charge),0) as cost,
         IFNULL(sum(t1.photo_show),0) as photoShow,
         IFNULL(sum(t1.photo_click),0) as photoClick,
-        CASE WHEN sum(t1.photo_click) / sum(t1.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.photo_click) / sum(t1.photo_show)) * 100,2),'%') END AS clickRate,
+        CASE WHEN sum(t1.photo_click) / sum(t1.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.photo_click) /
+        sum(t1.photo_show)) * 100,2),'%') END AS clickRate,
         IFNULL(sum(t1.aclick),0) as aclick,
         IFNULL(sum(t1.bclick),0) as bclick,
-        CASE WHEN sum(t1.bclick) / sum(t1.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.bclick) / sum(t1.aclick)) * 100,2),'%') END AS bClickRate,
-        CASE WHEN sum(t1.charge) / sum(t1.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_show)) * 1000, 2 ) END AS cpm ,
-        CASE WHEN sum(t1.charge) / sum(t1.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_click)), 2) END AS cpc ,
+        CASE WHEN sum(t1.bclick) / sum(t1.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.bclick) / sum(t1.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t1.charge) / sum(t1.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t1.charge) / sum(t1.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_click)),
+        2) END AS cpc ,
         IFNULL(sum(t1.activation),0) as active,
-        CASE WHEN sum(t1.charge) / sum(t1.activation) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.activation) end AS activeCost ,
-        CASE WHEN sum(t1.activation) / sum(t1.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t1.activation) / sum(t1.download_completed)*100,2),'%') end as activeRate ,
+        CASE WHEN sum(t1.charge) / sum(t1.activation) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t1.activation) / sum(t1.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t1.activation) /
+        sum(t1.download_completed)*100,2),'%') end as activeRate ,
         IFNULL(sum(t1.event_register),0) as register,
-        CASE WHEN sum(t1.charge) / sum(t1.event_register) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_register),3) end as activeRegisterCost ,
-        CASE WHEN sum(t1.event_register) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_register) / sum(t1.activation)*100,2),'%') end as activeRegisterRate ,
+        CASE WHEN sum(t1.charge) / sum(t1.event_register) IS NULL THEN 0 ELSE
+        round(sum(t1.charge)/sum(t1.event_register),3) end as activeRegisterCost ,
+        CASE WHEN sum(t1.event_register) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_register) /
+        sum(t1.activation)*100,2),'%') end as activeRegisterRate ,
         IFNULL(sum(t1.event_next_day_stay),0) as nextDayOpen,
-        CASE WHEN sum(t1.event_next_day_stay) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_next_day_stay) / sum(t1.activation)*100,2),'%') end as nextDayOpenRate
+        CASE WHEN sum(t1.event_next_day_stay) / sum(t1.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t1.event_next_day_stay) / sum(t1.activation)*100,2),'%') end as nextDayOpenRate
         FROM
         ctop_kuaishou_report_daily_campaign t1
         LEFT JOIN ctop_ai_kuaishou_strategy_map_creative t2 on t1.campaign_id=t2.campaign_id
@@ -104,20 +122,29 @@
         IFNULL(sum(t1.charge),0) as cost,
         IFNULL(sum(t1.photo_show),0) as photoShow,
         IFNULL(sum(t1.photo_click),0) as photoClick,
-        CASE WHEN sum(t1.photo_click) / sum(t1.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.photo_click) / sum(t1.photo_show)) * 100,2),'%') END AS clickRate,
+        CASE WHEN sum(t1.photo_click) / sum(t1.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.photo_click) /
+        sum(t1.photo_show)) * 100,2),'%') END AS clickRate,
         IFNULL(sum(t1.aclick),0) as aclick,
         IFNULL(sum(t1.bclick),0) as bclick,
-        CASE WHEN sum(t1.bclick) / sum(t1.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.bclick) / sum(t1.aclick)) * 100,2),'%') END AS bClickRate,
-        CASE WHEN sum(t1.charge) / sum(t1.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_show)) * 1000, 2 ) END AS cpm ,
-        CASE WHEN sum(t1.charge) / sum(t1.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_click)), 2) END AS cpc ,
+        CASE WHEN sum(t1.bclick) / sum(t1.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.bclick) / sum(t1.aclick)) *
+        100,2),'%') END AS bClickRate,
+        CASE WHEN sum(t1.charge) / sum(t1.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_show)) *
+        1000, 2 ) END AS cpm ,
+        CASE WHEN sum(t1.charge) / sum(t1.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_click)),
+        2) END AS cpc ,
         IFNULL(sum(t1.activation),0) as active,
-        CASE WHEN sum(t1.charge) / sum(t1.activation) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.activation) end AS activeCost ,
-        CASE WHEN sum(t1.activation) / sum(t1.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t1.activation) / sum(t1.download_completed)*100,2),'%') end as activeRate ,
+        CASE WHEN sum(t1.charge) / sum(t1.activation) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.activation) end AS
+        activeCost ,
+        CASE WHEN sum(t1.activation) / sum(t1.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t1.activation) /
+        sum(t1.download_completed)*100,2),'%') end as activeRate ,
         IFNULL(sum(t1.event_register),0) as register,
-        CASE WHEN sum(t1.charge) / sum(t1.event_register) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_register),3) end as activeRegisterCost ,
-        CASE WHEN sum(t1.event_register) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_register) / sum(t1.activation)*100,2),'%') end as activeRegisterRate ,
+        CASE WHEN sum(t1.charge) / sum(t1.event_register) IS NULL THEN 0 ELSE
+        round(sum(t1.charge)/sum(t1.event_register),3) end as activeRegisterCost ,
+        CASE WHEN sum(t1.event_register) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_register) /
+        sum(t1.activation)*100,2),'%') end as activeRegisterRate ,
         IFNULL(sum(t1.event_next_day_stay),0) as nextDayOpen,
-        CASE WHEN sum(t1.event_next_day_stay) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_next_day_stay) / sum(t1.activation)*100,2),'%') end as nextDayOpenRate
+        CASE WHEN sum(t1.event_next_day_stay) / sum(t1.activation) IS NULL THEN 0 ELSE
+        concat(round(sum(t1.event_next_day_stay) / sum(t1.activation)*100,2),'%') end as nextDayOpenRate
         FROM
         ctop_kuaishou_report_daily_group t1
         LEFT JOIN ctop_ai_kuaishou_strategy_map_creative t2 on t1.unit_id=t2.unit_id

+ 23 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiKuaiShouReportAnalyzeService.java

@@ -0,0 +1,23 @@
+package org.jeecg.modules.ads.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageInfo;
+
+import java.util.List;
+import java.util.Map;
+
+public interface IAiKuaiShouReportAnalyzeService {
+
+    List<JSONObject> getStrategyAndTarget(Long accountId);
+
+    List<JSONObject> getStrategyAndMaterial(Long accountId);
+
+    PageInfo<JSONObject> getTargetReportBy(JSONObject params);
+
+    PageInfo<JSONObject> getMaterialReportBy(JSONObject params);
+
+    Map<String,Object> getTargetChartBy(JSONObject params);
+
+    Map<String,Object> getMaterialChartBy(JSONObject params);
+
+}

+ 109 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiKuaiShouReportAnalyzeServiceImpl.java

@@ -0,0 +1,109 @@
+package org.jeecg.modules.ads.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.jeecg.modules.ads.mapper.IAiKuaiShouReportAnalyzeMapper;
+import org.jeecg.modules.ads.service.IAiKuaiShouReportAnalyzeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class AiKuaiShouReportAnalyzeServiceImpl implements IAiKuaiShouReportAnalyzeService {
+
+    @Autowired
+    private IAiKuaiShouReportAnalyzeMapper aiKuaiShouReportAnalyzeMapper;
+
+    @Override
+    public List<JSONObject> getStrategyAndTarget(Long accountId) {
+        List<JSONObject> strategies = aiKuaiShouReportAnalyzeMapper.queryStrategyByAccountId(accountId);
+        if (!strategies.isEmpty()) {
+            List<JSONObject> deletes = new ArrayList<>();
+            strategies.forEach(strategy -> {
+                List<JSONObject> targets = aiKuaiShouReportAnalyzeMapper.queryTargetByStrategyId(strategy.getLong("id"));
+                if (targets.isEmpty() || targets.get(0) == null) {
+                    deletes.add(strategy);
+                } else {
+                    strategy.put("targets", targets);
+                }
+            });
+            strategies.removeAll(deletes);
+        }
+        return strategies;
+    }
+
+    @Override
+    public List<JSONObject> getStrategyAndMaterial(Long accountId) {
+        List<JSONObject> strategies = aiKuaiShouReportAnalyzeMapper.queryStrategyByAccountId(accountId);
+        if (!strategies.isEmpty()) {
+            List<JSONObject> deletes = new ArrayList<>();
+            strategies.forEach(strategy -> {
+                List<JSONObject> materials = aiKuaiShouReportAnalyzeMapper.queryMaterialByStrategyId(strategy.getLong("id"));
+                if (materials.isEmpty() || materials.get(0) == null) {
+                    deletes.add(strategy);
+                } else {
+                    strategy.put("materials", materials);
+                }
+            });
+            strategies.removeAll(deletes);
+        }
+        return strategies;
+    }
+
+    @Override
+    public PageInfo<JSONObject> getTargetReportBy(JSONObject params) {
+        Long accountId = params.getLong("accountId");
+        Long strategyId = params.getLong("strategyId");
+        JSONArray targetIds = params.getJSONArray("targetIds");
+        String startDate = params.getString("startDate");
+        String endDate = params.getString("endDate");
+        int pageNo = params.getInteger("pageNo");
+        int pageSize = params.getInteger("pageSize");
+        PageHelper.startPage(pageNo, pageSize);
+        return new PageInfo<>(aiKuaiShouReportAnalyzeMapper.queryMaterialReportBy(accountId, strategyId, targetIds, startDate, endDate));
+    }
+
+    @Override
+    public PageInfo<JSONObject> getMaterialReportBy(JSONObject params) {
+        Long accountId = params.getLong("accountId");
+        Long strategyId = params.getLong("strategyId");
+        JSONArray codes = params.getJSONArray("codes");
+        String startDate = params.getString("startDate");
+        String endDate = params.getString("endDate");
+        int pageNo = params.getInteger("pageNo");
+        int pageSize = params.getInteger("pageSize");
+        PageHelper.startPage(pageNo, pageSize);
+        return new PageInfo<>(aiKuaiShouReportAnalyzeMapper.queryTargetReportBy(accountId, strategyId, codes, startDate, endDate));
+    }
+
+    @Override
+    public Map<String, Object> getTargetChartBy(JSONObject params) {
+        Map<String,Object> result =new HashMap<>();
+        Long strategyId = params.getLong("strategyId");
+        JSONArray targetIds = params.getJSONArray("targetIds");
+        String startDate = params.getString("startDate");
+        String endDate = params.getString("endDate");
+        result.put("age",aiKuaiShouReportAnalyzeMapper.queryAgeChartByTarget(strategyId,targetIds,startDate,endDate));
+        result.put("gender",aiKuaiShouReportAnalyzeMapper.queryGenderChartByTarget(strategyId,targetIds,startDate,endDate));
+        result.put("region",aiKuaiShouReportAnalyzeMapper.queryRegionChartByTarget(strategyId,targetIds,startDate,endDate));
+        return result;
+    }
+
+    @Override
+    public Map<String, Object> getMaterialChartBy(JSONObject params) {
+        Map<String,Object> result =new HashMap<>();
+        Long strategyId = params.getLong("strategyId");
+        JSONArray codes = params.getJSONArray("codes");
+        String startDate = params.getString("startDate");
+        String endDate = params.getString("endDate");
+        result.put("age",aiKuaiShouReportAnalyzeMapper.queryAgeChartByMaterial(strategyId,codes,startDate,endDate));
+        result.put("gender",aiKuaiShouReportAnalyzeMapper.queryGenderChartByMaterial(strategyId,codes,startDate,endDate));
+        result.put("region",aiKuaiShouReportAnalyzeMapper.queryRegionChartByMaterial(strategyId,codes,startDate,endDate));
+        return result;    }
+}

+ 2 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiKuaiShouStrategyListPageServiceImpl.java

@@ -1,6 +1,5 @@
 package org.jeecg.modules.ads.service.impl;
 
-import cn.com.ctop.common.module.constant.CtopRoleCodeConstant;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -11,7 +10,6 @@ import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.ads.mapper.AiKuaiShouStrategyListPageMapper;
 import org.jeecg.modules.ads.service.IAiKuaiShouStrategyListPageService;
-import org.jeecg.modules.system.service.ISysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -22,18 +20,16 @@ import java.util.List;
 public class AiKuaiShouStrategyListPageServiceImpl implements IAiKuaiShouStrategyListPageService {
 
     @Autowired
-    AiKuaiShouStrategyListPageMapper  aiKuaiShouStrategyListPageMapper;
+    AiKuaiShouStrategyListPageMapper aiKuaiShouStrategyListPageMapper;
 
     @Autowired
     IUserAllocationService userAllocationService;
-    @Autowired
-    private ISysRoleService sysRoleService;
 
     @Override
     public PageInfo<JSONObject> pageStrategy(JSONObject params) {
         JSONArray accountIds= params.getJSONArray("accountIds");
         if(null == accountIds||accountIds.isEmpty()){
-            accountIds = null;
+            accountIds=listToJSONArray(userAllocationService.getAccountIdsByUserId(((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId()));
         }
         String strategyName=params.getString("strategyName");
         Integer strategyState=params.getInteger("strategyState");

+ 0 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java

@@ -16,7 +16,6 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.StringUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -29,6 +29,8 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
 
     List<JSONObject> getAccountIdsByUserId(@Param("userId") String userId);
 
+    List<JSONObject> getAllAccountIdsByMediaId(@Param("mediaId") String mediaId);
+
     Long getProjectIdByAccountId(@Param("accountId") Long accountId);
 
     UserAllocation getUserAllocation(@Param("accountId") Long accountId);

+ 13 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -76,6 +76,19 @@
           and allocation.account_status=0
     </select>
 
+
+    <select id="getAllAccountIdsByMediaId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            account_id,
+            auth_name,
+            project_name
+        FROM
+            ctop_user_allocation
+        WHERE
+            media_id=#{mediaId}
+          and account_status=0
+    </select>
+
     <select id="getProjectIdByAccountId" resultType="java.lang.Long">
     select  project_id  from  ctop_user_allocation
     where account_id = #{accountId}

+ 9 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -123,7 +124,14 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
 
     @Override
     public List<JSONObject> getAccountIdsByUserId(String userId) {
-        return userAllocationMapper.getAccountIdsByUserId(userId);
+        List<JSONObject> result= new ArrayList<>();
+        if(userId.equals("e9ca23d68d884d4ebb19d07889727dae")){
+            result=userAllocationMapper.getAllAccountIdsByMediaId("2");
+        }else {
+            result=userAllocationMapper.getAccountIdsByUserId(userId);
+
+        }
+        return result;
     }
 
     @Override