Parcourir la source

Merge branch 'master' of http://39.106.184.70:3000/ctop/adsp-boot

yumeng il y a 5 ans
Parent
commit
39b93b1eee
14 fichiers modifiés avec 220 ajouts et 317 suppressions
  1. 27 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/EduLessonController.java
  2. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyAccountReportAsyncJob.java
  3. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyCampaignReportAsyncJob.java
  4. 2 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyCreativeReportAsyncJob.java
  5. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyMaterialReportJob.java
  6. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyMaterialReportRetryJob.java
  7. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/BytedanceDailyPlanReportAsyncJob.java
  8. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouDailyAccountReportNextDayStayJob.java
  9. 2 0
      module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/IEduLessonService.java
  10. 19 4
      module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/impl/EduLessonServiceImpl.java
  11. 6 6
      module-report/src/main/java/cn/com/ctop/bytedance/controller/BytedanceReportController.java
  12. 128 297
      module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java
  13. 1 1
      performance-appraisal/src/main/java/cn/com/ctop/huananvideoreport/controller/HuananVideoReportController.java
  14. 29 0
      performance-appraisal/src/main/java/cn/com/ctop/huananvideoreport/mapper/xml/HuananVideoReportMapper.xml

+ 27 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/EduLessonController.java

@@ -5,13 +5,14 @@ import cn.com.ctop.manage.modules.edu.service.IEduLessonService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Api(tags="在线培训")
@@ -92,4 +93,27 @@ public class EduLessonController {
         result.setSuccess(true);
         return result;
     }
+
+    @PostMapping(value = "/lesson/upload")
+    public Result<Map<String,String>> updaloadLesson(@RequestBody EduLesson eduLesson){
+        Result<Map<String,String>> result = new Result();
+        Map<String,String> resultMap = new HashMap<>();
+
+        if (StringUtils.isBlank(eduLesson.getMedia()) || StringUtils.isBlank(eduLesson.getTitle()) ||
+            StringUtils.isBlank(eduLesson.getTopic()) || StringUtils.isBlank(eduLesson.getName()) ||
+            StringUtils.isBlank(eduLesson.getOssFileUrl()) || StringUtils.isBlank(eduLesson.getFileType())
+        ){
+            result.error500("参数不可为空");
+            return result;
+        }
+        String lessonId = eduLessonService.uploadLesson(eduLesson);
+
+        resultMap.put("lessonId",lessonId);
+        result.setResult(resultMap);
+        result.setSuccess(true);
+
+        return result;
+    }
+
+
 }

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

@@ -33,7 +33,7 @@ public class BytedanceDailyAccountReportAsyncJob implements Job {
 
         Date getDate = DateUtils.addDay(new Date(), -1);
         String date = DateUtils.formatDate(getDate);
-
+        log.info("头条异步广告主报表执行开始。跑的是:"+ date + "的数据");
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         if (null == tokens || tokens.size() <= 0) {
             log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");

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

@@ -31,7 +31,7 @@ public class BytedanceDailyCampaignReportAsyncJob implements Job {
 
         Date getDate = DateUtils.addDay(new Date(), -1);
         String date = DateUtils.formatDate(getDate);
-
+        log.info("头条异步广告组报表数据执行开始,跑的是"+ date + "的数据");
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         if (null == tokens || tokens.size() <= 0) {
             log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");

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

@@ -31,8 +31,8 @@ public class BytedanceDailyCreativeReportAsyncJob implements Job {
 
         Date getDate = DateUtils.addDay(new Date(), -1);
         String date = DateUtils.formatDate(getDate);
-
-        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        log.info("头条创意报表异步任务执行开始.跑的是" + date + "的数据");
+     List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         if (null == tokens || tokens.size() <= 0) {
             log.info("头条获取异步报表数据任务执行失败:未获取到可用的token");
             return ;

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

@@ -30,9 +30,9 @@ public class BytedanceDailyMaterialReportJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-
         Date getDate = DateUtils.addDay(new Date(), -1);
         String date = DateUtils.formatDate(getDate);
+        log.info("头条获取素材报表数据任务开始,任务时间:" + date);
 
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         if (null == tokens || tokens.size() <= 0) {

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

@@ -30,7 +30,7 @@ public class BytedanceDailyMaterialReportRetryJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-
+        log.info("头条素材报表重试定时任务开始");
         List<BytedanceReportMaterialRetry> retryList = bytedanceReportService.getRetryList();
         //
         //多线程

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

@@ -31,6 +31,7 @@ public class BytedanceDailyPlanReportAsyncJob implements Job {
 
         Date getDate = DateUtils.addDay(new Date(), -1);
         String date = DateUtils.formatDate(getDate);
+        log.info("头条广告计划异步任务开始执行,跑的是" + date + "的数据");
 
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         if (null == tokens || tokens.size() <= 0) {

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

@@ -30,6 +30,7 @@ public class KuaishouDailyAccountReportNextDayStayJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        log.info("快手次留率定时任务开始");
         Thread thread = new Thread() {
             @Override
             public void run() {

+ 2 - 0
module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/IEduLessonService.java

@@ -16,4 +16,6 @@ public interface IEduLessonService extends IService<EduLesson> {
     public void getKuaishouEduLesson(String url);
     public List<String> getTitleList(String media);
     public List<String> getTopicList(String media,String title);
+
+    String uploadLesson(EduLesson eduLesson);
 }

+ 19 - 4
module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/impl/EduLessonServiceImpl.java

@@ -9,14 +9,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 在线培训
@@ -170,4 +169,20 @@ public class EduLessonServiceImpl extends ServiceImpl<EduLessonMapper, EduLesson
             e.printStackTrace();
         }
     }
+
+    //培训视频上传接口
+    @Override
+    public String uploadLesson(EduLesson eduLesson){
+        String uuid = UUID.randomUUID().toString().replaceAll("-","");
+        System.out.println();
+
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        eduLesson.setLessonId(uuid);
+        eduLesson.setCreator(sysUser.getRealname());
+
+        save(eduLesson);
+        return uuid;
+    }
+
+
 }

+ 6 - 6
module-report/src/main/java/cn/com/ctop/bytedance/controller/BytedanceReportController.java

@@ -106,7 +106,7 @@ public class BytedanceReportController {
 
         Result<List<JSONObject>> result = new Result<>();
         try {
-            log.info("头条获取素材报表数据任务执行开始");
+            log.info("头条获取异步报表数据任务执行开始");
             Long starttime = System.currentTimeMillis();
             List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
             if (null == tokens || tokens.size() <= 0) {
@@ -133,13 +133,13 @@ public class BytedanceReportController {
     public Result<List<JSONObject>> bytedanceAsyncTaskGet(@RequestBody JSONObject requestJson) {
         Result<List<JSONObject>> result = new Result<>();
         try {
-            log.info("头条获取素材报表数据定时任务执行开始");
+            log.info("头条下载异步报表数据定时任务执行开始");
             Long starttime = System.currentTimeMillis();
             bytedanceReportService.bytedanceAsyncTaskGet();
             Long endtime = System.currentTimeMillis();
-            log.info("头条异步报表数据定时任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
+            log.info("头条下载异步报表数据定时任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
         } catch (Exception e) {
-            log.error("头条获取异步报表数据定时任务执行报错");
+            log.error("头条下载异步报表数据定时任务执行报错");
             e.printStackTrace();
             result.setSuccess(false);
         }
@@ -164,7 +164,7 @@ public class BytedanceReportController {
                 return result;
             }
 
-            final ExecutorService executorService = Executors.newFixedThreadPool(8);
+            final ExecutorService executorService = Executors.newFixedThreadPool(3);
             tokens.forEach(token -> {
                 executorService.submit(new Runnable() {
                     @Override
@@ -211,7 +211,7 @@ public class BytedanceReportController {
 
                 //
                 //多线程
-                final ExecutorService executorService = Executors.newFixedThreadPool(8);
+                final ExecutorService executorService = Executors.newFixedThreadPool(3);
                 retryList.forEach(retry -> {
                     executorService.submit(new Runnable() {
                         @Override

+ 128 - 297
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java

@@ -15,6 +15,7 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
 import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
@@ -23,24 +24,13 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
 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;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.net.URI;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -677,24 +667,24 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
     /////////////////////////////////////////////////////////////////////////////////////////////////
     //创建异步任务
-    public void bytedanceAsyncTaskCreate(String startDate, String endDate, CtopOauthToken token, Integer type) throws ParseException {
-        int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"));
+    public void bytedanceAsyncTaskCreate (String startDate, String endDate, CtopOauthToken token, Integer type) throws ParseException {
+        int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate,"yyyy-MM-dd"),DateUtils.parseDate(endDate,"yyyy-MM-dd"));
         if (diffMonths == 0) {
             bytedanceAsyncTaskCreateByMonth(startDate, endDate, token, type);
-        } else {
-            for (int i = 0; i <= diffMonths; i++) {
-                if (i == 0) {
-                    Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
+        }else{
+            for(int i=0; i<=diffMonths ; i++){
+                if (i == 0){
+                    Map<String,String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate,"yyyy-MM-dd", i);
                     String end = dateMap.get("endDate");
                     //System.out.println(startDate + " ----- " + end);
                     bytedanceAsyncTaskCreateByMonth(startDate, end, token, type);
-                } else if (i == diffMonths) {
-                    Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
+                }else if(i == diffMonths){
+                    Map<String,String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate,"yyyy-MM-dd", i);
                     String start = dateMap.get("startDate");
                     //System.out.println(start + " ----- " + endDate);
                     bytedanceAsyncTaskCreateByMonth(start, endDate, token, type);
-                } else {
-                    Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
+                }else{
+                    Map<String,String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate,"yyyy-MM-dd", i);
                     String start = dateMap.get("startDate");
                     String end = dateMap.get("endDate");
                     //System.out.println(start + " ----- " + end);
@@ -710,7 +700,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
      * @param endDate
      * @param token
      */
-    private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token, Integer type) {
+    private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token, Integer type){
         String access_token = token.getAccessToken();
         Long accountId = token.getAccountId();
 
@@ -724,14 +714,14 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             {
                 put("start_date", startDate);
                 put("end_date", endDate);
-                if (type == 1) {//创意
-                    put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"});   //按照创意分组、天分组、创意类型分组查询
-                } else if (type == 2) {//广告主
-                    put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_PRICING_CATEGORY"});   //按照广告主分组、天分组、广告类型类型分组查询
-                } else if (type == 3) {//广告组
-                    put("group_by", new String[]{"STAT_GROUP_BY_CAMPAIGN_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CAMPAIGN_TYPE"});  //按照广告组、天、广告组类型分组
-                } else {//4广告计划
-                    put("group_by", new String[]{"STAT_GROUP_BY_AD_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_LANDING_TYPE"});  //按照广告计划、天、推广类型分组
+                if(type == 1){//创意
+                    put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"});   //按照创意分组、天分组、创意类型分组查询
+                }else if(type == 2){//广告主
+                    put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_PRICING_CATEGORY"});   //按照广告主分组、天分组、广告类型类型分组查询
+                }else if(type == 3){//广告组
+                    put("group_by", new String[]{"STAT_GROUP_BY_CAMPAIGN_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CAMPAIGN_TYPE"});  //按照广告组、天、广告组类型分组
+                }else {//4广告计划
+                    put("group_by", new String[]{"STAT_GROUP_BY_AD_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_LANDING_TYPE"});  //按照广告计划、天、推广类型分组
                 }
             }
         };
@@ -744,85 +734,43 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             }
         };
 
-        // 构造请求
-        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
-            @Override
-            public String getMethod() {
-                return "POST";
-            }
-        };
-
-        httpEntity.setHeader("Access-Token", access_token);
-
-        CloseableHttpResponse response = null;
-        CloseableHttpClient client = null;
-
-        try {
-            client = HttpClientBuilder.create().build();
-            httpEntity.setURI(URI.create(open_api_domain + path));
-            httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
-
-            response = client.execute(httpEntity);
-            if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                StringBuffer result = new StringBuffer();
-                String line = "";
-                while ((line = bufferedReader.readLine()) != null) {
-                    result.append(line);
-                }
-                bufferedReader.close();
+        JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
+        if(json == null){
+            log.error("请求有误:" + JSONObject.toJSONString(data));
+        }
 
-                JSONObject json = JSONObject.parseObject(result.toString());
-                String jsonString = JSON.toJSONString(json);
+        String jsonString = JSON.toJSONString(json);
 
-                if (!Check.isNull(json)) {
-                    Integer code = json.getInteger("code");
-                    if (code != 0) {
-                        log.info("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:" + json.getString("message"));
-                        return;
-                    }
-                    JSONObject dataJson = json.getJSONObject("data");
-
-                    //解析数据并入库
-                    BytedanceDailyReportTask task = new BytedanceDailyReportTask();
-                    task.setAccountId(accountId);
-                    task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
-                    task.setTaskId(dataJson.getLong("task_id") == null ? null : dataJson.getLong("task_id"));
-                    task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
-                    task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
-                    task.setJson(jsonString);
-                    task.setTaskStatus(dataJson.getString("task_status"));
-                    task.setTaskType(dataJson.getString("task_type"));
-                    task.setType(type);
-                    task.setIsDownload(0);
-                    task.setStatus(1); //状态1正常 0废弃
-                    bytedanceDailyReportTaskMapper.insert(task);
-                }
-
-            } else {
-                log.error("请求有误:" + response);
-            }
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                if (response != null) {
-                    response.close();
-                }
-                client.close();
-            } catch (IOException e) {
-                e.printStackTrace();
+        if(!Check.isNull(json)){
+            Integer code = json.getInteger("code");
+            if(code != 0){
+                log.error("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:"+ json.getString("message"));
+                return;
             }
+            JSONObject dataJson = json.getJSONObject("data");
+
+            //解析数据并入库
+            BytedanceDailyReportTask task = new BytedanceDailyReportTask();
+            task.setAccountId(accountId);
+            task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
+            task.setTaskId(dataJson.getLong("task_id") ==  null ? null : dataJson.getLong("task_id") );
+            task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
+            task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
+            task.setJson(jsonString);
+            task.setTaskStatus(dataJson.getString("task_status"));
+            task.setTaskType(dataJson.getString("task_type"));
+            task.setType(type);
+            task.setIsDownload(0);
+            task.setStatus(1); //状态1正常 0废弃
+            bytedanceDailyReportTaskMapper.insert(task);
         }
     }
 
     //获取任务列表
-    public void bytedanceAsyncTaskGet() {
+    public void bytedanceAsyncTaskGet(){
         QueryWrapper<BytedanceDailyReportTask> taskQueryWrapper = new QueryWrapper<>();
         //查询三种状态的信息--任务已创建、任务执行中、任务处理中
-        taskQueryWrapper.eq("is_download", 0);
+        taskQueryWrapper.eq("is_download",0);
         //taskQueryWrapper.in("task_status", "ASYNC_TASK_STATUS_CREATED","ASYNC_TASK_STATUS_EXECUTING","ASYNC_TASK_STATUS_EXECUTING_STAGE2");
         taskQueryWrapper.notIn("task_status", "ASYNC_TASK_STATUS_FAILED");
         taskQueryWrapper.orderByDesc("create_time");
@@ -844,136 +792,93 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     // 请求参数
                     final Map filtering = new HashMap() {
                         {
-                            put("task_ids", new Long[]{task.getTaskId()});
+                            put("task_ids",new Long[]{task.getTaskId()});
                             put("task_name", task.getTaskName());
                         }
                     };
-                    Map data = new HashMap() {
+                    Map data = new HashMap(){
                         {
                             put("advertiser_id", advertiser_id);
                             put("filtering", filtering);
                         }
                     };
 
-                    // 构造请求
-                    HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
-                        @Override
-                        public String getMethod() {
-                            return "GET";
-                        }
-                    };
-
-                    httpEntity.setHeader("Access-Token", access_token);
-
-                    CloseableHttpResponse response = null;
-                    CloseableHttpClient client = null;
+                    JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
+                    if(json == null){
+                        log.error("请求有误:" + JSONObject.toJSONString(data));
+                    }
 
                     try {
-                        client = HttpClientBuilder.create().build();
-                        httpEntity.setURI(URI.create(open_api_domain + path));
-                        httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
-
-                        response = client.execute(httpEntity);
-                        if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                            StringBuffer result = new StringBuffer();
-                            String line = "";
-                            while ((line = bufferedReader.readLine()) != null) {
-                                result.append(line);
+                        String jsonString = JSON.toJSONString(json);
+                        //log.info("返回json为" + jsonString);
+
+                        if(!Check.isNull(json)){
+                            Integer code = json.getInteger("code");
+                            if(code != 0){
+                                log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + "taskId:" + task.getTaskId());
+                                continue;
                             }
-                            bufferedReader.close();
 
-                            JSONObject json = JSONObject.parseObject(result.toString());
-                            String jsonString = JSON.toJSONString(json);
-
-                            if (!Check.isNull(json)) {
-                                Integer code = json.getInteger("code");
-                                if (code != 0) {
-                                    log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + "taskId:" + task.getTaskId());
-                                    return;
-                                }
-
-                                JSONObject jsonData = json.getJSONObject("data");
-                                if (Check.isNull(jsonData)) {
-                                    log.error("获取任务列表返回信息data内容为空");
-                                }
-                                JSONArray jsonArrayay = jsonData.getJSONArray("list");
+                            JSONObject jsonData = json.getJSONObject("data");
+                            if (Check.isNull(jsonData)){
+                                log.error("获取任务列表返回信息data内容为空");
+                            }
+                            JSONArray jsonArrayay = jsonData.getJSONArray("list");
 
-                                for (int i = 0; i < jsonArrayay.size(); i++) {
-                                    JSONObject detailJson = jsonArrayay.getJSONObject(i);
-                                    if (!Check.isNull(detailJson)) {
-                                        String taskStatus = detailJson.getString("task_status");
+                            for (int i = 0; i < jsonArrayay.size(); i++) {
+                                JSONObject detailJson = jsonArrayay.getJSONObject(i);
+                                if (!Check.isNull(detailJson)) {
+                                    String taskStatus = detailJson.getString("task_status");
 
-                                        if (taskStatus.equals("ASYNC_TASK_STATUS_COMPLETED")) {
-                                            bytedanceAsyncTaskDownload(task, token, task.getType());
-                                            task.setIsDownload(1);
-                                        }
+                                    if (taskStatus .equals( "ASYNC_TASK_STATUS_COMPLETED")) {
+                                        bytedanceAsyncTaskDownload(task,token,task.getType());
+                                        task.setIsDownload(1);
+                                    }
                                         task.setTaskStatus(taskStatus);
                                         bytedanceDailyReportTaskMapper.updateById(task);
                                     }
                                 }
                             }
-
-                        } else {
-                            log.error("请求有误:" + response);
-                        }
-
-                    } catch (ClientProtocolException e) {
+                    }  catch (Exception e) {
                         e.printStackTrace();
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    } finally {
-                        try {
-                            if (response != null) {
-                                response.close();
-                            }
-                            client.close();
-                        } catch (IOException e) {
-                            e.printStackTrace();
-                        }
                     }
-
                 }
             }
         }
     }
 
     //下载任务结果   type 1.creative 2.account 3.campaign 4.plan
-    private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token, Integer type) {
+    private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token, Integer type){
         // 请求地址
         String open_api_domain = "https://ad.toutiao.com";
         String path = "/open_api/2/async_task/download/";
 
         String url = open_api_domain + path;
-        String fileName = task.getAccountId() + "_" + "type" + type + "_" + System.currentTimeMillis() + ".csv";
+        String fileName = task.getAccountId() + "_" + "type" + type + "_" + task.getTaskId() + "_" + System.currentTimeMillis() + ".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, url, token.getAccessToken(), fileName);
-        if (task.getAccountId() != 1649961222605831L && task.getAccountId() != 1643726941045772L) {
-
-
-            if (type == 1) {
-                //素材异步报表
-                bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
-            } else if (type == 2) {
-                //账户异步报表
-                bytedanceDailyReportTaskMapper.loadBytedanceDailyAccountFileAsync(localPath);
-            } else if (type == 3) {
-                //campaign异步报表
-                bytedanceDailyReportTaskMapper.loadBytedanceDailyCampaignFileAsync(localPath);
-            } else if (type == 4) {
-                //plan异步报表
-                bytedanceDailyReportTaskMapper.loadBytedanceDailyPlanFileAsync(localPath);
-            } else {
-                log.error("异步报表类型传入错误,task_id:" + task.getTaskId() + ";类型:" + type);
-            }
+        if(type == 1){
+            //素材异步报表
+            bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
+        }else if(type == 2){
+            //账户异步报表
+            bytedanceDailyReportTaskMapper.loadBytedanceDailyAccountFileAsync(localPath);
+        }else if(type == 3){
+            //campaign异步报表
+            bytedanceDailyReportTaskMapper.loadBytedanceDailyCampaignFileAsync(localPath);
+        }else if(type == 4){
+            //plan异步报表
+            bytedanceDailyReportTaskMapper.loadBytedanceDailyPlanFileAsync(localPath);
+        }else{
+            log.error("异步报表类型传入错误,task_id:" + task.getTaskId() + ";类型:" + type);
         }
     }
 
     /////////////////////////////////////////////////////////\
     //素材报表
-    public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate) {
+    public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate){
         Long accountId = token.getAccountId();
         log.info("头条素材报表当前accountId为:" + accountId);
         Integer page = 1;
@@ -985,22 +890,22 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
         retry.setStartDate(startDate);
         retry.setEndDate(endDate);
         retry.setStatusCode(code);
-        if (code != 200 && code != 1) {
+        if (code != 200 && code != 1){
             retry.setStatus(0);
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
-        } else {
+        }else{
             retry.setStatus(1);
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
         }
     }
 
-    public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate) {
+    public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
         Long accountId = token.getAccountId();
         log.info("头条素材报表当前accountId为:" + accountId);
         Integer page = 1;
         Integer pageSize = 100;
         int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
-        if (code != 200 && code != 1) {
+        if (code != 200 && code != 1){
             BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
             retry.setAccountId(accountId);
             retry.setStatus(0);
@@ -1011,7 +916,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
         }
     }
 
-    private int bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate) {
+    private int bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
         //log.info("当前页数:"+ page);
         String access_token = token.getAccessToken();
 
@@ -1020,87 +925,46 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
         String path = "/open_api/2/report/integrated/get/";
 
         // 请求参数
-        final Map filtering = new HashMap() {
-            {
-                put("image_mode", new String[]{"MATERIAL_IMAGE_MODE_TITLE"});
-            }
-        };
-
-        Map data = new HashMap() {
+        Map data = new HashMap(){
             {
                 put("advertiser_id", accountId);
-                put("start_date", startDate);
-                put("end_date", endDate);
-                put("page", page);
-                put("page_size", pageSize);
-                put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_INVENTORY", "STAT_GROUP_BY_IMAGE_MODE", "STAT_GROUP_BY_TIME_DAY"});
-            }
-        };
-
-        // 构造请求
-        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
-            @Override
-            public String getMethod() {
-                return "GET";
+                put("start_date",startDate);
+                put("end_date",endDate);
+                put("page",page);
+                put("page_size",pageSize);
+                put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID","STAT_GROUP_BY_INVENTORY","STAT_GROUP_BY_IMAGE_MODE","STAT_GROUP_BY_TIME_DAY"});
             }
         };
 
-        httpEntity.setHeader("Access-Token", access_token);
-
-        CloseableHttpResponse response = null;
-        CloseableHttpClient client = null;
+        JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
+        if(json == null){
+            log.error("请求有误:" + JSONObject.toJSONString(data));
+            return -2;
+        }
 
         int returnCode = 200;
         try {
-            //Long connectStartTime = System.currentTimeMillis();
-
-            client = HttpClientBuilder.create().build();
-            httpEntity.setURI(URI.create(open_api_domain + path));
-            httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
-
-            //RequestConfig requestConfig = RequestConfig.custom()
-            //        .setConnectTimeout(60000).setConnectionRequestTimeout(60000)
-            //        .setSocketTimeout(60000).build();
-
-            //httpEntity.setConfig(requestConfig);
-
-            response = client.execute(httpEntity);
-            //Long connectEndTime = System.currentTimeMillis();
-            //log.info("头条获取素材报表数据任务获取服务器数据结束,执行耗时:{}秒", (connectEndTime - connectStartTime) / 1000);
-            //System.out.println(response);
-            if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                StringBuffer result = new StringBuffer();
-                String line = "";
-                while ((line = bufferedReader.readLine()) != null) {
-                    result.append(line);
-                }
-                bufferedReader.close();
-
-                JSONObject json = JSONObject.parseObject(result.toString());
-                String jsonString = JSON.toJSONString(json);
-                //log.info("返回值为:" + jsonString);
-
-                if (!Check.isNull(json)) {
+                if(!Check.isNull(json)){
                     Integer code = json.getInteger("code");
-                    if (code != 0) {
-                        log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
-                        returnCode = -1;
+                    if(code != 0){
+                        log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
+                        //returnCode = -1;
                         return -1;
                     }
 
                     JSONObject jsonData = json.getJSONObject("data");
-                    if (Check.isNull(jsonData)) {
+                    if (Check.isNull(jsonData)){
                         log.error("获取任务列表返回信息data内容为空");
+                        return -1;
                     }
                     JSONObject pageInfo = jsonData.getJSONObject("page_info");
                     Integer totalPage = pageInfo.getInteger("total_page");
                     Integer currentPage = pageInfo.getInteger("page");
 
                     JSONArray jsonArrayay = jsonData.getJSONArray("list");
-                    if (jsonArrayay.size() == 0) {
-                        log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
-                        returnCode = 1;
+                    if(jsonArrayay.size() == 0){
+                        log.info("accountId:" + accountId + ";没有数据。总页数为:" +  totalPage + "当前页数为:" + currentPage);
+                        //returnCode = 1;
                         return 1;
                     }
 
@@ -1114,7 +978,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                             daily.setImageMode(dimensions.getString("image_mode"));
                             daily.setMaterialId(dimensions.getLong("material_id"));
                             daily.setInventory(dimensions.getString("inventory"));
-                            daily.setStatDatetime(dimensions.getDate("stat_datetime") == null ? null : DateUtils.formatDate(dimensions.getDate("stat_datetime"), "yyyy-MM-dd"));
+                            daily.setStatDatetime(dimensions.getDate("stat_datetime")==null?null:DateUtils.formatDate(dimensions.getDate("stat_datetime"),"yyyy-MM-dd"));
 
                             JSONObject metrics = detailJson.getJSONObject("metrics");
                             daily.setActivePayAmount(metrics.getInteger("active_pay_amount"));
@@ -1217,60 +1081,27 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
                     //Long insertEndTime = System.currentTimeMillis();
                     //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
-                    if (currentPage >= totalPage) {
-                        log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:" + endDate);
+                    if(currentPage >= totalPage){
+                        //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
                         //returnCode = 1;
                         return 1;
-                    } else {
+                    }else{
                         bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
                     }
-                } else {
-                    returnCode = -1;
-                    log.error("服务器返回为空,json:" + jsonString);
+                }else{
+                    //returnCode = -1;
+                    log.error("服务器返回为空,json:"+JSONObject.toJSONString(data));
                     return -1;
                 }
-            } else {
-                log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" + response);
-                returnCode = 0;  //504等状态0;-2连接服务器报错 ;-1对方服务器返回值为空;200正常;1没有数据(也属于正常)
-                return 0;
-            }
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
-            returnCode = -2;
-        } catch (IOException e) {
+        } catch (Exception e) {
             e.printStackTrace();
-            returnCode = -2;
-        } finally {
-            try {
-                if (response != null) {
-                    response.close();
-                }
-                client.close();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
+            returnCode = -3;
         }
         return returnCode;
     }
 
-    public List<BytedanceReportMaterialRetry> getRetryList() {
+    public List<BytedanceReportMaterialRetry> getRetryList(){
         return bytedanceReportMaterialDailyMapper.getRetryList();
     }
 
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+ 1 - 1
performance-appraisal/src/main/java/cn/com/ctop/huananvideoreport/controller/HuananVideoReportController.java

@@ -250,7 +250,7 @@ public class HuananVideoReportController {
 	 @PostMapping(value = "/getHuananMaterialInfo")
 	 public Result getHuananMaterialInfo(HttpServletRequest req) throws ParseException {
 		 Result<List<UserDto2>> result = new Result<List<UserDto2>>();
-		 huananVideoReportService.getHuananMaterialInfo("2020-04-01", "2020-04-29");
+		 huananVideoReportService.getHuananMaterialInfo("2020-05-01", "2020-05-07");
 		 result.setSuccess(true);
 		 return result;
 	 }

+ 29 - 0
performance-appraisal/src/main/java/cn/com/ctop/huananvideoreport/mapper/xml/HuananVideoReportMapper.xml

@@ -53,5 +53,34 @@
         where a.material_id = #{materialId}
     </select>
 
+    <select id="getHuananVideoInfo" resultType="cn.com.ctop.huananvideoreport.entity.HuananVideoReport">
+        select
+        a.material_id as materialId,
+--         a.account_id as accountId,
+--         b.auth_name as authName,
+        b.project_id as projectId,
+        b.project_name as projectName,
+        b.advertiser_id as advertiserId,
+        b.advertiser_name as advertiserName,
+        a.stat_datetime as statDatetime,
+        sum(a.cost) as cost,
+        d.signature as signature,
+        d.video_url as video_url,
+        e.url as url,
+        e.material_name as materialName,
+        1 as appType
+        from ctop_bytedance_report_material_daily a
+        left join ctop_user_allocation b on a.account_id = b.account_id
+        left join user_company c on b.user_id = c.user_id
+        left join ctop_bytedance_video_info d on a.material_id = d.material_id
+        left join (select code,url,material_name from ctop_material_info group by code) e on d.signature = e.code
+        where c.company_id = '6608ed13c0dd42de93c790dbdf124234'
+        and a.image_mode in ('CREATIVE_IMAGE_MODE_VIDEO',
+        'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL')
+        and date_format(stat_datetime,'%Y-%m-%d') &gt;= #{startDate}
+        and date_format(stat_datetime,'%Y-%m-%d') &lt;= #{endDate}
+        group by `statDatetime`,`signature`
+        order by `statDatetime`,`projectId`,`materialId`
+    </select>
 
 </mapper>