소스 검색

feat(report): 新增并完善自定义报表获取和重试功能

- BytedanceController新增uniProjectReport接口支持全域项目日报调用
- BytedanceReportRetryJob添加对custom数据维度的重试任务支持
- CustomReportServiceImpl完善getCustomReport方法,增加errorId参数传递和错误信息处理
- HistoryDataController调用customReportService补充uni_project_daily报表数据采集
- ICustomReportService接口更新,新增errorId参数支持错误追踪
- POM配置中resources包含json文件资源,支持配置文件读取
hpk 3 달 전
부모
커밋
22dfb720db

+ 1 - 0
job-bytedance/pom.xml

@@ -244,6 +244,7 @@
                     <include>**/*.yml</include>
                     <include>**/*.properties</include>
                     <include>**/*.xml</include>
+                    <include>**/*.json</include>
                 </includes>
                 <filtering>false</filtering>
             </resource>

+ 14 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.controller;
 
 import cn.com.ctop.job.bytedance.data.entity.AdvertiserAccount;
 import cn.com.ctop.job.bytedance.data.enums.AccountTypeEnum;
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceRefreshTokenMapper;
 import cn.com.ctop.job.bytedance.data.service.*;
 import cn.com.ctop.job.bytedance.data.utils.Check;
 import com.alibaba.fastjson.JSONArray;
@@ -30,6 +31,8 @@ import java.util.concurrent.Executors;
 @Slf4j
 public class BytedanceController {
     @Autowired
+    private ICustomReportService customReportService;
+    @Autowired
     private IBytedanceProductReportService productReportService;
 
     private static final ExecutorService executor10Service1 = Executors.newFixedThreadPool(10);
@@ -394,4 +397,15 @@ public class BytedanceController {
         cdpProjectService.getWxAppInfo(advertiserId);
     }
 
+
+    @GetMapping("/uniProjectReport")
+    public void uniProjectReportDaily(String reportType, // uni_project_daily  uni_project_hour
+                                      @RequestParam(required = false) Long advertiserId,
+                                      String startDate,
+                                      String endDate) {
+        String accessToken = accountReportService.getTokenByAdvertiserId(advertiserId);
+        // 全域项目日报
+        customReportService.getCustomReport(reportType, advertiserId, accessToken, startDate, endDate, 0, null);
+    }
+
 }

+ 4 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/HistoryDataController.java

@@ -36,6 +36,9 @@ public class HistoryDataController {
     @Autowired
     private IBytedancePromoterReportService promoterReportService;
 
+    @Autowired
+    private ICustomReportService customReportService;
+
     @GetMapping("/getData")
     public JSONObject getData(Long advertiserId, String startDate, String endDate) {
         JSONObject json = new JSONObject();
@@ -50,6 +53,7 @@ public class HistoryDataController {
                 accountReportService.getBytedanceAccountDaily(advertiserId, token, startDate, endDate, 1, 1);
                 promoterReportService.getBytedancePromoterDaily(advertiserId, token, startDate, endDate, 1, 1);
                 byteDanceFlowDetailsReportService.getBytedanceFlowDetailsDailyReport(advertiserId, token, AccountTypeEnum.AD.getValue(), startDate, endDate, 1, null);
+                customReportService.getCustomReport("uni_project_daily", advertiserId, token, startDate, endDate, 1, null);
             }
         });
         json.put("code", 200);

+ 1 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/ICustomReportService.java

@@ -21,5 +21,5 @@ public interface ICustomReportService {
      * @param isLog        是否记录错误日志(1=是)
      */
     void getCustomReport(String reportType, Long advertiserId, String accessToken,
-                         String startDate, String endDate, Integer isLog);
+                         String startDate, String endDate, Integer isLog, Long errorId);
 }

+ 9 - 6
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/CustomReportServiceImpl.java

@@ -56,8 +56,8 @@ public class CustomReportServiceImpl implements ICustomReportService {
 
     @Override
     public void getCustomReport(String reportType, Long advertiserId, String accessToken,
-                                String startDate, String endDate, Integer isLog) {
-        getCustomReport(reportType, advertiserId, accessToken, startDate, endDate, isLog, 1);
+                                String startDate, String endDate, Integer isLog, Long errorId) {
+        getCustomReport(reportType, advertiserId, accessToken, startDate, endDate, isLog, 1, errorId);
     }
 
     /**
@@ -66,7 +66,7 @@ public class CustomReportServiceImpl implements ICustomReportService {
      * @param page 当前页码
      */
     private void getCustomReport(String reportType, Long advertiserId, String accessToken,
-                                String startDate, String endDate, Integer isLog, int page) {
+                                 String startDate, String endDate, Integer isLog, int page, Long errorId) {
         // 1. 读取配置
         CustomReportFieldConfig config = configLoader.getConfig(reportType);
         if (config == null) {
@@ -183,8 +183,11 @@ public class CustomReportServiceImpl implements ICustomReportService {
                 } catch (InterruptedException e) {
                     Thread.currentThread().interrupt();
                 }
-                getCustomReport(reportType, advertiserId, accessToken, startDate, endDate, isLog, page + 1);
+                getCustomReport(reportType, advertiserId, accessToken, startDate, endDate, isLog, page + 1, errorId);
             } else {
+                if (errorId != null) {
+                    promoterReportMapper.deleteInfoByErrorId(errorId);
+                }
                 log.info("账户ID:{},报表类型:{},所有页数据获取完成", advertiserId, reportType);
             }
         } catch (Exception e) {
@@ -201,8 +204,8 @@ public class CustomReportServiceImpl implements ICustomReportService {
             errorInfo.setAdvertiserId(advertiserId);
             errorInfo.setStartDate(startDate);
             errorInfo.setEndDate(endDate);
-            errorInfo.setDataDimension(reportType);
-            errorInfo.setDataType("custom");
+            errorInfo.setDataDimension("custom");
+            errorInfo.setDataType(reportType);
             errorInfo.setMsg(msg);
             promoterReportMapper.replaceErrorInfo(errorInfo);
         } catch (Exception e) {

+ 14 - 12
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceReportRetryJob.java

@@ -63,6 +63,9 @@ public class BytedanceReportRetryJob {
     @Autowired
     private BytedancePromoterReportMapper promoterReportMapper;
 
+    @Autowired
+    private ICustomReportService customReportService;
+
 
     private static ExecutorService hourAccountRetrExecutorService = Executors.newFixedThreadPool(2);
     private static ExecutorService dailyAccountRetrExecutorService = Executors.newFixedThreadPool(2);
@@ -92,8 +95,17 @@ public class BytedanceReportRetryJob {
                 String accessToken = jsonObject.getString("accessToken");
                 Integer isSend = jsonObject.getInteger("isSend");
                 String msg = jsonObject.getString("msg");
-                if ("promoter".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
+                promoterReportMapper.updateStatusByErrorId(id);
+                if ("custom".equals(dataDimension)) {
+                    dailyPromoterRetrExecutorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            if (!Check.isNull(accessToken)) {
+                                customReportService.getCustomReport(dataType, advertiserId, accessToken, startDate, endDate, 0, id);
+                            }
+                        }
+                    });
+                } else if ("promoter".equals(dataDimension)) {
                     if (dataType.equals("hour")) { // 广告时报
                         hourPromoterRetrExecutorService.submit(new Runnable() {
                             @Override
@@ -116,7 +128,6 @@ public class BytedanceReportRetryJob {
                         });
                     }
                 } else if ("product".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
                     productDailyRetrExecutor.submit(new Runnable() {
                         @Override
                         public void run() {
@@ -126,7 +137,6 @@ public class BytedanceReportRetryJob {
                         }
                     });
                 } else if ("account".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
                     if (dataType.equals("hour")) { // 账户时报
                         hourAccountRetrExecutorService.submit(new Runnable() {
                             @Override
@@ -150,7 +160,6 @@ public class BytedanceReportRetryJob {
                     }
 
                 } else if ("flow_details".equals(dataDimension)) { //日报流水详情
-                    promoterReportMapper.updateStatusByErrorId(id);
                     flowDailyRetrExecutor.submit(new Runnable() {
                         @Override
                         public void run() {
@@ -158,7 +167,6 @@ public class BytedanceReportRetryJob {
                         }
                     });
                 } else if ("material".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
                     materialRetrExecutor.submit(new Runnable() {
                         @Override
                         public void run() {
@@ -168,7 +176,6 @@ public class BytedanceReportRetryJob {
                         }
                     });
                 } else if ("material_video_get".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
                     HashSet<Long> materialIds = new HashSet<>();
                     JSONObject msgObject = JSONObject.parseObject(msg);
                     if (msgObject != null && msgObject.getJSONArray("material_ids") != null) {
@@ -183,7 +190,6 @@ public class BytedanceReportRetryJob {
                         }
                     });
                 } else if ("promotion_list".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
                     productDailyRetrExecutor.submit(new Runnable() {
                         @Override
                         public void run() {
@@ -193,7 +199,6 @@ public class BytedanceReportRetryJob {
                         }
                     });
                 } else if ("project_list".equals(dataDimension)) {
-                    promoterReportMapper.updateStatusByErrorId(id);
                     productDailyRetrExecutor.submit(new Runnable() {
                         @Override
                         public void run() {
@@ -204,10 +209,7 @@ public class BytedanceReportRetryJob {
                         }
                     });
                 }
-
-
             }
-
         } else {
             log.info("重试列表为空");
         }