|
@@ -0,0 +1,75 @@
|
|
|
+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.common.module.utils.CtopAdConstant;
|
|
|
+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.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取广告计划分时报表
|
|
|
+ * @author syh
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class KuaishouHourlyCampaignReportLoadJob implements Job {
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
|
+
|
|
|
+ static ExecutorService executorService = null;
|
|
|
+ //线程计数器
|
|
|
+ static CountDownLatch countDownLatch = null;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
+ Date getDate = new Date();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
|
|
|
+ String hour = simpleDateFormat.format(getDate);
|
|
|
+ if (null != hour && "00".equals(hour)) {
|
|
|
+ getDate = DateUtils.addDay(getDate, -1);
|
|
|
+ }
|
|
|
+ //1:查询当日数据
|
|
|
+ List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
|
|
|
+ if (null == tokens || tokens.size() <= 0) {
|
|
|
+ log.info("定时获取头条数据异常:为获取到可用的token");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ executorService = Executors.newFixedThreadPool(5);
|
|
|
+ countDownLatch = new CountDownLatch(tokens.size());
|
|
|
+ Date finalGetDate = getDate;
|
|
|
+ tokens.forEach(token -> {
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ // 获取 广告计划时报
|
|
|
+ kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, finalGetDate, finalGetDate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ countDownLatch.countDown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ countDownLatch.await();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ executorService.shutdown();
|
|
|
+ }
|
|
|
+}
|