Ver código fonte

feat(bytedance): 全域账户账户流水

- 在BytedanceController中新增uniFlowDetailsReport接口,支持按日期区间查询统一流量明细数据
- 使用线程池异步执行获取各广告主的流量明细日报
- 在ByteDanceFlowDetailsReportJob中新增uniFlowDetailsDaily定时任务,自动获取前一日统一流量明细数据
- 引入BytedanceCdpProjectMapper进行广告主和token信息查询
- 优化日期处理逻辑,支持日期参数的默认赋值和格式转换
hpk 3 meses atrás
pai
commit
449ba1735c

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

@@ -2,8 +2,10 @@ 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.BytedanceCdpProjectMapper;
 import cn.com.ctop.job.bytedance.data.service.*;
 import cn.com.ctop.job.bytedance.data.utils.Check;
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
@@ -32,6 +34,8 @@ public class BytedanceController {
     private ICustomReportService customReportService;
     @Autowired
     private IBytedanceProductReportService productReportService;
+    @Autowired
+    private BytedanceCdpProjectMapper bytedanceCdpProjectMapper;
 
     private static final ExecutorService executor10Service1 = Executors.newFixedThreadPool(10);
     private static final ExecutorService executor10Service2 = Executors.newFixedThreadPool(10);
@@ -210,6 +214,31 @@ public class BytedanceController {
 
     }
 
+    @GetMapping("/uniFlowDetailsReport")
+    public void uniFlowDetailsReport(@RequestParam(required = false) String startDate,
+                                     @RequestParam(required = false) String endDate) {
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String date = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        startDate = startDate == null ? date : startDate;
+        endDate = endDate == null ? nowDate : endDate;
+
+        List<JSONObject> jsonObjects = bytedanceCdpProjectMapper.queryUniCostAdvertiserIds(startDate.replace("-", ""), endDate.replace("-", ""));
+        for (JSONObject jsonObject : jsonObjects) {
+            Long advertiserId = jsonObject.getLong("advertiser_id");
+            String accessToken = jsonObject.getString("access_token");
+            String finalStartDate = startDate;
+            String finalEndDate = endDate;
+            executor10Service1.submit(new Runnable() {
+                @Override
+                public void run() {
+                    if (!Check.isNull(accessToken)) {
+                        byteDanceFlowDetailsReportService.getBytedanceFlowDetailsDailyReport(advertiserId, accessToken, AccountTypeEnum.AD.getValue(), finalStartDate, finalEndDate, 1, null);
+                    }
+                }
+            });
+        }
+    }
+
     @GetMapping("/generateFlowDetailsReport")
     public void generateFlowDetailsReport(String startDate, String endDate) {
         List<AdvertiserAccount> adAccount = byteDanceFlowDetailsReportService.getAdAccount();

+ 26 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceFlowDetailsReportJob.java

@@ -1,15 +1,18 @@
 package cn.com.ctop.job.bytedance.handler;
 
 import cn.com.ctop.job.bytedance.data.enums.AccountTypeEnum;
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceCdpProjectMapper;
 import cn.com.ctop.job.bytedance.data.service.IByteDanceFlowDetailsReportService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
 import cn.com.ctop.job.bytedance.data.utils.DateUtils;
+import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -23,6 +26,8 @@ import java.util.concurrent.Executors;
 @Slf4j
 @Component
 public class ByteDanceFlowDetailsReportJob {
+    @Autowired
+    private BytedanceCdpProjectMapper bytedanceCdpProjectMapper;
 
     @Autowired
     private IByteDanceFlowDetailsReportService byteDanceFlowDetailsReportService;
@@ -52,4 +57,25 @@ public class ByteDanceFlowDetailsReportJob {
             }
         });
     }
+
+    @XxlJob("uniFlowDetailsDaily")
+    public void uniFlowDetailsDaily() throws Exception {
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String date = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+
+        List<JSONObject> jsonObjects = bytedanceCdpProjectMapper.queryUniCostAdvertiserIds(date.replace("-", ""), date.replace("-", ""));
+        for (JSONObject jsonObject : jsonObjects) {
+            Long advertiserId = jsonObject.getLong("advertiser_id");
+            String accessToken = jsonObject.getString("access_token");
+
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    if (!Check.isNull(accessToken)) {
+                        byteDanceFlowDetailsReportService.getBytedanceFlowDetailsDailyReport(advertiserId, accessToken, AccountTypeEnum.AD.getValue(), date, date, 1, null);
+                    }
+                }
+            });
+        }
+    }
 }