|
@@ -39,6 +39,7 @@ import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAppListService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
|
|
@@ -59,6 +60,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
@@ -117,9 +119,45 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
private IKuaiShouAppListService appListService;
|
|
|
@Autowired
|
|
|
private IKuaiShouCampaignService campaignService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouGroupService groupService;
|
|
|
static ExecutorService executorService = Executors.newFixedThreadPool(2);
|
|
|
|
|
|
+ @Override
|
|
|
+ public void customCreativeSupplement(KuaishouProjectStrategy strategy, Integer hour) throws ParseException {
|
|
|
+ Integer customUnitCnt = strategy.getCustomUnitCnt();
|
|
|
+ if (Check.isNull(customUnitCnt)) {
|
|
|
+ Integer imageCnt = strategy.getImageCnt();
|
|
|
+ if (imageCnt <= 1) {
|
|
|
+ customUnitCnt = 600;
|
|
|
+ } else {
|
|
|
+ customUnitCnt = 2000 / imageCnt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int unitNum = customUnitCnt * hour / 20;
|
|
|
+ log.info("{}当前时间内需要创建组总数:{}", strategy.getAccountId(), unitNum);
|
|
|
+ //查询当前账户创建自定义类型组数量
|
|
|
+ int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId());
|
|
|
+ log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
|
|
|
+ int remindCnt = unitNum - unitCreateCnt;
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ log.info("{}组创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ //优先创建历史遗漏素材
|
|
|
+ remindCnt = this.autoCreateCreative(strategy, 3, remindCnt, 2);
|
|
|
+ }
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ log.info("{}组创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ //高质量素材
|
|
|
+ remindCnt = this.autoCreateCreative(strategy, 2, remindCnt, 2);
|
|
|
+ }
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ //历史打捞素材
|
|
|
+ log.info("{}组创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ this.autoCreateCreative(strategy, 4, remindCnt, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 项目自动创建
|
|
|
*
|
|
@@ -157,8 +195,8 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
} else if (strategy.getUnitType() == 7) {
|
|
|
this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
|
|
|
} else {
|
|
|
- this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
|
|
|
this.autoCreateCreative(strategy, createType, customUnitCnt, operationType);
|
|
|
+ this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -173,7 +211,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
* @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材 4:历史打捞
|
|
|
* @param videoCnt 视频数量
|
|
|
*/
|
|
|
- private void autoCreateCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt, Integer operationType) {
|
|
|
+ private Integer autoCreateCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt, Integer operationType) {
|
|
|
try {
|
|
|
String strategyUuid = UUID.randomUUID().toString();
|
|
|
strategy.setStrategyUuid(strategyUuid);
|
|
@@ -183,7 +221,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
if (null == token) {
|
|
|
log.info("token获取失败=>accountId:{}", accountId);
|
|
|
insertAccountOperationRecord(strategy, "获取token失败", operationType, 0);
|
|
|
- return;
|
|
|
+ return videoCnt;
|
|
|
}
|
|
|
//1:获取视频信息
|
|
|
kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
|
|
@@ -202,7 +240,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
if (null == newVideos || newVideos.isEmpty()) {
|
|
|
log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
|
|
|
insertAccountOperationRecord(strategy, "账户在" + startTime + "~" + endTime + "时间段内未获取到相应素材(" + replaceString + ")", operationType, 0);
|
|
|
- return;
|
|
|
+ return videoCnt;
|
|
|
}
|
|
|
Long appId = null;
|
|
|
//appId,当计划类型为2时必填
|
|
@@ -210,12 +248,12 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
Long appTemId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
|
|
|
if (Check.isNull(appTemId)) {
|
|
|
insertAccountOperationRecord(strategy, "未获取到项目应用模板", operationType, 0);
|
|
|
- return;
|
|
|
+ return videoCnt;
|
|
|
}
|
|
|
JSONObject app = appPackageService.queryAppId(appTemId, token.getAccountId());
|
|
|
if (Check.isNull(app) || Check.isNull(app.getLong("app_id"))) {
|
|
|
insertAccountOperationRecord(strategy, "未获取到appId", operationType, 0);
|
|
|
- return;
|
|
|
+ return videoCnt;
|
|
|
}
|
|
|
appId = app.getLong("app_id");
|
|
|
strategy.setClickTrackUrl(app.getString("track_url"));
|
|
@@ -226,7 +264,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
if (null == newCampaignId) {
|
|
|
insertAccountOperationRecord(strategy, "创建广告计划失败", operationType, 0);
|
|
|
- return;
|
|
|
+ return videoCnt;
|
|
|
}
|
|
|
strategy.setCampaignId(newCampaignId);
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
@@ -234,12 +272,12 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
Boolean unitOverrun = getUnitOverrun(accountId.toString());
|
|
|
if (unitOverrun) {
|
|
|
log.error("组创建超限,accountId:{}", accountId);
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
}
|
|
|
//快手账户创意创建超限记录信息,查到数据则说明已经超限
|
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
if (null != overrunInfo) {
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
}
|
|
|
// 每个组,搭配5个创意
|
|
|
List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
@@ -276,9 +314,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
videoCnt--;
|
|
|
JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
|
|
|
- if (videoCnt <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
if (unitCode != 0) {
|
|
|
unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
@@ -288,6 +324,9 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
unitLevelOperationRecord.setMessage(msg);
|
|
|
unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
}
|
|
|
+ if (videoCnt <= 0) {
|
|
|
+ return videoCnt;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -296,6 +335,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
insertAccountOperationRecord(strategy, "创建自定义创意异常", operationType, 0);
|
|
|
}
|
|
|
insertAccountOperationRecord(strategy, "success", operationType, 1);
|
|
|
+ return videoCnt;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -369,7 +409,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
}
|
|
|
strategy.setCampaignId(newCampaignId);
|
|
|
//创意
|
|
|
- List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
+ List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, strategy.getImageCnt());
|
|
|
for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
Boolean unitOverrun = getUnitOverrun(accountId.toString());
|
|
|
if (unitOverrun) {
|
|
@@ -873,13 +913,13 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
unitParams.put("smart_cover", strategy.getSmartCover());
|
|
|
}
|
|
|
//程序化创意2.0素材挖掘
|
|
|
- // if (!Check.isNull(strategy.getAssetMining())) {
|
|
|
- // if (strategy.getAssetMining() == 1) {
|
|
|
- // unitParams.put("asset_mining", true);
|
|
|
- // } else if (strategy.getAssetMining() == 0) {
|
|
|
- // unitParams.put("asset_mining", false);
|
|
|
- // }
|
|
|
- // }
|
|
|
+ if (!Check.isNull(strategy.getAssetMining())) {
|
|
|
+ if (strategy.getAssetMining() == 1) {
|
|
|
+ unitParams.put("asset_mining", true);
|
|
|
+ } else if (strategy.getAssetMining() == 0) {
|
|
|
+ unitParams.put("asset_mining", false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if (!Check.isNull(strategy.getTemplateIdArray())) {
|
|
|
//获取项目定向模板数据
|
|
@@ -1379,6 +1419,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
wildcard = wildcard + "-" + count;
|
|
|
}
|
|
|
wildcard = wildcard.replace("--", "-");
|
|
|
+ wildcard = wildcard.replace("--", "-");
|
|
|
if (wildcard.startsWith("-")) {
|
|
|
wildcard = wildcard.substring(1, wildcard.length());
|
|
|
}
|