|
@@ -98,6 +98,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
|
|
|
strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
@@ -149,7 +150,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;
|
|
|
}
|
|
@@ -185,7 +186,12 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
unitCnt++;
|
|
|
String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
|
|
|
String unitName = getName(strategy.getGroupName(), strategy, createType, null, timestamp, unitCnt);
|
|
|
- Long appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
+
|
|
|
+ Long appId = null;
|
|
|
+ if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
+ appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
+ }
|
|
|
+
|
|
|
JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
@@ -208,7 +214,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 +241,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 +316,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);
|
|
|
}
|
|
|
}
|
|
@@ -317,7 +333,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (null == newCampaignId) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
//创意
|
|
|
List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
|
|
|
for (int j = 1; j < splitVideos.size() + 1; j++) {
|
|
@@ -326,8 +341,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
String unitName = getName(strategy.getGroupName(), strategy, createType, null, timestamp, null);
|
|
|
String appIdString = strategy.getAppIdArray();
|
|
|
Long appId = null;
|
|
|
- if (!Check.isNull(appIdString) && !Check.isNull(JSON.parseArray(appIdString))) {
|
|
|
- appId = JSON.parseArray(appIdString).getLong(0);
|
|
|
+ if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
|
|
|
+ if (!Check.isNull(appIdString) && !Check.isNull(JSON.parseArray(appIdString))) {
|
|
|
+ appId = JSON.parseArray(appIdString).getLong(0);
|
|
|
+ }
|
|
|
}
|
|
|
JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
|
|
|
Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
@@ -349,7 +366,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 +453,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 +598,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 +614,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 +663,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;
|
|
@@ -633,6 +674,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
// 拼装创建组的入参 json
|
|
|
JSONObject unitParams = new JSONObject();
|
|
|
Integer unitType = strategy.getUnitType();
|
|
|
+
|
|
|
+
|
|
|
//创意制作方式
|
|
|
unitParams.put("unit_type", unitType);
|
|
|
unitParams.put("advertiser_id", token.getAccountId());
|
|
@@ -640,10 +683,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
unitParams.put("unit_name", unitName);
|
|
|
//出价类型
|
|
|
unitParams.put("bid_type", strategy.getBidType());
|
|
|
- // 优先从系统应用商店下载
|
|
|
- if (null != strategy.getUseAppMarket()) {
|
|
|
- unitParams.put("use_app_market", strategy.getUseAppMarket());
|
|
|
- }
|
|
|
+
|
|
|
//组单日预算
|
|
|
if (null != strategy.getUnitDayBudget() && strategy.getUnitDayBudget() != 0) {
|
|
|
unitParams.put("day_budget", strategy.getUnitDayBudget());
|
|
@@ -651,9 +691,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
unitParams.put("day_budget", 0);
|
|
|
}
|
|
|
//应用商店列表
|
|
|
- if (null != strategy.getAppStore() && !"".equals(strategy.getAppStore())) {
|
|
|
- unitParams.put("app_store", JSON.parseArray(strategy.getAppStore()));
|
|
|
- }
|
|
|
+
|
|
|
unitParams.put("ocpx_action_type", strategy.getOcpxActionType());
|
|
|
|
|
|
//出价
|
|
@@ -686,17 +724,63 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
Integer sceneId = null;
|
|
|
String scenceIdString = strategy.getSceneId();
|
|
|
+
|
|
|
if (!Check.isNull(scenceIdString) && !Check.isNull(JSON.parseArray(scenceIdString))) {
|
|
|
JSONArray scenceArray = JSON.parseArray(scenceIdString);
|
|
|
sceneId = scenceArray.getInteger(0);
|
|
|
- //资源位置
|
|
|
- if (unitType == 7) {
|
|
|
- //程序化
|
|
|
- scenceArray = cleanPramgramErrorScence(scenceArray);
|
|
|
- }
|
|
|
unitParams.put("scene_id", scenceArray);
|
|
|
}
|
|
|
|
|
|
+ Integer campaignType = strategy.getCampaignType();
|
|
|
+ if (campaignType == 2) { // 提升应用安装
|
|
|
+ //应用ID
|
|
|
+ if (!Check.isNull(appId)) {
|
|
|
+ unitParams.put("app_id", appId);
|
|
|
+ }
|
|
|
+ // 优先从系统应用商店下载
|
|
|
+ if (null != strategy.getUseAppMarket()) {
|
|
|
+ unitParams.put("use_app_market", strategy.getUseAppMarket());
|
|
|
+ }
|
|
|
+ if (null != strategy.getAppStore() && !"".equals(strategy.getAppStore())) {
|
|
|
+ unitParams.put("app_store", JSON.parseArray(strategy.getAppStore()));
|
|
|
+ }
|
|
|
+ } else if (campaignType == 3) { // 获取电商下单
|
|
|
+
|
|
|
+ //url类型
|
|
|
+ if (!Check.isNull(strategy.getUrlType())) {
|
|
|
+ unitParams.put("url_type", strategy.getUrlType());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(strategy.getUrl())) {
|
|
|
+ unitParams.put("url", strategy.getUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (campaignType == 5) { //收集销售线索
|
|
|
+ //url类型
|
|
|
+ if (!Check.isNull(strategy.getWebUriType())) {
|
|
|
+ unitParams.put("web_uri_type", strategy.getWebUriType());
|
|
|
+ }
|
|
|
+ //url
|
|
|
+ if (!Check.isNull(strategy.getUrl())) {
|
|
|
+ unitParams.put("url", strategy.getUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (campaignType == 7) { // 提高应用活跃
|
|
|
+ // appId
|
|
|
+ if (!Check.isNull(appId)) {
|
|
|
+ unitParams.put("app_id", appId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // url
|
|
|
+ if (!Check.isNull(strategy.getUrl())) {
|
|
|
+ unitParams.put("url", strategy.getUrl());
|
|
|
+ }
|
|
|
+ //调起链接
|
|
|
+ if (!Check.isNull(strategy.getSchemaUri())) {
|
|
|
+ unitParams.put("schema_uri", strategy.getSchemaUri());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//投放开始时间
|
|
|
if (!Check.isNull(strategy.getBeginTime())) {
|
|
|
unitParams.put("begin_time", strategy.getBeginTime());
|
|
@@ -715,26 +799,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
if (!Check.isNull(strategy.getConvertId())) {
|
|
|
unitParams.put("convert_id", strategy.getConvertId());
|
|
|
}
|
|
|
- //url类型
|
|
|
- if (!Check.isNull(strategy.getUrlType())) {
|
|
|
- unitParams.put("url_type", strategy.getUrlType());
|
|
|
- }
|
|
|
- //url类型
|
|
|
- if (!Check.isNull(strategy.getWebUriType())) {
|
|
|
- unitParams.put("web_uri_type", strategy.getWebUriType());
|
|
|
- }
|
|
|
- //url
|
|
|
- if (!Check.isNull(strategy.getUrl())) {
|
|
|
- unitParams.put("url", strategy.getUrl());
|
|
|
- }
|
|
|
- //调起链接
|
|
|
- if (!Check.isNull(strategy.getSchemaUri())) {
|
|
|
- unitParams.put("schema_uri", strategy.getSchemaUri());
|
|
|
- }
|
|
|
- //应用ID
|
|
|
- if (!Check.isNull(appId)) {
|
|
|
- unitParams.put("app_id", appId);
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
//创意展现方式
|
|
|
if (!Check.isNull(strategy.getShowMode())) {
|
|
|
unitParams.put("show_mode", strategy.getShowMode());
|
|
@@ -1007,14 +1073,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;
|
|
@@ -1088,8 +1154,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");
|