|
@@ -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("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",strategy.getUseAppMarket());
|
|
|
- unitParams.put("app_store",strategy.getAppStore());
|
|
|
+ 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());
|