|
@@ -6,7 +6,6 @@ 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;
|
|
@@ -14,29 +13,26 @@ 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 com.alibaba.fastjson.JSONObject;
|
|
|
-import com.sun.mail.imap.protocol.INTERNALDATE;
|
|
|
-import groovy.util.logging.Slf4j;
|
|
|
+import lombok.extern.slf4j.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;
|
|
|
+import org.jeecg.modules.ngalain.aop.LogRecordAspect;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
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 {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(AiStrategyServiceImpl.class);
|
|
|
@Autowired
|
|
|
private IKuaiShouVideoGetService videoGetService;
|
|
|
@Autowired
|
|
@@ -57,11 +53,9 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
|
private IMaterialCutFrameService materialCutFrameService;
|
|
|
@Autowired
|
|
|
private IMaterialImageInfoService materialImageInfoService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IKuaiShouImageGetService imageGetService;
|
|
|
-
|
|
|
-
|
|
|
+ @Autowired
|
|
|
private IKuaiShouMaterialUploadService materialUploadService;
|
|
|
/**
|
|
|
*
|
|
@@ -84,7 +78,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
|
log.info("策略模板信息获取失败=>testDirection:{}",scenes);
|
|
|
return;
|
|
|
}
|
|
|
- //1:获取相应账户下的最新的5条素材信息 TODO
|
|
|
+ //1:获取相应账户下的最新的5条素材信息
|
|
|
List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
|
|
|
if(null == videoGets){
|
|
|
log.info("素材获取失败=>accountId:{}",accountId);
|
|
@@ -97,21 +91,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
|
return;
|
|
|
}
|
|
|
//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();
|
|
|
- }
|
|
|
-
|
|
|
+ String definitionDomain = getStragyDefDomain(strategyTemplate,strategy);
|
|
|
//4:计算定向拆分逻辑
|
|
|
List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
|
|
|
if(null == getBases){
|
|
@@ -138,186 +118,50 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
|
return;
|
|
|
}
|
|
|
Long campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
- // 8、根据定向和素材,两层循环 创建组和创意
|
|
|
int unitCnt = 0;
|
|
|
+ // 8、根据定向和素材,两层循环 创建组和创意
|
|
|
for (AiKuaishouStrategyTargetBase item:getBases) {
|
|
|
unitCnt++;
|
|
|
// 策略定向拆分数据,写入数据库
|
|
|
- AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion();
|
|
|
- targetUnion.setStrategyMiddleId(strategyMiddle.getId());
|
|
|
- targetUnion.setStrategyTargetId(item.getId());
|
|
|
- targetUnion.setActualTargetContent(item.getTargetContent());
|
|
|
+ AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
|
|
|
targetUnionService.save(targetUnion);
|
|
|
-
|
|
|
- // 拼装创建组的入参 json
|
|
|
- JSONObject unitParams = new JSONObject();
|
|
|
- unitParams.put("advertiser_id",token.getAccountId());
|
|
|
- unitParams.put("campaign_id",campaignId);
|
|
|
- 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 前端添加对应设置项
|
|
|
- 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("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);
|
|
|
+ //拼装广告组参数
|
|
|
+ JSONObject unitParams = createUnitParams(token,campaignId,strategy,strategyTemplate, item,timestamp,unitCnt);
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams,1);
|
|
|
Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ String unitMessage = (String) unitCreateResult.get("message");
|
|
|
if(unitCode != 0 ){
|
|
|
- return;
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
|
+ continue;
|
|
|
}
|
|
|
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());
|
|
|
-
|
|
|
+ //
|
|
|
+ JSONObject creativeParams = creativeParams(token,unitId,videoItem,timestamp,unitCnt,strategy);
|
|
|
JSONArray sceneIdJsonArray = JSONArray.parseArray(strategy.getSceneId());
|
|
|
- JSONObject creativeParams = new JSONObject();
|
|
|
- Integer creativeCnt = 1;
|
|
|
+ // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成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",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
|
|
|
- {
|
|
|
+ //直接创建创意
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,1);
|
|
|
+ } else {
|
|
|
+ // 素材自带的封面 ctop_material_image_info 内部素材的自带封面,素造的没有
|
|
|
+ // 素材的智能抽帧封面 ctop_material_cut_frame 其中素造的为8张封面,内部的为15张封面
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
|
|
|
// 其他情况下,一个素材搭配15张封面,生成15个创意
|
|
|
- if (cutFrameList.size() == 0 && orgFrameList.size()==0){
|
|
|
- return;
|
|
|
+ if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}",videoItem.getSignature());
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (orgFrameList.size() !=0) {
|
|
|
+ int creativeCnt = 1;
|
|
|
+ if (null!=orgFrameList&&!orgFrameList.isEmpty()) {
|
|
|
for (int i = 0; i < orgFrameList.size(); i++) {
|
|
|
String imageCode = orgFrameList.get(i).getCode();
|
|
|
String imageUrl = orgFrameList.get(i).getUrl();
|
|
|
+ String imageToken = getImageToken(imageUrl,imageCode,accountId,token.getAccessToken());
|
|
|
+ creativeParams.put("image_token",imageToken);
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt);
|
|
|
creativeCnt++;
|
|
|
if (creativeCnt > 15) {
|
|
|
break;
|
|
@@ -325,56 +169,175 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ((cutFrameList.size() !=0) && (creativeCnt<=15)){
|
|
|
+ if ((null!=cutFrameList&&!cutFrameList.isEmpty()) && (creativeCnt<=15)){
|
|
|
for (int i = 0; i < cutFrameList.size(); i++) {
|
|
|
String imageCode = cutFrameList.get(i).getSignature();
|
|
|
String imageUrl = cutFrameList.get(i).getUrl();
|
|
|
+ String imageToken = getImageToken(imageUrl,imageCode,accountId,token.getAccessToken());
|
|
|
+ creativeParams.put("image_token",imageToken);
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt);
|
|
|
creativeCnt ++;
|
|
|
if (creativeCnt > 15) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 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 JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,String timestamp,int unitCnt,KuaishouStrategy strategy){
|
|
|
+ JSONObject creativeParams = new JSONObject();
|
|
|
+ creativeParams.put("advertiser_id",token.getAccountId());
|
|
|
+
|
|
|
+ creativeParams.put("unit_id",unitId);
|
|
|
+ creativeParams.put("photo_id",videoItem.getPhotoId());
|
|
|
+ creativeParams.put("creative_name","智能创意-"+timestamp+unitCnt+"-"+1);
|
|
|
+ creativeParams.put("creative_material_type",videoItem.getMaterialType());
|
|
|
+ creativeParams.put("action_bar_text","立即下载");
|
|
|
+ //TODO 广告语
|
|
|
+ creativeParams.put("description","测试广告语");
|
|
|
+ // 安卓下载中间页ID
|
|
|
+ if(null == strategy.getSiteId()||!"".equals(strategy.getSiteId())){
|
|
|
+ creativeParams.put("site_id",strategy.getSiteId());
|
|
|
+ }
|
|
|
+ if(null == strategy.getClickTrackUrl()||!"".equals(strategy.getClickTrackUrl())){
|
|
|
+ creativeParams.put("click_track_url",strategy.getClickTrackUrl());
|
|
|
+ }
|
|
|
+ if(null == strategy.getImpressionUrl()||!"".equals(strategy.getImpressionUrl())){
|
|
|
+ creativeParams.put("impression_url",strategy.getImpressionUrl());
|
|
|
+ }
|
|
|
+ if(null == strategy.getActionbarClickUrl()||!"".equals(strategy.getActionbarClickUrl())){
|
|
|
+ creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
|
|
|
+ }
|
|
|
+ return creativeParams;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ private String getStragyDefDomain(AiKuaishouStrategyTemplate strategyTemplate,KuaishouStrategy strategy){
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ return definitionDomain;
|
|
|
+ }
|
|
|
|
|
|
+ private JSONObject createUnitParams(CtopOauthToken token,Long campaignId,KuaishouStrategy strategy,AiKuaishouStrategyTemplate strategyTemplate,
|
|
|
+ AiKuaishouStrategyTargetBase item,String timestamp,int unitCnt){
|
|
|
+ // 拼装创建组的入参 json
|
|
|
+ JSONObject unitParams = new JSONObject();
|
|
|
+ unitParams.put("advertiser_id",token.getAccountId());
|
|
|
+ unitParams.put("campaign_id",campaignId);
|
|
|
+ unitParams.put("unit_name", strategy.getStrategyName() + item.getTargetType() +
|
|
|
+ item.getTargetContent() + timestamp + unitCnt);
|
|
|
+ unitParams.put("bid_type",10);
|
|
|
+
|
|
|
+ if(null!=strategy.getUseAppMarket()&&!"".equals(strategy.getUseAppMarket())){
|
|
|
+ unitParams.put("use_app_market",Integer.parseInt(strategy.getUseAppMarket()));
|
|
|
+ }
|
|
|
+ if(null!=strategy.getAppStore()&&!"".equals(strategy.getAppStore())){
|
|
|
+ unitParams.put("app_store",JSONArray.parseArray(strategy.getAppStore()));
|
|
|
+ }
|
|
|
|
|
|
+ // 在本策略中,都是 OCPM 的出价方式
|
|
|
+ unitParams.put("cpa_bid",strategy.getCpaBid());
|
|
|
+ unitParams.put("ocpx_action_type",strategy.getOcpxActionType());
|
|
|
+ unitParams.put("deep_conversion_type",strategy.getDeepConversionType());
|
|
|
+ unitParams.put("deep_conversion_bid",strategy.getDeepConversionBid());
|
|
|
+ unitParams.put("scene_id",JSONArray.parseArray(strategy.getSceneId()));
|
|
|
+ unitParams.put("unit_type",4);
|
|
|
+
|
|
|
+ // 格式为yyyy-MM-dd,需大于等于当前时间
|
|
|
+ unitParams.put("begin_time",DateUtils.formatDate(new Date()));
|
|
|
+ if(null!=strategy.getConvertId()){
|
|
|
+ unitParams.put("convert_id",strategy.getConvertId());
|
|
|
+ }
|
|
|
+ // 当计划类型是3/4/5时必填
|
|
|
+ if(null!=strategy.getUrl()&&!"".equals(strategy.getUrl())){
|
|
|
+ unitParams.put("url",strategy.getUrl());
|
|
|
+ }
|
|
|
+ JSONArray appIds = JSONArray.parseArray(strategy.getAppIds());
|
|
|
+ //TODO 先只做单appId的逻辑
|
|
|
+ if(null!=appIds&&!appIds.isEmpty()){
|
|
|
+ unitParams.put("app_id",appIds.getLong(0));
|
|
|
+ }
|
|
|
+ unitParams.put("show_mode",2);
|
|
|
+ unitParams.put("speed",1);
|
|
|
+ // 设置定向内容
|
|
|
+ JSONObject targetJsonObject = new JSONObject();
|
|
|
+ if (strategyTemplate.getTestDirection().equals("region")){
|
|
|
+ targetJsonObject.put("region",JSONArray.parseArray(item.getTargetContent()));
|
|
|
+ } else {
|
|
|
+ targetJsonObject.put("region",JSONArray.parseArray(strategy.getRegion()));
|
|
|
+ }
|
|
|
|
|
|
+ if (strategyTemplate.getTestDirection().equals("age")){
|
|
|
+ targetJsonObject.put("ages_range",JSONArray.parseArray(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());
|
|
|
+ }
|
|
|
+ JSONArray population = JSONArray.parseArray(strategy.getPopulation());
|
|
|
+ if(null!=population&&!population.isEmpty()){
|
|
|
+ targetJsonObject.put("population",population);
|
|
|
+ }
|
|
|
+ JSONArray excludePopulation = JSONArray.parseArray(strategy.getExcludePopulation());
|
|
|
+ if(null!=excludePopulation&&!excludePopulation.isEmpty()){
|
|
|
+ targetJsonObject.put("paid_audience",excludePopulation);
|
|
|
+ }
|
|
|
|
|
|
+ unitParams.put("target",targetJsonObject);
|
|
|
+ return unitParams;
|
|
|
+ }
|
|
|
+ private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
|
|
|
+ KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt){
|
|
|
+ creativeParams.put("creative_name",creativeParams.getString("creative_name")+creativeCnt);
|
|
|
+ Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
|
|
|
+ (token.getAccessToken(), token.getAccountId(), creativeParams,1);
|
|
|
+ Integer creativeCode = (Integer) creativeCreateResult.get("code");
|
|
|
+ String creativeMessage = (String) creativeCreateResult.get("message");
|
|
|
+ if(creativeCode != 0 ){
|
|
|
+ log.info("创意创建失败=>message:{}",creativeMessage);
|
|
|
+ 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 String getImageToken(String imageUrl, String imageCode, Long accountId,String token){
|
|
|
// 根据imageUrl 和 imageCode,获取 imageToken (创建创意用)
|
|
|
- KuaiShouImageGet imageGet = imageGetService.getOneByParams(imageUrl);
|
|
|
+ KuaiShouImageGet imageGet = imageGetService.getOneByParams(null,imageCode);
|
|
|
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 materialUploadService.kuauiShouImageUpload(imageUrl,imageCode,accountId,token);
|
|
|
}
|
|
|
|
|
|
return imageGet.getImageToken();
|