|
@@ -0,0 +1,81 @@
|
|
|
+package cn.com.ctop.job.bytedance.handler;
|
|
|
+
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
+import cn.com.ctop.common.module.utils.CtopAdConstant;
|
|
|
+import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
|
|
|
+import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
|
|
|
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
|
|
|
+import cn.com.ctop.toutiao.modules.report.service.IReportService;
|
|
|
+import com.xxl.job.core.biz.model.ReturnT;
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import com.xxl.job.core.log.XxlJobLogger;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.quartz.JobExecutionException;
|
|
|
+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 BytedanceDailyMaterialReportRetryJob {
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(4);
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
+ @Autowired
|
|
|
+ private IBytedanceReportService bytedanceReportService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
|
|
|
+
|
|
|
+ @XxlJob("bytedanceDailyMaterialReportRetryJob")
|
|
|
+ public ReturnT<String> execute(String param) throws Exception {
|
|
|
+ XxlJobLogger.log("头条素材报表重试定时任务开始");
|
|
|
+
|
|
|
+ List<BytedanceReportMaterialRetry> retryList = bytedanceReportService.getRetryList();
|
|
|
+ retryList.forEach(retry -> {
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ String startDate = retry.getStartDate();
|
|
|
+ String endDate = retry.getEndDate();
|
|
|
+ Long accountId = retry.getAccountId();
|
|
|
+ Integer type = retry.getType();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
|
|
|
+ XxlJobLogger.log("头条素材报表重试定时任务开始,当前accountId为:" + token.getAccountId());
|
|
|
+ Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
|
|
|
+ String start = null;
|
|
|
+ String end = null;
|
|
|
+ for (int i = 0; i <= days; i++) {
|
|
|
+ start = DateUtils.addDay(startDate, i);
|
|
|
+ end = start;
|
|
|
+ //获取头条素材报表数据
|
|
|
+ int code = bytedanceReportService.bytedanceMaterialReportRetry(type, token, start, end);
|
|
|
+ XxlJobLogger.log("头条素材报表重试定时任务完成,当前accountId为:" + token.getAccountId() + "code:" + code);
|
|
|
+ if (code == 200 || code == 1) {
|
|
|
+ if (type == 1) {
|
|
|
+ XxlJobLogger.log("头条素材报表重试定时任务清洗数据开始,当前accountId为:" + token.getAccountId());
|
|
|
+ //重试成功清洗数据
|
|
|
+ byteDanceVideoReportDailyService.videoInfoListByAccountId(start, end, accountId);
|
|
|
+ XxlJobLogger.log("头条素材报表重试定时任务清洗数据完成,当前accountId为:" + token.getAccountId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|