Jelajahi Sumber

定时 频库-视频关联创意数查询

zhaoxian 4 tahun lalu
induk
melakukan
91c71e85ca

+ 3 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouDailyAudienceReportJob.java

@@ -38,8 +38,6 @@ public class KuaishouDailyAudienceReportJob {
 
     @XxlJob("kuaishouDailyAudienceReportJob")
     public void execute() throws Exception {
-        //查询两天前数据  策略
-        String date = DateUtils.getLastDay(DateUtils.date2Str(), 2);
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
         if (null == tokens || tokens.isEmpty()) {
             XxlJobHelper.log("定时获取人群分析报表数据异常:未获取到可用的token");
@@ -49,7 +47,7 @@ public class KuaishouDailyAudienceReportJob {
         //查询有效策略的账户ID
         List<Long> accountIds = kuaishouStrategyService.queryActiveAccount();
         if (Check.isNull(accountIds) || accountIds.size() == 0) {
-            XxlJobHelper.log("定时获取人群分析报表数据异常:获取到有效策略账户信息");
+            XxlJobHelper.log("定时获取人群分析报表数据异常:获取到有效策略账户信息");
             XxlJobHelper.handleFail();
             return;
         }
@@ -65,6 +63,8 @@ public class KuaishouDailyAudienceReportJob {
         if (!Check.isNull(activeTokens) && activeTokens.size() > 0) {
             int page = 1;
             int pageSize = 2000;
+            //查询两天前日期
+            String date = DateUtils.getLastDay(DateUtils.date2Str(), 2);
             activeTokens.forEach(token -> executorService.submit(() -> {
                 getAudienceReportData(token, date, "province", page, pageSize);
                 getAudienceReportData(token, date, "city", page, pageSize);

+ 31 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouVideoRelateCreativesJob.java

@@ -5,12 +5,15 @@ import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouStrategyService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
 import com.alibaba.fastjson.JSONArray;
+import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -30,15 +33,40 @@ public class KuaishouVideoRelateCreativesJob {
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaishouStrategyService kuaishouStrategyService;
 
     static ExecutorService executorService = Executors.newFixedThreadPool(5);
 
     @XxlJob("kuaishouVideoRelateCreativesJob")
     public void execute() throws Exception {
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
-        tokens.forEach(token -> executorService.submit(() -> {
-            videoRelateCreatives(token.getAccountId());
-        }));
+        if (null == tokens || tokens.isEmpty()) {
+            XxlJobHelper.log("定时获取人群分析报表数据异常:未获取到可用的token");
+            XxlJobHelper.handleFail();
+            return;
+        }
+        //查询有效策略的账户ID
+        List<Long> accountIds = kuaishouStrategyService.queryActiveAccount();
+        if (Check.isNull(accountIds) || accountIds.size() == 0) {
+            XxlJobHelper.log("定时获取人群分析报表数据异常:未获取到有效策略账户信息");
+            XxlJobHelper.handleFail();
+            return;
+        }
+        //筛选出有效账户,获取该账户的组级人群报表数据
+        List<CtopOauthToken> activeTokens = new ArrayList<>();
+        for (Long accountId : accountIds) {
+            for (CtopOauthToken token : tokens) {
+                if (token.getAccountId() - accountId == 0) {
+                    activeTokens.add(token);
+                }
+            }
+        }
+        if (!Check.isNull(activeTokens) && activeTokens.size() > 0) {
+            activeTokens.forEach(token -> executorService.submit(() -> {
+                videoRelateCreatives(token.getAccountId());
+            }));
+        }
     }
 
     /**

+ 1 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouVideoRelateCreativesServiceImpl.java

@@ -6,10 +6,8 @@ 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.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouVideoRelateCreatives;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouVideoRelateCreativesMapper;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -84,6 +82,7 @@ public class KuaishouVideoRelateCreativesServiceImpl extends ServiceImpl<Kuaisho
                     return Result.ok(resultJson.getJSONObject("data"));
                 } else {
                     log.info("视频库-推送视频失败,accountId:{},返回信息:{}", accountId, resultJson);
+                    return Result.error("视频库-推送视频失败," + resultJson.getString("message"));
                 }
             }
         } catch (Exception e) {