Kaynağa Gözat

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-cloud

yumeng 3 yıl önce
ebeveyn
işleme
5cc2829c54

+ 25 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouProgramCreativeLevelOperationRecord.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.ai.entity;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
@@ -123,4 +124,28 @@ public class AiKuaishouProgramCreativeLevelOperationRecord {
      * 1:账户自动投放 2:项目自动投放
      */
     private Integer createType;
+
+    public AiKuaishouProgramCreativeLevelOperationRecord(){}
+
+    public AiKuaishouProgramCreativeLevelOperationRecord( JSONObject creativeParams ,Long campaignId, Long unitId, String uuid, String message) {
+        this.aiStrategyUuid = uuid;
+        this.accountId = creativeParams.getLong("advertiser_id");
+        this.campaignId = campaignId;
+        this.unitId = unitId;
+        this.packageName = creativeParams.getString("package_name");
+        this.horizontalPhotoIds = creativeParams.getString("hids");
+        this.verticalPhotoIds = creativeParams.getString("vids");
+        this.siteId = creativeParams.getInteger("site_id");
+        this.stickerStyles = creativeParams.getString("sticker_styles");
+        this.actionBar = creativeParams.getString("action_bar");
+        this.captions = creativeParams.getString("captions");
+        this.clickUrl = creativeParams.getString("click_url");
+        this.actionbarClickUrl = creativeParams.getString("actionbar_click_url");
+        this.creativeCategory = creativeParams.getInteger("creative_category");
+        this.creativeTag = creativeParams.getString("creative_tag");
+        this.createType = 3;
+        this.operationType = 1;
+        this.message = message;
+        this.createTime = new Date();
+    }
 }

+ 31 - 11
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountAutoDoServiceImpl.java

@@ -13,6 +13,7 @@ import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountAutoTarget;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountAutoVideo;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCampaignLevelOperationRecord;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCreativeLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouProgramCreativeLevelOperationRecord;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouAutoTypeEnum;
@@ -23,6 +24,7 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountAutoTargetServi
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountAutoVideoService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCampaignLevelOperationRecordService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreativeLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouProgramCreativeLevelOperationRecordService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouUnitLevelOperationRecordService;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
@@ -92,6 +94,10 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     private IKuaishouAccountCreativeOverrunInfoService overrunInfoService;
     @Autowired
     private IAiKuaishouCampaignLevelOperationRecordService aiKuaishouCampaignLevelOperationRecordService;
+
+    @Autowired
+    private IAiKuaishouProgramCreativeLevelOperationRecordService kuaishouProgramCreativeLevelOperationRecordService;
+
     @Autowired
     private IAiKuaiShouAppInfoService appInfoService;
     @Autowired
@@ -772,9 +778,9 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                         continue;
                     }
                     JSONObject unitParams = (JSONObject) result.getResult();
-                    log.info("--------------执行创建程序化广告组,参数:{}", unitParams);
+//                    log.info("--------------执行创建程序化广告组,参数:{}", unitParams);
                     Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-                    log.info("--------------创建程序化广告组结果,返回数据:{}", unitCreateResult.toString());
+//                    log.info("--------------创建程序化广告组结果,返回数据:{}", unitCreateResult.toString());
                     unitCode = (Integer) unitCreateResult.get("code");
                     unitMessage = (String) unitCreateResult.get("message");
 
@@ -802,7 +808,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                     //获取创意参数
                     JSONObject creativeParams = getProgramCreativeParams(token, unitId, videos, strategy, videoCnt, null, usedchannel);
                     //执行创建创意
-                    boolean flag = createProgramCreatives(token, creativeParams, strategy, 1);
+                    boolean flag = createProgramCreatives(token, creativeParams, strategy, newCampaignId, uuid, 1);
                     if (flag) {
                         //创意成功,则素材置为不可用,添加素材使用记录
                         updateVideoUsed(videoType, videos, "program", null);
@@ -967,7 +973,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 //获取创意参数
                 JSONObject creativeParams = getProgramCreativeParams(token, unitId, videos, strategy, videoCnt, videos.get(0).getAppVersion(), null);
                 //执行创建创意
-                createProgramCreatives(token, creativeParams, strategy, 1);
+//                createProgramCreatives(token, creativeParams, strategy, 1);
                 if (videoCnt <= 0) {
                     removeProRedisVideos(successVideoList, videoKey);
                     return 0;
@@ -1216,7 +1222,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             //获取创意参数
             JSONObject creativeParams = getProgramCreativeParams(token, unitId, videos, strategy, videoCnt, null, channel);
             //执行创建创意
-            boolean flag = createProgramCreatives(token, creativeParams, strategy, 1);
+            boolean flag = createProgramCreatives(token, creativeParams, strategy, newCampaignId, uuid, 1);
             if (flag) {
                 successVideoList.add(videos);
                 //创意成功,则素材置为不可用,添加素材使用记录
@@ -1595,15 +1601,25 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
 
             //素材列表
             JSONArray photoList = new JSONArray();
+            List<String> vids = new ArrayList<>();//竖版视频ID
+            List<String> hids = new ArrayList<>();//横版视频ID
             for (AiKuaishouAccountAutoVideo video : videos) {
+                Integer type = video.getMaterialType();
+                String photoId = video.getPhotoId();
                 JSONObject photo = new JSONObject();
-                photo.put("photo_id", video.getPhotoId());//视频 ID
+                photo.put("photo_id", photoId);//视频 ID
                 photo.put("cover_image_token", null);// 封面图片 token,通过上传图片接口获得,不传值则直接使用视频的首帧作为封面图片
-                photo.put("creative_material_type", video.getMaterialType());//1:竖版视频 2:横版视频
+                photo.put("creative_material_type", type);//1:竖版视频 2:横版视频
                 photoList.add(photo);
+                if(!Check.isNull(type)&&type==1){
+                    vids.add(photoId);
+                }else{
+                    hids.add(photoId);
+                }
             }
             programJson.put("photo_list", photoList);
-
+            programJson.put("vids",vids);
+            programJson.put("hids",hids);
             //落地页 ID
             if (!Check.isNull(strategy.getSiteId()) && !"-1".equals(strategy.getSiteId())) {
                 programJson.put("site_id", strategy.getSiteId());
@@ -1673,7 +1689,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     /**
      * 执行创建程序化创意
      */
-    private boolean createProgramCreatives(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAccountAutoStrategy strategy, int count) {
+    private boolean createProgramCreatives(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAccountAutoStrategy strategy, Long campaignId, String uuid, int count) {
         try {
             Map<String, String> headers = new HashMap<>();
             headers.put("Content-Type", "application/json");
@@ -1689,21 +1705,25 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             Integer code = resultJson.getInteger("code");
             String message = resultJson.getString("message");
             Long unitId = creativeParams.getLong("unit_id");
+            AiKuaishouProgramCreativeLevelOperationRecord record = new AiKuaishouProgramCreativeLevelOperationRecord(creativeParams, campaignId, unitId, uuid, message);
             if (code == 0) {
                 createLandPageAndUnit(creativeParams, resultJson.getJSONObject("data"));
+                record.setStatus(0);
+                kuaishouProgramCreativeLevelOperationRecordService.saveOrUpdate(record);
             } else {
                 log.error("快手创建程序化创意失败,accountId:{},unitId:{},返回信息:{},入参:{}", token.getAccountId(), unitId, message, creativeParams.toJSONString());
                 if ("系统错误".equals(message) && count <= 3) {
                     log.info("第{}次重新创建程序化创意", count);
                     //系统错误,则重新执行
-                    return createProgramCreatives(token, creativeParams, strategy, count + 1);
+                    return createProgramCreatives(token, creativeParams, strategy, campaignId, uuid, count + 1);
                 } else if (code == 400001 && "/rest/openapi/v2/creative/advanced/program/create调用已超日限,次日可恢复调用".equals(message)) {
                     String statDate = DateUtils.formatDate(new Date());
                     String programKey = token.getAccountId() + "_pcreativecount_" + statDate;
                     redisUtil.set(programKey, 1, 100000L);
                     updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
                 }
-
+                record.setStatus(-1);
+                kuaishouProgramCreativeLevelOperationRecordService.saveOrUpdate(record);
                 return false;
             }
         } catch (Exception e) {

+ 17 - 8
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountAutoVideoServiceImpl.java

@@ -43,22 +43,22 @@ public class AiKuaishouAccountAutoVideoServiceImpl extends ServiceImpl<AiKuaisho
     private ICtopOauthTokenService tokenService;
 
     @Override
-    public List<AiKuaishouAccountAutoVideo> getUpNewVideos(Long accountId, Integer channelType,  List<String>  keyword, Integer videoCnt, String statDate, String createType) {
+    public List<AiKuaishouAccountAutoVideo> getUpNewVideos(Long accountId, Integer channelType, List<String> keyword, Integer videoCnt, String statDate, String createType) {
         return autoVideoMapper.getUpNewVideos(accountId, channelType, keyword, videoCnt, statDate, createType);
     }
 
     @Override
-    public List<AiKuaishouAccountAutoVideo> getHistoryTopVideos(Long accountId, Integer channelType,  List<String>  keyword, Integer videoCnt, String statDate, String createType) {
+    public List<AiKuaishouAccountAutoVideo> getHistoryTopVideos(Long accountId, Integer channelType, List<String> keyword, Integer videoCnt, String statDate, String createType) {
         return autoVideoMapper.getHistoryTopVideos(accountId, channelType, keyword, videoCnt, createType, statDate);
     }
 
     @Override
-    public List<AiKuaishouAccountAutoVideo> getMissVideoByParams(Long accountId, Integer channelType,  List<String>  keyword, Integer videoCnt, String statDate) {
+    public List<AiKuaishouAccountAutoVideo> getMissVideoByParams(Long accountId, Integer channelType, List<String> keyword, Integer videoCnt, String statDate) {
         return autoVideoMapper.getZeroVideoByParams(accountId, channelType, keyword, videoCnt, statDate);
     }
 
     @Override
-    public List<AiKuaishouAccountAutoVideo> getHistoryCatchVideos(Long accountId, Integer channelType,  List<String>  keyword, Integer videoCnt, String statDate) {
+    public List<AiKuaishouAccountAutoVideo> getHistoryCatchVideos(Long accountId, Integer channelType, List<String> keyword, Integer videoCnt, String statDate) {
         return autoVideoMapper.getHistoryCatchVideos(accountId, channelType, keyword, videoCnt, statDate);
     }
 
@@ -107,18 +107,27 @@ public class AiKuaishouAccountAutoVideoServiceImpl extends ServiceImpl<AiKuaisho
                 log.error("获取快手视频列表数据异常:{},accountId:{}", message, token.getAccountId());
                 return;
             }
-            JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
-            if (null == details || details.size() <= 0) {
+            JSONArray videoList = resultJson.getJSONObject("data").getJSONArray("details");
+            if (null == videoList || videoList.size() <= 0) {
                 log.info("快手视频列表信息为空=》accountId:{}", token.getAccountId());
                 return;
             }
             Boolean doGet = true;
-            if (details.size() < pageSize) {
+            if (videoList.size() < pageSize) {
                 doGet = false;
             }
+            JSONArray details = new JSONArray();
+            for (int i = 0; i < videoList.size(); i++) {
+                JSONObject video = videoList.getJSONObject(i);
+                if (video != null && video.getInteger("new_status") == 1) {
+                    details.add(video);
+                }
+            }
+            if (Check.isNull(details) || details.isEmpty()) {
+                return;
+            }
 
             List<AiKuaishouAccountAutoVideo> videoGetList = new ArrayList<>();
-
             Long accountId = token.getAccountId();
             List<String> photoIds = autoVideoMapper.selectBatchByPhotoIds(details, date, accountId);
             for (int i = 0; i < details.size(); i++) {

+ 0 - 7
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -173,7 +173,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             //开始创建组+创意
                             String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appInfo.getAppId(), null);
                             JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId(), null);
-                            log.info("创建广告组入参:{}", unitParams);
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                             Integer unitCode = (Integer) unitCreateResult.get("code");
                             String unitMessage = (String) unitCreateResult.get("message");
@@ -254,7 +253,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             unitParams.put("deep_conversion_bid", multipleBids.getDeepConversionBid());
                         }
                         strategy.setCpaBid(multipleBids.getCpaBid() + "");
-                        log.info("创建广告组入参:{}", unitParams);
                         Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                         Integer unitCode = (Integer) unitCreateResult.get("code");
                         String unitMessage = (String) unitCreateResult.get("message");
@@ -392,7 +390,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     }
                     String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, usedchannel);
                     JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
-                    log.info("创建广告组入参:{}", unitParams);
                     Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                     Integer unitCode = (Integer) unitCreateResult.get("code");
                     String unitMessage = (String) unitCreateResult.get("message");
@@ -530,7 +527,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             //创建组
                             String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appInfo.getAppId(), null);
                             JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId(), null);
-                            log.info("创建广告组入参:{}", unitParams);
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                             Integer unitCode = (Integer) unitCreateResult.get("code");
                             String unitMessage = (String) unitCreateResult.get("message");
@@ -608,7 +604,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                                 unitParams.remove("deep_conversion_bid");
                                 unitParams.put("deep_conversion_bid", multipleBids.getDeepConversionBid());
                             }
-                            log.info("创建广告组入参:{}", unitParams);
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                             Integer unitCode = (Integer) unitCreateResult.get("code");
                             String unitMessage = (String) unitCreateResult.get("message");
@@ -752,7 +747,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     //创建组
                     String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, usedchannel);
                     JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
-                    log.info("创建广告组入参:{}", unitParams);
                     Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                     Integer unitCode = (Integer) unitCreateResult.get("code");
                     String unitMessage = (String) unitCreateResult.get("message");
@@ -857,7 +851,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.PROGRAM_CREATE;
         String result = HttpUtils.kuaiShouhttpPostRequest(url, creativeParams.toJSONString(), headers);
         JSONObject resultJson = JSON.parseObject(result);
-        log.info("创建程序化创意返回结果:{}", resultJson);
         if (Check.isNull(resultJson)) {
             log.error("程序化创意创意异常:api接口返回为空");
             return;