|
@@ -103,8 +103,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
timeEnd = -1*60*24;
|
|
|
}
|
|
|
Long now = System.currentTimeMillis();
|
|
|
- String startTime = DateUtils.formatDate(new Date(now + timeStart * 60 * 1000), DateUtils.NEW_FORMAT);
|
|
|
- String endTime = DateUtils.formatDate(new Date(now + timeEnd * 60 * 1000), DateUtils.NEW_FORMAT);
|
|
|
+ String startTime = DateUtils.formatDate(now+timeStart*60*1000L);
|
|
|
+ String endTime = DateUtils.formatDate(now + timeEnd * 60 * 1000L);
|
|
|
|
|
|
//2:判定账户是否单一应用
|
|
|
Integer singleAppid = strategy.getSingleAppid();
|
|
@@ -133,7 +133,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
//开始创建组+创意
|
|
|
String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
- String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
|
|
|
+ String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
|
|
|
int unitCnt = 0;
|
|
|
for (KuaiShouVideoGet videoItem : allVideos) {
|
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
@@ -166,7 +166,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
} else {
|
|
|
//单一应用
|
|
|
- List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId, startTime, endTime, strategy.getChannelType(), null, null);
|
|
|
+ List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, 100);
|
|
|
if (null == newVideos || newVideos.isEmpty()) {
|
|
|
log.info("账户:{},{} 到 {} 这段时间没有上新素材", accountId, startTime, endTime);
|
|
|
return;
|
|
@@ -178,7 +178,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
|
String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
- String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
|
|
|
+ String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
|
|
|
int unitCnt = 0;
|
|
|
for (KuaiShouVideoGet videoItem : newVideos) {
|
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
@@ -210,6 +210,13 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String getUnitNamePrefix(AiKuaishouAdvertiserStrategy strategy,String replaceString,String timestamp){
|
|
|
+ String unitNamePrefix = strategy.getGroupName();
|
|
|
+ if(!unitNamePrefix.contains("自定义")){
|
|
|
+ unitNamePrefix += "-自定义-";
|
|
|
+ }
|
|
|
+ return unitNamePrefix.replace("自定义", replaceString) + timestamp;
|
|
|
+ }
|
|
|
/**
|
|
|
* 创建程序化创意
|
|
|
*
|
|
@@ -246,8 +253,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
timeEnd = -1*60*24;
|
|
|
}
|
|
|
Long now = System.currentTimeMillis();
|
|
|
- String startTime = DateUtils.formatDate(new Date(now + timeStart * 60 * 1000), DateUtils.NEW_FORMAT);
|
|
|
- String endTime = DateUtils.formatDate(new Date(now + timeEnd * 60 * 1000), DateUtils.NEW_FORMAT);
|
|
|
+ String startTime = DateUtils.formatDate(now+timeStart*60*1000L);
|
|
|
+ String endTime = DateUtils.formatDate(now + timeEnd * 60 * 1000L);
|
|
|
|
|
|
//2:判定账户是否单一应用
|
|
|
Integer singleAppid = strategy.getSingleAppid();
|
|
@@ -282,7 +289,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN");
|
|
|
//创建组
|
|
|
String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
- String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
|
|
|
+ String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
|
|
|
String unitName = unitNamePrefix + "-" + timestamp;
|
|
|
JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
|
|
|
Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
@@ -303,9 +310,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
} else {
|
|
|
//单一应用
|
|
|
- List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId, startTime, endTime, strategy.getChannelType(), null, 150);
|
|
|
- if (null == newVideos || newVideos.isEmpty()) {
|
|
|
- log.info("账户:{},{} 到 {} 这段时间没有上新素材", accountId, startTime, endTime);
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType);
|
|
|
+ if (null == allVideos) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -313,36 +319,29 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (null == newCampaignId) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
|
+ //创建组
|
|
|
String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
- String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
|
|
|
- int unitCnt = 0;
|
|
|
- for (KuaiShouVideoGet videoItem : newVideos) {
|
|
|
- KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
- if (null != overrunInfo) {
|
|
|
- return;
|
|
|
- }
|
|
|
- unitCnt++;
|
|
|
- String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
- Long appId = JSON.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
- // 每个组,搭配n个创意
|
|
|
- List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
- if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
- log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
- 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");
|
|
|
- JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
- createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
|
+ String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
|
|
|
+ String unitName = unitNamePrefix + "-" + timestamp;
|
|
|
+ String appIdString = strategy.getAppIdArray();
|
|
|
+ Long appId = null;
|
|
|
+ if(!Check.isNull(appIdString)&&!Check.isNull(JSON.parseArray(appIdString))){
|
|
|
+ appId = JSON.parseArray(appIdString).getLong(0);
|
|
|
+ }
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
+ 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);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+ //创意
|
|
|
+ List<List<KuaiShouVideoGet>> splitVideos = new ListUtils<KuaiShouVideoGet>().split(allVideos, allVideos.size() / 5);
|
|
|
+ for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
|
|
|
+ createProgramCreative(token, creativeParams);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -378,7 +377,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
JSONArray coverImageTokens = new JSONArray();
|
|
|
for (KuaiShouVideoGet videoGet : list) {
|
|
|
List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoGet.getSignature());
|
|
|
- if (Check.isNull(cutFrameList)) {
|
|
|
+ if (!Check.isNull(cutFrameList)) {
|
|
|
MaterialCutFrame cutFrame = cutFrameList.get(0);
|
|
|
String imageToken = getImageToken(cutFrame.getUrl(), cutFrame.getSignature(), token.getAccountId(), token.getAccessToken());
|
|
|
if (!Check.isNull(imageToken)) {
|
|
@@ -397,6 +396,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (coverImageTokens.size() >= 5) {
|
|
|
coverImageTokens.remove(0);
|
|
|
}
|
|
|
+ programJson.put("cover_image_tokens", coverImageTokens);
|
|
|
+
|
|
|
if (!Check.isNull(strategy.getSiteId())) {
|
|
|
programJson.put("site_id", strategy.getSiteId());
|
|
|
}
|
|
@@ -413,6 +414,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (!Check.isNull(strategy.getActionbarClickUrl())) {
|
|
|
programJson.put("actionbar_click_url", strategy.getActionbarClickUrl());
|
|
|
}
|
|
|
+ JSONArray captions = new JSONArray();
|
|
|
+ captions.add(strategy.getDescription());
|
|
|
+ programJson.put("captions",captions);
|
|
|
if (!Check.isNull(strategy.getCreativeCategory())) {
|
|
|
programJson.put("creative_category", strategy.getCreativeCategory());
|
|
|
programJson.put("creative_tag", JSON.parseArray(strategy.getCreativeTag()));
|
|
@@ -424,7 +428,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
List<KuaiShouVideoGet> generalVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(), startTime, endTime, strategy.getChannelType(), null, null);
|
|
|
//2:查询特定素材
|
|
|
List<KuaiShouVideoGet> customVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(), startTime, endTime, strategy.getChannelType(), appInfo.getAppVersion(), null);
|
|
|
- if ((null == generalVideos || generalVideos.isEmpty()) &&(null == customVideos || customVideos.isEmpty())) {
|
|
|
+ if (Check.isNull(generalVideos) && Check.isNull(customVideos)) {
|
|
|
log.info("账户:{},appId({}){}到{}这段时间没有上新素材", strategy.getAccountId(), appInfo.getAppId(), startTime, endTime);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
@@ -444,7 +448,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
|
|
|
channelType = strategy.getChannelType();
|
|
|
}
|
|
|
- return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appInfo.getAppVersion(), channelType,relativeCnt);
|
|
|
+ String appVersion = null;
|
|
|
+ if(null!=appInfo&&null!=appInfo.getAppVersion()){
|
|
|
+ appVersion = appInfo.getAppVersion();
|
|
|
+ }
|
|
|
+ return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appVersion, channelType,relativeCnt);
|
|
|
}
|
|
|
|
|
|
private List<KuaiShouVideoGet> getHistoryTopVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
|
|
@@ -452,7 +460,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
|
|
|
channelType = strategy.getChannelType();
|
|
|
}
|
|
|
- return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appInfo.getAppVersion(), channelType);
|
|
|
+ String appVersion = null;
|
|
|
+ if(null!=appInfo&&null!=appInfo.getAppVersion()){
|
|
|
+ appVersion = appInfo.getAppVersion();
|
|
|
+ }
|
|
|
+ return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appVersion, channelType);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -497,7 +509,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
// 不存在“上新”计划,则创建一个计划
|
|
|
JSONObject campaignParams = new JSONObject();
|
|
|
campaignParams.put("advertiser_id", token.getAccountId());
|
|
|
- String campaignName = strategy.getCampaignName().replace("自定义", replaceString) + timestamp;
|
|
|
+ String campaignName = strategy.getCampaignName();
|
|
|
+ if(!campaignName.contains("自定义")){
|
|
|
+ campaignName+= "-自定义-";
|
|
|
+ }
|
|
|
+ campaignName =campaignName.replace("自定义", replaceString) + timestamp;
|
|
|
campaignParams.put("campaign_name", campaignName);
|
|
|
campaignParams.put("type", strategy.getCampaignType());
|
|
|
//TODO 目前设定为不限
|
|
@@ -535,6 +551,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
//组单日预算
|
|
|
if(null!=strategy.getUnitDayBudget()&&strategy.getUnitDayBudget()!=0){
|
|
|
unitParams.put("day_budget",strategy.getUnitDayBudget());
|
|
|
+ }else{
|
|
|
+ unitParams.put("day_budget",0);
|
|
|
}
|
|
|
//应用商店列表
|
|
|
if (null != strategy.getAppStore() && !"".equals(strategy.getAppStore())) {
|
|
@@ -572,7 +590,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
//资源位置
|
|
|
Integer sceneId = null;
|
|
|
String scenceIdString = strategy.getSceneId();
|
|
|
- if (!Check.isNull(scenceIdString) && Check.isNull(JSON.parseArray(scenceIdString))) {
|
|
|
+ if (!Check.isNull(scenceIdString) && !Check.isNull(JSON.parseArray(scenceIdString))) {
|
|
|
sceneId = JSON.parseArray(strategy.getSceneId()).getInteger(0);
|
|
|
unitParams.put("scene_id", JSON.parseArray(strategy.getSceneId()));
|
|
|
}
|
|
@@ -580,6 +598,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
//投放开始时间
|
|
|
if (!Check.isNull(strategy.getBeginTime())) {
|
|
|
unitParams.put("begin_time", strategy.getBeginTime());
|
|
|
+ }else {
|
|
|
+ unitParams.put("begin_time",DateUtils.formatDate());
|
|
|
}
|
|
|
//投放结束时间
|
|
|
if (!Check.isNull(strategy.getEndTime())) {
|