|
@@ -149,7 +149,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);
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, appInfo.getAppVersion());
|
|
|
if (videoCnt <= 0) {
|
|
|
return videoCnt;
|
|
|
}
|
|
@@ -208,7 +208,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);
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
|
|
|
if (videoCnt <= 0) {
|
|
|
return 0L;
|
|
|
}
|
|
@@ -235,14 +235,24 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
//1:获取视频信息
|
|
|
kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
|
|
|
- Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
- Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
|
|
|
+ //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);
|
|
|
|
|
|
- //2:判定账户是否单一应用
|
|
|
- Integer singleAppid = strategy.getSingleAppid();
|
|
|
+
|
|
|
if (null != singleAppid && singleAppid == 0) {
|
|
|
//多应用
|
|
|
String appidString = strategy.getAppIdArray();
|
|
@@ -300,7 +310,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
unitLevelOperationRecord.setUnitId(unitId);
|
|
|
unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, appInfo.getAppVersion());
|
|
|
createProgramCreative(token, creativeParams, strategy);
|
|
|
}
|
|
|
}
|
|
@@ -349,7 +359,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
unitLevelOperationRecord.setUnitId(unitId);
|
|
|
unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
- JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
|
|
|
+ JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
|
|
|
createProgramCreative(token, creativeParams, strategy);
|
|
|
}
|
|
|
}
|
|
@@ -436,11 +446,21 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
log.info("创建程序化创意成功");
|
|
|
}
|
|
|
|
|
|
- private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt) {
|
|
|
+ private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt, String appVersion) {
|
|
|
JSONObject programJson = new JSONObject();
|
|
|
programJson.put("advertiser_id", token.getAccountId());
|
|
|
programJson.put("unit_id", unitId);
|
|
|
- programJson.put("package_name", "程序化创意" + creativeCnt);
|
|
|
+ if (strategy.getSingleAppid() != null && strategy.getSingleAppid() == 0) { // 多应用情况下 创意名称已app-versionMI命名
|
|
|
+ if (!Check.isNull(appVersion)) {
|
|
|
+ programJson.put("package_name", appVersion);
|
|
|
+ } else {
|
|
|
+ programJson.put("package_name", "程序化创意" + creativeCnt);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ programJson.put("package_name", "程序化创意" + creativeCnt);
|
|
|
+ }
|
|
|
+
|
|
|
JSONArray horizontalPhotoIds = new JSONArray();
|
|
|
JSONArray verticalPhotoIds = new JSONArray();
|
|
|
JSONArray coverImageTokens = new JSONArray();
|
|
@@ -571,6 +591,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
* @param startTime 开始时间
|
|
|
* @param endTime 结束时间
|
|
|
*/
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouCampaignService campaignService;
|
|
|
+
|
|
|
private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo, Integer createType, Long videoCnt) {
|
|
|
if (createType == 1) {
|
|
|
return getNewVideoListByParams(strategy, startTime, endTime, appInfo);
|
|
@@ -584,23 +607,34 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
|
|
|
private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType, Integer createType, AiKuaiShouAppInfo appInfo, String uuid) {
|
|
|
- JSONArray campaignList;
|
|
|
- String timestamp = null;
|
|
|
- if ("ALL_CAMPAIGN".equals(checkType)) {
|
|
|
+ // JSONArray campaignList;
|
|
|
+ String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
+ /*if ("ALL_CAMPAIGN".equals(checkType)) {
|
|
|
campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
|
|
|
} else {
|
|
|
timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(), 1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- if (null != campaignList && !campaignList.isEmpty()) {
|
|
|
+ /* if (!Check.isNull(campaignList)){
|
|
|
for (int i = 0; i < campaignList.size(); i++) {
|
|
|
JSONObject jsonObject = campaignList.getJSONObject(i);
|
|
|
if (jsonObject.getString("campaign_name").contains(replaceString)) {
|
|
|
return jsonObject.getLong("campaign_id");
|
|
|
}
|
|
|
}
|
|
|
+ }*/
|
|
|
+ Long campaignId = null;
|
|
|
+ if ("ALL_CAMPAIGN".equals(checkType)) {
|
|
|
+ campaignId = campaignService.getCampaignIdByAccountAndName(strategy.getAccountId(), replaceString);
|
|
|
+ } else if ("TODAY".equals(checkType)) {
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd") + " 00:00:01";
|
|
|
+ campaignId = campaignService.getCampaignIdByAccountAndNameAndDate(strategy.getAccountId(), replaceString, nowDate);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(campaignId)) {
|
|
|
+ return campaignId;
|
|
|
}
|
|
|
+
|
|
|
// 不存在“上新”计划,则创建一个计划
|
|
|
JSONObject campaignParams = new JSONObject();
|
|
|
campaignParams.put("advertiser_id", token.getAccountId());
|
|
@@ -622,7 +656,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
|
|
|
return null;
|
|
|
}
|
|
|
- Long campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
+ campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
record.setCampaignId(campaignId);
|
|
|
aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
|
|
|
return campaignId;
|
|
@@ -1008,14 +1042,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
|
|
|
Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
|
|
|
- int imageNumber, AiKuaishouAdvertiserStrategy strategy, String uuid) {
|
|
|
+ int imageNumber, AiKuaishouAdvertiserStrategy strategy, String uuid, String appVersion) {
|
|
|
if ((null != cutFrameList && !cutFrameList.isEmpty())) {
|
|
|
for (int i = 0; i < cutFrameList.size(); i++) {
|
|
|
String imageCode = cutFrameList.get(i).getSignature();
|
|
|
String imageUrl = cutFrameList.get(i).getUrl();
|
|
|
String imageToken = getImageToken(imageUrl, imageCode, token.getAccountId(), token.getAccessToken());
|
|
|
creativeParams.put("image_token", imageToken);
|
|
|
- createCreative(token, creativeParams, campaignId, unitId, i + 1, videoItem, strategy, uuid);
|
|
|
+ createCreative(token, creativeParams, campaignId, unitId, i + 1, videoItem, strategy, uuid, appVersion);
|
|
|
imageNumber--;
|
|
|
if (imageNumber <= 0) {
|
|
|
break;
|
|
@@ -1089,8 +1123,13 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
|
|
|
private void createCreative(CtopOauthToken token, JSONObject creativeParams, Long campaignId, Long unitId,
|
|
|
- int creativeCnt, KuaiShouVideoGet videoGet, AiKuaishouAdvertiserStrategy strategy, String uuid) {
|
|
|
- String creativeName = "自定义创意_" + creativeCnt;
|
|
|
+ int creativeCnt, KuaiShouVideoGet videoGet, AiKuaishouAdvertiserStrategy strategy, String uuid, String appVersion) {
|
|
|
+ String creativeName = null;
|
|
|
+ if (!Check.isNull(appVersion)) {
|
|
|
+ creativeName = appVersion + "_" + creativeCnt;
|
|
|
+ } else {
|
|
|
+ creativeName = "自定义创意_" + creativeCnt;
|
|
|
+ }
|
|
|
creativeParams.put("creative_name", creativeName);
|
|
|
Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate(token.getAccessToken(), token.getAccountId(), creativeParams, 1);
|
|
|
Integer creativeCode = (Integer) creativeCreateResult.get("code");
|