|
@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.service.IMaterialImageInfoService;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
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.KuaiShouVideoGet;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
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.IKuaiShouMaterialUploadService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
@@ -56,6 +57,9 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
private IKuaiShouImageGetService imageGetService;
|
|
private IKuaiShouImageGetService imageGetService;
|
|
@Autowired
|
|
@Autowired
|
|
private IKuaiShouMaterialUploadService materialUploadService;
|
|
private IKuaiShouMaterialUploadService materialUploadService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaiShouVideoGetMapper videoGetMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @param strategy
|
|
* @param strategy
|
|
@@ -69,6 +73,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
log.info("token获取失败=>accountId:{}",strategy.getAccountId());
|
|
log.info("token获取失败=>accountId:{}",strategy.getAccountId());
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
//策略类型
|
|
//策略类型
|
|
String scenes = strategy.getScenes();
|
|
String scenes = strategy.getScenes();
|
|
//根据策略类型获取策略模板信息
|
|
//根据策略类型获取策略模板信息
|
|
@@ -77,12 +82,36 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
log.info("策略模板信息获取失败=>testDirection:{}",scenes);
|
|
log.info("策略模板信息获取失败=>testDirection:{}",scenes);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //1:获取相应账户下的最新的5条素材信息
|
|
|
|
- List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,1);
|
|
|
|
- if(null == videoGets){
|
|
|
|
|
|
+
|
|
|
|
+ // 1: 根据模板信息表里的 material_select_method (素材选择方式),得到"跑量视频"和"上新视频"获取方式
|
|
|
|
+ // {'highQualityMaterial':{'days':7, 'num':5},'newMaterialNum':5}
|
|
|
|
+ // TODO 更新该账户下的 ctop_kuaishou_video_get 数据
|
|
|
|
+
|
|
|
|
+ kuaishouInterfaceService.getVideoList(token,DateUtils.date2Str(),DateUtils.date2Str());
|
|
|
|
+
|
|
|
|
+ JSONObject MaterialSelectMethod = JSONObject.parseObject(strategyTemplate.getMaterialSelectMethod());
|
|
|
|
+ List<KuaiShouVideoGet> newVideos = new ArrayList<KuaiShouVideoGet>();
|
|
|
|
+ List<KuaiShouVideoGet> highQualityVideos = new ArrayList<KuaiShouVideoGet>();
|
|
|
|
+
|
|
|
|
+ if (MaterialSelectMethod.containsKey("newMaterialNum")){
|
|
|
|
+ int newVideoCnt = (int) MaterialSelectMethod.get("newMaterialNum");
|
|
|
|
+ newVideos = videoGetService.getNewVideoDescDate(accountId,newVideoCnt);
|
|
|
|
+ }
|
|
|
|
+ if(MaterialSelectMethod.containsKey("highQualityMaterial")){
|
|
|
|
+ int days = MaterialSelectMethod.getJSONObject("highQualityMaterial").getInteger("days");
|
|
|
|
+ int highQualityVideoCnt = MaterialSelectMethod.getJSONObject("highQualityMaterial").getInteger("num");
|
|
|
|
+ highQualityVideos = videoGetMapper.getHighQualityVideo(accountId,days,highQualityVideoCnt);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 跑量视频 + 上新视频 合并到一个list, 为单素材搭配组做准备 TODO
|
|
|
|
+ List<KuaiShouVideoGet> fullVideos = new ArrayList<KuaiShouVideoGet>();
|
|
|
|
+ fullVideos.addAll(highQualityVideos);
|
|
|
|
+ fullVideos.addAll(newVideos);
|
|
|
|
+ if(null == fullVideos){
|
|
log.info("素材获取失败=>accountId:{}",accountId);
|
|
log.info("素材获取失败=>accountId:{}",accountId);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
String materialFixType = strategyTemplate.getMaterialFixType();
|
|
String materialFixType = strategyTemplate.getMaterialFixType();
|
|
Date campaignDate = new Date();
|
|
Date campaignDate = new Date();
|
|
String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
|
|
String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
|
|
@@ -96,7 +125,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
//7、一个计划,拼装创建计划的入参json
|
|
//7、一个计划,拼装创建计划的入参json
|
|
JSONObject campaignParams = new JSONObject();
|
|
JSONObject campaignParams = new JSONObject();
|
|
campaignParams.put("advertiser_id",token.getAccountId());
|
|
campaignParams.put("advertiser_id",token.getAccountId());
|
|
- String campaignName = "户14-上下滑&信息流" + "-自定义001"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
|
|
|
|
|
|
+ String campaignName = "户14-上下滑&信息流" + "-自定义001-"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
|
|
campaignParams.put("campaign_name",campaignName);
|
|
campaignParams.put("campaign_name",campaignName);
|
|
campaignParams.put("type",Integer.parseInt(strategy.getMarketingGoal()));
|
|
campaignParams.put("type",Integer.parseInt(strategy.getMarketingGoal()));
|
|
campaignParams.put("day_budget",0L);
|
|
campaignParams.put("day_budget",0L);
|
|
@@ -109,12 +138,12 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
}
|
|
}
|
|
Long campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
Long campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
int unitCnt = 1;
|
|
int unitCnt = 1;
|
|
- // 8、根据定向和素材,两层循环 创建组和创意
|
|
|
|
|
|
+ // 8、根据素材和出价,两层循环 创建组和创意
|
|
for (Long item:getCapbids) {
|
|
for (Long item:getCapbids) {
|
|
//判定素材搭配方式
|
|
//判定素材搭配方式
|
|
if(null!=materialFixType&&materialFixType.trim().equals("single")){
|
|
if(null!=materialFixType&&materialFixType.trim().equals("single")){
|
|
// 选择素材,创建创意
|
|
// 选择素材,创建创意
|
|
- for(KuaiShouVideoGet videoItem: videoGets){
|
|
|
|
|
|
+ for(KuaiShouVideoGet videoItem: fullVideos){
|
|
//拼装广告组参数
|
|
//拼装广告组参数
|
|
unitCnt ++;
|
|
unitCnt ++;
|
|
String unitName = campaignName + "-" + unitCnt;
|
|
String unitName = campaignName + "-" + unitCnt;
|
|
@@ -146,41 +175,97 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
createCreativeByImage(cutFrameList,orgFrameList,token,creativeParams,campaignId,unitId,strategy,videoItem,15,null);
|
|
createCreativeByImage(cutFrameList,orgFrameList,token,creativeParams,campaignId,unitId,strategy,videoItem,15,null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
//混搭素材逻辑
|
|
//混搭素材逻辑
|
|
- String unitName = campaignName + "-" + unitCnt;
|
|
|
|
- JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
|
|
|
|
- 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 ){
|
|
|
|
- log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
|
|
- continue;
|
|
|
|
|
|
+ //跑量素材
|
|
|
|
+ if(highQualityVideos.size() > 0){
|
|
|
|
+ // 取模和余数:
|
|
|
|
+ int mod = highQualityVideos.size() / 15;
|
|
|
|
+ int rem = highQualityVideos.size() % 15;
|
|
|
|
+ int innerUnitCnt = 0;
|
|
|
|
+ if(mod!=0){
|
|
|
|
+ for(int i=0;i<mod;i++){
|
|
|
|
+ String unitName = campaignName + "-跑量-" + item + "-" + innerUnitCnt;
|
|
|
|
+ JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
|
|
|
|
+ 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 ){
|
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
|
+ for(int j=0;j<15;j++){
|
|
|
|
+ JSONObject creativeParams = creativeParams(token,unitId,highQualityVideos.get(i*15+j),unitCnt,strategy);
|
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,highQualityVideos.get(i*15+j));
|
|
|
|
+ }
|
|
|
|
+ innerUnitCnt++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if(rem!=0){
|
|
|
|
+ String unitName = campaignName + "-跑量-" + item + "-" + innerUnitCnt;
|
|
|
|
+ JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
|
|
|
|
+ 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 ){
|
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
|
+
|
|
|
|
+ for(int j=0;j<rem;j++){
|
|
|
|
+ JSONObject creativeParams = creativeParams(token,unitId,highQualityVideos.get(mod*15+j),unitCnt,strategy);
|
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,highQualityVideos.get(mod*15+j));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
|
- // 选择素材,创建创意
|
|
|
|
- for(KuaiShouVideoGet videoItem: videoGets){
|
|
|
|
- //拼装广告组参数
|
|
|
|
- JSONObject creativeParams = creativeParams(token,unitId,videoItem,unitCnt,strategy);
|
|
|
|
- JSONArray sceneIdJsonArray = JSONArray.parseArray(strategy.getSceneId());
|
|
|
|
- // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成1个创意
|
|
|
|
- if (sceneIdJsonArray.contains(6) && sceneIdJsonArray.size() == 1){
|
|
|
|
- //直接创建创意
|
|
|
|
- createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,videoItem);
|
|
|
|
- } 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 ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
|
|
|
|
- log.info("未获取到视频封面=>videoSignature:{}",videoItem.getSignature());
|
|
|
|
|
|
+ // 新上素材混搭
|
|
|
|
+ if(newVideos.size() > 0){
|
|
|
|
+ // 取模和余数:
|
|
|
|
+ int mod = newVideos.size() / 15;
|
|
|
|
+ int rem = newVideos.size() % 15;
|
|
|
|
+ int innerUnitCnt = 0;
|
|
|
|
+ if(mod!=0){
|
|
|
|
+ for(int i=0;i<mod;i++){
|
|
|
|
+ String unitName = campaignName + "-上新-" + item + "-" + innerUnitCnt;
|
|
|
|
+ JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
|
|
|
|
+ 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 ){
|
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
|
+ for(int j=0;j<15;j++){
|
|
|
|
+ JSONObject creativeParams = creativeParams(token,unitId,newVideos.get(i*15+j),unitCnt,strategy);
|
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,newVideos.get(i*15+j));
|
|
|
|
+ }
|
|
|
|
+ innerUnitCnt++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if(rem!=0){
|
|
|
|
+ String unitName = campaignName + "-上新-" + item + "-" + innerUnitCnt;
|
|
|
|
+ JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
|
|
|
|
+ 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 ){
|
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- createCreativeByImage(cutFrameList,orgFrameList,token,creativeParams,campaignId,unitId,strategy,videoItem,1,null);
|
|
|
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
|
+
|
|
|
|
+ for(int j=0;j<rem;j++){
|
|
|
|
+ JSONObject creativeParams = creativeParams(token,unitId,newVideos.get(mod*15+j),unitCnt,strategy);
|
|
|
|
+ createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,newVideos.get(mod*15+j));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- unitCnt ++;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else if(scenes.equals(2)){
|
|
}else if(scenes.equals(2)){
|
|
@@ -225,7 +310,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
|
|
AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
|
|
targetUnionService.save(targetUnion);
|
|
targetUnionService.save(targetUnion);
|
|
// 选择素材,创建创意
|
|
// 选择素材,创建创意
|
|
- for(KuaiShouVideoGet videoItem: videoGets){
|
|
|
|
|
|
+ for(KuaiShouVideoGet videoItem: fullVideos){
|
|
//拼装广告组参数
|
|
//拼装广告组参数
|
|
unitCnt++;
|
|
unitCnt++;
|
|
String unitName = campaignName + "-" + unitCnt;
|
|
String unitName = campaignName + "-" + unitCnt;
|
|
@@ -552,7 +637,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
}
|
|
}
|
|
private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
|
|
private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
|
|
KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt,KuaiShouVideoGet videoGet){
|
|
KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt,KuaiShouVideoGet videoGet){
|
|
- creativeParams.put("creative_name","自定义创意_竖版视频_"+creativeCnt+System.currentTimeMillis());
|
|
|
|
|
|
+ creativeParams.put("creative_name","自定义创意_竖版视频_"+creativeCnt);
|
|
Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
|
|
Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
|
|
(token.getAccessToken(), token.getAccountId(), creativeParams,1);
|
|
(token.getAccessToken(), token.getAccountId(), creativeParams,1);
|
|
Integer creativeCode = (Integer) creativeCreateResult.get("code");
|
|
Integer creativeCode = (Integer) creativeCreateResult.get("code");
|
|
@@ -588,7 +673,8 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
|
|
return imageGet.getImageToken();
|
|
return imageGet.getImageToken();
|
|
}
|
|
}
|
|
|
|
|
|
- private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain, List<AiKuaishouStrategyTargetBase> targetBases) {
|
|
|
|
|
|
+ private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain,
|
|
|
|
+ List<AiKuaishouStrategyTargetBase> targetBases) {
|
|
if(null==definitionDomain){
|
|
if(null==definitionDomain){
|
|
return targetBases;
|
|
return targetBases;
|
|
}
|
|
}
|