|
@@ -12,11 +12,9 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouNewCreateCampaign;
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouStrategyMapCreativeService;
|
|
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.KuaiShouImageGet;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouVideoRelateCreatives;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
|
|
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;
|
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.*;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -225,6 +223,94 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouVideoRelateCreativesService relateCreativesService;
|
|
|
|
+ @Override
|
|
|
|
+ public void kuaishouAiAddNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate) {
|
|
|
|
+ Long accountId = targetTemplate.getAccountId();
|
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
|
+ if(null == token){
|
|
|
|
+ log.info("token获取失败=>accountId:{}",accountId);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(),DateUtils.date2Str());
|
|
|
|
+
|
|
|
|
+ //获取创意关联数为0的素材
|
|
|
|
+ List<KuaishouVideoRelateCreatives> kuaishouVideoRelateCreatives = relateCreativesService.listByParams(accountId);
|
|
|
|
+ if(null == kuaishouVideoRelateCreatives||kuaishouVideoRelateCreatives.isEmpty()){
|
|
|
|
+ log.info("账户:{}, 不存在未创建创意素材",accountId);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //2、判断该账户下当天有没有“上新”计划,没有则创建一个“上新”计划
|
|
|
|
+ JSONArray campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(),1);
|
|
|
|
+ boolean isHaveNewCampaign = 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("素材上新")){
|
|
|
|
+ isHaveNewCampaign = true;
|
|
|
|
+ newCampaignId = jsonObject.getLong("campaign_id");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 不存在“上新”计划,则创建一个计划
|
|
|
|
+ if (!isHaveNewCampaign){
|
|
|
|
+ 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(KuaishouVideoRelateCreatives videoItem: kuaishouVideoRelateCreatives){
|
|
|
|
+ unitCnt ++;
|
|
|
|
+ KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(videoItem.getPhotoId());
|
|
|
|
+ if(null == videoGet){
|
|
|
|
+ log.info("未获取到视频信息=>photoId:{}",videoItem.getPhotoId());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 每个组,搭配5个创意
|
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoGet.getSignature());
|
|
|
|
+ List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoGet.getSignature());
|
|
|
|
+ if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
|
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}",videoGet.getSignature());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ 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");
|
|
|
|
+ JSONObject creativeParams = creativeParams(token, unitId, videoGet, targetTemplate);
|
|
|
|
+ createCreativeByImage(cutFrameList, orgFrameList,token, creativeParams, newCampaignId, unitId, videoGet,targetTemplate.getImageNumber());
|
|
|
|
+ videoItem.setCreativeCount(5);
|
|
|
|
+ relateCreativesService.updateById(videoItem);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAccountTargetTemplate targetTemplate){
|
|
private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAccountTargetTemplate targetTemplate){
|
|
JSONObject creativeParams = new JSONObject();
|
|
JSONObject creativeParams = new JSONObject();
|