Explorar el Código

Merge remote-tracking branch 'origin/master'

yumeng hace 5 años
padre
commit
670e26754c

+ 55 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceCampaignDailyReportLoadJob.java

@@ -0,0 +1,55 @@
+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.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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+@Component
+public class BytedanceCampaignDailyReportLoadJob {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IReportService reportService;
+    static ExecutorService executorService = null;
+
+
+    @XxlJob("bytedanceCampaignDailyReport")
+    public ReturnT<String> execute(String params) throws Exception {
+        XxlJobLogger.log("头条广告组日报获取任务执行开始");
+        Date getDate = DateUtils.addDay(new Date(), -1);
+        //1:查询当日数据
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.isEmpty()) {
+            XxlJobLogger.log("定时获取头条数据异常:为获取到可用的token");
+            return ReturnT.FAIL;
+        }
+        executorService = Executors.newFixedThreadPool(5);
+        CountDownLatch countDownLatch = new CountDownLatch(tokens.size());
+        tokens.forEach(token -> {
+            executorService.submit(() -> {
+                try {
+                    reportService.getAdvertiserCampaignReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+                } catch (Exception e) {
+                    XxlJobLogger.log(e);
+                } finally {
+                    countDownLatch.countDown();
+                }
+            });
+        });
+        countDownLatch.await();
+        XxlJobLogger.log("头条广告组日报获取任务执行结束");
+        return ReturnT.SUCCESS;
+    }
+}

+ 54 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceCampaignHourlyReportLoadJob.java

@@ -0,0 +1,54 @@
+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.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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class BytedanceCampaignHourlyReportLoadJob {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IReportService reportService;
+    static ExecutorService executorService = null;
+
+    @XxlJob("bytedanceCampaignHourlyReport")
+    public ReturnT<String> execute(String param) throws Exception {
+        XxlJobLogger.log("头条广告组时报数据获取开始");
+        Date getDate = new Date();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
+        String hour = simpleDateFormat.format(getDate);
+        //1:查询当日数据
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        if (null == tokens || tokens.isEmpty()) {
+            XxlJobLogger.log("定时获取头条小时数据异常:未获取到可用的token");
+            return ReturnT.FAIL;
+        }
+        executorService = Executors.newFixedThreadPool(4);
+        tokens.forEach(token -> {
+            executorService.submit(() -> {
+                if (null != hour && "00".equals(hour)) {
+                    Date finalGetDate = DateUtils.addDay(getDate, -1);
+                    //获取广告主信息数据
+                    reportService.getAdvertiserCampaignReport(token, finalGetDate, finalGetDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+                }
+                reportService.getAdvertiserCampaignReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+            });
+        });
+        XxlJobLogger.log("头条广告组时报数据获取结束");
+        return ReturnT.SUCCESS;
+    }
+}