Jelajahi Sumber

试玩报表定时任务

hcst_sunzhen 5 tahun lalu
induk
melakukan
134a8165fc

+ 69 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceDailyPlayableReportJob.java

@@ -0,0 +1,69 @@
+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.toutiao.modules.report.service.IBytedanceInterfaceService;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
+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.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 BytedanceDailyPlayableReportJob {
+
+    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IBytedanceInterfaceService bytedanceInterfaceService;
+
+    @XxlJob("bytedanceDailyPlayableReportJob")
+    public ReturnT<String> execute(String param) throws Exception {
+        Date getDate2 = DateUtils.addDay(new Date(), -2);
+        String date2 = DateUtils.formatDate(getDate2);
+
+        Date getDate = DateUtils.addDay(new Date(), -1);
+        String date = DateUtils.formatDate(getDate);
+        XxlJobLogger.log("头条获取试玩报表数据任务开始,任务时间:" + date2 + "~" + date);
+
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.size() <= 0) {
+            XxlJobLogger.log("头条获取试玩报表数据任务执行失败:未获取到可用的token");
+            return ReturnT.FAIL;
+        }
+
+        tokens.forEach(token -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        //获取头条素材报表两天前的数据
+                        XxlJobLogger.log("账户"+token.getAccountId() + "试玩报表数据任务开始,任务时间:" + date2 + "~" + date2);
+                        bytedanceInterfaceService.bytedancePlayableReport(token, date2, date2);
+                        XxlJobLogger.log("账户"+token.getAccountId() + "试玩报表数据任务完成,任务时间:" + date2 + "~" + date2);
+
+                        //获取头条素材报表数据
+                        XxlJobLogger.log("账户"+token.getAccountId() + "试玩报表数据任务开始,任务时间:" + date + "~" + date);
+                        bytedanceInterfaceService.bytedancePlayableReport(token, date, date);
+                        XxlJobLogger.log("账户"+token.getAccountId() + "试玩报表数据任务完成,任务时间:" + date + "~" + date);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+        return ReturnT.SUCCESS;
+    }
+
+
+
+}

+ 68 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceDailyPlayableReportRetryJob.java

@@ -0,0 +1,68 @@
+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.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
+import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportPlayableRetry;
+import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceInterfaceService;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class BytedanceDailyPlayableReportRetryJob {
+    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IBytedanceInterfaceService bytedanceInterfaceService;
+
+
+    @XxlJob("bytedanceDailyPlayableReportRetryJob")
+    public ReturnT<String> execute(String param) throws Exception {
+        XxlJobLogger.log("头条试玩报表重试定时任务开始");
+
+        List<BytedanceReportPlayableRetry> retryList = bytedanceInterfaceService.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 = bytedanceInterfaceService.bytedancePlayableReportRetry(type, token, start, end);
+                            XxlJobLogger.log("头条试玩报表重试定时任务完成,当前accountId为:" + token.getAccountId() + "code:" + code);
+
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+        return ReturnT.SUCCESS;
+    }
+
+
+}