|
@@ -12,6 +12,7 @@ import cn.com.ctop.kuaishou.modules.ai.entity.*;
|
|
|
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.service.*;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
|
|
|
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.service.*;
|
|
@@ -26,6 +27,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -58,6 +60,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
private IAiKuaishouUnitLevelOperationRecordService unitLevelOperationRecordService;
|
|
|
@Autowired
|
|
|
private IAiKuaishouCreativeLevelOperationRecordService creativeLevelOperationRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaishouLandpagePackageService landpagePackageService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouAppMultipleBidsService kuaiShouAppMultipleBidsService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -89,51 +95,141 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
Integer singleAppid = strategy.getSingleAppid();
|
|
|
if (null != singleAppid && singleAppid == 0) {
|
|
|
//多应用
|
|
|
- String appidString = strategy.getAppIdArray();
|
|
|
- JSONArray appIdArray = JSONArray.parseArray(appidString);
|
|
|
- if (null != appIdArray && !appIdArray.isEmpty()) {
|
|
|
- for (int i = 0; i < appIdArray.size(); i++) {
|
|
|
- String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(), appIdArray.getLong(i));
|
|
|
- if (null == appInfo) {
|
|
|
- log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
|
|
|
- continue;
|
|
|
- }
|
|
|
+ JSONArray appIdArray = JSONArray.parseArray(strategy.getAppIdArray());
|
|
|
+ if (strategy.getMultipleBids() == 0) { // 非多应用多出价
|
|
|
+ if (null != appIdArray && !appIdArray.isEmpty()) {
|
|
|
+ for (int i = 0; i < appIdArray.size(); i++) {
|
|
|
+ String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+
|
|
|
+ AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(), appIdArray.getLong(i));
|
|
|
+ if (null == appInfo) {
|
|
|
+ log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
|
|
|
+ strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
+ strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
|
+ }
|
|
|
+ replaceString = appInfo.getAppVersion() + "-" + replaceString;
|
|
|
+ //1:查询素材
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType, videoCnt);
|
|
|
+ if (null == allVideos || allVideos.isEmpty()) {
|
|
|
+ log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN", createType, appInfo.getAppId(), strategyUuid);
|
|
|
+ for (KuaiShouVideoGet videoItem : allVideos) {
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId);
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
|
|
|
- if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
|
|
|
- strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
- strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
|
+ KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
+ if (null != overrunInfo) {
|
|
|
+ log.info("该账户创意创建已超限=>accountId:{}", accountId);
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ // 获取视频封面数据
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //开始创建组+创意
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appInfo.getAppId());
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
|
|
|
+ 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.setCreateTime(new Date());
|
|
|
+ unitLevelOperationRecord.setStatus(unitCode);
|
|
|
+ unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
|
|
|
+ unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
|
|
|
+ unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
+ unitLevelOperationRecord.setMessage(unitMessage);
|
|
|
+ unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
+ 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, appInfo.getAppVersion());
|
|
|
+ if (videoCnt <= 0) {
|
|
|
+ return videoCnt;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- replaceString = appInfo.getAppVersion() + "-" + replaceString;
|
|
|
- //1:查询素材
|
|
|
- List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType, videoCnt);
|
|
|
- if (null == allVideos || allVideos.isEmpty()) {
|
|
|
- log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
|
|
|
+ }
|
|
|
+ } else if (strategy.getMultipleBids() == 1) { // 多应用多出价
|
|
|
+ String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
|
|
|
+ if (Check.isNull(allVideos)) {
|
|
|
+ return videoCnt;
|
|
|
+ }
|
|
|
+ for (KuaiShouVideoGet videoItem : allVideos) {
|
|
|
+ // 获取视频封面数据
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
continue;
|
|
|
}
|
|
|
- Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN", createType, appInfo, strategyUuid);
|
|
|
- int unitCnt = 0;
|
|
|
- for (KuaiShouVideoGet videoItem : allVideos) {
|
|
|
+ for (int i = 0; i < appIdArray.size(); i++) {
|
|
|
+
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId);
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long appId = appIdArray.getLong(i);
|
|
|
+ if (Check.isNull(appId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ KuaiShouAppMultipleBids multipleBids = kuaiShouAppMultipleBidsService.getInfoByAccountAndAppId(accountId, appId);
|
|
|
+ if (Check.isNull(multipleBids)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(multipleBids.getTrackUrl())) {
|
|
|
+ strategy.setClickTrackUrl(multipleBids.getTrackUrl());
|
|
|
+ }
|
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
if (null != overrunInfo) {
|
|
|
log.info("该账户创意创建已超限=>accountId:{}", accountId);
|
|
|
return 0L;
|
|
|
}
|
|
|
- // 获取视频封面数据
|
|
|
- List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
- if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
- log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
- continue;
|
|
|
- }
|
|
|
- unitCnt++;
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
//开始创建组+创意
|
|
|
- String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, videoItem.getPhotoName(), "unit", newCampaignId);
|
|
|
- JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId);
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
+ unitParams.remove("cpa_bid");
|
|
|
+ unitParams.put("cpa_bid", multipleBids.getCpaBid());
|
|
|
+ if (!Check.isNull(multipleBids.getDeepConversionBid())) {
|
|
|
+ unitParams.remove("deep_conversion_bid");
|
|
|
+ unitParams.put("deep_conversion_bid", multipleBids.getDeepConversionBid());
|
|
|
+ }
|
|
|
+ strategy.setCpaBid(multipleBids.getCpaBid() + "");
|
|
|
+ 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.setCampaignId(newCampaignId);
|
|
|
+ unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
|
|
|
+ unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
+ unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
|
|
|
unitLevelOperationRecord.setGroupName(unitName);
|
|
|
unitLevelOperationRecord.setCreateTime(new Date());
|
|
|
unitLevelOperationRecord.setStatus(unitCode);
|
|
@@ -150,7 +246,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
videoCnt--;
|
|
|
JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
- createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, appInfo.getAppVersion());
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
|
|
|
if (videoCnt <= 0) {
|
|
|
return videoCnt;
|
|
|
}
|
|
@@ -165,14 +261,26 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
|
|
|
return videoCnt;
|
|
|
}
|
|
|
- Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, null, strategyUuid);
|
|
|
+ Long appId = null;
|
|
|
+ if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
+ appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
+ if (Check.isNull(appId)) {
|
|
|
+ return videoCnt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
if (null == newCampaignId) {
|
|
|
return videoCnt;
|
|
|
}
|
|
|
-
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
|
- int unitCnt = 0;
|
|
|
for (KuaiShouVideoGet videoItem : newVideos) {
|
|
|
+
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId);
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
if (null != overrunInfo) {
|
|
|
return 0L;
|
|
@@ -183,27 +291,19 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
continue;
|
|
|
}
|
|
|
- unitCnt++;
|
|
|
- String unitName = getName(strategy.getGroupName(), strategy, createType, null, videoItem.getPhotoName(), "unit", newCampaignId);
|
|
|
-
|
|
|
- Long appId = null;
|
|
|
- if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
- appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
- }
|
|
|
-
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId);
|
|
|
JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
+ 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);
|
|
|
- if (!Check.isNull(strategy.getCpaBid())) {
|
|
|
- unitLevelOperationRecord.setCpaBid(Integer.valueOf(strategy.getCpaBid() + ""));
|
|
|
- }
|
|
|
- if (!Check.isNull(strategy.getBid())) {
|
|
|
- unitLevelOperationRecord.setBid(Integer.valueOf(strategy.getBid() + ""));
|
|
|
- }
|
|
|
+ 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);
|
|
@@ -228,7 +328,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
return videoCnt;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 创建程序化创意
|
|
|
*
|
|
@@ -249,92 +348,187 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
//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());
|
|
|
+ if (strategy.getMultipleBids() == 0) {
|
|
|
+ timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ } else if (strategy.getMultipleBids() == 1) {
|
|
|
+ if (createType == 1) {
|
|
|
+ timeStart = -1 * 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;
|
|
|
+ JSONArray appIdArray = JSON.parseArray(strategy.getAppIdArray());
|
|
|
+ if (null != singleAppid && singleAppid == 0) {
|
|
|
+ if (strategy.getMultipleBids() == 0) { // 非多应用多出价
|
|
|
+ //多应用
|
|
|
+ if (null != appIdArray && !appIdArray.isEmpty()) {
|
|
|
+ for (int i = 0; i < appIdArray.size(); i++) {
|
|
|
+ AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(), appIdArray.getLong(i));
|
|
|
+ if (null == appInfo) {
|
|
|
+ log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
|
|
|
+ //判定是否通用监测链接
|
|
|
+ if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
|
|
|
+ strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
+ strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
|
+ }
|
|
|
+ replaceString = appInfo.getAppVersion() + "-" + replaceString;
|
|
|
+ //1:查询可用素材
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType, videoCnt);
|
|
|
+ if (null == allVideos || allVideos.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId);
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (null != singleAppid && singleAppid == 0) {
|
|
|
- //多应用
|
|
|
- String appidString = strategy.getAppIdArray();
|
|
|
- JSONArray appIdArray = JSON.parseArray(appidString);
|
|
|
- if (null != appIdArray && !appIdArray.isEmpty()) {
|
|
|
- for (int i = 0; i < appIdArray.size(); i++) {
|
|
|
- AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(), appIdArray.getLong(i));
|
|
|
- if (null == appInfo) {
|
|
|
- log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
|
|
|
- continue;
|
|
|
- }
|
|
|
- //判定是否通用监测链接
|
|
|
- if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
|
|
|
- strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
- strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
|
- }
|
|
|
- String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- replaceString = appInfo.getAppVersion() + "-" + replaceString;
|
|
|
- //1:查询可用素材
|
|
|
- List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType, videoCnt);
|
|
|
- if (null == allVideos || allVideos.isEmpty()) {
|
|
|
- return;
|
|
|
+ //判定创意创建是否超限
|
|
|
+ KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
+ if (null != overrunInfo) {
|
|
|
+ log.info("该账户创意创建已超限=>accountId:{}", accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN", createType, appInfo.getAppId(), strategyUuid);
|
|
|
+ //创建组+创意
|
|
|
+ List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
+ for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
+ Object redisObj = redisUtil.get(key);
|
|
|
+ if (!Check.isNull(redisObj)) {
|
|
|
+ Integer value = (Integer) redisObj;
|
|
|
+ if (value == 1) {
|
|
|
+ log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建组
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appInfo.getAppId());
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, appInfo.getAppVersion());
|
|
|
+ createProgramCreative(token, creativeParams, strategy);
|
|
|
+ }
|
|
|
}
|
|
|
- //判定创意创建是否超限
|
|
|
- KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
- if (null != overrunInfo) {
|
|
|
- log.info("该账户创意创建已超限=>accountId:{}", accountId);
|
|
|
- return;
|
|
|
+ }
|
|
|
+ } else if (strategy.getMultipleBids() == 1) { // 多应用多出价
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
|
|
|
+ if (Check.isNull(allVideos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 1);
|
|
|
+ for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
+ List<KuaiShouVideoGet> kuaiShouVideoGets = splitVideos.get(j);
|
|
|
+ if (Check.isNull(kuaiShouVideoGets)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN", createType, appInfo, strategyUuid);
|
|
|
-
|
|
|
- //创建组+创意
|
|
|
- List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
- for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
-
|
|
|
- Object redisObj = redisUtil.get(key);
|
|
|
- if (!Check.isNull(redisObj)) {
|
|
|
- Integer value = (Integer) redisObj;
|
|
|
- if (value == 1) {
|
|
|
- log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
|
|
|
+ for (KuaiShouVideoGet videoGet : kuaiShouVideoGets) {
|
|
|
+ for (int i = 0; i < appIdArray.size(); i++) {
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId);
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
return;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //创建组
|
|
|
- String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, null, "unit", newCampaignId);
|
|
|
- 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");
|
|
|
- AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
|
|
|
- BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
|
|
|
- unitLevelOperationRecord.setGroupName(unitName);
|
|
|
- unitLevelOperationRecord.setCreateTime(new Date());
|
|
|
- unitLevelOperationRecord.setStatus(unitCode);
|
|
|
- unitLevelOperationRecord.setMessage(unitMessage);
|
|
|
- unitLevelOperationRecord.setCampaignId(newCampaignId);
|
|
|
- unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
- if (unitCode != 0) {
|
|
|
- log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
+ Object redisObj = redisUtil.get(key);
|
|
|
+ if (!Check.isNull(redisObj)) {
|
|
|
+ Integer value = (Integer) redisObj;
|
|
|
+ if (value == 1) {
|
|
|
+ log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long appId = appIdArray.getLong(i);
|
|
|
+ if (Check.isNull(appId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ KuaiShouAppMultipleBids multipleBids = kuaiShouAppMultipleBidsService.getInfoByAccountAndAppId(accountId, appId);
|
|
|
+ if (Check.isNull(multipleBids)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(multipleBids.getTrackUrl())) {
|
|
|
+ strategy.setClickTrackUrl(multipleBids.getTrackUrl());
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
+ //创建组
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, videoGet.getPhotoName(), "unit", newCampaignId, appId);
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
+ unitParams.remove("cpa_bid");
|
|
|
+ unitParams.put("cpa_bid", multipleBids.getCpaBid());
|
|
|
+ if (!Check.isNull(multipleBids.getDeepConversionBid())) {
|
|
|
+ unitParams.remove("deep_conversion_bid");
|
|
|
+ unitParams.put("deep_conversion_bid", multipleBids.getDeepConversionBid());
|
|
|
+ }
|
|
|
+ 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.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
|
|
|
+
|
|
|
+ unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
|
|
|
+ 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);
|
|
|
- continue;
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
|
|
|
+ createProgramCreative(token, creativeParams, strategy);
|
|
|
}
|
|
|
- Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
- unitLevelOperationRecord.setUnitId(unitId);
|
|
|
- unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, appInfo.getAppVersion());
|
|
|
- createProgramCreative(token, creativeParams, strategy);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -345,14 +539,29 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (null == allVideos) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, null, strategyUuid);
|
|
|
+ Long appId = null;
|
|
|
+ String appIdString = strategy.getAppIdArray();
|
|
|
+ if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
+ if (!Check.isNull(appIdString) && !Check.isNull(JSON.parseArray(appIdString))) {
|
|
|
+ appId = JSON.parseArray(appIdString).getLong(0);
|
|
|
+ if (Check.isNull(appId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
|
|
|
if (null == newCampaignId) {
|
|
|
return;
|
|
|
}
|
|
|
//创意
|
|
|
List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
|
+ Boolean unitOverrun = getUnitOverrun(accountId);
|
|
|
+ if (unitOverrun) {
|
|
|
+ log.error("组创建超限,accountId:{}", accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
Object redisObj = redisUtil.get(key);
|
|
|
if (!Check.isNull(redisObj)) {
|
|
|
Integer value = (Integer) redisObj;
|
|
@@ -362,21 +571,19 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
}
|
|
|
//创建组
|
|
|
- String unitName = getName(strategy.getGroupName(), strategy, createType, null, null, "unit", newCampaignId);
|
|
|
- String appIdString = strategy.getAppIdArray();
|
|
|
- Long appId = null;
|
|
|
- if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
- if (!Check.isNull(appIdString) && !Check.isNull(JSON.parseArray(appIdString))) {
|
|
|
- appId = JSON.parseArray(appIdString).getLong(0);
|
|
|
- }
|
|
|
- }
|
|
|
+ String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId);
|
|
|
JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
+ 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);
|
|
@@ -394,6 +601,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
createProgramCreative(token, creativeParams, strategy);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -469,14 +677,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
return;
|
|
|
}
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
-
|
|
|
-
|
|
|
String message = resultJson.getString("message");
|
|
|
-
|
|
|
Long unitId = creativeParams.getLong("unit_id");
|
|
|
if (code == 0) {
|
|
|
+ createLandPageAndUnit(creativeParams, resultJson.getJSONObject("data"));
|
|
|
log.info("创建程序化创意成功,accountId:{},unit:{}", token.getAccountId(), unitId);
|
|
|
-
|
|
|
} else {
|
|
|
log.error("快手创建程序化创意失败,accountId:{},unitId:{},返回信息:{}", token.getAccountId(), unitId, message);
|
|
|
if (code == 400001 && "/rest/openapi/v2/creative/advanced/program/create调用已超日限,次日可恢复调用".equals(message)) {
|
|
@@ -485,10 +690,20 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
redisUtil.set(key, 1, 100000L);
|
|
|
updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ //绑定落地页与广告组、创意的关系
|
|
|
+ private void createLandPageAndUnit(JSONObject programJson, JSONObject data) {
|
|
|
+ if (!Check.isNull(data) && !Check.isNull(programJson.getLong("site_id"))) {
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ landpagePackageService.createLandPageAndUnit(programJson.getLong("site_id"), data.getLong("creative_id"), programJson.getLong("unit_id"), programJson.getLong("advertiser_id"));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt, String appVersion) {
|
|
@@ -548,8 +763,8 @@ 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());
|
|
|
+
|
|
|
+ JSONArray captions = getCaptions(strategy.getDescription());
|
|
|
programJson.put("captions", captions);
|
|
|
if (!Check.isNull(strategy.getCreativeCategory())) {
|
|
|
programJson.put("creative_category", strategy.getCreativeCategory());
|
|
@@ -558,6 +773,22 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
return programJson;
|
|
|
}
|
|
|
|
|
|
+ private JSONArray getCaptions(String description) {
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(description);
|
|
|
+ if (jsonArray.size() <= 3) {
|
|
|
+ return jsonArray;
|
|
|
+ }
|
|
|
+ Collections.shuffle(jsonArray);
|
|
|
+ JSONArray captions = new JSONArray();
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ captions.add(jsonArray.getString(i));
|
|
|
+ if (captions.size() == 3) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return captions;
|
|
|
+ }
|
|
|
+
|
|
|
private List<KuaiShouVideoGet> getNewVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
|
|
|
if (null == appInfo) {
|
|
|
if (Check.isNull(strategy.getMaterialKeyword())) { // 素材名称为空 不需要标注特殊素材
|
|
@@ -652,7 +883,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
|
|
|
|
|
|
- private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType, Integer createType, AiKuaiShouAppInfo appInfo, String uuid) {
|
|
|
+ private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType, Integer createType, Long appId, String uuid) {
|
|
|
Long campaignId = null;
|
|
|
if ("ALL_CAMPAIGN".equals(checkType)) {
|
|
|
campaignId = campaignService.getCampaignIdByAccountAndName(strategy.getAccountId(), replaceString);
|
|
@@ -667,7 +898,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
// 不存在“上新”计划,则创建一个计划
|
|
|
JSONObject campaignParams = new JSONObject();
|
|
|
campaignParams.put("advertiser_id", token.getAccountId());
|
|
|
- String campaignName = getName(strategy.getCampaignName(), strategy, createType, appInfo, null, "plan", null);
|
|
|
+ String campaignName = getName(strategy.getCampaignName(), strategy, createType, null, "plan", null, appId);
|
|
|
campaignParams.put("campaign_name", campaignName);
|
|
|
campaignParams.put("type", strategy.getCampaignType());
|
|
|
if (null != strategy.getCampaignDayBudget() && strategy.getCampaignDayBudget() != 0) {
|
|
@@ -716,8 +947,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (null != strategy.getBid() && strategy.getBid() != 0) {
|
|
|
unitParams.put("bid", strategy.getBid());
|
|
|
}
|
|
|
- if (null != strategy.getCpaBid() && strategy.getCpaBid() != 0) {
|
|
|
- unitParams.put("cpa_bid", strategy.getCpaBid());
|
|
|
+ if (!Check.isNull(strategy.getCpaBid()) && !"0".equals((strategy.getCpaBid()))) {
|
|
|
+ Long cpdBid = getBidByString(strategy.getCpaBid());
|
|
|
+ unitParams.put("cpa_bid", cpdBid);
|
|
|
}
|
|
|
//优先低成本
|
|
|
if (null != strategy.getSmartBid() && strategy.getSmartBid() != 0) {
|
|
@@ -898,14 +1130,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- JSONArray appInterest = JSONArray.parseArray(strategy.getAppInterest());
|
|
|
- if (!Check.isNull(appInterest)) {
|
|
|
- targetJsonObject.put("app_interest", appInterest);
|
|
|
- }
|
|
|
// APP行为-按APP名称
|
|
|
- JSONArray appIds = JSONArray.parseArray(strategy.getAppIds());
|
|
|
- if (!Check.isNull(appIds)) {
|
|
|
- targetJsonObject.put("app_ids", appIds);
|
|
|
+ if (sceneId != 5) {
|
|
|
+ JSONArray appIds = JSONArray.parseArray(strategy.getAppIds());
|
|
|
+ if (!Check.isNull(appIds)) {
|
|
|
+ targetJsonObject.put("app_ids", appIds);
|
|
|
+ }
|
|
|
+ JSONArray appInterest = JSONArray.parseArray(strategy.getAppInterest());
|
|
|
+ if (!Check.isNull(appInterest)) {
|
|
|
+ targetJsonObject.put("app_interest", appInterest);
|
|
|
+ }
|
|
|
}
|
|
|
// 人群包定向
|
|
|
JSONArray populationString = JSONArray.parseArray(strategy.getPopulation());
|
|
@@ -941,10 +1175,33 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
}
|
|
|
unitParams.put("target", targetJsonObject);
|
|
|
- log.info("广告组创建参数:{}", unitParams.toJSONString());
|
|
|
return unitParams;
|
|
|
}
|
|
|
|
|
|
+ private Long getBidByString(String cpaBid) {
|
|
|
+ if (Check.isNull(cpaBid)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String bidString = null;
|
|
|
+ if (cpaBid.contains("/")) { // 阶梯出价
|
|
|
+ String[] split = cpaBid.split("/");
|
|
|
+ int random = new Random().nextInt(split.length);
|
|
|
+ bidString = split[random];
|
|
|
+
|
|
|
+ } else if (cpaBid.contains("-")) { // 随机出价
|
|
|
+ String[] split = cpaBid.split("-");
|
|
|
+ Double min = Double.valueOf(split[0]) / 1000;
|
|
|
+ Double max = Double.valueOf(split[1]) / 1000;
|
|
|
+ Double randomNumber = new BigDecimal(min + Math.random() * (max - min)).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ bidString = String.valueOf(new Double(randomNumber * 1000).longValue());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ bidString = cpaBid;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Long.valueOf(bidString);
|
|
|
+ }
|
|
|
+
|
|
|
private JSONArray cleanPramgramErrorScence(JSONArray scenceArray) {
|
|
|
JSONArray result = new JSONArray();
|
|
|
if (null == scenceArray || scenceArray.isEmpty()) {
|
|
@@ -1141,7 +1398,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
creativeParams.put("photo_id", videoItem.getPhotoId());
|
|
|
creativeParams.put("creative_material_type", videoItem.getMaterialType());
|
|
|
creativeParams.put("action_bar_text", strategy.getActionBarText());
|
|
|
- creativeParams.put("description", strategy.getDescription());
|
|
|
+ JSONArray descArr = JSONArray.parseArray(strategy.getDescription());
|
|
|
+ int index = new Random().nextInt(descArr.size());
|
|
|
+ String description = descArr.getString(index);
|
|
|
+ creativeParams.put("description", description);
|
|
|
// 封面广告语标题
|
|
|
if (!Check.isNull(strategy.getStickerTitle())) {
|
|
|
creativeParams.put("sticker_title", strategy.getStickerTitle());
|
|
@@ -1202,12 +1462,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
|
|
|
} else if (creativeCode == -1 && creativeMessage.contains("超过可关联的有效创意的上限")) {
|
|
|
updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
|
|
|
+ } else if (creativeCode == -1 && creativeMessage.contains("视频不存在")) {
|
|
|
+ updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
|
|
|
}
|
|
|
|
|
|
AiKuaishouCreativeLevelOperationRecord record = new AiKuaishouCreativeLevelOperationRecord();
|
|
|
BeanUtils.copyProperties(strategy, record);
|
|
|
record.setCreativeName(creativeName);
|
|
|
record.setStatus(creativeCode);
|
|
|
+ record.setDescription(creativeParams.getString("description"));
|
|
|
+ record.setPhotoId(creativeParams.getString("photo_id"));
|
|
|
record.setMessage(creativeMessage);
|
|
|
record.setUnitId(unitId);
|
|
|
record.setAiStrategyUuid(uuid);
|
|
@@ -1229,14 +1493,20 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
*/
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouAppListService appListService;
|
|
|
|
|
|
- private String getName(String wildcard, AiKuaishouAdvertiserStrategy strategy, Integer createType, AiKuaiShouAppInfo appInfo, String materialName, String type, Long campaignId) {
|
|
|
- if (wildcard.contains("{{应用包名}}")) {
|
|
|
- String appName = "";
|
|
|
- if (null != appInfo) {
|
|
|
- appName = appInfo.getAppName();
|
|
|
+
|
|
|
+ private String getName(String wildcard, AiKuaishouAdvertiserStrategy strategy, Integer createType, String materialName, String type, Long campaignId, Long appId) {
|
|
|
+ if (wildcard.contains("{{应用名称}}") || wildcard.contains("{{应用标记}}")) {
|
|
|
+ KuaiShouAppList getAppInfo = appListService.getAppInfo(strategy.getAccountId(), appId);
|
|
|
+ if (!Check.isNull(getAppInfo)) {
|
|
|
+ wildcard = wildcard.replace("{{应用名称}}", getAppInfo.getAppName());
|
|
|
+ wildcard = wildcard.replace("{{应用标记}}", getAppInfo.getAppVersion());
|
|
|
+ } else {
|
|
|
+ wildcard = wildcard.replace("{{应用名称}}", "");
|
|
|
+ wildcard = wildcard.replace("{{应用标记}}", "");
|
|
|
}
|
|
|
- wildcard = wildcard.replace("{{应用包名}}", appName);
|
|
|
}
|
|
|
if (wildcard.contains("{{创意制作方式}}")) {
|
|
|
if (strategy.getUnitType() == 4) {
|
|
@@ -1257,6 +1527,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
wildcard = wildcard.replace("{{素材名称}}", materialName);
|
|
|
}
|
|
|
}
|
|
|
+ if (wildcard.contains("{{渠道号}}")) {
|
|
|
+ KuaiShouAppMultipleBids multipleBids = kuaiShouAppMultipleBidsService.getInfoByAccountAndAppId(strategy.getAccountId(), appId);
|
|
|
+ if (!Check.isNull(multipleBids)) {
|
|
|
+ wildcard = wildcard.replace("{{渠道号}}", multipleBids.getChannelCode());
|
|
|
+ } else {
|
|
|
+ wildcard = wildcard.replace("{{渠道号}}", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!wildcard.contains("{{自定义}}")) {
|
|
|
wildcard = wildcard + "{{自定义}}";
|
|
|
}
|
|
@@ -1271,16 +1549,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
} else if ("unit".equals(type)) {
|
|
|
wildcard = wildcard.replace("{{日期}}", nowDate);
|
|
|
}
|
|
|
-
|
|
|
String targetName = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- if (null != appInfo) {
|
|
|
- targetName = appInfo.getAppVersion() + "-" + targetName;
|
|
|
- }
|
|
|
wildcard = wildcard.replace("{{自定义}}", targetName);
|
|
|
-
|
|
|
if (!Check.isNull(campaignId)) {
|
|
|
Integer count = null;
|
|
|
- if (null != strategy.getSingleAppid() && strategy.getSingleAppid() == 0) {
|
|
|
+ if (null != strategy.getSingleAppid() && strategy.getSingleAppid() == 0 && strategy.getMultipleBids() == 0) {
|
|
|
String redisKey = strategy.getAccountId() + "_" + campaignId;
|
|
|
Object redisValue = redisUtil.get(redisKey);
|
|
|
if (Check.isNull(redisValue)) {
|
|
@@ -1329,12 +1602,21 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- Date date = new Date();
|
|
|
- String s = DateUtils.formatDate(date, "yy-MMdd");
|
|
|
- String timestamp = DateUtils.formatDate(new Date(), "HHmmss");
|
|
|
- System.err.println(timestamp);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public Boolean getUnitOverrun(Long accountId) {
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String key = accountId + "_" + nowDate + "unit_create_overrun";
|
|
|
+ Object redisObj = redisUtil.get(key);
|
|
|
+ if (Check.isNull(redisObj)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Integer value = (Integer) redisObj;
|
|
|
+ if (value == 1) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|