|
@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.entity.MaterialCutFrame;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import cn.com.ctop.common.module.utils.ListUtils;
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaiShouAppInfo;
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaiShouAppInfo;
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouStrategyMapCreative;
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouStrategyMapCreative;
|
|
@@ -59,6 +60,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
@Override
|
|
@Override
|
|
public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy){
|
|
public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy){
|
|
strategy.setUnitType(4);
|
|
strategy.setUnitType(4);
|
|
|
|
+ String replaceString = "素材上新";
|
|
Long accountId = strategy.getAccountId();
|
|
Long accountId = strategy.getAccountId();
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
if(null == token){
|
|
if(null == token){
|
|
@@ -90,7 +92,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
}
|
|
}
|
|
- String replaceString = appInfo.getAppVersion()+"自动上新";
|
|
|
|
|
|
+ replaceString = appInfo.getAppVersion()+replaceString;
|
|
//1:查询通用素材
|
|
//1:查询通用素材
|
|
List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
|
|
List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
|
|
if(null == allVideos||allVideos.isEmpty()){
|
|
if(null == allVideos||allVideos.isEmpty()){
|
|
@@ -133,20 +135,19 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
//单一应用
|
|
//单一应用
|
|
- List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null);
|
|
|
|
|
|
+ List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null,null);
|
|
if (null == newVideos ||newVideos.isEmpty()){
|
|
if (null == newVideos ||newVideos.isEmpty()){
|
|
log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
|
|
log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- Long newCampaignId = getCampaignId(strategy,token,"素材上新","TODAY");
|
|
|
|
|
|
+ Long newCampaignId = getCampaignId(strategy,token,replaceString,"TODAY");
|
|
if(null== newCampaignId){
|
|
if(null== newCampaignId){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
- String unitNamePrefix = strategy.getGroupName().replace("自定义","素材上新")+ timestamp;
|
|
|
|
|
|
+ String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
|
|
int unitCnt = 0;
|
|
int unitCnt = 0;
|
|
for(KuaiShouVideoGet videoItem: newVideos) {
|
|
for(KuaiShouVideoGet videoItem: newVideos) {
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
@@ -185,6 +186,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
@Override
|
|
@Override
|
|
public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy){
|
|
public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy){
|
|
strategy.setUnitType(7);
|
|
strategy.setUnitType(7);
|
|
|
|
+ String replaceString = "程序化自动上新";
|
|
Long accountId = strategy.getAccountId();
|
|
Long accountId = strategy.getAccountId();
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
if(null == token){
|
|
if(null == token){
|
|
@@ -212,62 +214,61 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
log.info("账户:{},appid({}) 数据不存在",accountId, appIdArray.getLong(i));
|
|
log.info("账户:{},appid({}) 数据不存在",accountId, appIdArray.getLong(i));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- String replaceString = appInfo.getAppVersion()+"程序化";
|
|
|
|
|
|
+ //判定是否通用监测链接
|
|
|
|
+ if(null!=strategy.getGeneralTrack()&&strategy.getGeneralTrack() == 0){
|
|
|
|
+ strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
|
+ strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
|
|
+ }
|
|
|
|
+ replaceString = appInfo.getAppVersion()+replaceString;
|
|
//1:查询可用素材
|
|
//1:查询可用素材
|
|
List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
|
|
List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
|
|
if(null == allVideos){
|
|
if(null == allVideos){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
Long newCampaignId = getCampaignId(strategy,token,replaceString,"ALL_CAMPAIGN");
|
|
Long newCampaignId = getCampaignId(strategy,token,replaceString,"ALL_CAMPAIGN");
|
|
- //开始创建组+创意
|
|
|
|
|
|
+ //创建组
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
|
|
String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
|
|
- int unitCnt = 0;
|
|
|
|
- for(KuaiShouVideoGet videoItem: allVideos) {
|
|
|
|
|
|
+ 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);
|
|
|
|
+ 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");
|
|
|
|
+ //创意
|
|
|
|
+ List<List<KuaiShouVideoGet>> splitVideos = new ListUtils<KuaiShouVideoGet>().split(allVideos,allVideos.size()/5);
|
|
|
|
+ for(int j=1;j<splitVideos.size()+1;j++) {
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
if (null != overrunInfo) {
|
|
if (null != overrunInfo) {
|
|
log.info("该账户创意创建已超限=>accountId:{}",accountId);
|
|
log.info("该账户创意创建已超限=>accountId:{}",accountId);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- unitCnt++;
|
|
|
|
- String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
|
- JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appInfo.getAppId());
|
|
|
|
- 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");
|
|
|
|
|
|
|
|
- // 每个组,搭配n个创意
|
|
|
|
- List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
|
- if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
|
- log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j-1), strategy,j);
|
|
createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
//单一应用
|
|
//单一应用
|
|
- List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null);
|
|
|
|
|
|
+ List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null,150);
|
|
if (null == newVideos ||newVideos.isEmpty()){
|
|
if (null == newVideos ||newVideos.isEmpty()){
|
|
log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
|
|
log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- Long newCampaignId = getCampaignId(strategy,token,"素材上新","TODAY");
|
|
|
|
|
|
+ Long newCampaignId = getCampaignId(strategy,token,replaceString,"TODAY");
|
|
if(null== newCampaignId){
|
|
if(null== newCampaignId){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
- String unitNamePrefix = strategy.getGroupName().replace("自定义","素材上新")+ timestamp;
|
|
|
|
|
|
+ String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
|
|
int unitCnt = 0;
|
|
int unitCnt = 0;
|
|
for(KuaiShouVideoGet videoItem: newVideos) {
|
|
for(KuaiShouVideoGet videoItem: newVideos) {
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
@@ -299,10 +300,72 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy,Integer creativeCnt) {
|
|
|
|
+ JSONObject programJson = new JSONObject();
|
|
|
|
+ programJson.put("advertiser_id", token.getAccountId());
|
|
|
|
+ programJson.put("unit_id", unitId);
|
|
|
|
+ programJson.put("package_name", "程序化创意"+creativeCnt);
|
|
|
|
+ JSONArray horizontalPhotoIds = new JSONArray();
|
|
|
|
+ JSONArray verticalPhotoIds = new JSONArray();
|
|
|
|
+ JSONArray coverImageTokens = new JSONArray();
|
|
|
|
+ for(KuaiShouVideoGet videoGet:list){
|
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoGet.getSignature());
|
|
|
|
+ if (null!=cutFrameList&&!cutFrameList.isEmpty()){
|
|
|
|
+ MaterialCutFrame cutFrame = cutFrameList.get(0);
|
|
|
|
+ String imageToken = getImageToken(cutFrame.getUrl(),cutFrame.getSignature(), token.getAccountId(), token.getAccessToken());
|
|
|
|
+ if (!Check.isNull(imageToken)) {
|
|
|
|
+ coverImageTokens.add(imageToken);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(videoGet.getMaterialType() == 2){
|
|
|
|
+ horizontalPhotoIds.add(videoGet.getPhotoId());
|
|
|
|
+ }
|
|
|
|
+ if(videoGet.getMaterialType() == 1){
|
|
|
|
+ verticalPhotoIds.add(videoGet.getPhotoId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(!horizontalPhotoIds.isEmpty()){
|
|
|
|
+ programJson.put("horizontal_photo_ids", horizontalPhotoIds);
|
|
|
|
+ }
|
|
|
|
+ if(!verticalPhotoIds.isEmpty()){
|
|
|
|
+ programJson.put("vertical_photo_ids", verticalPhotoIds);
|
|
|
|
+ }
|
|
|
|
+ if(coverImageTokens.size()>=5){
|
|
|
|
+ coverImageTokens.remove(0);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(strategy.getSiteId())) {
|
|
|
|
+ programJson.put("site_id", strategy.getSiteId());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(strategy.getStickerTitle())) {
|
|
|
|
+ programJson.put("sticker_styles", strategy.getStickerTitle());
|
|
|
|
+ }
|
|
|
|
+// if (!Check.isNull(programCreativeJson.getJSONArray("cover_slogans"))) {
|
|
|
|
+// programJson.put("cover_slogans", programCreativeJson.getJSONArray("cover_slogans"));
|
|
|
|
+// }
|
|
|
|
+ if (!Check.isNull(strategy.getActionBarText())) {
|
|
|
|
+ programJson.put("action_bar", strategy.getActionBarText());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(programCreativeJson.getJSONArray("captions"))) {
|
|
|
|
+ programJson.put("captions", programCreativeJson.getJSONArray("captions"));
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(programCreativeJson.getString("click_url"))) {
|
|
|
|
+ programJson.put("click_url", programCreativeJson.getString("click_url"));
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(programCreativeJson.getString("actionbar_click_url"))) {
|
|
|
|
+ programJson.put("actionbar_click_url", programCreativeJson.getString("actionbar_click_url"));
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(programCreativeJson.getInteger("creative_category"))) {
|
|
|
|
+ programJson.put("creative_category", programCreativeJson.getInteger("creative_category"));
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(programCreativeJson.getJSONArray("creative_tag"))) {
|
|
|
|
+ programJson.put("creative_tag", programCreativeJson.getJSONArray("creative_tag"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy,String startTime,String endTime,AiKuaiShouAppInfo appInfo) {
|
|
private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy,String startTime,String endTime,AiKuaiShouAppInfo appInfo) {
|
|
- List<KuaiShouVideoGet> generalVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),null);
|
|
|
|
|
|
+ List<KuaiShouVideoGet> generalVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),null,null);
|
|
//2:查询特定素材
|
|
//2:查询特定素材
|
|
- List<KuaiShouVideoGet> customVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),appInfo.getAppVersion());
|
|
|
|
|
|
+ List<KuaiShouVideoGet> customVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),appInfo.getAppVersion(),null);
|
|
if(null == generalVideos||generalVideos.isEmpty()||null == customVideos||customVideos.isEmpty()){
|
|
if(null == generalVideos||generalVideos.isEmpty()||null == customVideos||customVideos.isEmpty()){
|
|
log.info("账户:{},appId({}){}到{}这段时间没有上新素材",strategy.getAccountId(),appInfo.getAppId(),startTime, endTime);
|
|
log.info("账户:{},appId({}){}到{}这段时间没有上新素材",strategy.getAccountId(),appInfo.getAppId(),startTime, endTime);
|
|
return null;
|
|
return null;
|