yumeng 1 سال پیش
والد
کامیت
58eaae76f2

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

@@ -0,0 +1,62 @@
+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.service.*;
+import cn.com.ctop.job.bytedance.data.utils.Check;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+
+/**
+ * zian Y
+ * 2022/2/9
+ **/
+
+@RestController
+@RequestMapping("/history")
+@Api(tags = "头条")
+@Slf4j
+public class HistoryDataController {
+    @Autowired
+    private IBytedanceProductReportService productReportService;
+
+    private static final ExecutorService dailyRetrExecutorService = Executors.newFixedThreadPool(3);
+    @Autowired
+    private IByteDanceFlowDetailsReportService byteDanceFlowDetailsReportService;
+
+    @Autowired
+    private IBytedanceAccountReportService accountReportService;
+
+    @Autowired
+    private IBytedancePromoterReportService promoterReportService;
+
+    @GetMapping("/getData")
+    public void getData(Long advertiserId, String startDate, String endDate) {
+        dailyRetrExecutorService.submit(new Runnable() {
+            @Override
+            public void run() {
+
+                String token = accountReportService.getTokenByAdvertiserId(advertiserId);
+                if (Check.isNull(token)) {
+                    return;
+                }
+                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);
+            }
+        });
+    }
+
+
+}

+ 2 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceAccountReportMapper.java

@@ -19,4 +19,6 @@ public interface BytedanceAccountReportMapper {
 
     void replaceErrorInfo(BytedanceErrorLog errorInfo);
     void deleteInfoByErrorId(@Param("errorId") Long errorId);
+
+    String getTokenByAdvertiserId(@Param("advertiserId") Long advertiserId);
 }

+ 6 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedanceAccountReportMapper.xml

@@ -273,4 +273,10 @@
         FROM bytedance_error_log
         WHERE id = #{errorId}
     </delete>
+    <select id="getTokenByAdvertiserId" resultType="java.lang.String">
+        select t2.access_token
+        from deepthink.bytedance_advertiser_list t1
+                 left join deepthink.bytedance_auth_list t2 on t1.admin_advertiser_id = t2.admin_advertiser_id
+        where t1.advertiser_id = #{advertiserId}
+    </select>
 </mapper>

+ 2 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceAccountReportService.java

@@ -8,4 +8,6 @@ public interface IBytedanceAccountReportService {
     void getBytedanceAccountHour(Long advertiserId, String accessToken, String startDate, String ebdDate, Integer page, Integer isLog);
 
     void getBytedanceAccountDaily(Long advertiserId, String accessToken, String startDate, String ebdDate, Integer page, Integer isLog);
+
+    String getTokenByAdvertiserId(Long advertiserId);
 }

+ 13 - 8
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceAccountReportServiceImpl.java

@@ -71,7 +71,7 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
                             advertiserReportHour.setHour(hour);
                             hours.add(advertiserReportHour);
 
-                            dorisLoadManager.add("media_api","bytedance_advertiser_report_hour", advertiserReportHour);
+                            dorisLoadManager.add("media_api", "bytedance_advertiser_report_hour", advertiserReportHour);
 
                         }
                     }
@@ -145,7 +145,7 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
                             advertiserReportDaily.setStatTimeDay(statTimeDay);
                             dailyList.add(advertiserReportDaily);
 
-                            dorisLoadManager.add("media_api","bytedance_advertiser_report_daily", advertiserReportDaily);
+                            dorisLoadManager.add("media_api", "bytedance_advertiser_report_daily", advertiserReportDaily);
                         }
                     }
                 }
@@ -228,7 +228,7 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
                             advertiserReportHour.setHour(hour);
                             hours.add(advertiserReportHour);
 
-                            dorisLoadManager.add("media_api","bytedance_advertiser_report_hour", advertiserReportHour);
+                            dorisLoadManager.add("media_api", "bytedance_advertiser_report_hour", advertiserReportHour);
                         }
                     } else {
                         log.info("账户id:{},日期:{}广告时报(账户粒度)请求结果为空", advertiserId, startDate);
@@ -288,7 +288,7 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
             String s = HttpUtils.httpGet(url, paramsMap, headers);
             JSONObject result = JSONObject.parseObject(s);
             if (Check.isNull(result)) {
-                log.info("账户id:{},日期:{},广告时报(账户粒度)请求结果返回为空", advertiserId, startDate);
+                log.info("账户id:{},日期:{},账户日报(账户粒度)请求结果返回为空", advertiserId, startDate);
                 if (isLog == 1) {
                     BytedanceErrorLog errorInfo = new BytedanceErrorLog();
                     errorInfo.setAdvertiserId(advertiserId);
@@ -317,15 +317,15 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
                             advertiserReportDaily.setStatTimeDay(statTimeDay);
                             dailyList.add(advertiserReportDaily);
 
-                            dorisLoadManager.add("media_api","bytedance_advertiser_report_daily", advertiserReportDaily);
+                            dorisLoadManager.add("media_api", "bytedance_advertiser_report_daily", advertiserReportDaily);
                         }
                     } else {
-                        log.info("账户id:{},日期:{},广告日报(账户粒度)请求结果为空", advertiserId, startDate);
+                        log.info("账户id:{},日期:{},账户日报(账户粒度)请求结果为空", advertiserId, startDate);
                         return;
                     }
                 }
             } else {
-                log.info("账户id:{},日期:{},广告日报(账户粒度)请求结果失败,返回数据:{}", advertiserId, startDate, result);
+                log.info("账户id:{},日期:{},账户日报(账户粒度)请求结果失败,返回数据:{}", advertiserId, startDate, result);
                 if (isLog == 1) {
                     BytedanceErrorLog errorInfo = new BytedanceErrorLog();
                     errorInfo.setAdvertiserId(advertiserId);
@@ -350,11 +350,16 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
                 }
                 getBytedanceAccountDaily(advertiserId, accessToken, startDate, endDate, page + 1, isLog);
             } else {
-                log.info("账户ID:{},日期:{},广告日报(账户粒度)数据请求成功", advertiserId, startDate);
+                log.info("账户ID:{},日期:{},账户日报(账户粒度)数据请求成功", advertiserId, startDate);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
+    @Override
+    public String getTokenByAdvertiserId(Long advertiserId) {
+        return accountReportMapper.getTokenByAdvertiserId(advertiserId);
+    }
+
 }