liyuyi@c-top.com.cn 4 роки тому
батько
коміт
0d11fd2e3e

+ 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() {
+	}
 }

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

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

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

@@ -1,47 +1,163 @@
 package org.jeecg.modules.ads.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IOauthAgentTokenService;
 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.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 groovy.util.logging.Slf4j;
+import org.jeecg.modules.ads.entity.*;
+import org.jeecg.modules.ads.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
+@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;
     /**
      *
-     * @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);
+        if(null == getBases){
+            //TODO
+            return;
+        }
+        //5、策略--策略模板 关联表,写入数据库
+        AiKuaishouStrategyMiddle strategyMiddle =
+                new AiKuaishouStrategyMiddle(strategyTemplate.getId(),strategy.getId());
+        middleService.save(strategyMiddle);
+
+        //6、策略定向拆分数据,写入数据库
+        for (AiKuaishouStrategyTargetBase item:getBases) {
+
+        }
+
         //5:循环创建计划,组,创意
+        //拼装计划创建 入参 json
+        JSONObject campaignParams = new JSONObject();
+        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");
+        for (AiKuaishouStrategyTargetBase item:getBases) {
+            AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion();
+            targetUnion.setStrategyMiddleId(strategyMiddle.getId());
+            targetUnion.setStrategyTargetId(item.getId());
+            targetUnion.setActualTargetContent(item.getTargetContent());
+            targetUnionService.save(targetUnion);
+
+            for(KuaiShouVideoGet videoItem: videoGets){
+                JSONObject unitParams = new JSONObject();
+                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");
+
+
+                JSONObject creativeParams = new JSONObject();
+                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 List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain,
+                                                                  List<AiKuaishouStrategyTargetBase> targetBases) {
+        if(null==definitionDomain){
+            return targetBases;
+        }
         if(null == targetBases||targetBases.isEmpty()){
             return null;
         }
@@ -49,8 +165,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);

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

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