Browse Source

定时任务修改

hcst_sunzhen 5 năm trước cách đây
mục cha
commit
4efe91ad47

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

@@ -29,9 +29,12 @@ public class BytedanceDailyMaterialReportJob implements Job {
 
     @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("头条获取素材报表数据任务开始,任务时间:" + date);
+        log.info("头条获取素材报表数据任务开始,任务时间:" + date2 + "~" + date);
 
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         if (null == tokens || tokens.size() <= 0) {
@@ -45,6 +48,8 @@ public class BytedanceDailyMaterialReportJob implements Job {
                 @Override
                 public void run() {
                     try {
+                        //获取头条素材报表两天前的数据
+                        bytedanceReportService.bytedanceMaterialReport(token, date2, date2);
                         //获取头条素材报表数据
                         bytedanceReportService.bytedanceMaterialReport(token, date, date);
                     } catch (Exception e) {

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

@@ -3,8 +3,10 @@ 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.entity.BytedanceReportMaterialRetry;
+import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
 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;
@@ -25,6 +27,8 @@ public class BytedanceDailyMaterialReportRetryJob implements Job {
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IBytedanceReportService bytedanceReportService;
+    @Autowired
+    private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
@@ -38,9 +42,25 @@ public class BytedanceDailyMaterialReportRetryJob implements Job {
                 @Override
                 public void run() {
                     try {
-                        CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(retry.getAccountId()));
+                        String startDate = retry.getStartDate();
+                        String endDate = retry.getEndDate();
+                        Long accountId = retry.getAccountId();
+                        CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
                         log.info("头条素材报表重试定时任务,当前accountId为:" + token.getAccountId());
-                        bytedanceReportService.bytedanceMaterialReportRetry(token, retry.getStartDate(), retry.getEndDate());
+
+                        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(token, start, end);
+                            if(code ==200 || code == 1){
+                                //重试成功清洗数据
+                                byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
+                            }
+                        }
                     } catch (Exception e) {
                         e.printStackTrace();
                     } finally {

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

@@ -33,6 +33,7 @@ public class KuaishouDailyAccountReportLoadJob implements Job {
         Thread thread = new Thread() {
             @Override
             public void run() {
+                Date getDate2 = DateUtils.addDay(new Date(), -2);
                 Date getDate = DateUtils.addDay(new Date(), -1);
                 //1:查询当日数据
                 List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
@@ -46,6 +47,8 @@ public class KuaishouDailyAccountReportLoadJob implements Job {
                     executorService.submit(new Runnable() {
                         @Override
                         public void run() {
+                            //跑两天前的账户报表---次留统计用
+                            kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate2, getDate2);
                             //1: 获取广告主信息数据
                             kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate, getDate);
                         }

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouDailyAccountReportNextDayStayJob.java

@@ -34,7 +34,7 @@ public class KuaishouDailyAccountReportNextDayStayJob implements Job {
         Thread thread = new Thread() {
             @Override
             public void run() {
-                Date getDate = DateUtils.addDay(new Date(), -2);
+                Date getDate = new Date();
                 //1:查询当日数据
                 List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
                 if (null == tokens || tokens.size() <= 0) {

+ 4 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceVideoReportJob.java

@@ -22,6 +22,10 @@ public class ByteDanceVideoReportJob {
 
     @XxlJob("byteDanceVideoReport")
     public ReturnT<String> execute(String param) throws Exception {
+        String getDate2 = DateUtils.formatDate(DateUtils.addDay(new Date(), -2));
+        XxlJobLogger.log("头条视频报表清洗数据定时任务开始, 执行时间为:" + getDate2);
+        byteDanceVideoReportDailyService.videoInfoList(getDate2, getDate2);
+
         String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -1));
         XxlJobLogger.log("头条视频报表清洗数据定时任务开始, 执行时间为:" + getDate);
         byteDanceVideoReportDailyService.videoInfoList(getDate, getDate);

+ 8 - 1
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouDailyAccountReportLoadJob.java

@@ -31,6 +31,7 @@ public class KuaishouDailyAccountReportLoadJob {
     @XxlJob("kuaishouDailyAccountReport")
     public ReturnT<String> execute(String param) throws Exception {
         Date getDate = DateUtils.addDay(new Date(), -1);
+        Date getDate2 = DateUtils.addDay(new Date(), -2);
         //1:查询当日数据
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
         if (null == tokens || tokens.size() <= 0) {
@@ -39,7 +40,13 @@ public class KuaishouDailyAccountReportLoadJob {
         }
 
         executorService = Executors.newFixedThreadPool(3);
-        tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate, getDate)));
+        tokens.forEach(token ->
+                executorService.submit(() ->{
+                    kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate2, getDate2);
+                    kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate, getDate);
+                }
+                )
+        );
         return ReturnT.SUCCESS;
     }
 }

+ 2 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/ByteDanceVideoReportDailyController.java

@@ -56,15 +56,15 @@ public class ByteDanceVideoReportDailyController {
 			 dateList.add(endStr);
 		 }
 
-
 		 final ExecutorService executorService = Executors.newFixedThreadPool(8);
 		 dateList.forEach(date -> {
 			 executorService.submit(new Runnable() {
 				 @Override
 				 public void run() {
 					 try {
-						 System.out.println("头条视频按天汇总接口现在在跑的时间为:" + date + "~" + date);
+						 log.info("头条视频按天汇总接口现在在跑的时间为:" + date + "~" + date);
 						 videoReportDailyService.videoInfoList(date, date);
+						 log.info("头条视频按天汇总接口运行结束,时间为" + date + "~" + date);
 					 } catch (Exception e) {
 						 e.printStackTrace();
 					 } finally {

+ 1 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceReportController.java

@@ -203,7 +203,7 @@ public class BytedanceReportController {
                                 start = DateUtils.addDay(startDate, i);
                                 end = start;
                                 //获取头条素材报表数据
-                                int code = bytedanceReportService.bytedanceMaterialReport(token, start, end);
+                                int code = bytedanceReportService.bytedanceMaterialReportRetry(token, start, end);
                                 if(code ==200 || code == 1){
                                     //重试成功清洗数据
                                     byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
@@ -212,7 +212,6 @@ public class BytedanceReportController {
 
                         } catch (Exception e) {
                             e.printStackTrace();
-                        } finally {
                         }
                     }
                 });

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ByteDanceVideoReportDailyServiceImpl.java

@@ -43,6 +43,7 @@ public class ByteDanceVideoReportDailyServiceImpl extends ServiceImpl<ByteDanceV
         videoInfoListByCompanyId(startDate, endDate, "d57fecdcf7a94d009736d9c850731582");
         //华东
         videoInfoListByCompanyId(startDate, endDate, "4b10089775c040119e139087517aed88");
+
     }
 
     private void videoInfoListByCompanyId(String startDate, String endDate, String companyId){