소스 검색

修改定时任务日志

syh 4 년 전
부모
커밋
c614639333
1개의 변경된 파일18개의 추가작업 그리고 14개의 파일을 삭제
  1. 18 14
      module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceDailyMaterialReportJob.java

+ 18 - 14
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceDailyMaterialReportJob.java

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
 
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -19,6 +20,7 @@ import java.util.concurrent.Executors;
 public class BytedanceDailyMaterialReportJob {
 
     static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    CountDownLatch countDownLatch ;
     @Autowired
     private ICtopOauthTokenService tokenService;
     @Autowired
@@ -28,7 +30,7 @@ public class BytedanceDailyMaterialReportJob {
     public ReturnT<String> execute(String param) throws Exception {
         Date getDate2 = DateUtils.addDay(new Date(), -2);
         String date2 = DateUtils.formatDate(getDate2);
-
+        Long start = System.currentTimeMillis();
         Date getDate = DateUtils.addDay(new Date(), -1);
         String date = DateUtils.formatDate(getDate);
         XxlJobLogger.log("头条获取素材报表数据任务开始,任务时间:" + date2 + "~" + date);
@@ -38,33 +40,35 @@ public class BytedanceDailyMaterialReportJob {
             XxlJobLogger.log("头条获取素材报表数据任务执行失败:未获取到可用的token");
             return ReturnT.FAIL;
         }
+        CountDownLatch countDownLatch = new CountDownLatch(tokens.size());
 
-        tokens.forEach(token -> {
-            executorService.submit(new Runnable() {
+        tokens.forEach(token -> executorService.submit(new Runnable() {
                 @Override
                 public void run() {
                     try {
                         //获取头条素材报表两天前的数据
-                        XxlJobLogger.log("账户"+token.getAccountId() + "素材报表数据任务开始,任务时间:" + date2 + "~" + date2);
+                        XxlJobLogger.log("账户"+token.getAccountId() + "素材报表数据任务开始,任务时间:" + date + "~" + date2);
                         bytedanceReportService.bytedanceMaterialReport(token, date2, date2);
-                        XxlJobLogger.log("账户"+token.getAccountId() + "素材报表数据任务完成,任务时间:" + date2 + "~" + date2);
-
-                        //获取头条素材报表数据
-                        XxlJobLogger.log("账户"+token.getAccountId() + "素材报表数据任务开始,任务时间:" + date + "~" + date);
                         bytedanceReportService.bytedanceMaterialReport(token, date, date);
-                        XxlJobLogger.log("账户"+token.getAccountId() + "素材报表数据任务完成,任务时间:" + date + "~" + date);
-
-                        //获取头条素材报表两天前的数据
-                        bytedanceReportService.bytedanceVideoMaterialReport(token, date2, date2);
                         //获取头条素材报表数据
+                        bytedanceReportService.bytedanceVideoMaterialReport(token, date2, date2);
                         bytedanceReportService.bytedanceVideoMaterialReport(token, date, date);
+                        XxlJobLogger.log("账户"+token.getAccountId() + "素材报表数据任务完成,任务时间:" + date + "~" + date2);
                     } catch (Exception e) {
                         e.printStackTrace();
                     } finally {
+                        countDownLatch.countDown();
                     }
                 }
-            });
-        });
+            }));
+
+        try {
+            countDownLatch.await();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        Long end = System.currentTimeMillis();
+        XxlJobLogger.log("头条素材数据获取耗时:{}毫秒", end - start);
         return ReturnT.SUCCESS;
     }
 }