浏览代码

定时任务

syh 4 年之前
父节点
当前提交
a9ddb7d2dc

+ 10 - 2
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDancePlanRuleDataJob.java

@@ -11,6 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Component
 public class ByteDancePlanRuleDataJob {
@@ -18,6 +21,7 @@ public class ByteDancePlanRuleDataJob {
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IReportService reportService;
+    private ExecutorService executorService = Executors.newFixedThreadPool(10);
 
     @XxlJob("bytedancePlanLoadJob")
     public ReturnT<String> execute(String param) throws Exception {
@@ -26,8 +30,12 @@ public class ByteDancePlanRuleDataJob {
             Long accountId = Long.parseLong(param);
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
             reportService.getAdvertiserPlanRuleData(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+            XxlJobLogger.log("头条计划数据清洗完成:accountId=>{}",param);
+            return ReturnT.SUCCESS;
+        }else{
+            List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+            tokens.forEach(token -> executorService.submit(()->reportService.getAdvertiserPlanRuleData(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY)));
+            return ReturnT.SUCCESS;
         }
-        XxlJobLogger.log("头条计划数据清洗完成:accountId=>{}",param);
-        return ReturnT.SUCCESS;
     }
 }

+ 12 - 7
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/RuleDataAccountCleanJob.java

@@ -3,6 +3,8 @@ package cn.com.ctop.job.bytedance.handler;
 /**
  *  Created by JQ.bi on 2020.11.16
  */
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.toutiao.modules.report.service.IRuleByteDanceAccountService;
 import com.xxl.job.core.biz.model.ReturnT;
@@ -11,6 +13,7 @@ import com.xxl.job.core.log.XxlJobLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -23,18 +26,20 @@ public class RuleDataAccountCleanJob {
     @Autowired
     private IRuleByteDanceAccountService ruleByteDanceAccountService;
 
-    private ExecutorService executorPool = Executors.newFixedThreadPool(6);
+    private ExecutorService executorService = Executors.newFixedThreadPool(10);
 
     @XxlJob("ruleDataAccountCleanJob")
     public ReturnT<String> execute(String param) throws Exception {
         XxlJobLogger.log("规则预警账户维度数据开始清洗");
         if (null == param || "".equals(param.trim())) {
-            XxlJobLogger.log("参数异常");
-            return ReturnT.FAIL;
+            List<CtopOauthToken> tokens = oauthTokenService.selectToutiaoToken();
+            tokens.forEach(token -> executorService.submit(()->ruleByteDanceAccountService.cleanRuleDataAccount(token.getAccountId())));
+            return ReturnT.SUCCESS;
+        }else{
+            Long accountId = Long.parseLong(param);
+            ruleByteDanceAccountService.cleanRuleDataAccount(accountId);
+            XxlJobLogger.log("规则预警账户维度数据清洗结束");
+            return ReturnT.SUCCESS;
         }
-        Long accountId = Long.parseLong(param);
-        ruleByteDanceAccountService.cleanRuleDataAccount(accountId);
-        XxlJobLogger.log("规则预警账户维度数据清洗结束");
-        return ReturnT.SUCCESS;
     }
 }