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