瀏覽代碼

添加日志

syh 4 年之前
父節點
當前提交
e85b959146

+ 15 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouCampaignLevelOperationRecord.java

@@ -4,8 +4,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
 
 import java.util.Date;
 
@@ -17,8 +15,6 @@ import java.util.Date;
  */
 @Data
 @TableName("ctop_ai_kuaishou_campaign_level_operation_record")
-@EqualsAndHashCode(callSuper = false)
-@Accessors(chain = true)
 public class AiKuaishouCampaignLevelOperationRecord {
 
 	/**计划操作表uuid*/
@@ -27,15 +23,15 @@ public class AiKuaishouCampaignLevelOperationRecord {
 	/**AI策略ID*/
 	private String aiStrategyUuid;
 	/**账户ID*/
-	private Integer accountId;
+	private Long accountId;
 	/**广告计划ID*/
-	private Integer campaignId;
+	private Long campaignId;
 	/**广告计划名称*/
 	private String campaignName;
 	/**计划类型 2-提升应用安装 3-获取电商下单 4-推广品牌活动 5-收集销售线索 7-提高应用活跃*/
 	private Integer campaignType;
 	/**单日预算*/
-	private Integer dayBudget;
+	private Long dayBudget;
 	/**分日预算*/
 	private String dayBudgetSchedule;
 	/**操作类型 1-新增 2-修改*/
@@ -50,4 +46,16 @@ public class AiKuaishouCampaignLevelOperationRecord {
 	private Integer status;
 	/**状态详情*/
 	private String message;
+
+	public AiKuaishouCampaignLevelOperationRecord(AiKuaishouAdvertiserStrategy strategy, Long campaignId, Integer code, String message) {
+		this.accountId = strategy.getAccountId();
+		this.dayBudget = strategy.getCampaignDayBudget();
+		this.dayBudgetSchedule = strategy.getCampaignDayBudgetSchedule();
+		this.campaignType = strategy.getCampaignType();
+		this.campaignId = campaignId;
+		this.status = code;
+		this.message = message;
+		this.operationType = 1;
+		this.createTime = new Date();
+	}
 }

+ 4 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouCreativeLevelOperationRecord.java

@@ -23,13 +23,13 @@ public class AiKuaishouCreativeLevelOperationRecord {
 	/**AI策略ID*/
 	private String aiStrategyUuid;
 	/**账户ID*/
-	private Integer accountId;
+	private Long accountId;
 	/**广告计划ID*/
-	private Integer campaignId;
+	private Long campaignId;
 	/**广告组ID*/
-	private Integer unitId;
+	private Long unitId;
 	/**广告创意ID*/
-	private Integer creativeId;
+	private Long creativeId;
 	/**是否为便利贴,默认为0*/
 	private Integer isSticky;
 	/**创意名称*/

+ 3 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouUnitLevelOperationRecord.java

@@ -3,9 +3,7 @@ package cn.com.ctop.kuaishou.modules.ai.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
-import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import org.jeecgframework.poi.excel.annotation.Excel;
 
 import java.util.Date;
 
@@ -25,11 +23,11 @@ public class AiKuaishouUnitLevelOperationRecord {
 	/**AI策略ID*/
 	private String aiStrategyUuid;
 	/**账户ID*/
-	private Integer accountId;
+	private Long accountId;
 	/**广告计划ID*/
-	private Integer campaignId;
+	private Long campaignId;
 	/**广告组ID*/
-	private Integer unitId;
+	private Long unitId;
 	/**广告组名称*/
 	private String groupName;
 	/**定向模板id*/

+ 73 - 30
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -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);
     }
 
     /**