|
@@ -8,16 +8,10 @@ import cn.com.ctop.common.module.utils.Check;
|
|
|
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.AiKuaishouAdvertiserStrategy;
|
|
|
-import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouStrategyMapCreative;
|
|
|
-import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
|
|
|
+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.IAiKuaiShouAppInfoService;
|
|
|
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
|
|
|
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouStrategyMapCreativeService;
|
|
|
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.*;
|
|
|
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.*;
|
|
@@ -27,6 +21,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -47,8 +42,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
@Autowired
|
|
|
private IKuaiShouVideoGetService videoGetService;
|
|
|
@Autowired
|
|
|
- private IAiKuaishouStrategyMapCreativeService mapCreativeService;
|
|
|
- @Autowired
|
|
|
private IMaterialCutFrameService materialCutFrameService;
|
|
|
@Autowired
|
|
|
private IKuaiShouImageGetService imageGetService;
|
|
@@ -57,7 +50,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
@Autowired
|
|
|
private IKuaishouAccountCreativeOverrunInfoService overrunInfoService;
|
|
|
@Autowired
|
|
|
+ private IAiKuaishouCampaignLevelOperationRecordService aiKuaishouCampaignLevelOperationRecordService;
|
|
|
+ @Autowired
|
|
|
private IAiKuaiShouAppInfoService appInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IAiKuaishouUnitLevelOperationRecordService unitLevelOperationRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IAiKuaishouCreativeLevelOperationRecordService creativeLevelOperationRecordService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 创建自定义创意
|
|
@@ -130,14 +130,23 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
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);
|
|
|
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());
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(),strategy);
|
|
|
if(videoCnt<=0){
|
|
|
return videoCnt;
|
|
|
}
|
|
@@ -178,14 +187,23 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
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);
|
|
|
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());
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(),strategy);
|
|
|
if(videoCnt<=0){
|
|
|
return 0L;
|
|
|
}
|
|
@@ -259,13 +277,22 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
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);
|
|
|
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);
|
|
|
- createProgramCreative(token, creativeParams);
|
|
|
+ createProgramCreative(token, creativeParams,strategy);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -297,13 +324,22 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
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);
|
|
|
if (unitCode != 0) {
|
|
|
log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
return;
|
|
|
}
|
|
|
Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+ unitLevelOperationRecord.setUnitId(unitId);
|
|
|
+ unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
|
|
|
JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
|
|
|
- createProgramCreative(token, creativeParams);
|
|
|
+ createProgramCreative(token, creativeParams,strategy);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -347,7 +383,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void createProgramCreative(CtopOauthToken token, JSONObject creativeParams) {
|
|
|
+ private void createProgramCreative(CtopOauthToken token, JSONObject creativeParams,AiKuaishouAdvertiserStrategy strategy) {
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Content-Type", "application/json");
|
|
|
headers.put("Access-Token", token.getAccessToken());
|
|
@@ -495,7 +531,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType,Integer createType,AiKuaiShouAppInfo appInfo) {
|
|
|
JSONArray campaignList;
|
|
|
- if (null != checkType && "ALL_CAMPAIGN".equals(checkType)) {
|
|
|
+ if ("ALL_CAMPAIGN".equals(checkType)) {
|
|
|
campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
|
|
|
} else {
|
|
|
campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(), 1);
|
|
@@ -521,15 +557,19 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(), token.getAccountId(), campaignParams);
|
|
|
Integer code = (Integer) campaignCreateResult.get("code");
|
|
|
String message = (String) campaignCreateResult.get("message");
|
|
|
+ AiKuaishouCampaignLevelOperationRecord record = new AiKuaishouCampaignLevelOperationRecord(strategy,null,code,message);
|
|
|
+ record.setCampaignName(campaignName);
|
|
|
if (code != 0) {
|
|
|
- //TODO 写入日志信息表
|
|
|
log.info("计划创建失败=>message:{}", message);
|
|
|
+ aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
|
|
|
return null;
|
|
|
}
|
|
|
- return (Long) campaignCreateResult.get("campaignId");
|
|
|
+ Long campaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
+ record.setCampaignId(campaignId);
|
|
|
+ aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
|
|
|
+ return campaignId;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, AiKuaishouAdvertiserStrategy strategy,
|
|
|
String unitName, Long appId) {
|
|
|
// 拼装创建组的入参 json
|
|
@@ -909,14 +949,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
|
|
|
Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
|
|
|
- int imageNumber) {
|
|
|
+ int imageNumber,AiKuaishouAdvertiserStrategy strategy) {
|
|
|
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);
|
|
|
+ createCreative(token, creativeParams, campaignId, unitId, i+1, videoItem,strategy);
|
|
|
imageNumber --;
|
|
|
if (imageNumber<=0) {
|
|
|
break;
|
|
@@ -990,23 +1030,26 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
|
|
|
|
|
|
|
|
|
private void createCreative(CtopOauthToken token, JSONObject creativeParams, Long campaignId, Long unitId,
|
|
|
- int creativeCnt, KuaiShouVideoGet videoGet) {
|
|
|
- creativeParams.put("creative_name", "自定义创意_" + creativeCnt);
|
|
|
+ int creativeCnt, KuaiShouVideoGet videoGet,AiKuaishouAdvertiserStrategy strategy) {
|
|
|
+ String 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");
|
|
|
String creativeMessage = (String) creativeCreateResult.get("message");
|
|
|
+ AiKuaishouCreativeLevelOperationRecord record = new AiKuaishouCreativeLevelOperationRecord();
|
|
|
+ BeanUtils.copyProperties(strategy,record);
|
|
|
+ record.setCreativeName(creativeName);
|
|
|
+ record.setStatus(creativeCode);
|
|
|
+ record.setMessage(creativeMessage);
|
|
|
+ record.setCreateTime(new Date());
|
|
|
if (creativeCode != 0) {
|
|
|
+ creativeLevelOperationRecordService.saveOrUpdate(record);
|
|
|
log.info("创意创建失败=>message:{}", creativeMessage);
|
|
|
return;
|
|
|
}
|
|
|
Long creativeId = (Long) creativeCreateResult.get("creativeId");
|
|
|
- AiKuaishouStrategyMapCreative mapCreative = new AiKuaishouStrategyMapCreative();
|
|
|
- mapCreative.setAccountId(token.getAccountId());
|
|
|
- mapCreative.setCampaignId(campaignId);
|
|
|
- mapCreative.setUnitId(unitId);
|
|
|
- mapCreative.setVideoSignature(videoGet.getSignature());
|
|
|
- mapCreative.setCreativeId(creativeId);
|
|
|
- mapCreativeService.save(mapCreative);
|
|
|
+ record.setCreativeId(creativeId);
|
|
|
+ creativeLevelOperationRecordService.saveOrUpdate(record);
|
|
|
}
|
|
|
|
|
|
/**
|