|
@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaiShouAppInfo;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountLevelOperationRecord;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCampaignLevelOperationRecord;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCreativeLevelOperationRecord;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouProgramCreativeLevelOperationRecord;
|
|
@@ -22,6 +23,7 @@ import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeAdsenceTypeEnum;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeMatTypeEnum;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouVideoDirectionalPackageMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouAppInfoService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountLevelOperationRecordService;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCampaignLevelOperationRecordService;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreativeLevelOperationRecordService;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouProgramCreativeLevelOperationRecordService;
|
|
@@ -29,8 +31,8 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouProjectCreateCreativeS
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouUnitLevelOperationRecordService;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAppPackageService;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
|
|
|
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
@@ -94,6 +96,8 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
@Autowired
|
|
|
private IAiKuaishouCampaignLevelOperationRecordService aiKuaishouCampaignLevelOperationRecordService;
|
|
|
@Autowired
|
|
|
+ private IAiKuaishouAccountLevelOperationRecordService kuaishouAccountLevelOperationRecordService;
|
|
|
+ @Autowired
|
|
|
private IAiKuaiShouAppInfoService appInfoService;
|
|
|
@Autowired
|
|
|
private IAiKuaishouUnitLevelOperationRecordService unitLevelOperationRecordService;
|
|
@@ -106,6 +110,8 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
@Autowired
|
|
|
private KuaishouVideoDirectionalPackageMapper packageMapper;
|
|
|
@Autowired
|
|
|
+ private IKuaishouAppPackageService appPackageService;
|
|
|
+ @Autowired
|
|
|
private IKuaishouDirectionalPackageService directionalPackageService;
|
|
|
@Autowired
|
|
|
private IKuaiShouCreativeService kuaiShouCreativeService;
|
|
@@ -118,7 +124,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
* @return void
|
|
|
*/
|
|
|
@Override
|
|
|
- public void projectAutomaticCreates(KuaishouProjectStrategy strategy) {
|
|
|
+ public void projectAutomaticCreates(KuaishouProjectStrategy strategy, Integer operationType) {
|
|
|
try {
|
|
|
//自定义组数,最多540
|
|
|
Integer customUnitCnt = strategy.getCustomUnitCnt();
|
|
@@ -145,12 +151,12 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
//创意制作方式,0-不限,4-自定义,7-程序化创意
|
|
|
for (Integer createType : sourceMaterial) {
|
|
|
if (strategy.getUnitType() == 4) {
|
|
|
- this.autoCreateCreative(strategy, createType, customUnitCnt);
|
|
|
+ this.autoCreateCreative(strategy, createType, customUnitCnt, operationType);
|
|
|
} else if (strategy.getUnitType() == 7) {
|
|
|
- this.autoCreateProgramCreative(strategy, createType, programUnitCnt);
|
|
|
+ this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
|
|
|
} else {
|
|
|
- this.autoCreateProgramCreative(strategy, createType, programUnitCnt);
|
|
|
- this.autoCreateCreative(strategy, createType, customUnitCnt);
|
|
|
+ this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
|
|
|
+ this.autoCreateCreative(strategy, createType, customUnitCnt, operationType);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -165,14 +171,16 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
* @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材 4:历史打捞
|
|
|
* @param videoCnt 视频数量
|
|
|
*/
|
|
|
- private Integer autoCreateCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt) {
|
|
|
+ private void autoCreateCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt, Integer operationType) {
|
|
|
try {
|
|
|
String strategyUuid = UUID.randomUUID().toString();
|
|
|
+ strategy.setStrategyUuid(strategyUuid);
|
|
|
Long accountId = strategy.getAccountId();
|
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
if (null == token) {
|
|
|
log.info("token获取失败=>accountId:{}", accountId);
|
|
|
- return videoCnt;
|
|
|
+ insertAccountOperationRecord(strategy, "获取token失败", operationType, 0);
|
|
|
+ return;
|
|
|
}
|
|
|
//1:获取视频信息
|
|
|
kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
|
|
@@ -190,31 +198,40 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, Long.valueOf(videoCnt));
|
|
|
if (null == newVideos || newVideos.isEmpty()) {
|
|
|
log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
|
|
|
- return videoCnt;
|
|
|
+ insertAccountOperationRecord(strategy, "账户在" + startTime + "~" + endTime + "时间段内未获取到相应素材(" + replaceString + ")", operationType, 0);
|
|
|
+ return;
|
|
|
}
|
|
|
Long appId = null;
|
|
|
//appId,当计划类型为2时必填
|
|
|
if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
- appId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
|
|
|
- if (Check.isNull(appId)) {
|
|
|
- return videoCnt;
|
|
|
+ Long appTemId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
|
|
|
+ if (Check.isNull(appTemId)) {
|
|
|
+ insertAccountOperationRecord(strategy, "未获取到项目应用模板", operationType, 0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ appId = appPackageService.queryAppId(appTemId, token.getAccountId());
|
|
|
+ if (Check.isNull(appTemId)) {
|
|
|
+ insertAccountOperationRecord(strategy, "未获取到appId", operationType, 0);
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
if (null == newCampaignId) {
|
|
|
- return videoCnt;
|
|
|
+ insertAccountOperationRecord(strategy, "创建广告计划失败", operationType, 0);
|
|
|
+ return;
|
|
|
}
|
|
|
+ strategy.setCampaignId(newCampaignId);
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
|
for (KuaiShouVideoGet videoItem : newVideos) {
|
|
|
Boolean unitOverrun = getUnitOverrun(accountId.toString());
|
|
|
if (unitOverrun) {
|
|
|
log.error("组创建超限,accountId:{}", accountId);
|
|
|
- return 0;
|
|
|
+ return;
|
|
|
}
|
|
|
//快手账户创意创建超限记录信息,查到数据则说明已经超限
|
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
if (null != overrunInfo) {
|
|
|
- return 0;
|
|
|
+ return;
|
|
|
}
|
|
|
// 每个组,搭配5个创意
|
|
|
List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
@@ -223,44 +240,54 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
continue;
|
|
|
}
|
|
|
String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, videoItem.getMaterialType());
|
|
|
- JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, videoItem);
|
|
|
- log.info("创建广告组入参:{}", unitParams);
|
|
|
- Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
- Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
- String unitMessage = (String) unitCreateResult.get("message");
|
|
|
- AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
|
|
|
- BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
|
|
|
- unitLevelOperationRecord.setGroupName(unitName);
|
|
|
- unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
- unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
|
|
|
- unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
|
|
|
- unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
- unitLevelOperationRecord.setCreateTime(new Date());
|
|
|
- unitLevelOperationRecord.setStatus(unitCode);
|
|
|
- unitLevelOperationRecord.setMessage(unitMessage);
|
|
|
- unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
- unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
- unitLevelOperationRecord.setCreateType(2);//项目创建
|
|
|
- if (unitCode != 0) {
|
|
|
- log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
- unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- continue;
|
|
|
- }
|
|
|
- Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
- unitLevelOperationRecord.setUnitId(unitId);
|
|
|
- unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- videoCnt--;
|
|
|
- JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
- createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
|
|
|
- if (videoCnt <= 0) {
|
|
|
- return 0;
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, videoItem, operationType);
|
|
|
+ if (!Check.isNull(unitParams) && operationType == 2) {
|
|
|
+ AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
|
|
|
+ BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
|
|
|
+ unitLevelOperationRecord.setGroupName(unitName);
|
|
|
+ unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
|
|
|
+ unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
|
|
|
+ unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
+ unitLevelOperationRecord.setCreateTime(new Date());
|
|
|
+ unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
+ unitLevelOperationRecord.setCreateType(2);//项目创建
|
|
|
+ Integer unitCode = -1;
|
|
|
+ String msg = unitParams.getString("errorMsg");
|
|
|
+ if (Check.isNull(msg)) {
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
+ unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ msg = (String) unitCreateResult.get("message");
|
|
|
+ unitLevelOperationRecord.setStatus(unitCode);
|
|
|
+ unitLevelOperationRecord.setMessage(msg);
|
|
|
+ if (unitCode == 0) {
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+ unitLevelOperationRecord.setUnitId(unitId);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ unitLevelOperationRecord.setStatus(unitCode);
|
|
|
+ unitLevelOperationRecord.setMessage(msg);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} catch (BeansException e) {
|
|
|
log.error("创建自定义创意异常", e);
|
|
|
+ insertAccountOperationRecord(strategy, "创建自定义创意异常", operationType, 0);
|
|
|
}
|
|
|
- return videoCnt;
|
|
|
+ insertAccountOperationRecord(strategy, "success", operationType, 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -268,172 +295,133 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
*
|
|
|
* @param strategy
|
|
|
*/
|
|
|
- public void autoCreateProgramCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt) {
|
|
|
- String strategyUuid = UUID.randomUUID().toString();
|
|
|
- strategy.setStrategyUuid(strategyUuid);
|
|
|
- strategy.setUnitType(7);
|
|
|
- Long accountId = strategy.getAccountId();
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
- if (null == token) {
|
|
|
- log.info("token获取失败=>accountId:{}", accountId);
|
|
|
- return;
|
|
|
- }
|
|
|
- //1:获取视频信息
|
|
|
- kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
|
|
|
- //2:判定账户是否单一应用
|
|
|
- Long timeStart = null;
|
|
|
- Long timeEnd = null;
|
|
|
- Integer singleAppid = strategy.getSingleAppid();
|
|
|
- if (null != singleAppid && singleAppid == 0) {
|
|
|
- timeStart = -7 * 60 * 24L;
|
|
|
- timeEnd = -5L;
|
|
|
- } else {
|
|
|
- timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- }
|
|
|
- Long now = System.currentTimeMillis();
|
|
|
- String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
|
|
|
- String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
|
|
|
- String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
- String key = token.getAccountId() + "_ProgramCreative" + "_" + nowDate;
|
|
|
-
|
|
|
- //单/多应用,1单应用,2多应用
|
|
|
- if (null != singleAppid && singleAppid == 1) {
|
|
|
- String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- //单一应用
|
|
|
- List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, Long.valueOf(videoCnt));
|
|
|
- if (null == allVideos) {
|
|
|
+ public void autoCreateProgramCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt, Integer operationType) {
|
|
|
+ try {
|
|
|
+ String strategyUuid = UUID.randomUUID().toString();
|
|
|
+ strategy.setStrategyUuid(strategyUuid);
|
|
|
+ strategy.setUnitType(7);
|
|
|
+ Long accountId = strategy.getAccountId();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
+ if (null == token) {
|
|
|
+ log.info("token获取失败=>accountId:{}", accountId);
|
|
|
+ insertAccountOperationRecord(strategy, "token获取失败", operationType, 0);
|
|
|
return;
|
|
|
}
|
|
|
- Long appId = null;
|
|
|
- //appId,当计划类型为2时必填
|
|
|
- if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
- appId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
|
|
|
- if (Check.isNull(appId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
- if (null == newCampaignId) {
|
|
|
- return;
|
|
|
+ //1:获取视频信息
|
|
|
+ kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
|
|
|
+ //2:判定账户是否单一应用
|
|
|
+ Long timeStart = null;
|
|
|
+ Long timeEnd = null;
|
|
|
+ Integer singleAppid = strategy.getSingleAppid();
|
|
|
+ if (null != singleAppid && singleAppid == 0) {
|
|
|
+ timeStart = -7 * 60 * 24L;
|
|
|
+ timeEnd = -5L;
|
|
|
+ } else {
|
|
|
+ timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
}
|
|
|
- strategy.setCampaignId(newCampaignId);
|
|
|
- //创意
|
|
|
- List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
- for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
- Boolean unitOverrun = getUnitOverrun(accountId.toString());
|
|
|
- if (unitOverrun) {
|
|
|
- log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
|
|
|
+ String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String key = token.getAccountId() + "_ProgramCreative" + "_" + nowDate;
|
|
|
+
|
|
|
+ //单/多应用,1单应用,2多应用
|
|
|
+ if (null != singleAppid && singleAppid == 1) {
|
|
|
+ String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ //单一应用
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, Long.valueOf(videoCnt));
|
|
|
+ if (null == allVideos) {
|
|
|
+ insertAccountOperationRecord(strategy, "账户在" + startTime + "~" + endTime + "时间段内未获取到相应素材(" + replaceString + ")", operationType, 0);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- Object redisObj = redisUtil.get(key);
|
|
|
- if (!Check.isNull(redisObj)) {
|
|
|
- Integer value = (Integer) redisObj;
|
|
|
- if (value == 1) {
|
|
|
- log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
|
|
|
+ Long appId = null;
|
|
|
+ //appId,当计划类型为2时必填
|
|
|
+ if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
+ Long appTemId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
|
|
|
+ if (Check.isNull(appTemId)) {
|
|
|
+ insertAccountOperationRecord(strategy, "未获取到项t目应用模板", operationType, 0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ appId = appPackageService.queryAppId(appTemId, token.getAccountId());
|
|
|
+ if (Check.isNull(appTemId)) {
|
|
|
+ insertAccountOperationRecord(strategy, "未获取到appId", operationType, 0);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- //创建组
|
|
|
- String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, null);
|
|
|
- JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, null);
|
|
|
- if (!Check.isNull(unitParams)) {
|
|
|
- AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
|
|
|
- BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
|
|
|
- unitLevelOperationRecord.setGroupName(unitName);
|
|
|
- unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
- unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
|
|
|
- unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
|
|
|
- unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
- unitLevelOperationRecord.setCreateTime(new Date());
|
|
|
- unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
- unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
- unitLevelOperationRecord.setCreateType(2);//项目创建
|
|
|
- Integer unitCode = -1;
|
|
|
- String errorMsg = unitParams.getString("errorMsg");
|
|
|
- if (Check.isNull(errorMsg)) {
|
|
|
- log.info("创建广告组入参:{}", unitParams);
|
|
|
- Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
- unitCode = (Integer) unitCreateResult.get("code");
|
|
|
- errorMsg = (String) unitCreateResult.get("message");
|
|
|
- unitLevelOperationRecord.setStatus(unitCode);
|
|
|
- unitLevelOperationRecord.setMessage(errorMsg);
|
|
|
- if (unitCode == 0) {
|
|
|
- Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
- unitLevelOperationRecord.setUnitId(unitId);
|
|
|
- unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
|
|
|
- createProgramCreative(token, creativeParams, strategy);
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
+ if (null == newCampaignId) {
|
|
|
+ insertAccountOperationRecord(strategy, "创建广告计划失败", operationType, 0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ strategy.setCampaignId(newCampaignId);
|
|
|
+ //创意
|
|
|
+ List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
+ for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId.toString());
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Object redisObj = redisUtil.get(key);
|
|
|
+ if (!Check.isNull(redisObj)) {
|
|
|
+ Integer value = (Integer) redisObj;
|
|
|
+ if (value == 1) {
|
|
|
+ log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
- if (unitCode != 0) {
|
|
|
- unitLevelOperationRecord.setMessage(errorMsg);
|
|
|
- log.error("组创建失败=>accountId:{};message:{}", accountId, errorMsg);
|
|
|
- unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- return;
|
|
|
+ //创建组
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, null);
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, null, operationType);
|
|
|
+ if (!Check.isNull(unitParams)) {
|
|
|
+ AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
|
|
|
+ BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
|
|
|
+ unitLevelOperationRecord.setGroupName(unitName);
|
|
|
+ unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
|
|
|
+ unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
|
|
|
+ unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
+ unitLevelOperationRecord.setCreateTime(new Date());
|
|
|
+ unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
+ unitLevelOperationRecord.setCreateType(2);//项目创建
|
|
|
+ Integer unitCode = -1;
|
|
|
+ String errorMsg = unitParams.getString("errorMsg");
|
|
|
+ if (Check.isNull(errorMsg)) {
|
|
|
+ log.info("创建广告组入参:{}", unitParams);
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
+ unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ errorMsg = (String) unitCreateResult.get("message");
|
|
|
+ unitLevelOperationRecord.setStatus(unitCode);
|
|
|
+ unitLevelOperationRecord.setMessage(errorMsg);
|
|
|
+ if (unitCode == 0) {
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+ unitLevelOperationRecord.setUnitId(unitId);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
|
|
|
+ createProgramCreative(token, creativeParams, strategy);
|
|
|
+ }
|
|
|
+ if (unitCode != 0) {
|
|
|
+ log.error("组创建失败=>accountId:{};message:{}", accountId, errorMsg);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ unitLevelOperationRecord.setStatus(unitCode);
|
|
|
+ unitLevelOperationRecord.setMessage(errorMsg);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } catch (BeansException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("创建程序化创意异常", e);
|
|
|
}
|
|
|
+ insertAccountOperationRecord(strategy, "success", operationType, 1);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void customCreativeSupplement(KuaishouProjectStrategy strategy, Integer hour) {
|
|
|
- Integer customUnitCnt = strategy.getCustomUnitCnt();
|
|
|
- if (Check.isNull(customUnitCnt)) {
|
|
|
- Integer imageCnt = strategy.getImageCnt();
|
|
|
- if (imageCnt <= 1) {
|
|
|
- customUnitCnt = 600;
|
|
|
- } else {
|
|
|
- customUnitCnt = 2000 / imageCnt;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Integer unitNum = customUnitCnt * hour / 20;
|
|
|
- log.info("{}当前时间内需要创建组总数:{}", strategy.getAccountId(), unitNum);
|
|
|
- //查询当前账户创建自定义类型组数量
|
|
|
- int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId());
|
|
|
- log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
|
|
|
- Integer remindCnt = unitNum - unitCreateCnt;
|
|
|
- if (remindCnt >= 1) {
|
|
|
- log.info("{}组创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- //优先创建历史遗漏素材
|
|
|
- remindCnt = this.autoCreateCreative(strategy, 3, remindCnt);
|
|
|
- }
|
|
|
- if (remindCnt >= 1) {
|
|
|
- log.info("{}组创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- //高质量素材
|
|
|
- remindCnt = this.autoCreateCreative(strategy, 2, remindCnt);
|
|
|
- }
|
|
|
- if (remindCnt >= 1) {
|
|
|
- //历史打捞素材
|
|
|
- log.info("{}组创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- this.autoCreateCreative(strategy, 4, remindCnt);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void customCreativeLimit(KuaishouProjectStrategy strategy) {
|
|
|
- Integer unitNum = strategy.getCustomUnitCnt();
|
|
|
- if (Check.isNull(unitNum)) {
|
|
|
- Integer imageCnt = strategy.getImageCnt();
|
|
|
- if (imageCnt <= 1) {
|
|
|
- unitNum = 600;
|
|
|
- } else {
|
|
|
- unitNum = 2000 / imageCnt;
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("{}当天可创建组总数:{}", strategy.getAccountId(), unitNum);
|
|
|
- //查询当前账户创建自定义类型组数量
|
|
|
- int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId());
|
|
|
- log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
|
|
|
- Integer remindCnt = unitNum - unitCreateCnt;
|
|
|
- if (remindCnt >= 1) {
|
|
|
- log.info("{}组创建不足,剩余需要创建个数{},开始上新素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- this.autoCreateCreative(strategy, 1, remindCnt);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Autowired
|
|
|
private IKuaiShouUpdateService updateService;
|
|
@@ -724,7 +712,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
return campaignId;
|
|
|
}
|
|
|
|
|
|
- private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, KuaishouProjectStrategy strategy, String unitName, Long appId, KuaiShouVideoGet videoItem) {
|
|
|
+ private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, KuaishouProjectStrategy strategy, String unitName, Long appId, KuaiShouVideoGet videoItem, Integer operationType) {
|
|
|
JSONObject unitParams = null;
|
|
|
try {
|
|
|
// 拼装创建组的入参 json
|
|
@@ -894,12 +882,14 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
List<KuaishouDirectionalPackage> targets = directionalPackageService.getProjectTargetByIds(templateIds);
|
|
|
if (Check.isNull(targets)) {
|
|
|
unitParams.put("errorMsg", "获取项目定向模板失败");
|
|
|
+ insertAccountOperationRecord(strategy, "获取项目定向模板失败", operationType, 0);
|
|
|
return unitParams;
|
|
|
}
|
|
|
if (!Check.isNull(videoItem)) {
|
|
|
targets = checkTemplateIds(targets, videoItem);
|
|
|
if (Check.isNull(targets)) {
|
|
|
unitParams.put("errorMsg", "未匹配到符合素材的定向");
|
|
|
+ insertAccountOperationRecord(strategy, "未匹配到符合素材的定向", operationType, 0);
|
|
|
return unitParams;
|
|
|
}
|
|
|
}
|
|
@@ -912,6 +902,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
}
|
|
|
if (Check.isNull(tempIds)) {
|
|
|
unitParams.put("errorMsg", "定向包管理中,该账户未在项目定向模板下进行推送创建");
|
|
|
+ insertAccountOperationRecord(strategy, "定向包管理中,该账户未在项目定向模板下进行推送创建", operationType, 0);
|
|
|
return unitParams;
|
|
|
}
|
|
|
|
|
@@ -927,12 +918,14 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
unitParams.put("target", target);
|
|
|
} else {
|
|
|
unitParams.put("errorMsg", "组创建异常=》accountId(" + strategy.getAccountId() + ")联盟广告位定向模板错误");
|
|
|
+ insertAccountOperationRecord(strategy, "联盟广告位定向模板错误", operationType, 0);
|
|
|
return unitParams;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
unitParams.put("errorMsg", "策略未选择定向");
|
|
|
+ insertAccountOperationRecord(strategy, "策略未选择定向", operationType, 0);
|
|
|
return unitParams;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -1431,4 +1424,43 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 记录账户维度操作数据
|
|
|
+ *
|
|
|
+ * @param strategy 策略
|
|
|
+ * @param msg 说明
|
|
|
+ * @param errType 异常类型 1 检查错误,2创建时错误
|
|
|
+ * @param status 状态 0失败,1成功
|
|
|
+ * @throws
|
|
|
+ */
|
|
|
+ private void insertAccountOperationRecord(KuaishouProjectStrategy strategy, String msg, Integer errType, Integer status) {
|
|
|
+ String statDate = DateUtils.formatDate(new Date());
|
|
|
+ QueryWrapper<AiKuaishouAccountLevelOperationRecord> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("account_id", strategy.getAccountId());
|
|
|
+ wrapper.eq("stat_date", statDate);
|
|
|
+ wrapper.last("limit 1");
|
|
|
+ AiKuaishouAccountLevelOperationRecord accountOperationRecord = kuaishouAccountLevelOperationRecordService.getOne(wrapper);
|
|
|
+ if (Check.isNull(accountOperationRecord)) {
|
|
|
+ accountOperationRecord = new AiKuaishouAccountLevelOperationRecord();
|
|
|
+ accountOperationRecord.setMessage(msg);
|
|
|
+ accountOperationRecord.setProjectId(strategy.getProjectId());
|
|
|
+ accountOperationRecord.setAccountId(strategy.getAccountId());
|
|
|
+ accountOperationRecord.setErrType(errType);
|
|
|
+ accountOperationRecord.setCreateTime(new Date());
|
|
|
+ accountOperationRecord.setAiStrategyUuid(strategy.getStrategyUuid());
|
|
|
+ accountOperationRecord.setStatDate(statDate);
|
|
|
+ accountOperationRecord.setStatus(status);
|
|
|
+ } else {
|
|
|
+ if (status == 1 && !accountOperationRecord.getAiStrategyUuid().equals(strategy.getAccountId())) {
|
|
|
+ accountOperationRecord.setStatus(status);
|
|
|
+ accountOperationRecord.setMessage(msg);
|
|
|
+ }
|
|
|
+ if (status == 0) {
|
|
|
+ accountOperationRecord.setStatus(status);
|
|
|
+ accountOperationRecord.setMessage(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kuaishouAccountLevelOperationRecordService.saveOrUpdate(accountOperationRecord);
|
|
|
+ }
|
|
|
+
|
|
|
}
|