|
@@ -12,9 +12,7 @@ import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.modules.bytedance.advertise.dockapi.MarketingService;
|
|
|
import org.jeecg.modules.bytedance.advertise.entity.*;
|
|
|
import org.jeecg.modules.bytedance.advertise.enums.BytedanceCreativeMatTypeEnum;
|
|
|
-import org.jeecg.modules.bytedance.advertise.mapper.AiBytedanceAdvertiserStrategyMapper;
|
|
|
-import org.jeecg.modules.bytedance.advertise.mapper.BytedanceAreaInfoMapper;
|
|
|
-import org.jeecg.modules.bytedance.advertise.mapper.RuleDataAccountMapper;
|
|
|
+import org.jeecg.modules.bytedance.advertise.mapper.*;
|
|
|
import org.jeecg.modules.bytedance.advertise.service.*;
|
|
|
import org.jeecg.modules.bytedance.advertise.vo.AdConvertQueryVo;
|
|
|
import org.jeecg.modules.bytedance.advertise.vo.AdGroupSearchVo;
|
|
@@ -27,6 +25,7 @@ import org.jeecg.modules.bytedance.common.entity.MaterialInfo;
|
|
|
import org.jeecg.modules.bytedance.common.entity.UserAllocation;
|
|
|
import org.jeecg.modules.bytedance.common.service.*;
|
|
|
import org.jeecg.modules.bytedance.common.utils.Check;
|
|
|
+import org.jeecg.modules.bytedance.common.utils.GetCampaignNum;
|
|
|
import org.jeecg.modules.bytedance.common.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -72,15 +71,15 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
private IByteDanceVideoInfoService videoInfoService;
|
|
|
@Autowired
|
|
|
private MarketingService marketingService;
|
|
|
+ @Resource
|
|
|
+ ByteDanceGeneralCopywriterMapper byteDanceGeneralCopywriterMapper;
|
|
|
+ @Resource
|
|
|
+ BytedanceMaterialRejectReasonMapper bytedanceMaterialRejectReasonMapper;
|
|
|
+ @Autowired
|
|
|
+ IAiBytedanceAutocreateLogService iBytedanceAutocreateLogService;
|
|
|
|
|
|
@Override
|
|
|
- public Long createCreative(AiBytedanceAdvertiserStrategy strategy, Integer createType, Long videoCnt, String openUrl) {
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(strategy.getAccountId()+"");
|
|
|
- if (null == token) {
|
|
|
- log.info("token获取失败=>accountId:{}", strategy.getAccountId());
|
|
|
- return videoCnt;
|
|
|
- }
|
|
|
-
|
|
|
+ public Long createCreative(CtopOauthToken token, AiBytedanceAdvertiserStrategy strategy, Integer createType, Long videoCnt, String openUrl) {
|
|
|
UserAllocation userAllocation = userAllocationService.getByAccountId(strategy.getAccountId());
|
|
|
if(null == userAllocation||userAllocation.getAccountStatus()!=0){
|
|
|
log.info("此账户不存在或者已经被关闭=>accountId:{}", token.getAccountId());
|
|
@@ -100,17 +99,26 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
if(timeEnd != 0){
|
|
|
endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
|
|
|
}
|
|
|
- List<ByteDanceVideoInfo> videoInfos = getVideoInfoByCreateType(userAllocation.getProjectId(),strategy,startTime,endTime,createType,videoCnt);
|
|
|
+ List<ByteDanceVideoInfo> videoInfos = getvideoOrImageInfoByCreateType(userAllocation.getProjectId(),strategy,startTime,endTime,createType,videoCnt);
|
|
|
if(null == videoInfos||videoInfos.isEmpty()){
|
|
|
log.info("获取{}视频素材为空=>accountId:{}",BytedanceCreativeMatTypeEnum.getNameByType(createType+""),token.getAccountId());
|
|
|
return videoCnt;
|
|
|
}
|
|
|
- log.info("获取{}视频素材个数:{}=>accountId:{}",BytedanceCreativeMatTypeEnum.getNameByType(createType+""),videoInfos.size(),token.getAccountId());
|
|
|
-
|
|
|
+ log.info("获取{}素材个数:{}=>accountId:{}",BytedanceCreativeMatTypeEnum.getNameByType(createType+""),videoInfos.size(),token.getAccountId());
|
|
|
for (ByteDanceVideoInfo video:videoInfos) {
|
|
|
+ //判断此素材为视频
|
|
|
+ if ("video".equalsIgnoreCase(video.getMaterialType())){
|
|
|
+ //视频是否是低质视频,为1跳过
|
|
|
+ Integer isLowQuality = bytedanceMaterialRejectReasonMapper.getIsLowQualityByVideoId(video.getVid());
|
|
|
+ if(!Check.isNull(isLowQuality) && 1 == isLowQuality){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Integer useDplinkIndex = strategy.getDpLinkIndexUsed();
|
|
|
if(null==useDplinkIndex||useDplinkIndex.equals(0)){
|
|
|
- AiBytedanceAdDplinkInfo adDplinkInfo = adDplinkInfoService.getlatestDpLinkInfo(strategy.getId(),strategy.getAccountId(),1);
|
|
|
+ //查看已使用的dp链接
|
|
|
+ AiBytedanceAdDplinkInfo adDplinkInfo = adDplinkInfoService.getlatestDpLinkInfo(strategy.getId(),strategy.getAccountId(),strategy.getCreativeImageMode(),1);
|
|
|
if(null == adDplinkInfo){
|
|
|
adDplinkInfo = new AiBytedanceAdDplinkInfo();
|
|
|
if("FIX".equalsIgnoreCase(strategy.getAdBidCreateType())){
|
|
@@ -121,6 +129,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
adDplinkInfo.setDpLinkIndex(strategy.getDpLinkStartIndex());
|
|
|
}else{
|
|
|
adDplinkInfo.setId(null);
|
|
|
+ adDplinkInfo.setCreateTime(new Date());
|
|
|
adDplinkInfo.setDpLinkIndex(adDplinkInfo.getDpLinkIndex()+1);
|
|
|
}
|
|
|
|
|
@@ -134,7 +143,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
return videoCnt;
|
|
|
}
|
|
|
//计划名称
|
|
|
- String adName = getAdName(strategy,null,video);
|
|
|
+ String adName = getAdName(strategy,null,video,userAllocation.getProjectId());
|
|
|
+ //截取 计划名称
|
|
|
+ adName = StringUtils.adNameSubMaterial(adName);
|
|
|
//计算本次出价
|
|
|
BigDecimal currentCpaBid = StringUtils.getRandomAdCpaBid(strategy.getAdBidCreateType(),strategy.getAdMaxBid(),strategy.getAdMinBid(),strategy.getAdStepBid(),adDplinkInfo.getAdBid(),strategy.getAdCpaBid());
|
|
|
JSONObject adParams = getAdParams(strategy,adName,campaignId,currentCpaBid);
|
|
@@ -142,22 +153,36 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
if(null == adId){
|
|
|
continue;
|
|
|
}
|
|
|
- adDplinkInfo.setAdId(adId);
|
|
|
- adDplinkInfo.setAccountId(strategy.getAccountId());
|
|
|
- adDplinkInfo.setStatus(1);
|
|
|
- adDplinkInfo.setStrategyId(strategy.getId());
|
|
|
- adDplinkInfoService.save(adDplinkInfo);
|
|
|
+
|
|
|
//3:创建创意
|
|
|
JSONObject creativeParams = getCreativeParams(strategy,adId,video,token);
|
|
|
- log.info("创意创建参数:{}",creativeParams);
|
|
|
+ log.info("账户id:{};创意创建参数:{}",strategy.getAccountId(),creativeParams);
|
|
|
JSONObject creativeObject = marketingService.creativeCreate(token,adId,creativeParams);
|
|
|
if(null!=creativeObject.getInteger("code")&&creativeObject.getInteger("code")!=0){
|
|
|
+ List<Long> adIds = new ArrayList<>();
|
|
|
+ adIds.add(adId);
|
|
|
+ marketingService.updPlanStatus(token,adIds,"delete");
|
|
|
String message = creativeObject.getString("message");
|
|
|
Integer code = creativeObject.getInteger("code");
|
|
|
//创建创意失败
|
|
|
- log.info("创意创建失败:code==>{};message==>{}",code,message);
|
|
|
+ log.info("账户id:{};创意创建失败:code==>{};message==>{}",strategy.getAccountId(),code,message);
|
|
|
+ AiBytedanceAutocreateLog iBytedanceAutocreateLog = new AiBytedanceAutocreateLog(
|
|
|
+ strategy.getAccountId(),
|
|
|
+ "创意创建失败",
|
|
|
+ code,
|
|
|
+ message,
|
|
|
+ "marketingService.creativeCreate => token:"+ token.toString()+",adIds:"+adIds.toString()+",creativeParams:"+creativeParams.toJSONString());
|
|
|
+ iBytedanceAutocreateLogService.save(iBytedanceAutocreateLog);
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
+ adDplinkInfo.setAdId(adId);
|
|
|
+ adDplinkInfo.setAccountId(strategy.getAccountId());
|
|
|
+ adDplinkInfo.setStatus(1);
|
|
|
+ adDplinkInfo.setStrategyId(strategy.getId());
|
|
|
+ adDplinkInfo.setImageMode(strategy.getCreativeImageMode());
|
|
|
+ adDplinkInfoService.save(adDplinkInfo);
|
|
|
+
|
|
|
BytedanceAiVideoCreativeLog creativeLog = new BytedanceAiVideoCreativeLog(strategy,adId,campaignId,video);
|
|
|
videoCreativeLogService.saveOrUpdate(creativeLog);
|
|
|
videoCnt --;
|
|
@@ -166,7 +191,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
}
|
|
|
}else{
|
|
|
Long dpIndex ;
|
|
|
- AiBytedanceAdDplinkInfo adDplinkInfo = adDplinkInfoService.getlatestDpLinkInfo(strategy.getId(),strategy.getAccountId(),1);
|
|
|
+ AiBytedanceAdDplinkInfo adDplinkInfo = adDplinkInfoService.getlatestDpLinkInfo(strategy.getId(),strategy.getAccountId(),strategy.getCreativeImageMode(),1);
|
|
|
if(null == adDplinkInfo){
|
|
|
adDplinkInfo = new AiBytedanceAdDplinkInfo();
|
|
|
if("FIX".equalsIgnoreCase(strategy.getAdBidCreateType())){
|
|
@@ -177,11 +202,14 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
adDplinkInfo.setDpLinkIndex(strategy.getDpLinkStartIndex());
|
|
|
}else{
|
|
|
adDplinkInfo.setId(null);
|
|
|
+ adDplinkInfo.setCreateTime(new Date());
|
|
|
adDplinkInfo.setDpLinkIndex(adDplinkInfo.getDpLinkIndex()+1);
|
|
|
}
|
|
|
dpIndex = adDplinkInfo.getDpLinkIndex();
|
|
|
- if(dpIndex>strategy.getDpLinkEndIndex()){
|
|
|
- log.info("此账户策略创建结束=>账户id:{};策略id:{}", token.getAccountId(),strategy.getId());
|
|
|
+ // 超出下标范围
|
|
|
+ // 已使用dp链接 < 账户配置结束下标 || 已使用dp链接 > 结束下标
|
|
|
+ if( dpIndex < strategy.getDpLinkStartIndex() || dpIndex > strategy.getDpLinkEndIndex()){
|
|
|
+ log.info("策略创建结束===dp链接超过了限制===>账户id:{};策略id:{}", token.getAccountId(),strategy.getId());
|
|
|
return 0L;
|
|
|
}
|
|
|
//组名称
|
|
@@ -194,7 +222,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
strategy.setAdOpenUrl(openUrl.replace("{{dp链接下标}}",dpIndex.toString()));
|
|
|
String dplinkCode = StringUtils.getParamFromUrl(strategy.getAdOpenUrl(),"bc_fl_src");
|
|
|
//计划名称
|
|
|
- String adName = getAdName(strategy,dplinkCode,video);
|
|
|
+ String adName = getAdName(strategy,dplinkCode,video,userAllocation.getProjectId());
|
|
|
+ //截取 计划名称
|
|
|
+ adName = StringUtils.adNameSubMaterial(adName);
|
|
|
//计算本次出价
|
|
|
BigDecimal currentCpaBid = StringUtils.getRandomAdCpaBid(strategy.getAdBidCreateType(),strategy.getAdMaxBid(),strategy.getAdMinBid(),strategy.getAdStepBid(),adDplinkInfo.getAdBid(),strategy.getAdCpaBid());
|
|
|
adDplinkInfo.setAdBid(currentCpaBid);
|
|
@@ -203,21 +233,35 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
if(null == adId){
|
|
|
continue;
|
|
|
}
|
|
|
- adDplinkInfo.setAdId(adId);
|
|
|
- adDplinkInfo.setAccountId(strategy.getAccountId());
|
|
|
- adDplinkInfo.setStatus(1);
|
|
|
- adDplinkInfo.setStrategyId(strategy.getId());
|
|
|
- adDplinkInfoService.save(adDplinkInfo);
|
|
|
//3:创建创意
|
|
|
JSONObject creativeParams = getCreativeParams(strategy,adId,video,token);
|
|
|
log.info("创意创建参数:{}",creativeParams);
|
|
|
JSONObject creativeObject = marketingService.creativeCreate(token,adId,creativeParams);
|
|
|
log.info("创意创建返回数据:{}",creativeObject);
|
|
|
if(null!=creativeObject.getInteger("code")&&creativeObject.getInteger("code")!=0){
|
|
|
+ List<Long> adIds = new ArrayList<>();
|
|
|
+ adIds.add(adId);
|
|
|
+ marketingService.updPlanStatus(token,adIds,"delete");
|
|
|
String message = creativeObject.getString("message");
|
|
|
Integer code = creativeObject.getInteger("code");
|
|
|
+ //创建创意失败
|
|
|
+ log.info("账户id:{};创意创建失败:code==>{};message==>{}",strategy.getAccountId(),code,message);
|
|
|
+ AiBytedanceAutocreateLog iBytedanceAutocreateLog = new AiBytedanceAutocreateLog(
|
|
|
+ strategy.getAccountId(),
|
|
|
+ "创意创建失败",
|
|
|
+ code,
|
|
|
+ message,
|
|
|
+ "marketingService.creativeCreate => token:"+ token.toString()+",adIds:"+adIds.toString()+",creativeParams:"+creativeParams.toJSONString());
|
|
|
+ iBytedanceAutocreateLogService.save(iBytedanceAutocreateLog);
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
+ adDplinkInfo.setAdId(adId);
|
|
|
+ adDplinkInfo.setAccountId(strategy.getAccountId());
|
|
|
+ adDplinkInfo.setStatus(1);
|
|
|
+ adDplinkInfo.setStrategyId(strategy.getId());
|
|
|
+ adDplinkInfo.setImageMode(strategy.getCreativeImageMode());
|
|
|
+ adDplinkInfoService.save(adDplinkInfo);
|
|
|
BytedanceAiVideoCreativeLog creativeLog = new BytedanceAiVideoCreativeLog(strategy,adId,campaignId,video);
|
|
|
videoCreativeLogService.saveOrUpdate(creativeLog);
|
|
|
videoCnt --;
|
|
@@ -230,15 +274,20 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
}
|
|
|
private JSONObject getCreativeParams(AiBytedanceAdvertiserStrategy strategy, Long adId,ByteDanceVideoInfo videoInfo,CtopOauthToken token) {
|
|
|
JSONObject params = new JSONObject();
|
|
|
- params.put("advertiser_id",strategy.getAccountId());
|
|
|
- params.put("ad_id",adId);
|
|
|
+ params.put("advertiser_id", strategy.getAccountId());
|
|
|
+ params.put("ad_id", adId);
|
|
|
String inventoryType = strategy.getCreativeInventoryType();
|
|
|
- if(null!=inventoryType&&!"".equals(inventoryType)){
|
|
|
+ if ("CREATIVE_IMAGE_MODE_UNION_SPLASH".equalsIgnoreCase(strategy.getCreativeImageMode())) {
|
|
|
+ params.put("inventory_type", new String[]{"INVENTORY_UNION_SPLASH_SLOT"});
|
|
|
+ } else {
|
|
|
+ if (null != inventoryType && !"".equals(inventoryType)) {
|
|
|
String[] inventoryTypeString = inventoryType.split(",");
|
|
|
- if(inventoryTypeString.length>0){
|
|
|
- params.put("inventory_type",inventoryTypeString);
|
|
|
+ if (inventoryTypeString.length > 0) {
|
|
|
+ params.put("inventory_type", inventoryTypeString);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
Integer smartInventory = strategy.getCreativeSmartInventory();
|
|
|
if(null!=smartInventory&&smartInventory!=0){
|
|
|
params.put("smart_inventory",smartInventory);
|
|
@@ -263,27 +312,37 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
//视频素材
|
|
|
JSONArray imageArray = new JSONArray();
|
|
|
JSONObject imageObject = new JSONObject();
|
|
|
- //视频类型
|
|
|
- if(videoInfo.getType() == 1){
|
|
|
- //竖版视频
|
|
|
- imageObject.put("image_mode","CREATIVE_IMAGE_MODE_VIDEO_VERTICAL");
|
|
|
- }
|
|
|
- if(videoInfo.getType() == 2){
|
|
|
- //横版视频
|
|
|
- imageObject.put("image_mode","CREATIVE_IMAGE_MODE_VIDEO");
|
|
|
- }
|
|
|
- imageObject.put("video_id",videoInfo.getVid());
|
|
|
- //获取视频封面id
|
|
|
- String imageId = getSuggestImageId(token,videoInfo.getVid());
|
|
|
- if(!Check.isNull(imageId)){
|
|
|
- imageObject.put("image_id",imageId);
|
|
|
+
|
|
|
+ if ("video".equalsIgnoreCase(videoInfo.getMaterialType())){
|
|
|
+ //视频类型
|
|
|
+ //1-竖版视频 2-横版视频
|
|
|
+// String imageMode = videoInfo.getType() == 1 ? "CREATIVE_IMAGE_MODE_VIDEO_VERTICAL" : "CREATIVE_IMAGE_MODE_VIDEO";
|
|
|
+ String imageMode = strategy.getCreativeImageMode();
|
|
|
+ imageObject.put("image_mode",imageMode);
|
|
|
+ imageObject.put("video_id",videoInfo.getVid());
|
|
|
+ //获取视频封面id
|
|
|
+ String imageId = getSuggestImageId(token,videoInfo.getVid());
|
|
|
+ if(!Check.isNull(imageId)){
|
|
|
+ imageObject.put("image_id",imageId);
|
|
|
+ }
|
|
|
+ }else if ("image".equalsIgnoreCase(videoInfo.getMaterialType())){
|
|
|
+ //1-大图横图; 2-大图竖图
|
|
|
+// String imageMode = videoInfo.getType() == 1 ? "CREATIVE_IMAGE_MODE_LARGE" : "CREATIVE_IMAGE_MODE_LARGE_VERTICAL";
|
|
|
+ String imageMode = strategy.getCreativeImageMode();
|
|
|
+ imageObject.put("image_mode",imageMode);
|
|
|
+ imageObject.put("image_ids",new String[]{videoInfo.getId()});
|
|
|
}
|
|
|
+
|
|
|
imageArray.add(imageObject);
|
|
|
params.put("image_list",imageArray);
|
|
|
JSONArray titleArray = new JSONArray();
|
|
|
- List<BytedanceVideoSlogenInfo>slogenInfos = slogenInfoService.listByParams(videoInfo.getSignature(),1);
|
|
|
+ List<BytedanceVideoSlogenInfo> slogenInfos = slogenInfoService.listByParams(videoInfo.getSignature(),1);
|
|
|
+ //使用指定文案
|
|
|
if(!Check.isNull(slogenInfos)){
|
|
|
- slogenInfos.forEach(slogenInfo->{
|
|
|
+ for (BytedanceVideoSlogenInfo slogenInfo:slogenInfos) {
|
|
|
+ if(titleArray.size() >= 10){ //接口中是要求一个视频最多10个标题
|
|
|
+ break;
|
|
|
+ }
|
|
|
JSONObject titleObject = new JSONObject();
|
|
|
titleObject.put("title",slogenInfo.getSlogan());
|
|
|
String creativeWordsIds = slogenInfo.getCreativeWordIds();
|
|
@@ -294,8 +353,48 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
}
|
|
|
}
|
|
|
titleArray.add(titleObject);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 视频 指定文案不够的时候 使用通用文案 最多3条
|
|
|
+ if ("video".equalsIgnoreCase(videoInfo.getMaterialType())){
|
|
|
+ List<ByteDanceGeneralCopywriter> byteDanceGeneralCopywriter = byteDanceGeneralCopywriterMapper.getRandThree(strategy.getAccountId());
|
|
|
+ if(!Check.isNull(byteDanceGeneralCopywriter)){
|
|
|
+ for(int i = 0; i < byteDanceGeneralCopywriter.size(); i++){
|
|
|
+ if(titleArray.size() >= 10){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ JSONObject titleObject = new JSONObject();
|
|
|
+ titleObject.put("title",byteDanceGeneralCopywriter.get(i).getTextCopywriter());
|
|
|
+ String creativeWordsIds = byteDanceGeneralCopywriter.get(i).getCreativeWordIds();
|
|
|
+ if(null!=creativeWordsIds&&!creativeWordsIds.trim().equals("")){
|
|
|
+ JSONArray creativeWordsArray = JSON.parseArray(creativeWordsIds);
|
|
|
+ if(null!=creativeWordsArray&&!creativeWordsArray.isEmpty()){
|
|
|
+ titleObject.put("creative_word_ids",creativeWordsArray);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ titleArray.add(titleObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 图片 使用通用文案 最多10条
|
|
|
+ }else if ("image".equalsIgnoreCase(videoInfo.getMaterialType())){
|
|
|
+ List<ByteDanceGeneralCopywriter> byteDanceGeneralCopywriterList = byteDanceGeneralCopywriterMapper.getRandTen(strategy.getAccountId());
|
|
|
+ if(!Check.isNull(byteDanceGeneralCopywriterList)){
|
|
|
+ for (ByteDanceGeneralCopywriter byteDanceGeneralCopywriter : byteDanceGeneralCopywriterList){
|
|
|
+ JSONObject titleObject = new JSONObject();
|
|
|
+ titleObject.put("title",byteDanceGeneralCopywriter.getTextCopywriter());
|
|
|
+ String creativeWordsIds = byteDanceGeneralCopywriter.getCreativeWordIds();
|
|
|
+ if(null!=creativeWordsIds&&!creativeWordsIds.trim().equals("")){
|
|
|
+ JSONArray creativeWordsArray = JSON.parseArray(creativeWordsIds);
|
|
|
+ if(null!=creativeWordsArray&&!creativeWordsArray.isEmpty()){
|
|
|
+ titleObject.put("creative_word_ids",creativeWordsArray);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ titleArray.add(titleObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(!Check.isNull(titleArray)){
|
|
|
params.put("title_list",titleArray);
|
|
|
}
|
|
@@ -339,6 +438,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
params.put("action_text",actionText);
|
|
|
}
|
|
|
|
|
|
+ //搭配试玩素材url
|
|
|
String playableUrl = strategy.getCreativePlayableUrl();
|
|
|
if(!Check.isNull(playableUrl)){
|
|
|
params.put("playable_url",playableUrl);
|
|
@@ -464,8 +564,15 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
|
|
|
private Long createAdInfo(CtopOauthToken token, AiBytedanceAdvertiserStrategy strategy, JSONObject adParams) {
|
|
|
Result result = marketingService.createAdvertiserPlan(token,adParams,strategy);
|
|
|
+ System.out.println(result);
|
|
|
if(result.getCode()!=0){
|
|
|
- //TODO 计划创建异常 后续需要加日志
|
|
|
+ AiBytedanceAutocreateLog iBytedanceAutocreateLog = new AiBytedanceAutocreateLog(
|
|
|
+ strategy.getAccountId(),
|
|
|
+ "计划创建异常",
|
|
|
+ result.getCode(),
|
|
|
+ result.getMessage(),
|
|
|
+ adParams.toJSONString());
|
|
|
+ iBytedanceAutocreateLogService.save(iBytedanceAutocreateLog);
|
|
|
return null;
|
|
|
}
|
|
|
return (Long)result.getResult();
|
|
@@ -480,7 +587,12 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
//竞价策略 默认优先跑量
|
|
|
params.put("flow_control_mode","FLOW_CONTROL_MODE_FAST");
|
|
|
//投放范围
|
|
|
- params.put("delivery_range",strategy.getAdDeliveryRange());
|
|
|
+ if(null!=strategy.getAdDeliveryRange()&&!"".equals(strategy.getAdDeliveryRange().trim())){
|
|
|
+ params.put("delivery_range",strategy.getAdDeliveryRange());
|
|
|
+ if(!"UNION".equals(strategy.getAdDeliveryRange())){
|
|
|
+ params.put("feed_delivery_search","DISABLED");
|
|
|
+ }
|
|
|
+ }
|
|
|
if(!Check.isNull(strategy.getAdUnionVideoType())){
|
|
|
params.put("union_video_type",strategy.getAdUnionVideoType());
|
|
|
}
|
|
@@ -489,7 +601,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
if(!Check.isNull(strategy.getAdDownloadUrl())){
|
|
|
params.put("download_url",strategy.getAdDownloadUrl());
|
|
|
}
|
|
|
- if(!Check.isNull(strategy.getAdPackage())){
|
|
|
+ if(!Check.isNull(strategy.getAdPackage())&&!strategy.getAdPackage().equals("NONE")){
|
|
|
params.put("package",strategy.getAdPackage());
|
|
|
}
|
|
|
//params.put("download_url","https://apps.bytesfield.com/download/basic/cur/1c728178004c8d4d6c83444a05c414c1a1cfae48");
|
|
@@ -688,6 +800,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
params.put("exclude_flow_package",excludeFlowPackage);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if(!Check.isNull(strategy.getAdPlatform())){
|
|
|
String[] platform = strategy.getAdPlatform().split(",");
|
|
|
if(platform.length>0){
|
|
@@ -795,6 +908,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
if(!Check.isNull(strategy.getAdAutoExtendEnabled())){
|
|
|
params.put("auto_extend_enabled",strategy.getAdAutoExtendEnabled());
|
|
|
}
|
|
|
+ //可放开定向
|
|
|
if(!Check.isNull(strategy.getAdAutoExtendTargets())){
|
|
|
String[] autoExtendTargets = strategy.getAdAutoExtendTargets().split(",");
|
|
|
if(autoExtendTargets.length>0){
|
|
@@ -857,7 +971,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
return params;
|
|
|
}
|
|
|
|
|
|
- private String getAdName(AiBytedanceAdvertiserStrategy strategy, String dplinkCode, ByteDanceVideoInfo videoInfo) {
|
|
|
+ private String getAdName(AiBytedanceAdvertiserStrategy strategy, String dplinkCode, ByteDanceVideoInfo videoInfo,Long projectId) {
|
|
|
String adName = strategy.getAdName();
|
|
|
if(null == adName|| "".equals(adName.trim())){
|
|
|
return null;
|
|
@@ -866,6 +980,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
String date = DateUtils.formatDate(new Date(),"yyyyMMdd");
|
|
|
adName = adName.replace("{{日期}}",date);
|
|
|
}
|
|
|
+ if(adName.contains("{{创意方式}}")){
|
|
|
+ adName = adName.replace("{{创意方式}}","程序化");
|
|
|
+ }
|
|
|
if(adName.contains("{{dp链接标识}}")&&null!=dplinkCode){
|
|
|
adName = adName.replace("{{dp链接标识}}",dplinkCode);
|
|
|
}
|
|
@@ -873,13 +990,23 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
String pricing = strategy.getAdPricing().replace("PRICING_","").toLowerCase(Locale.ROOT);
|
|
|
adName = adName.replace("{{出价方式}}",pricing);
|
|
|
}
|
|
|
+
|
|
|
if(adName.contains("{{素材名称}}")){
|
|
|
- MaterialInfo info = materialInfoService.getParams(videoInfo.getSignature(),null);
|
|
|
- if(null!=info&&null!=info.getMaterialName()){
|
|
|
- adName = adName.replace("{{素材名称}}",info.getMaterialName());
|
|
|
+ if ("video".equals(videoInfo.getMaterialType())){
|
|
|
+ MaterialInfo info = materialInfoService.getParams(videoInfo.getSignature(),null,projectId);
|
|
|
+ if(null!=info&&null!=info.getMaterialName()){
|
|
|
+ adName = adName.replace("{{素材名称}}","["+info.getMaterialName()+"]");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ adName = adName.replace("{{素材名称}}","["+videoInfo.getFilename()+"]");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(adName.contains("{{序号}}")){
|
|
|
+ int i = adDplinkInfoService.getDpLinkInfoCount(strategy.getAccountId(),strategy.getCreativeImageMode());
|
|
|
+ adName = adName.replace("{{序号}}",String.valueOf(i+1));
|
|
|
+ }
|
|
|
+
|
|
|
adName = adName.replace("--","-");
|
|
|
if(adName.startsWith("-")){
|
|
|
adName = adName.substring(1);
|
|
@@ -926,7 +1053,13 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
//创建组
|
|
|
Result campaignData = marketingService.createCampaign(token, campaignParam);
|
|
|
if(campaignData.getCode()!=0){
|
|
|
- //TODO 组创建异常 后续需要加日志
|
|
|
+ AiBytedanceAutocreateLog iBytedanceAutocreateLog = new AiBytedanceAutocreateLog(
|
|
|
+ strategy.getAccountId(),
|
|
|
+ "组创建异常",
|
|
|
+ campaignData.getCode(),
|
|
|
+ campaignData.getMessage(),
|
|
|
+ campaignParam.toJSONString());
|
|
|
+ iBytedanceAutocreateLogService.save(iBytedanceAutocreateLog);
|
|
|
return null;
|
|
|
}
|
|
|
return (Long)campaignData.getResult();
|
|
@@ -942,6 +1075,18 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
result = result + "-" + date;
|
|
|
}
|
|
|
|
|
|
+ if(result.contains("{{序号}}")){
|
|
|
+ //查询同素材类型当天已有计划数量
|
|
|
+ int i = adDplinkInfoService.getDpLinkInfoCount(strategy.getAccountId(),strategy.getCreativeImageMode());
|
|
|
+ Long num = GetCampaignNum.getCampaignNameNum(strategy.getCampaignCnt(),strategy.getCampaignAdCnt(), i+1);
|
|
|
+ result = result.replace("{{序号}}",String.valueOf(num));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(result.contains("{{日期}}")){
|
|
|
+ String time = DateUtils.formatDate(new Date(),"yyyyMMdd");
|
|
|
+ result = result.replace("{{日期}}",time);
|
|
|
+ }
|
|
|
+
|
|
|
result = result.replace("--","-");
|
|
|
if(result.startsWith("-")){
|
|
|
result = result.substring(1);
|
|
@@ -954,10 +1099,10 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
}
|
|
|
|
|
|
private String getRangeIndex(Long dpLinkStartIndex,Long dpLinkEndIndex, Long campaignAdCnt, Long dpIndex) {
|
|
|
- if(dpIndex<dpLinkStartIndex||dpIndex>dpLinkEndIndex){
|
|
|
+ /* if(dpIndex<dpLinkStartIndex||dpIndex>dpLinkEndIndex){
|
|
|
//超出下标范围
|
|
|
return null;
|
|
|
- }
|
|
|
+ }*/
|
|
|
Long startIndex ;
|
|
|
Long endIndex ;
|
|
|
//计算当前下标值和范围区段的余数
|
|
@@ -969,24 +1114,69 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
startIndex = dpIndex-yzIndex+1;
|
|
|
endIndex = dpIndex-yzIndex+campaignAdCnt;
|
|
|
}
|
|
|
+ //dp 链接 超出可用范围
|
|
|
+ if (endIndex > dpLinkEndIndex){
|
|
|
+ endIndex = dpLinkEndIndex;
|
|
|
+ }
|
|
|
return "-("+startIndex+"/"+endIndex+")";
|
|
|
}
|
|
|
|
|
|
- //TODO -- 高质量素材 一天只能创建一次 两周内总消耗》=500
|
|
|
- //TODO -- 打捞素材 两周消耗 <500 并且总关联创意数<20
|
|
|
private List<ByteDanceVideoInfo> getVideoInfoByCreateType(Long projectId,AiBytedanceAdvertiserStrategy strategy, String startTime, String endTime, Integer createType, Long videoCnt) {
|
|
|
+ //根据 imageMode 获取素材类型
|
|
|
+ //2-竖版视频 1-横板视频
|
|
|
+ String imageMode = BytedanceCreativeMatTypeEnum.getNameByType(strategy.getCreativeImageMode());
|
|
|
//1:上新素材 2:跑量素材 3:遗漏素材 4:打捞素材
|
|
|
if(createType == 1||createType == 3){
|
|
|
- return videoInfoService.listByParams(projectId,strategy.getAccountId(),startTime,endTime,videoCnt,0);
|
|
|
+ return videoInfoService.listByParams(projectId,strategy.getAccountId(),imageMode,startTime,endTime,videoCnt,0);
|
|
|
}else if(createType == 2){
|
|
|
startTime = startTime.substring(0,10);
|
|
|
endTime = endTime.substring(0,10);
|
|
|
- return videoInfoService.topMatByParams(projectId,strategy.getAccountId(),startTime,endTime,videoCnt);
|
|
|
+ return videoInfoService.topMatByParams(projectId,strategy.getAccountId(),imageMode,startTime,endTime,videoCnt);
|
|
|
}else if(createType == 4){
|
|
|
- return videoInfoService.listByParams(projectId,strategy.getAccountId(),startTime,endTime,videoCnt,20);
|
|
|
+ return videoInfoService.historyMatByParams(projectId,strategy.getAccountId(),imageMode,startTime,endTime,videoCnt);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图片素材
|
|
|
+ */
|
|
|
+ private List<ByteDanceVideoInfo> getImageInfoByCreateType(Long projectId,AiBytedanceAdvertiserStrategy strategy, String startTime, String endTime, Integer createType, Long videoCnt) {
|
|
|
+ //根据 imageMode 获取素材类型
|
|
|
+ //1-大图横图; 2-大图竖图 3-开屏
|
|
|
+ String imageMode = BytedanceCreativeMatTypeEnum.getNameByType(strategy.getCreativeImageMode());
|
|
|
+ //1:上新素材 2:跑量素材 3:遗漏素材 4:打捞素材
|
|
|
+ if(createType == 1||createType == 3){
|
|
|
+ return videoInfoService.imageListByParams(projectId,strategy.getAccountId(),imageMode,startTime,endTime,videoCnt,0);
|
|
|
+ }else if(createType == 2){
|
|
|
+ return videoInfoService.imageTopMatByParams(projectId,strategy.getAccountId(),imageMode,startTime,endTime,videoCnt);
|
|
|
+ }else if(createType == 4){
|
|
|
+ return videoInfoService.imageHistoryMatByParams(projectId,strategy.getAccountId(),imageMode,startTime,endTime,videoCnt);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ByteDanceVideoInfo> getvideoOrImageInfoByCreateType(Long projectId,AiBytedanceAdvertiserStrategy strategy, String startTime, String endTime, Integer createType, Long videoCnt) {
|
|
|
+ //横板视频 || 竖版视频
|
|
|
+ if (strategy.getCreativeImageMode().equalsIgnoreCase("CREATIVE_IMAGE_MODE_VIDEO")
|
|
|
+ || strategy.getCreativeImageMode().equalsIgnoreCase("CREATIVE_IMAGE_MODE_VIDEO_VERTICAL")){
|
|
|
+ //获取 视频 素材
|
|
|
+ return getVideoInfoByCreateType(projectId,strategy,startTime,endTime,createType,videoCnt);
|
|
|
+ }
|
|
|
+ //获取 图片 素材
|
|
|
+ return getImageInfoByCreateType(projectId,strategy,startTime,endTime,createType,videoCnt);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 修改状态 (0开-1关)
|
|
|
* 同一账户下只能有一条数据信息为开启,可以全部关闭
|
|
@@ -995,13 +1185,13 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Result updStaById(String id,String state,String accountId) {
|
|
|
+ public Result updStaById(String id,String state,String accountId,String creativeImageMode) {
|
|
|
//开启
|
|
|
if (org.apache.commons.lang3.StringUtils.equals(state,"0")){
|
|
|
//修改状态为开启
|
|
|
aiBytedanceAdvertiserStrategyMapper.updStaById(id,state);
|
|
|
//关闭 账户下 其他数据信息(不包含本条id信息) 状态为 关闭
|
|
|
- aiBytedanceAdvertiserStrategyMapper.updStaByAccountId(accountId,"1",id);
|
|
|
+ aiBytedanceAdvertiserStrategyMapper.updStaByAccountId(accountId,creativeImageMode,"1",id);
|
|
|
}
|
|
|
//关闭
|
|
|
if (org.apache.commons.lang3.StringUtils.equals(state,"1")){
|
|
@@ -1020,6 +1210,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
*/
|
|
|
@Override
|
|
|
public Result updStaOrCpaOrBudgetById(UpdAdStaOrCpaOrBudget updAdStaOrCpaOrBudget) {
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(updAdStaOrCpaOrBudget.getAccountId()));
|
|
|
//1-修改出价
|
|
|
if (BytedanceConstant.UPDTYPE_BID.equals(updAdStaOrCpaOrBudget.getType())) {
|
|
|
//查询计划预算
|
|
@@ -1032,30 +1223,42 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
// 出价不为空 则 固定出价
|
|
|
if (!Check.isNull(updAdStaOrCpaOrBudget.getAdCpaBid())){
|
|
|
// 出价 > 计划预算
|
|
|
- a = updAdStaOrCpaOrBudget.getAdCpaBid().compareTo(new BigDecimal(strategyVo.getAdBudget()));
|
|
|
+ a = updAdStaOrCpaOrBudget.getAdCpaBid().compareTo(strategyVo.getAdBudget());
|
|
|
//出价为空 则 随机出价 或者 阶梯出价
|
|
|
// 最高出价 不能大于 计划预算
|
|
|
}else {
|
|
|
// 最高出价 > 计划预算
|
|
|
- a = updAdStaOrCpaOrBudget.getAdMaxBid().compareTo(new BigDecimal(strategyVo.getAdBudget()));
|
|
|
+ a = updAdStaOrCpaOrBudget.getAdMaxBid().compareTo(strategyVo.getAdBudget());
|
|
|
}
|
|
|
if (a == 1){
|
|
|
return Result.errorMsg("最高出价不能大于计划预算。");
|
|
|
}
|
|
|
aiBytedanceAdvertiserStrategyMapper.updCpaById(updAdStaOrCpaOrBudget);
|
|
|
}
|
|
|
- //2-修改预算
|
|
|
+ //2-修改预算(给西安提供 修改 预算)
|
|
|
if (BytedanceConstant.UPDTYPE_BUDGET.equals(updAdStaOrCpaOrBudget.getType())) {
|
|
|
|
|
|
//指定预算
|
|
|
if (updAdStaOrCpaOrBudget.getBudgetType().equals("2")){
|
|
|
- // 前者 < 后者
|
|
|
- int a = new BigDecimal(updAdStaOrCpaOrBudget.getBudget()).compareTo(updAdStaOrCpaOrBudget.getCost().multiply(new BigDecimal(1.05)));
|
|
|
- if (a == -1){
|
|
|
- return Result.errorMsg("修改后预算金额不能低于当前已消费金额的105%");
|
|
|
+ if (!Check.isNull(updAdStaOrCpaOrBudget.getCost())){
|
|
|
+ // 前者 < 后者
|
|
|
+ int a = new BigDecimal(updAdStaOrCpaOrBudget.getBudget()).compareTo(updAdStaOrCpaOrBudget.getCost().multiply(new BigDecimal(1.05)));
|
|
|
+ if (a == -1){
|
|
|
+ return Result.errorMsg("修改后预算金额不能低于当前已消费金额的105%");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
aiBytedanceAdvertiserStrategyMapper.updBudgetById(updAdStaOrCpaOrBudget.getId(), updAdStaOrCpaOrBudget.getBudget(),updAdStaOrCpaOrBudget.getBudgetType());
|
|
|
+
|
|
|
+ //账户预算 同步 头条
|
|
|
+ //BUDGET_MODE_DAY-日预算
|
|
|
+ // BUDGET_MODE_INFINITE-不限
|
|
|
+ String accountBudgetMode = updAdStaOrCpaOrBudget.getBudgetType().equals("1") ? "BUDGET_MODE_INFINITE" : "BUDGET_MODE_DAY";
|
|
|
+ Result resultBudget = marketingService.updateBudget(token,accountBudgetMode,new BigDecimal(updAdStaOrCpaOrBudget.getBudget()));
|
|
|
+ if (!resultBudget.isSuccess()){
|
|
|
+ return Result.error(resultBudget.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
return Result.successMsg("修改"+(BytedanceConstant.UPDTYPE_BID.equals(updAdStaOrCpaOrBudget.getType()) ? "出价" : "预算")+"成功。",null);
|
|
|
}
|
|
@@ -1265,7 +1468,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
* @author zianY
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public Result addBytedanceStrategy(AiBytedanceAdvertiserStrategy aiBytedanceAdvertiserStrategy) {
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(aiBytedanceAdvertiserStrategy.getAccountId()));
|
|
|
//预算金额不能低于当前已消费金额的105%
|
|
|
QueryWrapper<RuleDataAccount> ruleDataAccountQueryWrapper = new QueryWrapper<>();
|
|
|
ruleDataAccountQueryWrapper.eq("account_id",aiBytedanceAdvertiserStrategy.getAccountId());
|
|
@@ -1274,14 +1479,15 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
// 值 为0 不限预算
|
|
|
// !0 指定预算
|
|
|
if (!aiBytedanceAdvertiserStrategy.getAccountBudget().equals(new BigDecimal("0"))){
|
|
|
- // 前者 < 后者
|
|
|
- int a = aiBytedanceAdvertiserStrategy.getAccountBudget().compareTo(ruleDataAccountVo.getCost().multiply(new BigDecimal(1.05)));
|
|
|
- if (a == -1){
|
|
|
- return Result.errorMsg("预算金额不能低于当前已消费金额的105%");
|
|
|
+ if (!Check.isNull(ruleDataAccountVo)){
|
|
|
+ // 前者 < 后者
|
|
|
+ int a = aiBytedanceAdvertiserStrategy.getAccountBudget().compareTo(ruleDataAccountVo.getCost().multiply(new BigDecimal(1.05)));
|
|
|
+ if (a == -1){
|
|
|
+ return Result.errorMsg("预算金额不能低于当前已消费金额的105%");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 数据入库 string[] 转 string
|
|
|
//商品卖点
|
|
|
aiBytedanceAdvertiserStrategy.setCreativeProductSellingPoints(org.apache.commons.lang3.StringUtils.join(aiBytedanceAdvertiserStrategy.getProductSellingPoints(), ","));
|
|
@@ -1293,9 +1499,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
//默认组数量为 1 -前端已修改完成
|
|
|
//aiBytedanceAdvertiserStrategy.setCampaignAdCnt(aiBytedanceAdvertiserStrategy.getCampaignAdCnt() == 0L ? 1 : aiBytedanceAdvertiserStrategy.getCampaignAdCnt());
|
|
|
|
|
|
- //同一账户下 只能有一条信息为开启
|
|
|
+ //同一账户下 同素材类型 只能有一条信息为开启
|
|
|
//关闭 账户下 其他数据信息(不包含本条id信息) 状态为 关闭
|
|
|
- aiBytedanceAdvertiserStrategyMapper.updStaByAccountId(String.valueOf(aiBytedanceAdvertiserStrategy.getAccountId()),"1",null);
|
|
|
+ aiBytedanceAdvertiserStrategyMapper.updStaByAccountId(String.valueOf(aiBytedanceAdvertiserStrategy.getAccountId()),aiBytedanceAdvertiserStrategy.getCreativeImageMode(),"1",null);
|
|
|
//状态(0开 1关)
|
|
|
aiBytedanceAdvertiserStrategy.setStatus(0);
|
|
|
|
|
@@ -1305,8 +1511,19 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
imageInfo.setUserId(aiBytedanceAdvertiserStrategy.getUserId());
|
|
|
materialImageInfoService.initImageCode(imageInfo);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
aiBytedanceAdvertiserStrategyMapper.insert(aiBytedanceAdvertiserStrategy);
|
|
|
|
|
|
+
|
|
|
+ //账户预算 同步 头条
|
|
|
+ //BUDGET_MODE_DAY-日预算
|
|
|
+ // BUDGET_MODE_INFINITE-不限
|
|
|
+ String accountBudgetMode = aiBytedanceAdvertiserStrategy.getAccountBudgetMode().equals("1") ? "BUDGET_MODE_INFINITE" : "BUDGET_MODE_DAY";
|
|
|
+ Result resultBudget = marketingService.updateBudget(token,accountBudgetMode,aiBytedanceAdvertiserStrategy.getAccountBudget());
|
|
|
+ /* if (!resultBudget.isSuccess()){
|
|
|
+ return Result.error(resultBudget.getMessage());
|
|
|
+ }*/
|
|
|
return Result.successMsg("新增成功。",aiBytedanceAdvertiserStrategy);
|
|
|
}
|
|
|
|
|
@@ -1325,34 +1542,58 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
|
|
|
@Autowired
|
|
|
private IByteDanceAdvertisePlanService planService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserDataService advertiserDataService;
|
|
|
+
|
|
|
@Override
|
|
|
public void customCreativeSupplement(AiBytedanceAdvertiserStrategy strategy, Integer hour,String openUrl) {
|
|
|
- Long customUnitCnt = strategy.getCampaignAdCnt()*strategy.getCampaignCnt();
|
|
|
- Long unitNum = customUnitCnt * hour / 15;
|
|
|
- log.info("{}当前时间内需要创建计划总数:{}", strategy.getAccountId(), unitNum);
|
|
|
- //查询当前账户创建自定义类型计划数量
|
|
|
- int unitCreateCnt = planService.queryToDayBuiltCount(strategy.getAccountId());
|
|
|
- log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
|
|
|
- long remindCnt = unitNum - unitCreateCnt;
|
|
|
- if (remindCnt >= 1) {
|
|
|
- log.info("{}计划创建不足,剩余需要创建个数{},使用上新素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- //优先创建历史遗漏素材
|
|
|
- remindCnt = this.createCreative(strategy, 1, remindCnt,openUrl);
|
|
|
- }
|
|
|
- if (remindCnt >= 1) {
|
|
|
- log.info("{}计划创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- //优先创建历史遗漏素材
|
|
|
- remindCnt = this.createCreative(strategy, 3, remindCnt,openUrl);
|
|
|
- }
|
|
|
- if (remindCnt >= 1) {
|
|
|
- log.info("{}计划创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- //高质量素材
|
|
|
- remindCnt = this.createCreative(strategy, 2, remindCnt,openUrl);
|
|
|
- }
|
|
|
- if (remindCnt >= 1) {
|
|
|
- //历史打捞素材
|
|
|
- log.info("{}计划创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
|
|
|
- this.createCreative(strategy, 4, remindCnt,openUrl);
|
|
|
+ try{
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(strategy.getAccountId()+"");
|
|
|
+ if (null == token) {
|
|
|
+ log.info("token获取失败=>accountId:{}", strategy.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long customUnitCnt = strategy.getCampaignAdCnt()*strategy.getCampaignCnt();
|
|
|
+ Long unitNum = customUnitCnt * hour / 19;
|
|
|
+ log.info("{}当前时间内需要创建计划总数:{}", strategy.getAccountId(), unitNum);
|
|
|
+ //查询当前账户创建自定义类型计划数量
|
|
|
+ int unitCreateCnt = planService.queryToDayBuiltCount(strategy.getAccountId());
|
|
|
+ log.info("{}截止目前创建计划总数:{}", strategy.getAccountId(), unitCreateCnt);
|
|
|
+ long remindCnt = unitNum - unitCreateCnt;
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ log.info("{}计划创建不足,剩余需要创建个数{},使用上新素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ //优先创建历史遗漏素材
|
|
|
+ remindCnt = this.createCreative(token, strategy, 1, remindCnt,openUrl);
|
|
|
+ }
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ log.info("{}计划创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ //优先创建历史遗漏素材
|
|
|
+ remindCnt = this.createCreative(token, strategy, 3, remindCnt,openUrl);
|
|
|
+ }
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ log.info("{}计划创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ //高质量素材
|
|
|
+ remindCnt = this.createCreative(token, strategy, 2, remindCnt,openUrl);
|
|
|
+ }
|
|
|
+ if (remindCnt >= 1) {
|
|
|
+ //历史打捞素材
|
|
|
+ log.info("{}计划创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
|
|
|
+ this.createCreative(token, strategy, 4, remindCnt,openUrl);
|
|
|
+ }
|
|
|
+ //获取最新的plan计划更新到表格
|
|
|
+ String nowDate = DateUtils.formatDate();
|
|
|
+ advertiserDataService.getAdvertiserPlan(token, "", nowDate, nowDate);
|
|
|
+
|
|
|
+ int newUnitCreateCnt = planService.queryToDayBuiltCount(strategy.getAccountId());
|
|
|
+ AiBytedanceAutocreateLog iBytedanceAutocreateLog = new AiBytedanceAutocreateLog(
|
|
|
+ strategy.getAccountId(),
|
|
|
+ "创建广告计划",
|
|
|
+ 200,
|
|
|
+ "当前账户需要创建计划总数为"+unitNum+"个,截止目前有"+unitCreateCnt+"个,此次创建成功"+(newUnitCreateCnt - unitCreateCnt)+"个。",
|
|
|
+ "aiBytedanceAdvertiserStrategyService.customCreativeSupplement => strategy:"+ strategy.toString()+",hour:"+hour);
|
|
|
+ iBytedanceAutocreateLogService.save(iBytedanceAutocreateLog);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1501,5 +1742,50 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
|
|
|
return Result.successMsg("获取橙子建站站点列表成功。",dataList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *查询 组名称 计划名称
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getStrategyInfoByName(AiBytedanceAdvertiserStrategy aiBytedanceAdvertiserStrategy) {
|
|
|
+ //查询 组名称
|
|
|
+ QueryWrapper<AiBytedanceAdvertiserStrategy> queryWrapperCampaign = new QueryWrapper<>();
|
|
|
+ //查询计划名称
|
|
|
+ QueryWrapper<AiBytedanceAdvertiserStrategy> queryWrapperAdName = new QueryWrapper<>();
|
|
|
+ List<AiBytedanceAdvertiserStrategy> strategyInfoCampain = new ArrayList<>();
|
|
|
+ List<AiBytedanceAdvertiserStrategy> strategyInfoAdName = new ArrayList<>();
|
|
|
+ //新增
|
|
|
+ if (Check.isNull(aiBytedanceAdvertiserStrategy.getId())){
|
|
|
+ queryWrapperCampaign.eq("campaign_name",aiBytedanceAdvertiserStrategy.getCampaignName());
|
|
|
+ strategyInfoCampain = aiBytedanceAdvertiserStrategyMapper.selectList(queryWrapperCampaign);
|
|
|
+ if (!Check.isNull(strategyInfoCampain)){
|
|
|
+ return Result.error("新创建的账户配置已存在相同的组名称【"+aiBytedanceAdvertiserStrategy.getCampaignName()+"】请修改后重新保存。");
|
|
|
+ }
|
|
|
+ queryWrapperAdName.eq("ad_name",aiBytedanceAdvertiserStrategy.getAdName());
|
|
|
+ strategyInfoAdName = aiBytedanceAdvertiserStrategyMapper.selectList(queryWrapperAdName);
|
|
|
+ if (!Check.isNull(strategyInfoAdName)){
|
|
|
+ return Result.error("新创建的账户配置已存在相同的计划名称【"+aiBytedanceAdvertiserStrategy.getAdName()+"】请修改后重新保存。");
|
|
|
+ }
|
|
|
+ // 编辑
|
|
|
+ }else {
|
|
|
+ queryWrapperCampaign.eq("campaign_name",aiBytedanceAdvertiserStrategy.getCampaignName());
|
|
|
+ strategyInfoCampain = aiBytedanceAdvertiserStrategyMapper.selectList(queryWrapperCampaign);
|
|
|
+ strategyInfoCampain.stream().map(AiBytedanceAdvertiserStrategy::getId).collect(Collectors.toList());
|
|
|
+ if (!Check.isNull(strategyInfoCampain) &&
|
|
|
+ !strategyInfoCampain.stream().map(AiBytedanceAdvertiserStrategy::getId).collect(Collectors.toList()).contains(aiBytedanceAdvertiserStrategy.getId())){
|
|
|
+ return Result.error("新创建的账户配置已存在相同的组名称【"+aiBytedanceAdvertiserStrategy.getCampaignName()+"】请修改后重新保存。");
|
|
|
+ }
|
|
|
+ queryWrapperAdName.eq("ad_name",aiBytedanceAdvertiserStrategy.getAdName());
|
|
|
+ strategyInfoAdName = aiBytedanceAdvertiserStrategyMapper.selectList(queryWrapperAdName);
|
|
|
+ if (!Check.isNull(strategyInfoAdName) &&
|
|
|
+ !strategyInfoAdName.stream().map(AiBytedanceAdvertiserStrategy::getId).collect(Collectors.toList()).contains(aiBytedanceAdvertiserStrategy.getId())){
|
|
|
+ return Result.error("新创建的账户配置已存在相同的计划名称【"+aiBytedanceAdvertiserStrategy.getAdName()+"】请修改后重新保存。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return Result.successMsg("成功。",null);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|