Browse Source

异步报表定时任务、素材报表定时任务

hcst_sunzhen 5 years ago
parent
commit
ca595ea385

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

@@ -0,0 +1,52 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+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.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 头条素材报表按天跑前一天的数据任务
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyAccountReportAsyncJob 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 date = DateUtils.formatDate(getDate);
+
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");
+            return ;
+        }
+
+        for (CtopOauthToken token : tokens) {
+            try {
+                bytedanceReportService.bytedanceAsyncTaskCreate(date, date, token, 2);  //1.创意 2.广告主 3.广告主 4.广告计划
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+}

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

@@ -0,0 +1,50 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+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.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 头条素材报表按天跑前一天的数据任务
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyCampaignReportAsyncJob 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 date = DateUtils.formatDate(getDate);
+
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");
+            return ;
+        }
+
+        for (CtopOauthToken token : tokens) {
+            try {
+                bytedanceReportService.bytedanceAsyncTaskCreate(date, date, token, 3);  //1.创意 2.广告主 3.广告组 4.广告计划
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+}

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

@@ -0,0 +1,50 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+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.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 头条素材报表按天跑前一天的数据任务
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyCreativeReportAsyncJob 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 date = DateUtils.formatDate(getDate);
+
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");
+            return ;
+        }
+
+        for (CtopOauthToken token : tokens) {
+            try {
+                bytedanceReportService.bytedanceAsyncTaskCreate(date, date, token, 1);  //1.创意 2.广告主 3.广告主 4.广告计划
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+}

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

@@ -0,0 +1,60 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+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 BytedanceDailyMaterialReportJob 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 date = DateUtils.formatDate(getDate);
+
+        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.bytedanceMaterialReport(token, date, date);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+
+    }
+}

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

@@ -0,0 +1,56 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+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 BytedanceDailyMaterialReportRetryJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IBytedanceReportService bytedanceReportService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+
+        List<BytedanceReportMaterialRetry> retryList = bytedanceReportService.getRetryList();
+        //
+        //多线程
+        final ExecutorService executorService = Executors.newFixedThreadPool(3);
+        retryList.forEach(retry -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(retry.getAccountId()));
+                        log.info("头条素材报表重试定时任务,当前accountId为:" + token.getAccountId());
+                        bytedanceReportService.bytedanceMaterialReportRetry(token,retry.getStartDate(),retry.getEndDate());
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+        ////
+
+    }
+}

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

@@ -0,0 +1,50 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+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.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 头条素材报表按天跑前一天的数据任务
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyPlanReportAsyncJob 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 date = DateUtils.formatDate(getDate);
+
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");
+            return ;
+        }
+
+        for (CtopOauthToken token : tokens) {
+            try {
+                bytedanceReportService.bytedanceAsyncTaskCreate(date, date, token, 4);  //1.创意 2.广告主 3.广告组 4.广告计划
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+}

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

@@ -0,0 +1,40 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.bytedance.service.IBytedanceReportService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+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.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 头条素材报表按天跑前一天的数据任务
+ *
+ * @author sunzhen
+ */
+@Slf4j
+public class BytedanceDailyReportAsyncTaskGetJob implements Job {
+    @Autowired
+    private IBytedanceReportService bytedanceReportService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        try {
+            log.info("头条获取素材报表数据定时任务执行开始");
+            Long starttime = System.currentTimeMillis();
+            bytedanceReportService.bytedanceAsyncTaskGet();
+            Long endtime = System.currentTimeMillis();
+            log.info("头条异步报表数据定时任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
+        } catch (Exception e) {
+            log.error("头条获取异步报表数据定时任务执行报错");
+            e.printStackTrace();
+        }
+    }
+}

+ 1 - 1
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java

@@ -724,7 +724,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             {
                 put("start_date", startDate);
                 put("end_date", endDate);
-                if(type == 1){//素材
+                if(type == 1){//创意
                     put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"});   //按照创意分组、天分组、创意类型分组查询
                 }else if(type == 2){//广告主
                     put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_PRICING_CATEGORY"});   //按照广告主分组、天分组、广告类型类型分组查询