Browse Source

智能投放策略展示页

jiequan.bi 4 years ago
parent
commit
2556181594

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

@@ -0,0 +1,55 @@
+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.IAiKuaiShouStrategyListPageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("/ai/list")
+@RestController
+public class AiKuaiShouStrategyListPageCtrl {
+
+    @Autowired
+    IAiKuaiShouStrategyListPageService aiKuaiShouStrategyListPageService;
+
+    @PostMapping("/pageStrategy")
+    public Result<PageInfo<JSONObject>> pageStrategy(@RequestBody JSONObject params){
+        Result<PageInfo<JSONObject>> result=new Result<>();
+        if(params.isEmpty()){
+            result.error500("参数为空");
+        }else {
+            result.setSuccess(true);
+            result.setResult(aiKuaiShouStrategyListPageService.pageStrategy(params));
+        }
+        return result;
+    }
+
+    @PostMapping("/pageCampaign")
+    public Result<PageInfo<JSONObject>> pageCampaign(@RequestBody JSONObject params){
+        Result<PageInfo<JSONObject>> result=new Result<>();
+        if(params.isEmpty()){
+            result.error500("参数为空");
+        }else {
+            result.setSuccess(true);
+            result.setResult(aiKuaiShouStrategyListPageService.pageCampaign(params));
+        }
+        return result;
+    }
+
+    @PostMapping("/pageUnit")
+    public Result<PageInfo<JSONObject>> pageUnit(@RequestBody JSONObject params){
+        Result<PageInfo<JSONObject>> result=new Result<>();
+        if(params.isEmpty()){
+            result.error500("参数为空");
+        }else {
+            result.setSuccess(true);
+            result.setResult(aiKuaiShouStrategyListPageService.pageUnit(params));
+        }
+        return result;
+    }
+}

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

@@ -0,0 +1,23 @@
+package org.jeecg.modules.ads.mapper;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+
+/**
+ *  Created by JQ.bi on 2020.12.16
+ */
+@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> 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);
+
+}

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

@@ -0,0 +1,138 @@
+<?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.AiKuaiShouStrategyListPageMapper">
+
+    <select id="queryStrategyBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            t1.id,
+            t1.strategy_state as strategyState,
+            t1.strategy_name as strategyName,
+            t1.create_time as createTime,
+            t1.account_id as accountId,
+            '' 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,
+            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 ,
+            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 ,
+            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 ,
+            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
+        FROM
+            ctop_kuaishou_strategy t1
+                LEFT JOIN ctop_ai_kuaishou_strategy_map_creative t2 on t1.id=t2.strategy_id
+                left join ctop_kuaishou_report_daily_campaign t3 on t2.campaign_id=t3.campaign_id
+        where t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        <if test="strategyName != null">
+            AND t1.strategy_name like '%${strategyName}%'
+        </if>
+        <if test="strategyState != null">
+            AND t1.t1.strategy_state=#{strategyState}
+        </if>
+        <if test="id != null">
+            AND t1.id=#{id}
+        </if>
+        order by t1.create_time desc
+    </select>
+
+    <select id="queryCampaignByStrategyId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.campaign_id as campaignId,
+        t1.campaign_name as campaignName,
+        t1.status,
+        t3.id as strategyId,
+        t3.strategy_name as strategyName,
+        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,
+        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 ,
+        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 ,
+        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 ,
+        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
+        FROM
+        ctop_kuaishou_report_daily_campaign t1
+        LEFT JOIN ctop_ai_kuaishou_strategy_map_creative t2 on t1.campaign_id=t2.campaign_id
+        left join ctop_kuaishou_strategy t3 on t2.strategy_id=t3.id
+        where t3.id= #{strategyId}
+        <if test="campaignName != null">
+            and t1.campaign_name like '%${campaignName}}%'
+        </if>
+        <if test="campaignId != null">
+            and t1.campaign_id=#{campaignId}
+        </if>
+        <if test="status != null">
+            AND t1.status=#{status}
+        </if>
+        GROUP BY t1.campaign_id
+        order by t1.create_time desc
+    </select>
+
+    <select id="queryUnitByCampaignId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.campaign_id as campaignId,
+        t1.campaign_name as campaignName,
+        t1.unit_id as unitId,
+        t1.unit_name as unitName,
+        t1.status,
+        t3.id as strategyId,
+        t3.strategy_name as strategyName,
+        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,
+        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 ,
+        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 ,
+        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 ,
+        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
+        FROM
+        ctop_kuaishou_report_daily_group t1
+        LEFT JOIN ctop_ai_kuaishou_strategy_map_creative t2 on t1.unit_id=t2.unit_id
+        left join ctop_kuaishou_strategy t3 on t2.strategy_id=t3.id
+        where t1.campaign_id= #{campaignId}
+        <if test="unitName != null">
+            and t1.unit_name like '%${unitName}}%'
+        </if>
+        <if test="unitId != null">
+            and t1.unit_id=#{unitId}
+        </if>
+        <if test="status != null">
+            AND t1.status=#{status}
+        </if>
+        GROUP BY t1.unit_id
+        order by t1.create_time desc
+    </select>
+</mapper>

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

@@ -0,0 +1,17 @@
+package org.jeecg.modules.ads.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageInfo;
+
+/**
+ *  Created by JQ.bi on 2020.12.16
+ */
+public interface IAiKuaiShouStrategyListPageService {
+
+    PageInfo<JSONObject> pageStrategy(JSONObject params);
+
+    PageInfo<JSONObject> pageCampaign(JSONObject params);
+
+    PageInfo<JSONObject> pageUnit(JSONObject params);
+
+}

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

@@ -0,0 +1,86 @@
+package org.jeecg.modules.ads.service.impl;
+
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.log4j.Log4j;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Log4j
+@Service
+public class AiKuaiShouStrategyListPageServiceImpl implements IAiKuaiShouStrategyListPageService {
+
+    @Autowired
+    AiKuaiShouStrategyListPageMapper  aiKuaiShouStrategyListPageMapper;
+
+    @Autowired
+    IUserAllocationService userAllocationService;
+
+    @Override
+    public PageInfo<JSONObject> pageStrategy(JSONObject params) {
+        JSONArray accountIds= params.getJSONArray("accountIds");
+        if(accountIds.isEmpty()){
+            accountIds=listToJSONArray(userAllocationService.getAccountIdsByUserId(((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId()));
+        }
+        if(accountIds.isEmpty()){
+            return null;
+        }
+        String strategyName=params.getString("strategyName");
+        Integer strategyState=params.getInteger("strategyState");
+        Long id=params.getLong("id");
+        int pageNo=params.getInteger("pageNo");
+        int pageSize=params.getInteger("pageSize");
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> list=aiKuaiShouStrategyListPageMapper.queryStrategyBy(accountIds,strategyName,strategyState,id);
+        return new PageInfo<>(list);
+    }
+
+    @Override
+    public PageInfo<JSONObject> pageCampaign(JSONObject params) {
+        Long strategyId= params.getLong("strategyId");
+        if(null==strategyId){
+            log.error("参数异常,strategyId is no present");
+            return null;
+        }
+        String campaignName=params.getString("campaignName");
+        Integer status=params.getInteger("status");
+        Long campaignId=params.getLong("campaignId");
+        int pageNo=params.getInteger("pageNo");
+        int pageSize=params.getInteger("pageSize");
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> list=aiKuaiShouStrategyListPageMapper.queryCampaignByStrategyId(strategyId,campaignName,campaignId,status);
+        return new PageInfo<>(list);
+    }
+
+    @Override
+    public PageInfo<JSONObject> pageUnit(JSONObject params) {
+        Long campaignId= params.getLong("campaignId");
+        if(null==campaignId){
+            log.error("参数异常,campaignId is no present");
+            return null;
+        }
+        String unitName=params.getString("unitName");
+        Integer status=params.getInteger("status");
+        Long unitId=params.getLong("unitId");
+        int pageNo=params.getInteger("pageNo");
+        int pageSize=params.getInteger("pageSize");
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> list=aiKuaiShouStrategyListPageMapper.queryCampaignByStrategyId(campaignId,unitName,unitId,status);
+        return new PageInfo<>(list);
+    }
+
+    private JSONArray listToJSONArray(List<JSONObject> data){
+        JSONArray result=new JSONArray();
+        data.forEach(jsonObject->result.add(jsonObject.getLong("account_id")));
+        return result;
+    }
+}

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

@@ -16,6 +16,7 @@ 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;
@@ -305,6 +306,19 @@ public class UserAllocationController {
         return result;
     }
 
+    @GetMapping(value = "/getAccountIdsByUserId")
+    public Result<List<JSONObject>> getAccountIdsByUserId(String userId) {
+        Result<List<JSONObject>> result = new Result<>();
+        try {
+            List<JSONObject> accountIds = userAllocationService.getAccountIdsByUserId(userId);
+            result.setSuccess(true);
+            result.setResult(accountIds);
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.success(e.getMessage());
+        }
+        return result;
+    }
 
     /**
      * 分页列表查询

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

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.UserAllocation;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
@@ -26,6 +27,8 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
 
     List<JSONObject> getAccountIdListByUserId(@Param("userId") Long userId);
 
+    List<JSONObject> getAccountIdsByUserId(@Param("userId") String userId);
+
     Long getProjectIdByAccountId(@Param("accountId") Long accountId);
 
     UserAllocation getUserAllocation(@Param("accountId") Long accountId);

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

@@ -63,6 +63,18 @@
     AND t1.account_status = 0
     </select>
 
+    <select id="getAccountIdsByUserId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            account_id,
+            auth_name,
+            project_name
+        FROM
+            ctop_user_allocation
+        WHERE
+            user_id = #{userId}
+          and account_status=0
+    </select>
+
     <select id="getProjectIdByAccountId" resultType="java.lang.Long">
     select  project_id  from  ctop_user_allocation
     where account_id = #{accountId}

+ 3 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.UserAllocation;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -33,6 +34,8 @@ public interface IUserAllocationService extends IService<UserAllocation> {
 
     List<JSONObject> getAccountIdListByUserId(Long userId);
 
+    List<JSONObject> getAccountIdsByUserId(String userId);
+
     List<UserAllocation> getUserAllocations(String mediaId ,int switchType);
 
     JSONObject getSwitchStatusByAccount(Long accountId);

+ 6 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -6,6 +6,7 @@ import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.utils.ResultMapUtils;
 import cn.com.ctop.common.module.utils.StatusCode;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -121,6 +122,11 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     }
 
     @Override
+    public List<JSONObject> getAccountIdsByUserId(String userId) {
+        return userAllocationMapper.getAccountIdsByUserId(userId);
+    }
+
+    @Override
     public List<UserAllocation> getUserAllocations(String mediaId, int switchType) {
         QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("media_id", mediaId);