Browse Source

Merge branch 'kuaishou-ai-advertising' of http://git.tjyourong.com.cn/ctop/adsp-boot into kuaishou-ai-advertising

 Conflicts:
	jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java
jiequan.bi 4 years ago
parent
commit
9090f94300

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

@@ -27,6 +27,8 @@ public class AiKuaishouStrategyMapCreative {
 	private Long creativeId;
 	/**策略_定向关联id*/
 	private Long strategyTargetUnionId;
+	/**素材签名*/
+	private String video_signature;
 	/**策略id*/
 	private Long strategyId;
 	/**是否创建成功*/

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

@@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.sun.mail.imap.protocol.INTERNALDATE;
 import groovy.util.logging.Slf4j;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ads.entity.*;
 import org.jeecg.modules.ads.service.*;
 import org.openqa.selenium.json.Json;
@@ -72,6 +73,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         Long accountId = strategy.getAccountId();
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
         if(null == token){
+            log.info("token获取失败=>accountId:{}",strategy.getAccountId());
             return;
         }
         //策略类型
@@ -79,68 +81,67 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         //根据策略类型获取策略模板信息
         AiKuaishouStrategyTemplate strategyTemplate = templateService.getOneByParams(scenes, 1);
         if(null == strategyTemplate){
+            log.info("策略模板信息获取失败=>testDirection:{}",scenes);
             return;
         }
         //1:获取相应账户下的最新的5条素材信息 TODO
         List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
         if(null == videoGets){
+            log.info("素材获取失败=>accountId:{}",accountId);
             return;
         }
         //2:根据测试方向获取相应的定向拆分数据类型
         List<AiKuaishouStrategyTargetBase>targetBases = targetBaseService.listByType(strategyTemplate.getTestDirection());
         if(null == targetBases){
+            log.info("定向拆分信息获取失败=>testDirection:{}",strategyTemplate.getTestDirection());
             return;
         }
         //3:获取相应字段相应的用户定义域
         String definitionDomain = null;
 
-        if (strategyTemplate.getTestDirection().equals("age"))
+        if (strategyTemplate.getTestDirection().equals("age")){
             definitionDomain = strategy.getAgesRange();
-        if (strategyTemplate.getTestDirection().equals("gender"))
+        }
+        if (strategyTemplate.getTestDirection().equals("gender")){
             definitionDomain = strategy.getGender().toString();
-        if (strategyTemplate.getTestDirection().equals("region"))
+        }
+        if (strategyTemplate.getTestDirection().equals("region")){
             definitionDomain = strategy.getRegion();
-        if (strategyTemplate.getTestDirection().equals("operation_system"))
+        }
+        if (strategyTemplate.getTestDirection().equals("operation_system")){
             definitionDomain = strategy.getPlatformOs().toString();
+        }
 
         //4:计算定向拆分逻辑
         List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
         if(null == getBases){
-            //TODO
+            log.info("定向拆分失败=>definitionDomain:{}",definitionDomain);
             return;
         }
         //5、策略--策略模板 关联表,写入数据库
-        AiKuaishouStrategyMiddle strategyMiddle =
-                new AiKuaishouStrategyMiddle(strategyTemplate.getId(),strategy.getId());
+        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());
+        String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
+        campaignParams.put("campaign_name",strategy.getStrategyName()+ timestamp);
         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);
+        Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(), token.getAccountId(), campaignParams);
         Integer code = (Integer) campaignCreateResult.get("code");
+        String message = (String) campaignCreateResult.get("message");
         if(code != 0 ){
+            log.info("计划创建失败=>message:{}",message);
             return;
         }
         Long campaignId = (Long) campaignCreateResult.get("campaignId");
-
         // 8、根据定向和素材,两层循环 创建组和创意
-        Integer unitCnt = 1;
+        int unitCnt = 0;
         for (AiKuaishouStrategyTargetBase item:getBases) {
+            unitCnt++;
             // 策略定向拆分数据,写入数据库
             AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion();
             targetUnion.setStrategyMiddleId(strategyMiddle.getId());
@@ -148,29 +149,29 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             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("unit_name", strategy.getStrategyName() + item.getTargetType() +
+                                        item.getTargetContent() + timestamp + unitCnt);
+
+            //TODO
+//            unitParams.put("template_id",strategy.getTemplateId());
             unitParams.put("bid_type",10);
 
             //TODO 前端添加对应设置项
-            unitParams.put("use_app_market","?");
-            unitParams.put("app_store","?");
+            if(null!=strategy.getUseAppMarket()&&!"".equals(strategy.getUseAppMarket())){
+                unitParams.put("use_app_market",Integer.parseInt(strategy.getUseAppMarket()));
+            }else{
+                unitParams.put("use_app_market",0);
+            }
+            if(null!=strategy.getAppStore()&&!"".equals(strategy.getAppStore())){
+                unitParams.put("app_store",JSONArray.parseArray(strategy.getAppStore()));
+            }
 
             // 非 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());
@@ -299,13 +300,13 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
 //                    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",""); //创意标签
+                    creativeParams.put("site_id",strategy.getSiteId()); // 安卓下载中间页ID
+                    creativeParams.put("click_track_url",strategy.getClickTrackUrl());
+                    creativeParams.put("impression_url",strategy.getImpressionUrl());
+//                    creativeParams.put("ad_photo_played_t3s_url","?");
+                    creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
+//                    creativeParams.put("creative_category","");// 创意分类
+//                    creativeParams.put("creative_tag",""); //创意标签
                 }
                 else
                 {
@@ -336,17 +337,8 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
                     }
 
                 }
-                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);