ソースを参照

添加定时任务

syh 5 年 前
コミット
5bb4e3054a

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

@@ -1,16 +1,37 @@
 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.IKuaiShouHistoryReportTaskService;
+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;
 
+@Slf4j
 public class KuaishouDailyReportTaskJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaiShouHistoryReportTaskService reportTaskService;
+
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         Date getDate = DateUtils.addDay(new Date(), -1);
-
+        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("快手获取日报数据任务执行失败:未获取到可用的token");
+            return;
+        }
+        String getDateStr = DateUtils.formatDate(getDate);
+        tokens.forEach(token -> {
+            reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr);
+        });
     }
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouHistoryReportTaskService.java

@@ -11,7 +11,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @date 2020-03-09
  */
 public interface IKuaiShouHistoryReportTaskService extends IService<KuaiShouHistoryReportTask> {
-    void createTask(Long accountId, String token);
+    void createTask(Long accountId, String token, String date);
 
     void getTaskList();
 

+ 6 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouHistoryReportTaskServiceImpl.java

@@ -19,7 +19,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
-import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -62,7 +61,7 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
     private KuaishouReportDailyCreativeMapper reportDailyCreativeMapper;
 
     @Override
-    public void createTask(Long accountId, String token) {
+    public void createTask(Long accountId, String token, String date) {
         if (Check.isNull(accountId) || Check.isNull(token)) {
             log.error("token或accountId为空");
             return;
@@ -74,11 +73,9 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
             headers.put("Access-Token", token);
             JSONObject param = new JSONObject();
             param.put("advertiser_id", accountId);
-            String endDate = DateUtils.getDate("yyyy-MM-dd");
-            String startDate = DateUtils.addMonth(endDate, -6);
             JSONObject taskParams = new JSONObject();
-            taskParams.put("start_date", "2020-03-11");
-            taskParams.put("end_date", "2020-03-11");
+            taskParams.put("start_date", date);
+            taskParams.put("end_date", date);
 
             if (Check.isNull(typeList)) {
                 getTypeList();
@@ -97,8 +94,8 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
                         JSONObject dataJson = resultJson.getJSONObject("data");
                         KuaiShouHistoryReportTask reportTask = new KuaiShouHistoryReportTask();
                         reportTask.setAccountId(accountId);
-                        reportTask.setStartDate(startDate);
-                        reportTask.setEndDate(endDate);
+                        reportTask.setStartDate(date);
+                        reportTask.setEndDate(date);
                         reportTask.setTaskId(dataJson.getString("task_id"));
                         reportTask.setViewType(type);
                         reportTask.setTaskStatus(0);
@@ -208,7 +205,7 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
 
     private void getTypeList() {
         typeList = new ArrayList<>();
-        typeList.add(1);
+//        typeList.add(1);
         typeList.add(2);
         typeList.add(3);
         typeList.add(4);