Browse Source

头条视频素材报表编写

hcst_sunzhen 5 years ago
parent
commit
dfde365cea

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

@@ -45,6 +45,7 @@ public class BytedanceDailyMaterialReportRetryJob implements Job {
                         String startDate = retry.getStartDate();
                         String endDate = retry.getEndDate();
                         Long accountId = retry.getAccountId();
+                        Integer type = retry.getType();
                         CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
                         log.info("头条素材报表重试定时任务,当前accountId为:" + token.getAccountId());
 
@@ -55,10 +56,12 @@ public class BytedanceDailyMaterialReportRetryJob implements Job {
                             start = DateUtils.addDay(startDate, i);
                             end = start;
                             //获取头条素材报表数据
-                            int code = bytedanceReportService.bytedanceMaterialReportRetry(token, start, end);
+                            int code = bytedanceReportService.bytedanceMaterialReportRetry(type, token, start, end);
                             if(code ==200 || code == 1){
-                                //重试成功清洗数据
-                                byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
+                                if(type == 1){
+                                    //重试成功清洗数据
+                                    byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
+                                }
                             }
                         }
                     } catch (Exception e) {

+ 7 - 7
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceReportController.java

@@ -190,12 +190,11 @@ public class BytedanceReportController {
                     @Override
                     public void run() {
                         try {
+                            Integer type = retry.getType();
                             String startDate = retry.getStartDate();
                             String endDate = retry.getEndDate();
                             Long accountId = retry.getAccountId();
                             CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
-                            log.info("头条素材报表当前accountId为:" + token.getAccountId());
-                            //int code = bytedanceReportService.bytedanceMaterialReportRetry(token, startDate, endDate);
 
                             Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
                             String start = null;
@@ -204,10 +203,12 @@ public class BytedanceReportController {
                                 start = DateUtils.addDay(startDate, i);
                                 end = start;
                                 //获取头条素材报表数据
-                                int code = bytedanceReportService.bytedanceMaterialReportRetry(token, start, end);
+                                int code = bytedanceReportService.bytedanceMaterialReportRetry(type, token, start, end);
                                 if(code ==200 || code == 1){
-                                    //重试成功清洗数据
-                                    byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
+                                    if(type == 1){
+                                        //重试成功清洗数据
+                                        byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
+                                    }
                                 }
                             }
 
@@ -220,12 +221,11 @@ public class BytedanceReportController {
             ////
 
         } catch (Exception e) {
-            log.error("条获取素材报表失败数据任务重试失败");
+            log.error("条获取素材报表失败数据任务重试失败");
             e.printStackTrace();
             result.setSuccess(false);
         }
 
-        log.info("头条获取素材报表数据任务重试结束");
         return result;
     }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceReportMaterialDailyMapper.xml

@@ -232,7 +232,8 @@
             account_id,
             start_date,
             end_date,
-            status
+            status,
+            type
         from
         ctop_bytedance_report_material_retry
         where status = 0

+ 1 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceReportService.java

@@ -39,7 +39,7 @@ public interface IBytedanceReportService {
 
     int bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate);
 
-    int bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate);
+    int bytedanceMaterialReportRetry(Integer type, CtopOauthToken token, String startDate, String endDate);
 
     List<BytedanceReportMaterialRetry> getRetryList();
 

+ 24 - 23
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceReportServiceImpl.java

@@ -711,19 +711,25 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
     /////////////////////////////////////////////////////////\
     //素材报表
     @Override
-    public int bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate) {
+    public int bytedanceMaterialReportRetry(Integer type, CtopOauthToken token, String startDate, String endDate) {
         Long accountId = token.getAccountId();
-        // log.info("头条素材报表当前accountId为:" + accountId);
+        log.info("头条素材报表重试开始 当前accountId:{}  {}~{},type:{}" , accountId, startDate,endDate,type);
         Integer page = 1;
         Integer pageSize = 100;
-        int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
+        Integer code = null;
+        if(type == 1){
+            code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
+
+        }else if(type == 2){
+            code = bytedanceVideoMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
+        }
 
         BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
         retry.setAccountId(accountId);
         retry.setStartDate(startDate);
         retry.setEndDate(endDate);
         retry.setStatusCode(code);
-        retry.setType(1);
+        retry.setType(type);
         if (code != 200 && code != 1) {
             retry.setStatus(0);
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
@@ -731,13 +737,14 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             retry.setStatus(1);
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
         }
+        log.info("头条素材报表重试结束 当前accountId:{}  {}~{},type:{},code:{}" , accountId, startDate,endDate,type,code);
         return code;
     }
 
     @Override
     public int bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate) {
         Long accountId = token.getAccountId();
-        log.info("头条素材报表当前accountId为:" + accountId);
+        log.info("头条素材报表开始 当前accountId:{}  {}~{}" , accountId, startDate,endDate);
         Integer page = 1;
         Integer pageSize = 100;
         int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
@@ -751,7 +758,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             retry.setType(1);
             bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
         }
-        log.info("头条素材报表当前accountId为:{}  {}~{}" , accountId, startDate,endDate);
+        log.info("头条素材报表结束 当前accountId为:{}  {}~{}" , accountId, startDate,endDate);
         return code;
     }
 
@@ -777,8 +784,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
         JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
         if (json == null) {
-            //insertMaterialRetry(accountId, startDate, endDate, -2);
-            log.error("请求有误:" + JSONObject.toJSONString(data));
+            log.error("返回为空,请求有误:" + JSONObject.toJSONString(data));
             return -2;
         }
 
@@ -787,13 +793,13 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             if (!Check.isNull(json)) {
                 Integer code = json.getInteger("code");
                 if (code != 0) {
-                    log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
+                    log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为" + json + "请求为:" + JSONObject.toJSONString(data));
                     return -1;
                 }
 
                 JSONObject jsonData = json.getJSONObject("data");
                 if (Check.isNull(jsonData)) {
-                    log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
+                    log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为" + json + "请求为:" + JSONObject.toJSONString(data));
                     return -1;
                 }
                 JSONObject pageInfo = jsonData.getJSONObject("page_info");
@@ -803,7 +809,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 JSONArray jsonArrayay = jsonData.getJSONArray("list");
                 if (jsonArrayay.size() == 0) {
                     log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
-                    //returnCode = 1;
                     return 1;
                 }
 
@@ -915,19 +920,15 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                         bytedanceReportMaterialDailyList.add(daily);
                     }
                 }
-                //Long insertStartTime = System.currentTimeMillis();
                 bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
-                //Long insertEndTime = System.currentTimeMillis();
-                //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
                 if (currentPage >= totalPage) {
-                    //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
+                    log.info("头条素材报表当前accountId为:{}  {}~{},接口数据拉取成功" , accountId, startDate,endDate);
                     return 1;
                 } else {
                     int pageCode = bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
                     return pageCode;
                 }
             } else {
-                //returnCode = -1;
                 log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
                 return -1;
             }
@@ -992,7 +993,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
         JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
         if (json == null) {
-            log.error("请求有误:" + JSONObject.toJSONString(data));
+            log.error("返回为空,请求有误:" + JSONObject.toJSONString(data));
             return -2;
         }
 
@@ -1001,13 +1002,13 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             if (!Check.isNull(json)) {
                 Integer code = json.getInteger("code");
                 if (code != 0) {
-                    log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
+                    log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
                     return -1;
                 }
 
                 JSONObject jsonData = json.getJSONObject("data");
                 if (Check.isNull(jsonData)) {
-                    log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
+                    log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + json + "请求为:" + JSONObject.toJSONString(data));
                     return -1;
                 }
                 JSONObject pageInfo = jsonData.getJSONObject("page_info");
@@ -1030,18 +1031,18 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 }
                 bytedanceReportMaterialDailyMapper.replaceIntoVideoMaterialBatch(bytedanceReportVideoMaterialDailyList);
                 if (currentPage >= totalPage) {
+                    log.info("头条视频素材报表当前accountId为:{}  {}~{},接口数据拉取成功" , accountId, startDate,endDate);
                     return 1;
                 } else {
-                    int pageCode = bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
-                    return pageCode;
+                    return bytedanceVideoMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
                 }
             } else {
-                log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
+                log.error("头条视频素材报表服务器返回为空,accountId:" + accountId + ",json:" + json + "请求为:" + JSONObject.toJSONString(data));
                 return -1;
             }
         } catch (Exception e) {
             e.printStackTrace();
-            log.error("头条报表其他错误,accountId:" + accountId + ",json:" + JSONObject.toJSONString(data));
+            log.error("头条视频素材报表其他错误,accountId:" + accountId + ",json:" + json + "请求为:" + JSONObject.toJSONString(data));
             returnCode = -3;
         }
         return returnCode;