Bladeren bron

直播间整理数据 初版

zhaoxian 11 maanden geleden
bovenliggende
commit
a377fdf12a

+ 11 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/controller/KuaishouController.java

@@ -237,4 +237,15 @@ public class KuaishouController {
         kuaishouAccountReportDailyService.effectNativeChartReport(accountId, token, beforeYesterday, beforeYesterday);
     }
 
+    @GetMapping(value = "getLiveInfo")
+    public void getLiveInfo(Long accountId) throws Exception {
+        String token = tokenService.getByAccountId(Long.valueOf(accountId));
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
+
+        kuaishouAccountReportDailyService.liveUserReport(accountId, token, yesterday, yesterday);
+
+        kuaishouAccountReportDailyService.liveComponentReport(accountId, token, yesterday, yesterday);
+    }
+
 }

+ 5 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IKuaishouAccountReportDailyService.java

@@ -10,9 +10,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @version V1.0
  */
 public interface IKuaishouAccountReportDailyService extends IService<KuaishouAccountReportDaily> {
+
     void getAdvertiserReportDaily(Long advertiserId, String accessToken, String startDate, String endDate, int page) throws Exception;
 
     void sendMessage(Long accountId, String startDate, String endDate, String date_type);
 
     void effectNativeChartReport(Long accountId, String token, String beginDate, String endDate);
+
+    void liveComponentReport(Long accountId, String token, String beginDate, String endDate);
+
+    void liveUserReport(Long accountId, String token, String beginDate, String endDate);
 }

+ 84 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/KuaishouAccountReportDailyServiceImpl.java

@@ -166,4 +166,88 @@ public class KuaishouAccountReportDailyServiceImpl extends ServiceImpl<KuaishouA
             }
         }
     }
+
+    @Override
+    public void liveComponentReport(Long accountId, String token, String beginDate, String endDate) {
+        String url = postUrl + KuaishouConstant.LIVE_COMPONENT_REPORT;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", token);
+        Map<String, Object> param = new HashMap<>();
+        param.put("advertiser_id", accountId);
+//        param.put("temporal_granularity", "HOURLY");
+        param.put("start_date", beginDate);
+        param.put("end_date", endDate);
+        param.put("page", 1);
+        param.put("page_size", 2000);
+        JSONObject search_param = new JSONObject();
+
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        System.out.println("---直播间组件报表----------------" + param);
+        System.out.println("");
+        System.err.println(resultJson);
+        Integer code = resultJson.getInteger("code");
+        if (null == code || code != 0) {
+            String message = resultJson.getString("message");
+            log.error("直播间组件报表异常:{},accountId:{}", message, accountId);
+            return;
+        }
+        JSONObject data = resultJson.getJSONObject("data");
+        JSONArray details = data.getJSONArray("details");
+
+      /*  if (!Check.isNull(details)) {
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject jsonObject = details.getJSONObject(i);
+                jsonObject.put("start_date", DateUtils.tempToDate(jsonObject.getLong("live_start_time"), "yyyy-MM-dd HH:mm:ss"));
+                jsonObject.put("end_date", DateUtils.tempToDate(jsonObject.getLong("live_end_time"), "yyyy-MM-dd HH:mm:ss"));
+            }
+
+            System.out.println("-------------------直播间" + param);
+            System.out.println("");
+            System.err.println(details);
+
+        }*/
+
+    }
+
+
+    @Override
+    public void liveUserReport(Long accountId, String token, String beginDate, String endDate) {
+        String url = postUrl + KuaishouConstant.LIVE_USER_REPORT;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", token);
+        Map<String, Object> param = new HashMap<>();
+        param.put("advertiser_id", accountId);
+//        param.put("temporal_granularity", "HOURLY");
+        param.put("start_date", beginDate);
+        param.put("end_date", endDate);
+        param.put("page", 1);
+        param.put("page_size", 2000);
+        JSONObject search_param = new JSONObject();
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        System.out.println("-------------------直播间" + param);
+        System.out.println("");
+        System.err.println(resultJson);
+        Integer code = resultJson.getInteger("code");
+        if (null == code || code != 0) {
+            String message = resultJson.getString("message");
+            log.error("直播间报表异常:{},accountId:{}", message, accountId);
+            return;
+        }
+        JSONObject data = resultJson.getJSONObject("data");
+        JSONArray details = data.getJSONArray("details");
+        if (!Check.isNull(details)) {
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject jsonObject = details.getJSONObject(i);
+                jsonObject.put("start_date", DateUtils.tempToDate(jsonObject.getLong("live_start_time"), "yyyy-MM-dd HH:mm:ss"));
+                jsonObject.put("end_date", DateUtils.tempToDate(jsonObject.getLong("live_end_time"), "yyyy-MM-dd HH:mm:ss"));
+                jsonObject.put("charge", jsonObject.getBigDecimal("ad_live_follow").multiply(jsonObject.getBigDecimal("ad_live_follow_cost")));
+            }
+
+            System.err.println("-------------------直播间整理数据\n" + details);
+
+        }
+
+    }
 }