|
@@ -12,6 +12,7 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouNewCreateCampaign;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouStrategyMapCreativeService;
|
|
|
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.mapper.KuaiShouVideoGetMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
@@ -48,6 +49,9 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
|
|
|
private IKuaiShouImageGetService imageGetService;
|
|
|
@Autowired
|
|
|
private IKuaiShouMaterialUploadService materialUploadService;
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouVideoGetMapper videoGetMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void kuaishouAiAdsNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate) {
|
|
@@ -101,7 +105,7 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
|
|
|
String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
|
|
|
JSONObject campaignParams = new JSONObject();
|
|
|
campaignParams.put("advertiser_id",token.getAccountId());
|
|
|
- String campaignName = "户14-上下滑&信息流" + "-素材上新-"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
|
|
|
+ String campaignName = targetTemplate.getTitlePrefix() + "素材上新"+ targetTemplate.getTitleMiddle()+ timestamp;
|
|
|
campaignParams.put("campaign_name",campaignName);
|
|
|
campaignParams.put("type",Integer.parseInt(targetTemplate.getMarketingGoal()));
|
|
|
campaignParams.put("day_budget",0L);
|
|
@@ -117,7 +121,7 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
|
|
|
|
|
|
//3、在“上新”计划中新增广告组,一个素材搭配5张封面,组成一个广告组
|
|
|
String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
|
- String unitNamePrefix = "户14-上下滑&信息流" + "-素材上新-"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
|
|
|
+ String unitNamePrefix = targetTemplate.getTitlePrefix() + "素材上新"+ targetTemplate.getTitleMiddle()+ timestamp;
|
|
|
int unitCnt = 0;
|
|
|
for(KuaiShouVideoGet videoItem: newVideos){
|
|
|
unitCnt ++;
|
|
@@ -144,6 +148,85 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void kuaishouAiAdsHotMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate) {
|
|
|
+ Long accountId = targetTemplate.getAccountId();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
+ if(null == token){
|
|
|
+ log.info("token获取失败=>accountId:{}",accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int days = 14;
|
|
|
+ int highQualityVideoCnt = 100;
|
|
|
+ List<KuaiShouVideoGet>highQualityVideos = videoGetMapper.getHighQualityVideo(accountId,days,highQualityVideoCnt);
|
|
|
+ if (null == highQualityVideos||highQualityVideos.isEmpty()){
|
|
|
+ log.info("此项目下无视频");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(),1);
|
|
|
+ boolean isHaveHotCampaign = false;
|
|
|
+ Long newCampaignId = 0L;
|
|
|
+ if (null!=campaignList&&campaignList.size()>0){
|
|
|
+ for(int i = 0;i<campaignList.size();i++){
|
|
|
+ JSONObject jsonObject = campaignList.getJSONObject(i);
|
|
|
+ if (jsonObject.getString("campaign_name").contains("爆量素材")){
|
|
|
+ isHaveHotCampaign = true;
|
|
|
+ newCampaignId = jsonObject.getLong("campaign_id");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isHaveHotCampaign){
|
|
|
+ Date campaignDate = new Date();
|
|
|
+ String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
|
|
|
+ JSONObject campaignParams = new JSONObject();
|
|
|
+ campaignParams.put("advertiser_id",token.getAccountId());
|
|
|
+ String campaignName = targetTemplate.getTitlePrefix() + "爆量素材"+ targetTemplate.getTitleMiddle() + timestamp;
|
|
|
+ campaignParams.put("campaign_name",campaignName);
|
|
|
+ campaignParams.put("type",Integer.parseInt(targetTemplate.getMarketingGoal()));
|
|
|
+ campaignParams.put("day_budget",0L);
|
|
|
+ Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(), token.getAccountId(), campaignParams);
|
|
|
+ Integer code = (Integer) campaignCreateResult.get("code");
|
|
|
+ String message = (String) campaignCreateResult.get("message");
|
|
|
+ if(code != 0 ){
|
|
|
+ log.info("计划创建失败=>message:{}",message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ newCampaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
+ }
|
|
|
+
|
|
|
+ //3、在“上新”计划中新增广告组,一个素材搭配5张封面,组成一个广告组
|
|
|
+ String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
|
+ String unitNamePrefix = targetTemplate.getTitlePrefix() + "爆量素材"+ targetTemplate.getTitleMiddle()+timestamp;
|
|
|
+ int unitCnt = 0;
|
|
|
+ for(KuaiShouVideoGet videoItem: highQualityVideos){
|
|
|
+ unitCnt ++;
|
|
|
+ String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, targetTemplate, unitName);
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams,1);
|
|
|
+ Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ String unitMessage = (String) unitCreateResult.get("message");
|
|
|
+ if(unitCode != 0 ){
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+
|
|
|
+ // 每个组,搭配5个创意
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}",videoItem.getSignature());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject creativeParams = creativeParams(token, unitId, videoItem, targetTemplate);
|
|
|
+ createCreativeByImage(cutFrameList, orgFrameList,token, creativeParams, newCampaignId, unitId, videoItem,targetTemplate.getImageNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAccountTargetTemplate targetTemplate){
|