Explorar el Código

项目自动化调试

zhaoxian hace 4 años
padre
commit
c420890403
Se han modificado 19 ficheros con 420 adiciones y 290 borrados
  1. 1 74
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouProjectCreateCreativeController.java
  2. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouAppPackageController.java
  3. 2 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouProjectStrategyController.java
  4. 84 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouAccountLevelOperationRecord.java
  5. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouProjectStrategy.java
  6. 20 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/AiKuaishouAccountLevelOperationRecordMapper.java
  7. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouAppPackageRelMapper.java
  8. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouProjectStrategyMapper.java
  9. 17 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/AiKuaishouAccountLevelOperationRecordMapper.xml
  10. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouAppPackageRelMapper.xml
  11. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouProjectStrategyMapper.xml
  12. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouAccountLevelOperationRecordService.java
  13. 1 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouProjectCreateCreativeService.java
  14. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouAppPackageService.java
  15. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouProjectStrategyService.java
  16. 19 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountLevelOperationRecordServiceImpl.java
  17. 230 198
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouProjectCreateCreativeServiceImpl.java
  18. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouAppPackageServiceImpl.java
  19. 10 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouProjectStrategyServiceImpl.java

+ 1 - 74
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouProjectCreateCreativeController.java

@@ -66,7 +66,7 @@ public class AiKuaishouProjectCreateCreativeController {
                 Boolean unitOverrun = projectCreateCreativeService.getUnitOverrun(projectId.toString().concat(accountId.toString()));
                 if (!unitOverrun) {
                     strategy.setAccountId(accountId);
-                    projectCreateCreativeService.projectAutomaticCreates(strategy);
+                    projectCreateCreativeService.projectAutomaticCreates(strategy,1);
                 }
             }));
             return Result.ok("异步创建中...");
@@ -77,78 +77,5 @@ public class AiKuaishouProjectCreateCreativeController {
     }
 
 
-    /**
-     * 自动上新
-     *
-     * @param id
-     * @return
-     */
-    @GetMapping(value = "/customCreativeLimit")
-    public JSONObject customCreativeLimit(String id) {
-        JSONObject returnJson = new JSONObject();
-        try {
-            if (Check.isNull(id)) {
-                throw new Exception("主键id不能为空");
-            }
-            KuaishouProjectStrategy strategy = kuaishouProjectStrategyService.getById(id);
-            if (Check.isNull(strategy)) {
-                throw new Exception("根据id获取详细信息为空");
-            }
-            Boolean unitOverrun = projectCreateCreativeService.getUnitOverrun(strategy.getAccountId().toString());
-            if (unitOverrun) {
-                log.error("组创建超限,accountId:{}", strategy.getAccountId());
-                throw new Exception("今日组创建已超限");
-            }
-
-            executorService.submit(() ->
-                    projectCreateCreativeService.customCreativeLimit(strategy)
-            );
-            returnJson.put("code", 0);
-            returnJson.put("message", "异步创建中");
-        } catch (Exception e) {
-            returnJson.put("code", -1);
-            returnJson.put("message", e.getMessage());
-        }
-        return returnJson;
-
-    }
-
-    /**
-     * 自定义创意补充
-     * @param id
-     * @param hour
-     * @return
-     */
-    @GetMapping(value = "/kuaishouCustomCreativeSupplement")
-    public JSONObject kuaishouCustomCreativeSupplement(String id, Integer hour) {
-        JSONObject returnJson = new JSONObject();
-        try {
-            if (Check.isNull(id)) {
-                throw new Exception("主键id不能为空");
-            }
-            KuaishouProjectStrategy strategy = kuaishouProjectStrategyService.getById(id);
-            if (Check.isNull(strategy)) {
-                throw new Exception("根据id获取详细信息为空");
-            }
-            Boolean unitOverrun = projectCreateCreativeService.getUnitOverrun(strategy.getAccountId().toString());
-            if (unitOverrun) {
-                log.error("组创建超限,accountId:{}", strategy.getAccountId());
-                throw new Exception("今日组创建已超限");
-            }
-            if (Check.isNull(hour)) {
-                throw new Exception("小时数据为空");
-            }
-            kuaishouCustomCreativeSupplementExecutorService.submit(() -> {
-                projectCreateCreativeService.customCreativeSupplement(strategy, hour);
-            });
-            returnJson.put("code", 0);
-            returnJson.put("message", "异步创建中");
-        } catch (Exception e) {
-            returnJson.put("code", -1);
-            returnJson.put("message", e.getMessage());
-        }
-        return returnJson;
-
-    }
 
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouAppPackageController.java

@@ -113,7 +113,7 @@ public class KuaishouAppPackageController {
         String actionbarClickUrl = data.getString("actionbarClickUrl");
         String adPhotoPlayedT3sUrl = data.getString("adPhotoPlayedT3sUrl");
 
-        if (Check.isNull(impressionUrl) || Check.isNull(actionbarClickUrl) || Check.isNull(adPhotoPlayedT3sUrl) || Check.isNull(trackUrl)) {
+        if (Check.isNull(impressionUrl) && Check.isNull(actionbarClickUrl) && Check.isNull(adPhotoPlayedT3sUrl) && Check.isNull(trackUrl)) {
             return Result.error("缺少参数");
         }
         Long id = data.getLong("id");

+ 2 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouProjectStrategyController.java

@@ -172,14 +172,10 @@ public class KuaishouProjectStrategyController {
      * 查询项目策略匹配结果
      */
     @GetMapping(value = "/queryMatchResult")
-    public Result<Object> queryMatchResult(@RequestParam(name = "id", required = true) String id) {
+    public Result<Object> queryMatchResult(Long projectId, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
         Result<KuaishouProjectStrategy> result = new Result<>();
         try {
-            //账户名称:authName
-            //账户状态:authStatus
-            //失败原因:resultText
-
-            return kuaishouProjectStrategyService.queryMatchResult(id);
+            return kuaishouProjectStrategyService.queryMatchResult(projectId, pageNo, pageSize);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 84 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouAccountLevelOperationRecord.java

@@ -0,0 +1,84 @@
+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.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 智能投放-账户层级操作记录表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-07-11
+ */
+@Data
+@TableName("ctop_ai_kuaishou_account_level_operation_record")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_ai_kuaishou_account_level_operation_record对象", description = "智能投放-账户层级操作记录表")
+public class AiKuaishouAccountLevelOperationRecord {
+
+    /**
+     * 账户操作表uuid
+     */
+    @TableId(type = IdType.ASSIGN_UUID)
+    @ApiModelProperty(value = "账户操作表uuid")
+    private String id;
+    /**
+     * AI策略ID
+     */
+    @Excel(name = "AI策略ID", width = 15)
+    @ApiModelProperty(value = "AI策略ID")
+    private String aiStrategyUuid;
+    /**
+     * 项目ID
+     */
+    @Excel(name = "项目ID", width = 15)
+    @ApiModelProperty(value = "项目ID")
+    private Long projectId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 异常类型 1 检查错误,2创建时错误
+     */
+    @Excel(name = "错误类型", width = 15)
+    @ApiModelProperty(value = "状态")
+    private Integer errType;
+    /**
+     * 1:账户自动投放 2:项目自动投放
+     */
+    @Excel(name = "1:账户自动投放 2:项目自动投放", width = 15)
+    @ApiModelProperty(value = "1:账户自动投放 2:项目自动投放")
+    private Integer createType;
+    /**
+     * 状态详情
+     */
+    @Excel(name = "状态详情", width = 15)
+    @ApiModelProperty(value = "状态详情")
+    private String message;
+    private String statDate;
+    /**
+     * 状态
+     */
+    @Excel(name = "状态", width = 15)
+    @ApiModelProperty(value = "状态")
+    private Integer status;
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    private Date updateTime;
+}

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouProjectStrategy.java

@@ -369,4 +369,5 @@ public class KuaishouProjectStrategy {
     private Long campaignId;
     @TableField(exist = false)
     private String projectName;
+
 }

+ 20 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/AiKuaishouAccountLevelOperationRecordMapper.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountLevelOperationRecord;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 智能投放-账户层级操作记录表
+ *
+ * @author jeecg-boot
+ * 2021-07-11
+ * @version V1.0
+ */
+public interface AiKuaishouAccountLevelOperationRecordMapper extends BaseMapper<AiKuaishouAccountLevelOperationRecord> {
+
+    List<JSONObject> queryMatchResult(@Param("projectId") Long projectId);
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouAppPackageRelMapper.java

@@ -28,4 +28,6 @@ public interface KuaishouAppPackageRelMapper extends BaseMapper<KuaishouAppPacka
     List<JSONObject> getAccountByProjectId(@Param("projectId") Long projectId, @Param("id") String id);
 
     List<JSONObject> getAppsDetail(@Param("ids") List<Long> ids);
+
+    Long queryAppId(@Param("appTemId") Long appTemId, @Param("accountId") Long accountId);
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouProjectStrategyMapper.java

@@ -23,5 +23,5 @@ public interface KuaishouProjectStrategyMapper extends BaseMapper<KuaishouProjec
 
     JSONObject queryAccountAll(JSONObject data);
 
-    int checkProjectisOpen(Long projectId);
+    Integer checkProjectisOpen(Long projectId);
 }

+ 17 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/AiKuaishouAccountLevelOperationRecordMapper.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouAccountLevelOperationRecordMapper">
+
+    <select id="queryMatchResult" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            t1.account_id as 'accountId',
+            t1.message as 'resultText',
+            t1.`status` as 'authStatus',
+            t2.auth_name as 'authName'
+        FROM
+            ctop_ai_kuaishou_account_level_operation_record t1
+                LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where t1.project_id = #{projectId}
+        and stat_date = DATE_FORMAT(now(), '%Y-%m-%d')
+    </select>
+</mapper>

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouAppPackageRelMapper.xml

@@ -92,6 +92,13 @@
           AND t1.project_id = #{projectId}
     </select>
 
+    <select id="queryAppId" resultType="java.lang.Long">
+        SELECT app_id FROM  ctop_kuaishou_app_package_rel
+        where data_status = 1
+        AND account_id = #{accountId}
+        AND apptem_id = #{appTemId}
+    </select>
+
     <select id="getAppsDetail" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
             t2.id,

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouProjectStrategyMapper.xml

@@ -150,7 +150,7 @@
 
 
     <select id="checkProjectisOpen" resultType="java.lang.Integer">
-        SELECT 1 FROM ctop_ai_kuaishou_project_strategy WHERE data_status = 1
+        SELECT COUNT(1) FROM ctop_ai_kuaishou_project_strategy WHERE data_status = 1
         AND project_id = #{projectId}
         LIMIT 1
     </select>

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouAccountLevelOperationRecordService.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountLevelOperationRecord;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 智能投放-账户层级操作记录表
+ *
+ * @author jeecg-boot
+ * 2021-07-11
+ * @version V1.0
+ */
+public interface IAiKuaishouAccountLevelOperationRecordService extends IService<AiKuaishouAccountLevelOperationRecord> {
+
+}

+ 1 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouProjectCreateCreativeService.java

@@ -4,11 +4,7 @@ import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouProjectStrategy;
 
 public interface IAiKuaishouProjectCreateCreativeService {
 
-    void projectAutomaticCreates(KuaishouProjectStrategy strategy);
-
-    void customCreativeSupplement(KuaishouProjectStrategy strategy, Integer hour);
-
-    void customCreativeLimit(KuaishouProjectStrategy strategy);
+    void projectAutomaticCreates(KuaishouProjectStrategy strategy,Integer operationType);
 
     // 组创建是否超限
     Boolean getUnitOverrun(String keyx);

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouAppPackageService.java

@@ -40,4 +40,6 @@ public interface IKuaishouAppPackageService extends IService<KuaishouAppPackage>
     Result<Object> getProjectAppList(Long projectId);
 
     Result<Object> getAppsDetail(List<Long> list);
+
+    Long queryAppId(Long appTemId, Long accountId);
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouProjectStrategyService.java

@@ -18,7 +18,7 @@ public interface IKuaishouProjectStrategyService extends IService<KuaishouProjec
 
     Result<Object> queryAccountList(JSONObject data);
 
-    Result<Object> queryMatchResult(String id);
+    Result<Object> queryMatchResult(Long projectId,Integer pageNo, Integer pageSize);
 
     boolean checkProjectisOpen(Long projectId);
 }

+ 19 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountLevelOperationRecordServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouAccountLevelOperationRecordMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountLevelOperationRecordService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 智能投放-账户层级操作记录表
+ *
+ * @author jeecg-boot
+ * 2021-07-11
+ * @version V1.0
+ */
+@Service
+public class AiKuaishouAccountLevelOperationRecordServiceImpl extends ServiceImpl<AiKuaishouAccountLevelOperationRecordMapper, AiKuaishouAccountLevelOperationRecord> implements IAiKuaishouAccountLevelOperationRecordService {
+
+}

+ 230 - 198
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouProjectCreateCreativeServiceImpl.java

@@ -9,6 +9,7 @@ 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.AiKuaishouAccountLevelOperationRecord;
 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;
@@ -22,6 +23,7 @@ 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.mapper.KuaishouVideoDirectionalPackageMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouAppInfoService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountLevelOperationRecordService;
 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;
@@ -29,8 +31,8 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouProjectCreateCreativeS
 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;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAppPackageService;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
@@ -94,6 +96,8 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
     @Autowired
     private IAiKuaishouCampaignLevelOperationRecordService aiKuaishouCampaignLevelOperationRecordService;
     @Autowired
+    private IAiKuaishouAccountLevelOperationRecordService kuaishouAccountLevelOperationRecordService;
+    @Autowired
     private IAiKuaiShouAppInfoService appInfoService;
     @Autowired
     private IAiKuaishouUnitLevelOperationRecordService unitLevelOperationRecordService;
@@ -106,6 +110,8 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
     @Autowired
     private KuaishouVideoDirectionalPackageMapper packageMapper;
     @Autowired
+    private IKuaishouAppPackageService appPackageService;
+    @Autowired
     private IKuaishouDirectionalPackageService directionalPackageService;
     @Autowired
     private IKuaiShouCreativeService kuaiShouCreativeService;
@@ -118,7 +124,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
      * @return void
      */
     @Override
-    public void projectAutomaticCreates(KuaishouProjectStrategy strategy) {
+    public void projectAutomaticCreates(KuaishouProjectStrategy strategy, Integer operationType) {
         try {
             //自定义组数,最多540
             Integer customUnitCnt = strategy.getCustomUnitCnt();
@@ -145,12 +151,12 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
             //创意制作方式,0-不限,4-自定义,7-程序化创意
             for (Integer createType : sourceMaterial) {
                 if (strategy.getUnitType() == 4) {
-                    this.autoCreateCreative(strategy, createType, customUnitCnt);
+                    this.autoCreateCreative(strategy, createType, customUnitCnt, operationType);
                 } else if (strategy.getUnitType() == 7) {
-                    this.autoCreateProgramCreative(strategy, createType, programUnitCnt);
+                    this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
                 } else {
-                    this.autoCreateProgramCreative(strategy, createType, programUnitCnt);
-                    this.autoCreateCreative(strategy, createType, customUnitCnt);
+                    this.autoCreateProgramCreative(strategy, createType, programUnitCnt, operationType);
+                    this.autoCreateCreative(strategy, createType, customUnitCnt, operationType);
                 }
             }
         } catch (Exception e) {
@@ -165,14 +171,16 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
      * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材 4:历史打捞
      * @param videoCnt   视频数量
      */
-    private Integer autoCreateCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt) {
+    private void autoCreateCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt, Integer operationType) {
         try {
             String strategyUuid = UUID.randomUUID().toString();
+            strategy.setStrategyUuid(strategyUuid);
             Long accountId = strategy.getAccountId();
             CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
             if (null == token) {
                 log.info("token获取失败=>accountId:{}", accountId);
-                return videoCnt;
+                insertAccountOperationRecord(strategy, "获取token失败", operationType, 0);
+                return;
             }
             //1:获取视频信息
             kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
@@ -190,31 +198,40 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                 List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, Long.valueOf(videoCnt));
                 if (null == newVideos || newVideos.isEmpty()) {
                     log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
-                    return videoCnt;
+                    insertAccountOperationRecord(strategy, "账户在" + startTime + "~" + endTime + "时间段内未获取到相应素材(" + replaceString + ")", operationType, 0);
+                    return;
                 }
                 Long appId = null;
                 //appId,当计划类型为2时必填
                 if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
-                    appId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
-                    if (Check.isNull(appId)) {
-                        return videoCnt;
+                    Long appTemId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
+                    if (Check.isNull(appTemId)) {
+                        insertAccountOperationRecord(strategy, "未获取到项目应用模板", operationType, 0);
+                        return;
+                    }
+                    appId = appPackageService.queryAppId(appTemId, token.getAccountId());
+                    if (Check.isNull(appTemId)) {
+                        insertAccountOperationRecord(strategy, "未获取到appId", operationType, 0);
+                        return;
                     }
                 }
                 Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
                 if (null == newCampaignId) {
-                    return videoCnt;
+                    insertAccountOperationRecord(strategy, "创建广告计划失败", operationType, 0);
+                    return;
                 }
+                strategy.setCampaignId(newCampaignId);
                 //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
                 for (KuaiShouVideoGet videoItem : newVideos) {
                     Boolean unitOverrun = getUnitOverrun(accountId.toString());
                     if (unitOverrun) {
                         log.error("组创建超限,accountId:{}", accountId);
-                        return 0;
+                        return;
                     }
                     //快手账户创意创建超限记录信息,查到数据则说明已经超限
                     KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                     if (null != overrunInfo) {
-                        return 0;
+                        return;
                     }
                     // 每个组,搭配5个创意
                     List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
@@ -223,44 +240,54 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                         continue;
                     }
                     String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, videoItem.getMaterialType());
-                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, videoItem);
-                    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");
-                    AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
-                    BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
-                    unitLevelOperationRecord.setGroupName(unitName);
-                    unitLevelOperationRecord.setCampaignId(newCampaignId);
-                    unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
-                    unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
-                    unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
-                    unitLevelOperationRecord.setCreateTime(new Date());
-                    unitLevelOperationRecord.setStatus(unitCode);
-                    unitLevelOperationRecord.setMessage(unitMessage);
-                    unitLevelOperationRecord.setCampaignId(newCampaignId);
-                    unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
-                    unitLevelOperationRecord.setCreateType(2);//项目创建
-                    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(), strategy, strategyUuid, null);
-                    if (videoCnt <= 0) {
-                        return 0;
+                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, videoItem, operationType);
+                    if (!Check.isNull(unitParams) && operationType == 2) {
+                        AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
+                        BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
+                        unitLevelOperationRecord.setGroupName(unitName);
+                        unitLevelOperationRecord.setCampaignId(newCampaignId);
+                        unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
+                        unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
+                        unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
+                        unitLevelOperationRecord.setCreateTime(new Date());
+                        unitLevelOperationRecord.setCampaignId(newCampaignId);
+                        unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
+                        unitLevelOperationRecord.setCreateType(2);//项目创建
+                        Integer unitCode = -1;
+                        String msg = unitParams.getString("errorMsg");
+                        if (Check.isNull(msg)) {
+                            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
+                            unitCode = (Integer) unitCreateResult.get("code");
+                            msg = (String) unitCreateResult.get("message");
+                            unitLevelOperationRecord.setStatus(unitCode);
+                            unitLevelOperationRecord.setMessage(msg);
+                            if (unitCode == 0) {
+                                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(), strategy, strategyUuid, null);
+                                if (videoCnt <= 0) {
+                                    return;
+                                }
+                            }
+                            if (unitCode != 0) {
+                                unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                            }
+                        } else {
+                            unitLevelOperationRecord.setStatus(unitCode);
+                            unitLevelOperationRecord.setMessage(msg);
+                            unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                        }
                     }
                 }
             }
         } catch (BeansException e) {
             log.error("创建自定义创意异常", e);
+            insertAccountOperationRecord(strategy, "创建自定义创意异常", operationType, 0);
         }
-        return videoCnt;
+        insertAccountOperationRecord(strategy, "success", operationType, 1);
     }
 
     /**
@@ -268,172 +295,133 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
      *
      * @param strategy
      */
-    public void autoCreateProgramCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt) {
-        String strategyUuid = UUID.randomUUID().toString();
-        strategy.setStrategyUuid(strategyUuid);
-        strategy.setUnitType(7);
-        Long accountId = strategy.getAccountId();
-        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
-        if (null == token) {
-            log.info("token获取失败=>accountId:{}", accountId);
-            return;
-        }
-        //1:获取视频信息
-        kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
-        //2:判定账户是否单一应用
-        Long timeStart = null;
-        Long timeEnd = null;
-        Integer singleAppid = strategy.getSingleAppid();
-        if (null != singleAppid && singleAppid == 0) {
-            timeStart = -7 * 60 * 24L;
-            timeEnd = -5L;
-        } else {
-            timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
-            timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
-        }
-        Long now = System.currentTimeMillis();
-        String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
-        String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
-        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
-        String key = token.getAccountId() + "_ProgramCreative" + "_" + nowDate;
-
-        //单/多应用,1单应用,2多应用
-        if (null != singleAppid && singleAppid == 1) {
-            String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
-            //单一应用
-            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, Long.valueOf(videoCnt));
-            if (null == allVideos) {
+    public void autoCreateProgramCreative(KuaishouProjectStrategy strategy, Integer createType, Integer videoCnt, Integer operationType) {
+        try {
+            String strategyUuid = UUID.randomUUID().toString();
+            strategy.setStrategyUuid(strategyUuid);
+            strategy.setUnitType(7);
+            Long accountId = strategy.getAccountId();
+            CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
+            if (null == token) {
+                log.info("token获取失败=>accountId:{}", accountId);
+                insertAccountOperationRecord(strategy, "token获取失败", operationType, 0);
                 return;
             }
-            Long appId = null;
-            //appId,当计划类型为2时必填
-            if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
-                appId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
-                if (Check.isNull(appId)) {
-                    return;
-                }
-            }
-            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
-            if (null == newCampaignId) {
-                return;
+            //1:获取视频信息
+            kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
+            //2:判定账户是否单一应用
+            Long timeStart = null;
+            Long timeEnd = null;
+            Integer singleAppid = strategy.getSingleAppid();
+            if (null != singleAppid && singleAppid == 0) {
+                timeStart = -7 * 60 * 24L;
+                timeEnd = -5L;
+            } else {
+                timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
+                timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
             }
-            strategy.setCampaignId(newCampaignId);
-            //创意
-            List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
-            for (int j = 1; j < splitVideos.size() + 1; j++) {
-                Boolean unitOverrun = getUnitOverrun(accountId.toString());
-                if (unitOverrun) {
-                    log.error("组创建超限,accountId:{}", accountId);
+            Long now = System.currentTimeMillis();
+            String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+            String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            String key = token.getAccountId() + "_ProgramCreative" + "_" + nowDate;
+
+            //单/多应用,1单应用,2多应用
+            if (null != singleAppid && singleAppid == 1) {
+                String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
+                //单一应用
+                List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, Long.valueOf(videoCnt));
+                if (null == allVideos) {
+                    insertAccountOperationRecord(strategy, "账户在" + startTime + "~" + endTime + "时间段内未获取到相应素材(" + replaceString + ")", operationType, 0);
                     return;
                 }
-
-                Object redisObj = redisUtil.get(key);
-                if (!Check.isNull(redisObj)) {
-                    Integer value = (Integer) redisObj;
-                    if (value == 1) {
-                        log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
+                Long appId = null;
+                //appId,当计划类型为2时必填
+                if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
+                    Long appTemId = Check.isNull(strategy.getAppId()) ? JSONArray.parseArray(strategy.getAppIdArray()).getLong(0) : strategy.getAppId();
+                    if (Check.isNull(appTemId)) {
+                        insertAccountOperationRecord(strategy, "未获取到项t目应用模板", operationType, 0);
+                        return;
+                    }
+                    appId = appPackageService.queryAppId(appTemId, token.getAccountId());
+                    if (Check.isNull(appTemId)) {
+                        insertAccountOperationRecord(strategy, "未获取到appId", operationType, 0);
                         return;
                     }
                 }
-                //创建组
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, null);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, null);
-                if (!Check.isNull(unitParams)) {
-                    AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
-                    BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
-                    unitLevelOperationRecord.setGroupName(unitName);
-                    unitLevelOperationRecord.setCampaignId(newCampaignId);
-                    unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
-                    unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
-                    unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
-                    unitLevelOperationRecord.setCreateTime(new Date());
-                    unitLevelOperationRecord.setCampaignId(newCampaignId);
-                    unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
-                    unitLevelOperationRecord.setCreateType(2);//项目创建
-                    Integer unitCode = -1;
-                    String errorMsg = unitParams.getString("errorMsg");
-                    if (Check.isNull(errorMsg)) {
-                        log.info("创建广告组入参:{}", unitParams);
-                        Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-                        unitCode = (Integer) unitCreateResult.get("code");
-                        errorMsg = (String) unitCreateResult.get("message");
-                        unitLevelOperationRecord.setStatus(unitCode);
-                        unitLevelOperationRecord.setMessage(errorMsg);
-                        if (unitCode == 0) {
-                            Long unitId = (Long) unitCreateResult.get("unitId");
-                            unitLevelOperationRecord.setUnitId(unitId);
-                            unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                            JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
-                            createProgramCreative(token, creativeParams, strategy);
+                Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
+                if (null == newCampaignId) {
+                    insertAccountOperationRecord(strategy, "创建广告计划失败", operationType, 0);
+                    return;
+                }
+                strategy.setCampaignId(newCampaignId);
+                //创意
+                List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
+                for (int j = 1; j < splitVideos.size() + 1; j++) {
+                    Boolean unitOverrun = getUnitOverrun(accountId.toString());
+                    if (unitOverrun) {
+                        log.error("组创建超限,accountId:{}", accountId);
+                        return;
+                    }
+
+                    Object redisObj = redisUtil.get(key);
+                    if (!Check.isNull(redisObj)) {
+                        Integer value = (Integer) redisObj;
+                        if (value == 1) {
+                            log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
+                            return;
                         }
                     }
-                    if (unitCode != 0) {
-                        unitLevelOperationRecord.setMessage(errorMsg);
-                        log.error("组创建失败=>accountId:{};message:{}", accountId, errorMsg);
-                        unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                        return;
+                    //创建组
+                    String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, null);
+                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, null, operationType);
+                    if (!Check.isNull(unitParams)) {
+                        AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
+                        BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
+                        unitLevelOperationRecord.setGroupName(unitName);
+                        unitLevelOperationRecord.setCampaignId(newCampaignId);
+                        unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
+                        unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
+                        unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
+                        unitLevelOperationRecord.setCreateTime(new Date());
+                        unitLevelOperationRecord.setCampaignId(newCampaignId);
+                        unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
+                        unitLevelOperationRecord.setCreateType(2);//项目创建
+                        Integer unitCode = -1;
+                        String errorMsg = unitParams.getString("errorMsg");
+                        if (Check.isNull(errorMsg)) {
+                            log.info("创建广告组入参:{}", unitParams);
+                            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
+                            unitCode = (Integer) unitCreateResult.get("code");
+                            errorMsg = (String) unitCreateResult.get("message");
+                            unitLevelOperationRecord.setStatus(unitCode);
+                            unitLevelOperationRecord.setMessage(errorMsg);
+                            if (unitCode == 0) {
+                                Long unitId = (Long) unitCreateResult.get("unitId");
+                                unitLevelOperationRecord.setUnitId(unitId);
+                                unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
+                                createProgramCreative(token, creativeParams, strategy);
+                            }
+                            if (unitCode != 0) {
+                                log.error("组创建失败=>accountId:{};message:{}", accountId, errorMsg);
+                                unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                            }
+                        } else {
+                            unitLevelOperationRecord.setStatus(unitCode);
+                            unitLevelOperationRecord.setMessage(errorMsg);
+                            unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                        }
                     }
                 }
             }
+        } catch (BeansException e) {
+            e.printStackTrace();
+            log.error("创建程序化创意异常", e);
         }
+        insertAccountOperationRecord(strategy, "success", operationType, 1);
     }
 
-    @Override
-    public void customCreativeSupplement(KuaishouProjectStrategy strategy, Integer hour) {
-        Integer customUnitCnt = strategy.getCustomUnitCnt();
-        if (Check.isNull(customUnitCnt)) {
-            Integer imageCnt = strategy.getImageCnt();
-            if (imageCnt <= 1) {
-                customUnitCnt = 600;
-            } else {
-                customUnitCnt = 2000 / imageCnt;
-            }
-        }
-
-        Integer unitNum = customUnitCnt * hour / 20;
-        log.info("{}当前时间内需要创建组总数:{}", strategy.getAccountId(), unitNum);
-        //查询当前账户创建自定义类型组数量
-        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId());
-        log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
-        Integer remindCnt = unitNum - unitCreateCnt;
-        if (remindCnt >= 1) {
-            log.info("{}组创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
-            //优先创建历史遗漏素材
-            remindCnt = this.autoCreateCreative(strategy, 3, remindCnt);
-        }
-        if (remindCnt >= 1) {
-            log.info("{}组创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
-            //高质量素材
-            remindCnt = this.autoCreateCreative(strategy, 2, remindCnt);
-        }
-        if (remindCnt >= 1) {
-            //历史打捞素材
-            log.info("{}组创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
-            this.autoCreateCreative(strategy, 4, remindCnt);
-        }
-    }
-
-    @Override
-    public void customCreativeLimit(KuaishouProjectStrategy strategy) {
-        Integer unitNum = strategy.getCustomUnitCnt();
-        if (Check.isNull(unitNum)) {
-            Integer imageCnt = strategy.getImageCnt();
-            if (imageCnt <= 1) {
-                unitNum = 600;
-            } else {
-                unitNum = 2000 / imageCnt;
-            }
-        }
-        log.info("{}当天可创建组总数:{}", strategy.getAccountId(), unitNum);
-        //查询当前账户创建自定义类型组数量
-        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId());
-        log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
-        Integer remindCnt = unitNum - unitCreateCnt;
-        if (remindCnt >= 1) {
-            log.info("{}组创建不足,剩余需要创建个数{},开始上新素材创建", strategy.getAccountId(), remindCnt);
-            this.autoCreateCreative(strategy, 1, remindCnt);
-        }
-    }
 
     @Autowired
     private IKuaiShouUpdateService updateService;
@@ -724,7 +712,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
         return campaignId;
     }
 
-    private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, KuaishouProjectStrategy strategy, String unitName, Long appId, KuaiShouVideoGet videoItem) {
+    private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, KuaishouProjectStrategy strategy, String unitName, Long appId, KuaiShouVideoGet videoItem, Integer operationType) {
         JSONObject unitParams = null;
         try {
             // 拼装创建组的入参 json
@@ -894,12 +882,14 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                 List<KuaishouDirectionalPackage> targets = directionalPackageService.getProjectTargetByIds(templateIds);
                 if (Check.isNull(targets)) {
                     unitParams.put("errorMsg", "获取项目定向模板失败");
+                    insertAccountOperationRecord(strategy, "获取项目定向模板失败", operationType, 0);
                     return unitParams;
                 }
                 if (!Check.isNull(videoItem)) {
                     targets = checkTemplateIds(targets, videoItem);
                     if (Check.isNull(targets)) {
                         unitParams.put("errorMsg", "未匹配到符合素材的定向");
+                        insertAccountOperationRecord(strategy, "未匹配到符合素材的定向", operationType, 0);
                         return unitParams;
                     }
                 }
@@ -912,6 +902,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                 }
                 if (Check.isNull(tempIds)) {
                     unitParams.put("errorMsg", "定向包管理中,该账户未在项目定向模板下进行推送创建");
+                    insertAccountOperationRecord(strategy, "定向包管理中,该账户未在项目定向模板下进行推送创建", operationType, 0);
                     return unitParams;
                 }
 
@@ -927,12 +918,14 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                             unitParams.put("target", target);
                         } else {
                             unitParams.put("errorMsg", "组创建异常=》accountId(" + strategy.getAccountId() + ")联盟广告位定向模板错误");
+                            insertAccountOperationRecord(strategy, "联盟广告位定向模板错误", operationType, 0);
                             return unitParams;
                         }
                     }
                 }
             } else {
                 unitParams.put("errorMsg", "策略未选择定向");
+                insertAccountOperationRecord(strategy, "策略未选择定向", operationType, 0);
                 return unitParams;
             }
         } catch (Exception e) {
@@ -1431,4 +1424,43 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
 
     }
 
+    /**
+     * 记录账户维度操作数据
+     *
+     * @param strategy 策略
+     * @param msg      说明
+     * @param errType  异常类型 1 检查错误,2创建时错误
+     * @param status   状态 0失败,1成功
+     * @throws
+     */
+    private void insertAccountOperationRecord(KuaishouProjectStrategy strategy, String msg, Integer errType, Integer status) {
+        String statDate = DateUtils.formatDate(new Date());
+        QueryWrapper<AiKuaishouAccountLevelOperationRecord> wrapper = new QueryWrapper<>();
+        wrapper.eq("account_id", strategy.getAccountId());
+        wrapper.eq("stat_date", statDate);
+        wrapper.last("limit 1");
+        AiKuaishouAccountLevelOperationRecord accountOperationRecord = kuaishouAccountLevelOperationRecordService.getOne(wrapper);
+        if (Check.isNull(accountOperationRecord)) {
+            accountOperationRecord = new AiKuaishouAccountLevelOperationRecord();
+            accountOperationRecord.setMessage(msg);
+            accountOperationRecord.setProjectId(strategy.getProjectId());
+            accountOperationRecord.setAccountId(strategy.getAccountId());
+            accountOperationRecord.setErrType(errType);
+            accountOperationRecord.setCreateTime(new Date());
+            accountOperationRecord.setAiStrategyUuid(strategy.getStrategyUuid());
+            accountOperationRecord.setStatDate(statDate);
+            accountOperationRecord.setStatus(status);
+        } else {
+            if (status == 1 && !accountOperationRecord.getAiStrategyUuid().equals(strategy.getAccountId())) {
+                accountOperationRecord.setStatus(status);
+                accountOperationRecord.setMessage(msg);
+            }
+            if (status == 0) {
+                accountOperationRecord.setStatus(status);
+                accountOperationRecord.setMessage(msg);
+            }
+        }
+        kuaishouAccountLevelOperationRecordService.saveOrUpdate(accountOperationRecord);
+    }
+
 }

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouAppPackageServiceImpl.java

@@ -192,6 +192,11 @@ public class KuaishouAppPackageServiceImpl extends ServiceImpl<KuaishouAppPackag
         return Result.ok(list);
     }
 
+    @Override
+    public Long queryAppId(Long appTemId, Long accountId) {
+        return relMapper.queryAppId(appTemId, accountId);
+    }
+
     private String getCellValue(Cell cell) {
         String value = "";
         if (cell != null) {

+ 10 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouProjectStrategyServiceImpl.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.kuaishou.modules.ai.service.impl;
 
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountLevelOperationRecord;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouProjectStrategy;
+import cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouAccountLevelOperationRecordMapper;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouProjectStrategyMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouProjectStrategyService;
 import com.alibaba.fastjson.JSONObject;
@@ -27,6 +29,9 @@ public class KuaishouProjectStrategyServiceImpl extends ServiceImpl<KuaishouProj
     @Autowired
     private KuaishouProjectStrategyMapper kuaishouProjectStrategyMapper;
 
+    @Autowired
+    private AiKuaishouAccountLevelOperationRecordMapper kuaishouAccountLevelOperationRecordMapper;
+
     @Override
     public Result<Object> queryProjectList(JSONObject data, Integer pageNo, Integer pageSize) {
         JSONObject result = new JSONObject();
@@ -52,13 +57,15 @@ public class KuaishouProjectStrategyServiceImpl extends ServiceImpl<KuaishouProj
     }
 
     @Override
-    public Result<Object> queryMatchResult(String id) {
-        return null;
+    public Result<Object> queryMatchResult(Long projectId ,Integer pageNo, Integer pageSize) {
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> list = kuaishouAccountLevelOperationRecordMapper.queryMatchResult(projectId);
+        return Result.ok(new PageInfo<>(list));
     }
 
     @Override
     public boolean checkProjectisOpen(Long projectId) {
-        int num = kuaishouProjectStrategyMapper.checkProjectisOpen(projectId);
+        Integer num = kuaishouProjectStrategyMapper.checkProjectisOpen(projectId);
         return  num>0;
     }
 }