Преглед на файлове

头条视频素材报表定时任务编写

hcst_sunzhen преди 5 години
родител
ревизия
9cf8f1c0e8

+ 67 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyVideoMaterialReportAddJob.java

@@ -0,0 +1,67 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 头条视频素材报表每天将前一天新绑定的账户数据从20200101开始跑到前一天
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyVideoMaterialReportAddJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IBytedanceReportService bytedanceReportService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        Date getDate = DateUtils.addDay(new Date(), -1);
+        String endDate = DateUtils.formatDate(getDate);
+        String startDate = "2020-01-01";
+        log.info("头条获取视频素材报表数据补充任务开始,任务时间:{}~{}",startDate,endDate);
+
+        List<CtopOauthToken> tokens = tokenService.getToutiaoTokenByCreateTime(endDate);
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("头条获取素材报表数据任务执行失败:未获取到可用的token");
+            return;
+        }
+
+        final ExecutorService executorService = Executors.newFixedThreadPool(3);
+        tokens.forEach(token -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+
+                        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;
+                            bytedanceReportService.bytedanceVideoMaterialReport(token, start, end);
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+
+    }
+}

+ 64 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyVideoMaterialReportJob.java

@@ -0,0 +1,64 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 头条视频素材报表按天跑前两天的数据任务
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyVideoMaterialReportJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IBytedanceReportService bytedanceReportService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        Date getDate2 = DateUtils.addDay(new Date(), -2);
+        String date2 = DateUtils.formatDate(getDate2);
+
+        Date getDate = DateUtils.addDay(new Date(), -1);
+        String date = DateUtils.formatDate(getDate);
+        log.info("头条获取素材报表数据任务开始,任务时间:" + date2 + "~" + date);
+
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("头条获取素材报表数据任务执行失败:未获取到可用的token");
+            return;
+        }
+
+        final ExecutorService executorService = Executors.newFixedThreadPool(3);
+        tokens.forEach(token -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        //获取头条视频素材报表两天前的数据
+                        bytedanceReportService.bytedanceVideoMaterialReport(token, date2, date2);
+                        //获取头条视频素材报表数据
+                        bytedanceReportService.bytedanceVideoMaterialReport(token, date, date);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+
+    }
+}