浏览代码

Merge remote-tracking branch 'origin/kuaishou-ai-advertising' into kuaishou-ai-advertising

syh 4 年之前
父节点
当前提交
20d3e709e0
共有 23 个文件被更改,包括 811 次插入44 次删除
  1. 55 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/controller/AiKuaiShouStrategyListPageCtrl.java
  2. 0 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMapCreative.java
  3. 10 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMiddle.java
  4. 23 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/mapper/AiKuaiShouStrategyListPageMapper.java
  5. 138 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/mapper/xml/AiKuaishouStrategyListPageMapper.xml
  6. 17 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiKuaiShouStrategyListPageService.java
  7. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiKuaishouStrategyTemplateService.java
  8. 3 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiStrategyService.java
  9. 86 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiKuaiShouStrategyListPageServiceImpl.java
  10. 15 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiKuaishouStrategyTemplateServiceImpl.java
  11. 370 15
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java
  12. 12 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/TestImpl.java
  13. 14 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  14. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java
  15. 12 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  16. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialImageInfoService.java
  17. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  18. 11 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialImageInfoServiceImpl.java
  19. 6 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  20. 0 24
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml
  21. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouImageGetService.java
  22. 13 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouImageGetServiceImpl.java
  23. 14 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

+ 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;
+    }
+}

+ 0 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMapCreative.java

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 
 import lombok.Data;
-import org.omg.CORBA.LongHolder;
 
 /**
  * 策略创意表

+ 10 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyMiddle.java

@@ -28,4 +28,14 @@ public class AiKuaishouStrategyMiddle {
 	/**updateTime*/
     @ApiModelProperty(value = "updateTime")
 	private Date updateTime;
+
+	public AiKuaishouStrategyMiddle(Long templateId, Long strategyId) {
+		this.strategyTemplateId = templateId;
+		this.strategyId = strategyId;
+		this.createTime = new Date();
+		this.updateTime = new Date();
+	}
+
+	public AiKuaishouStrategyMiddle() {
+	}
 }

+ 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);
+
+}

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

@@ -11,4 +11,5 @@ import org.jeecg.modules.ads.entity.AiKuaishouStrategyTemplate;
  */
 public interface IAiKuaishouStrategyTemplateService extends IService<AiKuaishouStrategyTemplate> {
 
+    AiKuaishouStrategyTemplate getOneByParams(String testDirection, Integer status);
 }

+ 3 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/IAiStrategyService.java

@@ -1,5 +1,7 @@
 package org.jeecg.modules.ads.service;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+
 public interface IAiStrategyService {
-    void createCreativeByStrategy(Integer strategyType);
+    void createCreativeByStrategy(KuaishouStrategy strategy);
 }

+ 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;
+    }
+}

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

@@ -1,9 +1,11 @@
 package org.jeecg.modules.ads.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.ads.entity.AiKuaishouStrategyTemplate;
 import org.jeecg.modules.ads.mapper.AiKuaishouStrategyTemplateMapper;
 import org.jeecg.modules.ads.service.IAiKuaishouStrategyTemplateService;
+import org.jeecg.modules.ctop.vo.QueryParam;
 import org.springframework.stereotype.Service;
 
 /**
@@ -15,4 +17,17 @@ import org.springframework.stereotype.Service;
 @Service
 public class AiKuaishouStrategyTemplateServiceImpl extends ServiceImpl<AiKuaishouStrategyTemplateMapper, AiKuaishouStrategyTemplate> implements IAiKuaishouStrategyTemplateService {
 
+    @Override
+    public AiKuaishouStrategyTemplate getOneByParams(String templateType, Integer status) {
+        QueryWrapper<AiKuaishouStrategyTemplate> queryWrapper= new QueryWrapper<>();
+        if(null!=templateType&&!"".equals(templateType.trim())){
+            queryWrapper.eq("template_type",templateType);
+        }
+        if(null!=status){
+            queryWrapper.eq("status",status);
+        }
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        return this.getOne(queryWrapper);
+    }
 }

+ 370 - 15
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java

@@ -1,46 +1,401 @@
 package org.jeecg.modules.ads.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.MaterialCutFrame;
+import cn.com.ctop.common.module.entity.MaterialImageInfo;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IMaterialCutFrameService;
+import cn.com.ctop.common.module.service.IMaterialImageInfoService;
+import cn.com.ctop.common.module.service.IOauthAgentTokenService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
-import org.jeecg.modules.ads.entity.AiKuaishouStrategyTargetBase;
-import org.jeecg.modules.ads.service.IAiKuaishouStrategyTargetBaseService;
-import org.jeecg.modules.ads.service.IAiStrategyService;
+import com.alibaba.fastjson.JSONObject;
+import com.sun.mail.imap.protocol.INTERNALDATE;
+import groovy.util.logging.Slf4j;
+import org.jeecg.modules.ads.entity.*;
+import org.jeecg.modules.ads.service.*;
+import org.openqa.selenium.json.Json;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
+import java.util.Date;
 
+import static com.bstek.ureport.definition.datasource.DataType.Date;
+
+@Slf4j
 @Service
 public class AiStrategyServiceImpl implements IAiStrategyService {
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
     @Autowired
     private IAiKuaishouStrategyTargetBaseService targetBaseService;
+    @Autowired
+    private IAiKuaishouStrategyTemplateService templateService;
+    @Autowired
+    private IAiKuaishouStrategyMiddleService middleService;
+    @Autowired
+    private IAiKuaishouStrategyTargetUnionService targetUnionService;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IAiKuaishouStrategyMapCreativeService mapCreativeService;
+    @Autowired
+    private IMaterialCutFrameService materialCutFrameService;
+    @Autowired
+    private IMaterialImageInfoService materialImageInfoService;
+
+    @Autowired
+    private IKuaiShouImageGetService imageGetService;
+
 
+    private IKuaiShouMaterialUploadService materialUploadService;
     /**
      *
-     * @param strategyType
+     * @param strategy
      */
     @Override
-    public void createCreativeByStrategy(Integer strategyType){
+    public void createCreativeByStrategy(KuaishouStrategy strategy){
         //获取账户id
-        Long accountId = 23212L;
-        //获取测试方向
-        String testDirection = "device_price";
-        //1:获取相应账户下的最新的5条素材信息
+        Long accountId = strategy.getAccountId();
+        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
+        if(null == token){
+            return;
+        }
+        //策略类型
+        String scenes = strategy.getScenes();
+        //根据策略类型获取策略模板信息
+        AiKuaishouStrategyTemplate strategyTemplate = templateService.getOneByParams(scenes, 1);
+        if(null == strategyTemplate){
+            return;
+        }
+        //1:获取相应账户下的最新的5条素材信息 TODO
         List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
+        if(null == videoGets){
+            return;
+        }
         //2:根据测试方向获取相应的定向拆分数据类型
-        List<AiKuaishouStrategyTargetBase>targetBases = targetBaseService.listByType(testDirection);
+        List<AiKuaishouStrategyTargetBase>targetBases = targetBaseService.listByType(strategyTemplate.getTestDirection());
+        if(null == targetBases){
+            return;
+        }
         //3:获取相应字段相应的用户定义域
-        String definitionDomain = "[1,2,3]";
+        String definitionDomain = null;
+
+        if (strategyTemplate.getTestDirection().equals("age"))
+            definitionDomain = strategy.getAgesRange();
+        if (strategyTemplate.getTestDirection().equals("gender"))
+            definitionDomain = strategy.getGender().toString();
+        if (strategyTemplate.getTestDirection().equals("region"))
+            definitionDomain = strategy.getRegion();
+        if (strategyTemplate.getTestDirection().equals("operation_system"))
+            definitionDomain = strategy.getPlatformOs().toString();
+
         //4:计算定向拆分逻辑
         List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
-        //5:循环创建计划,组,创意
+        if(null == getBases){
+            //TODO
+            return;
+        }
+        //5、策略--策略模板 关联表,写入数据库
+        AiKuaishouStrategyMiddle strategyMiddle =
+                new AiKuaishouStrategyMiddle(strategyTemplate.getId(),strategy.getId());
+        middleService.save(strategyMiddle);
+
+        //6、策略定向拆分数据,写入数据库
+//        for (AiKuaishouStrategyTargetBase item:getBases) {
+//
+//        }
+
+        //7、一个计划,拼装创建计划的入参json
+        JSONObject campaignParams = new JSONObject();
+        campaignParams.put("advertiser_id",token.getAccountId());
+        Date campaignDate = new Date();
+        campaignParams.put("campaign_name",strategy.getStrategyName()+ campaignDate.toString());
+        campaignParams.put("type",Integer.parseInt(strategy.getMarketingGoal()));
+        campaignParams.put("day_budget",0L);
+        JSONArray dayBudgetSchedule = new JSONArray();
+        dayBudgetSchedule.add(0L);
+        campaignParams.put("day_budget_schedule",dayBudgetSchedule);
+
+        Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(),
+                token.getAccountId(), campaignParams);
+        Integer code = (Integer) campaignCreateResult.get("code");
+        if(code != 0 ){
+            return;
+        }
+        Long campaignId = (Long) campaignCreateResult.get("campaignId");
+
+        // 8、根据定向和素材,两层循环 创建组和创意
+        Integer unitCnt = 1;
+        for (AiKuaishouStrategyTargetBase item:getBases) {
+            // 策略定向拆分数据,写入数据库
+            AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion();
+            targetUnion.setStrategyMiddleId(strategyMiddle.getId());
+            targetUnion.setStrategyTargetId(item.getId());
+            targetUnion.setActualTargetContent(item.getTargetContent());
+            targetUnionService.save(targetUnion);
+
+
+            // 拼装创建组的入参 json
+            JSONObject unitParams = new JSONObject();
+            unitParams.put("advertiser_id",token.getAccountId());
+            unitParams.put("campaign_id",campaignId);
+            Date unitDate = new Date();
+            unitParams.put("unit_name", strategy.getStrategyName() +
+                                        item.getTargetType() +
+                                        item.getTargetContent() +
+                                        unitDate.toString() +
+                                        (unitCnt++).toString());
+
+            //TODO 模板里的内容与测试方向冲突?
+            unitParams.put("template_id",strategy.getTemplateId());
+            unitParams.put("bid_type",10);
+
+            //TODO 前端添加对应设置项
+            unitParams.put("use_app_market","?");
+            unitParams.put("app_store","?");
+
+            // 非 OCPM 出价方式,是手动通过AD后台,走通几个成功下载APP的案例
+            // 在本策略中,都是 OCPM 的出价方式
+//            unitParams.put("bid","");
+            unitParams.put("cpa_bid",strategy.getCpaBid());
+//            unitParams.put("smart_bid","");  //当 speed 等于 3 时可用
+            unitParams.put("ocpx_action_type",strategy.getOcpxActionType());
+            unitParams.put("deep_conversion_typ",strategy.getDeepConversionType());
+//            unitParams.put("roi_ratio",""); 付费ROI系数 优化目标为「首日ROI」时必填
+            unitParams.put("deep_conversion_bid",strategy.getDeepConversionBid());
+            unitParams.put("scene_id",JSONArray.parseArray(strategy.getSceneId()));
+            unitParams.put("unit_type",4);
+
+            Date putDate = new Date();
+            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+            String putDateString = formatter.format(putDate);
+            unitParams.put("begin_time",putDateString); // 格式为yyyy-MM-dd,需大于等于当前时间
+//            unitParams.put("end_time",""); 不传值表示从今天开始长期投放
+//            unitParams.put("schedule_time","");
+//            unitParams.put("day_budget","");
+//            unitParams.put("day_budget_schedule","");
+            unitParams.put("convert_id",strategy.getConvertId()); // ?
+//            unitParams.put("url_type",""); 当计划类型为3(获取电商下单)时必填
+            unitParams.put("url_type",strategy.getUrlType()); // 当计划类型为3(获取电商下单)
+//            unitParams.put("web_uri_type",""); // 当计划类型为5(收集销售线索)&使用建站时必填:需使用魔力建站
+            unitParams.put("url",strategy.getUrl()); // 当计划类型是3/4/5时必填
+            unitParams.put("schema_uri",""); // 可选
+            unitParams.put("app_id",""); // long 当计划类型为2时必填,可通过应用列表接口获取应用ID  但是前端为app_ids,是集合?
+            unitParams.put("show_mode",2);
+            unitParams.put("speed",1); // 前端没有设置,暂时默认为加速投放
+//            unitParams.put("site_type",""); // 预约广告,1:IOS预约 缺省为不传或传0
+//            unitParams.put("gift_data",""); // 游戏礼包码 "gift_data": {},仅支持计划类型为 2
+//            unitParams.put("video_landing_page","");
+//            unitParams.put("auto_target","");   智能定向
+//            unitParams.put("smart_cover","");   是否开启智能抽帧
+//            unitParams.put("asset_mining","");  是否开启历史素材挖掘
+
+            // 设置定向内容
+            JSONObject targetJsonObject = new JSONObject();
+            if (strategyTemplate.getTestDirection().equals("region"))
+                targetJsonObject.put("region",item.getTargetContent());
+            else
+                targetJsonObject.put("region",JSONArray.parseArray(strategy.getRegion()));
+
+//            targetJsonObject.put("district_ids",""); 商圈定向 与region字段不能同时传
+//            targetJsonObject.put("user_type",""); 用户类型
+//            targetJsonObject.put("age","");
+
+            if (strategyTemplate.getTestDirection().equals("age"))
+                targetJsonObject.put("ages_range",item.getTargetContent());
+            else
+                targetJsonObject.put("ages_range",JSONArray.parseArray(strategy.getAgesRange()));
+
+            if (strategyTemplate.getTestDirection().equals("gender"))
+                targetJsonObject.put("gender",item.getTargetContent());
+            else
+                targetJsonObject.put("gender",strategy.getGender());
+
+            if (strategyTemplate.getTestDirection().equals("operation_system"))
+                targetJsonObject.put("platform_os",item.getTargetContent());
+            else
+                targetJsonObject.put("platform_os",strategy.getPlatformOs());
+//            targetJsonObject.put("android_osv","");
+//            targetJsonObject.put("ios_osv","");
+//            targetJsonObject.put("network","");
+//            targetJsonObject.put("device_brand","");
+//            targetJsonObject.put("device_price","");
+//            targetJsonObject.put("business_interest_type","");
+//            targetJsonObject.put("business_interest","");
+//            targetJsonObject.put("fans_star","");
+//            targetJsonObject.put("interest_video","");
+//            targetJsonObject.put("app_interest","");
+//            targetJsonObject.put("app_ids",""); // APP行为-按APP名称
+//            targetJsonObject.put("filter_converted_level","");
+            targetJsonObject.put("population",JSONArray.parseArray(strategy.getPopulation()));
+//            targetJsonObject.put("exclude_population","");
+//            targetJsonObject.put("paid_audience","");
+//            targetJsonObject.put("intelli_extend","");
+//            targetJsonObject.put("behavior_interest","");
+            unitParams.put("target",targetJsonObject);
+
+
+            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(),
+                    token.getAccountId(), unitParams,1);
+            Integer unitCode = (Integer) unitCreateResult.get("code");
+            if(unitCode != 0 ){
+                return;
+            }
+            Long unitId = (Long) unitCreateResult.get("unitId");
+
+            // 选择素材,创建创意
+            for(KuaiShouVideoGet videoItem: videoGets){
+                // 素材自带的封面 ctop_material_image_info 内部素材的自带封面,素造的没有
+                // 素材的智能抽帧封面 ctop_material_cut_frame 其中素造的为8张封面,内部的为15张封面
+                List<MaterialCutFrame> cutFrameList =
+                        materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
+                List<MaterialImageInfo> orgFrameList =
+                        materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
+
+                JSONArray sceneIdJsonArray = JSONArray.parseArray(strategy.getSceneId());
+                JSONObject creativeParams = new JSONObject();
+                Integer creativeCnt = 1;
+                if (sceneIdJsonArray.contains(6) && sceneIdJsonArray.size() == 1){
+                    // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成1个创意
+                    String imageCode;
+                    String imageUrl;
+                    if (cutFrameList.size() == 0 && orgFrameList.size()==0){
+                        return;
+                    }
+                    if (orgFrameList.size()!=0){
+                        imageCode = orgFrameList.get(0).getCode();
+                        imageUrl = orgFrameList.get(0).getUrl();
+                    }
+                    else{
+                        imageCode = cutFrameList.get(0).getSignature();
+                        imageUrl = cutFrameList.get(0).getUrl();
+                    }
+                    String imageToken = getImageToken(imageUrl,
+                            imageCode,
+                            token.getAccountId(),
+                            token.getAccessToken());
+
+                    creativeParams.put("advertiser_id",token.getAccountId());
+                    creativeParams.put("unit_id",unitId);
+                    Date creativeDate = new Date();
+                    creativeParams.put("creative_name",creativeDate.toString() + creativeCnt.toString());
+                    creativeParams.put("photo_id",videoItem.getPhotoId());
+                    creativeParams.put("image_token",imageToken);
+                    creativeParams.put("creative_material_type",1); // 1:竖版视频  2:横版视频 4:便利贴单图图片创意 5:竖版图片 6:横版图片
+//                    creativeParams.put("image_tokens",""); 便利贴单图图片创意token
+                    creativeParams.put("action_bar_text","立即下载");
+                    creativeParams.put("description",""); // 广告语 -- 看小说太累?不妨试一试听书,解放双手,缓解压力!
+                    creativeParams.put("site_id",""); // 安卓下载中间页ID
+                    creativeParams.put("click_track_url","");
+                    creativeParams.put("impression_url","");
+                    creativeParams.put("ad_photo_played_t3s_url","");
+                    creativeParams.put("actionbar_click_url","");
+                    creativeParams.put("creative_category","");// 创意分类
+                    creativeParams.put("creative_tag",""); //创意标签
+                }
+                else
+                {
+                    // 其他情况下,一个素材搭配15张封面,生成15个创意
+                    if (cutFrameList.size() == 0 && orgFrameList.size()==0){
+                        return;
+                    }
+                    if (orgFrameList.size() !=0) {
+                        for (int i = 0; i < orgFrameList.size(); i++) {
+                            String imageCode = orgFrameList.get(i).getCode();
+                            String imageUrl = orgFrameList.get(i).getUrl();
+                            creativeCnt++;
+                            if (creativeCnt > 15) {
+                                break;
+                            }
+                        }
+                    }
+
+                    if ((cutFrameList.size() !=0) && (creativeCnt<=15)){
+                        for (int i = 0; i < cutFrameList.size(); i++) {
+                            String imageCode = cutFrameList.get(i).getSignature();
+                            String imageUrl = cutFrameList.get(i).getUrl();
+                            creativeCnt ++;
+                            if (creativeCnt > 15) {
+                                break;
+                            }
+                        }
+                    }
+
+                }
+
+
+
+                creativeParams.put("advertiser_id",token.getAccountId());
+                creativeParams.put("unit_id",unitId);
+                creativeParams.put("creative_name","");
+                creativeParams.put("photo_id","");
+                creativeParams.put("image_token","");
+                creativeParams.put("creative_material_type","");
+                creativeParams.put("","");
+                creativeParams.put("","");
+                creativeParams.put("","");
+                creativeParams.put("","");
+                creativeParams.put("","");
+
+                Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
+                        (token.getAccessToken(), token.getAccountId(), creativeParams,1);
+                Integer creativeCode = (Integer) creativeCreateResult.get("code");
+                if(creativeCode != 0 ){
+                    return;
+                }
+                Long creativeId = (Long) creativeCreateResult.get("creativeId");
+                AiKuaishouStrategyMapCreative mapCreative = new AiKuaishouStrategyMapCreative();
+                mapCreative.setAccountId(token.getAccountId());
+                mapCreative.setCampaignId(campaignId);
+                mapCreative.setUnitId(unitId);
+                mapCreative.setCreativeId(creativeId);
+                mapCreative.setStrategyId(strategy.getId());
+                mapCreative.setStrategyTargetUnionId(targetUnion.getId());
+                mapCreativeService.save(mapCreative);
+
+
+            }
+
+
+
+
+        }
+
+
     }
 
-    private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain, List<AiKuaishouStrategyTargetBase> targetBases) {
+    private String getImageToken(String imageUrl, String imageCode, Long accountId,String token){
+        // 根据imageUrl 和 imageCode,获取 imageToken (创建创意用)
+        KuaiShouImageGet imageGet = imageGetService.getOneByParams(imageUrl);
+        if ((null == imageGet) || ("".equals(imageGet.getImageToken()))){
+            // 如果取不到image_token
+            // 则调用上传url的方法 kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
+            String imageToken = materialUploadService.kuauiShouImageUpload(imageUrl,imageCode,accountId,token);
+            return imageToken;
+        }
+
+        return imageGet.getImageToken();
+    }
+
+    private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain,
+                                                                  List<AiKuaishouStrategyTargetBase> targetBases) {
+        if(null==definitionDomain){
+            return targetBases;
+        }
         if(null == targetBases||targetBases.isEmpty()){
             return null;
         }
@@ -48,8 +403,8 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         List<AiKuaishouStrategyTargetBase> resultBase = null;
         //数字
         if("number".equals(type)){
-            resultBase = targetBases.stream().filter(target -> definitionDomain.contains(target.getTargetContent().
-                    replace("[","").replace("]",""))).collect(Collectors.toList());
+            resultBase = targetBases.stream().filter(target -> definitionDomain.equals(target.getTargetContent())).
+                    collect(Collectors.toList());
         }
         //数组
         if("array".equals(type)){

+ 12 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/TestImpl.java

@@ -30,7 +30,18 @@ public class TestImpl implements Test {
     }
 
     public static String getStrategy(){
-
+        /**
+         *
+         * [{
+         *     "matGetType":"highQualityMaterial",
+         *     "matNum":5
+         * },
+         *    {
+         *     "matGetType":"highQualityMaterial",
+         *     "matNum":5
+         *     "intervalDays": 7,
+         * }]
+         */
 
        /* String materialCombinationMode = "{'highQualityMaterial':{'intervalDays':7, 'highQualityMaterialNum':5}, 'newMaterialNum':5}";
         JSONObject jsonObject = JSONObject.parseObject(materialCombinationMode);

+ 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/IMaterialImageInfoService.java

@@ -29,4 +29,7 @@ public interface IMaterialImageInfoService extends IService<MaterialImageInfo> {
     void initImageCode(MaterialImageInfo image);
 
     MaterialImageInfo getByCode(String signature);
+
+
+    List<MaterialImageInfo> getListByVideoSignature(String signature);
 }

+ 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);

+ 11 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialImageInfoServiceImpl.java

@@ -151,4 +151,15 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
         return this.getOne(queryWrapper);
     }
 
+
+    @Override
+    public List<MaterialImageInfo> getListByVideoSignature(String signature) {
+        QueryWrapper<MaterialImageInfo>queryWrapper =new QueryWrapper<>();
+        if(null!=signature&&!signature.trim().equals("")){
+            queryWrapper.eq("video_id",signature);
+        }
+        return this.list(queryWrapper);
+    }
+
+
 }

+ 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);

+ 0 - 24
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml

@@ -59,28 +59,4 @@
 
 
 
-    <select id="getNewMaterialSignature" parameterType="java.util.Map"
-            resultType="cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo">
-        select
-        stat_date as 'statDate',
-        photo_id as 'photoId',
-        url as 'url',
-        cover_url as 'coverUrl',
-        signature as 'signature',
-        material_type as 'materialType'
-        from ctop_kuaishou_video_get
-        where account_id = #{accountId}
-        and channel_type = #{channelType}
-        and material_type = #{materialType}
-        and status = 0
-        <if test="startDate != null and startDate != '' ">
-            and stat_date &gt;= #{startDate}
-        </if>
-        <if test="endDate != null and endDate != '' ">
-            and stat_date &lt;= #{endDate}
-        </if>
-        group by signature
-        order by stat_date desc
-    </select>
-
 </mapper>

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouImageGetService.java

@@ -15,4 +15,6 @@ public interface IKuaiShouImageGetService extends IService<KuaiShouImageGet> {
     void replaceBatch(List<KuaiShouImageGet> imageGets);
 
     String getUrlByCode(String signature);
+
+    KuaiShouImageGet getOneByParams(String url);
 }

+ 13 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouImageGetServiceImpl.java

@@ -4,6 +4,7 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouImageGetMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -38,4 +39,16 @@ public class KuaiShouImageGetServiceImpl extends ServiceImpl<KuaiShouImageGetMap
 
     }
 
+
+    @Override
+    public KuaiShouImageGet getOneByParams(String url) {
+        QueryWrapper<KuaiShouImageGet> queryWrapper= new QueryWrapper<>();
+        if(null!=url&&!"".equals(url.trim())){
+            queryWrapper.eq("url",url);
+        }
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        return this.getOne(queryWrapper);
+    }
+
 }

+ 14 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -1019,8 +1019,20 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     returnMap.put("campaignId", campaignId);
                     returnMap.put("success", true);
                     // 创建成功 拉取广告组信息
-                    Thread.sleep(500);
-                    getCampaign(accessToken, advertiserId, campaignId);
+
+                    Thread thread = new Thread(){
+                        @Override
+                        public void run(){
+                            try {
+                                Thread.sleep(500);
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                            getCampaign(accessToken, advertiserId, campaignId);
+                        }
+                    };
+                    thread.start();
+
                 } else {
                     log.error("创建广告计划失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
                     returnMap.put("code", -1);