Kaynağa Gözat

文件提交

yumeng 5 yıl önce
ebeveyn
işleme
fe910df719

+ 7 - 2
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -816,10 +816,15 @@ public class DateUtils extends PropertyEditorSupport {
      * @return
      * @throws ParseException
      */
-    public static String getAnotherDay(String format, String date, Integer num) throws ParseException {
+    public static String getAnotherDay(String format, String date, Integer num)  {
 
         SimpleDateFormat sdf = new SimpleDateFormat(format);
-        Date getDate = sdf.parse(date);
+        Date getDate = null;
+        try {
+            getDate = sdf.parse(date);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(getDate);
         calendar.add(Calendar.DAY_OF_MONTH, num);

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

@@ -7,8 +7,6 @@ import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.text.ParseException;
-
 /**
  * 出价预警
  */
@@ -31,7 +29,7 @@ public class DeleteCreativeStaticJob implements Job {
                     String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
                     String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
                     reportHourlyCreativeStatisticService.deleteHourlyReportByStatDate(anotherDay);
-                } catch (ParseException e) {
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
             }

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

@@ -0,0 +1,60 @@
+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.IKuaiShouDailyReportTaskService;
+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.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.jeecg.common.util.DateUtils.getAnotherDay;
+
+/**
+ * 获取文件状态并下载入库
+ *
+ * @author yumeng
+ */
+@Slf4j
+public class KuaishouDailyLoadFileJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    static ExecutorService executorService = null;
+    @Autowired
+    private IKuaiShouDailyReportTaskService dailyReportTaskService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                String nowDate = DateUtils.getDate("yyyy-MM-dd");
+                String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -1);
+                //  查询快手token
+                List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                if (null == tokens || tokens.size() <= 0) {
+                    log.info("定时获取快手数据异常:未获取到可用的token");
+                    return;
+                }
+                executorService = Executors.newFixedThreadPool(3);
+                for (CtopOauthToken token : tokens) {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate);
+                        }
+                    });
+                }
+            }
+        };
+        thread.start();
+
+    }
+}

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

@@ -0,0 +1,55 @@
+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.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 获取文件状态并下载入库
+ *
+ * @author yumeng
+ */
+@Slf4j
+public class KuaishouHistoryLoadFileJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    static ExecutorService executorService = null;
+    @Autowired
+    private IKuaiShouHistoryReportTaskService historyReportTaskService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                //  查询快手token
+                List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                if (null == tokens || tokens.size() <= 0) {
+                    log.info("定时获取快手数据异常:未获取到可用的token");
+                    return;
+                }
+                executorService = Executors.newFixedThreadPool(3);
+                for (CtopOauthToken token : tokens) {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            historyReportTaskService.getTaskList();
+                        }
+                    });
+                }
+            }
+        };
+        thread.start();
+
+    }
+}

+ 2 - 1
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -1,4 +1,3 @@
-
 server:
   port: 8080
   ip: 39.106.184.70
@@ -149,6 +148,8 @@ jeecg:
     image-upload: D://upFiles//image//
     chrome-driver: D://chromedriver.exe
     csv-upload: D://upFiles//csv//
+    report-history: D://report//history//
+    report-daily: D://report//daily//
 kuaishou:
   group-control:
     path: http://39.106.184.70

+ 2 - 0
jeecg-boot-module-system/src/main/resources/application-prod.yml

@@ -151,6 +151,8 @@ jeecg:
     chrome-driver: /usr/bin/chromedriver
     csv-upload: /mnt/upload/csv/
     bak-database-file: /mnt/data/bak/
+    report-history: /mnt/upload/report/history/
+    report-daily: /mnt/upload/report/daily/
 kuaishou:
   group-control:
     path: http://39.106.184.70

+ 2 - 0
jeecg-boot-module-system/src/main/resources/application-test.yml

@@ -152,6 +152,8 @@ jeecg:
     image-upload: /data/upload/image/
     chrome-driver: /usr/bin/chromedriver
     csv-upload: /data/upload/csv/
+    report-history: /data/report/history/
+    report-daily: /data/report/daily/
 kuaishou:
   group-control:
     path: http://127.0.0.1

+ 7 - 8
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,6 +1,7 @@
 package org.jeecg;
 
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouReportTaskService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -15,7 +16,9 @@ public class SampleTest {
 
 
     @Autowired
-    private IKuaiShouReportTaskService reportTaskService;
+    private IKuaiShouHistoryReportTaskService reportTaskService;
+    @Autowired
+    private IKuaiShouDailyReportTaskService dailyReportTaskService;
 
     @Test
     public void kuaisShouReport() {
@@ -24,8 +27,8 @@ public class SampleTest {
         try {
 
 
-            reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc");
-            reportTaskService.getTaskList();
+            //  reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc");
+            dailyReportTaskService.getTaskList(3727345L, "871fc2c248782a94ad2962c941555abc", "2020-03-11");
 
 
 
@@ -94,10 +97,6 @@ public class SampleTest {
     }
 
 
-
-
-
-
 }
 
 

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouDailyReportTask.java

@@ -39,7 +39,7 @@ public class KuaiShouDailyReportTask {
      */
     @Excel(name = "广告账户ID(相当于头条返回的access_token数据中的advertiser_id)", width = 15)
     @ApiModelProperty(value = "广告账户ID(相当于头条返回的access_token数据中的advertiser_id)")
-    private Integer accountId;
+    private Long accountId;
     /**
      * 任务id
      */

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

@@ -11,5 +11,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @date 2020-03-12
  */
 public interface IKuaiShouDailyReportTaskService extends IService<KuaiShouDailyReportTask> {
+    void getTaskList(Long accountId, String token, String statDate);
 
 }

+ 121 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouDailyReportTaskServiceImpl.java

@@ -1,11 +1,29 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouDailyReportTask;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouDailyReportTaskMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCampaignMapper;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCreativeMapper;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyGroupMapper;
+import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
+import com.alibaba.fastjson.JSONArray;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 分天记录表
  *
@@ -13,7 +31,110 @@ import org.springframework.stereotype.Service;
  * @version V1.0
  * @date 2020-03-12
  */
+@Slf4j
 @Service
 public class KuaiShouDailyReportTaskServiceImpl extends ServiceImpl<KuaiShouDailyReportTaskMapper, KuaiShouDailyReportTask> implements IKuaiShouDailyReportTaskService {
 
+
+    @Value("${jeecg.path.report-daily}")
+    private static String downloadPath;
+    @Autowired
+    private KuaishouReportDailyCampaignMapper reportDailyCampaignMapper;
+
+    @Autowired
+    private KuaishouReportDailyGroupMapper reportDailyGroupMapper;
+
+    @Autowired
+    private KuaishouReportDailyCreativeMapper reportDailyCreativeMapper;
+
+    /**
+     * 获取任务列表
+     */
+    @Override
+    public void getTaskList(Long accountId, String token, String statDate) {
+        QueryWrapper<KuaiShouDailyReportTask> taskQueryWrapper = new QueryWrapper<>();
+
+
+        taskQueryWrapper.eq("task_status", 0);
+        taskQueryWrapper.eq("account_id", accountId);
+        taskQueryWrapper.eq("stat_date", statDate);
+        taskQueryWrapper.orderByDesc("create_time");
+        List<KuaiShouDailyReportTask> dailyTaskList = this.list(taskQueryWrapper);
+        if (!Check.isNull(dailyTaskList)) {
+            for (KuaiShouDailyReportTask task : dailyTaskList) {
+                String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ASYNC_TASK_LIST;
+                Map<String, String> headers = new HashMap<>();
+                headers.put("Content-Type", "application/json");
+                headers.put("Access-Token", token);
+                JSONObject param = new JSONObject();
+                param.put("advertiser_id", task.getAccountId());
+                JSONArray taskIds = new JSONArray();
+                taskIds.add(task.getTaskId());
+                param.put("task_ids", taskIds);
+                String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+                JSONObject resultJson = JSONObject.parseObject(result);
+                if (!Check.isNull(resultJson)) {
+                    Integer code = resultJson.getInteger("code");
+                    if (code == 0) {
+                        JSONObject dataJson = resultJson.getJSONObject("data");
+                        if (!Check.isNull(dataJson)) {
+                            JSONArray details = dataJson.getJSONArray("details");
+                            if (!Check.isNull(details)) {
+                                for (int i = 0; i < details.size(); i++) {
+                                    JSONObject detailJson = details.getJSONObject(i);
+                                    if (!Check.isNull(detailJson)) {
+                                        Integer taskStatus = detailJson.getInteger("task_status");
+                                        if (taskStatus == 2) {
+                                            loadFile(token, task);
+                                        } else if (taskStatus == 3) {
+                                            task.setTaskStatus(3);
+                                            this.updateById(task);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    } else {
+                        log.error("快手获取任务列表返回错误,accountId:{},返回结果:{}", task.getAccountId(), resultJson);
+                    }
+                } else {
+                    log.error("快手获取任务列表返回信息为空,accountId:{}", task.getAccountId());
+                }
+            }
+        }
+
+    }
+
+
+    private void loadFile(String token, KuaiShouDailyReportTask task) {
+        try {
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ASYNC_TASK_DOWNLOAD;
+            String fileName = task.getAccountId() + "_" + task.getStatDate() + "_" + task.getViewType() + ".csv";
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("advertiser_id", task.getAccountId());
+            requestMap.put("task_id", task.getTaskId());
+            String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath + task.getStatDate() + "//", url, token, fileName);
+            if (!Check.isNull(localPath)) {
+                if (task.getViewType() == 2) {
+                    reportDailyCampaignMapper.loadCampaignDailyReport(task.getAccountId(), localPath);
+
+                } else if (task.getViewType() == 3) {
+                    reportDailyGroupMapper.loadGroupDailyReport(task.getAccountId(), localPath);
+
+                } else if (task.getViewType() == 4) {
+                    reportDailyCreativeMapper.loadCreativeDailyReport(task.getAccountId(), localPath);
+
+                }
+            }
+            task.setTaskStatus(4);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            task.setTaskStatus(5);
+        }
+        this.updateById(task);
+
+    }
+
+
 }

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

@@ -41,7 +41,7 @@ import java.util.concurrent.Executors;
 @Slf4j
 @Service
 public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHistoryReportTaskMapper, KuaiShouHistoryReportTask> implements IKuaiShouHistoryReportTaskService {
-    @Value("${jeecg.path.reportDownload}")
+    @Value("${jeecg.path.report-history}")
     private static String downloadPath;
     static List<Integer> typeList;
     static ExecutorService executorService = Executors.newFixedThreadPool(3);
@@ -139,7 +139,6 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
                     param.put("task_ids", taskIds);
                     String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
                     JSONObject resultJson = JSONObject.parseObject(result);
-                    System.err.println(resultJson);
                     if (!Check.isNull(resultJson)) {
                         Integer code = resultJson.getInteger("code");
                         if (code == 0) {
@@ -164,6 +163,8 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
                         } else {
                             log.error("快手获取任务列表返回错误,accountId:{},返回结果:{}", task.getAccountId(), resultJson);
                         }
+                    } else {
+                        log.error("快手获取任务列表返回数据为空,accountId:{}}", task.getAccountId());
                     }
                 }
             }
@@ -178,7 +179,7 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
             Map<String, Object> requestMap = new HashMap<>();
             requestMap.put("advertiser_id", task.getAccountId());
             requestMap.put("task_id", task.getTaskId());
-            String localPath = DownloadUtils.downloadByUrl(requestMap, "D://report//", url, token, fileName);
+            String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token, fileName);
             if (!Check.isNull(localPath)) {
                 if (task.getViewType() == 1) {
                     reportDailyAccountMapper.loadAccountDailyReport(task.getAccountId(), localPath);
@@ -193,7 +194,6 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
 
                 }
 
-
             }
             task.setTaskStatus(4);