Browse Source

快手分销第三方数据

hpk 10 tháng trước cách đây
mục cha
commit
a6e500492e

+ 2 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/constant/KuaishouLinkConstants.java

@@ -14,8 +14,10 @@ public class KuaishouLinkConstants {
     public static final String V1_GROUP_REPORT = "/rest/openapi/v1/report/unit_report";
     public static final String DRAMA_AD_REPORT_DETAIL = "/rest/openapi/gw/dsp/series/report/queryAdDetail";
     public static final String DRAMA_ORDER_DETAIL = "/rest/openapi/gw/dsp/series/report/queryOrderDetail";
+    public static final String DRAMA_SALER_ORDER_DETAIL = "/rest/openapi/gw/dsp/series/report/querySalerOrderDetail";
     public static final String DRAMA_SERIES_EPISODE_LIST = "/rest/openapi/gw/dsp/series/report/seriesEpisodeList";
     public static final String DRAMA_SALER_COPY_RIGHT_DATA = "/rest/openapi/gw/dsp/series/report/querySalerCopyRightData";
+    public static final String DRAMA_SALER_DATA = "/rest/openapi/gw/dsp/series/report/querySalerData";
     public static final String DRAMA_SERIES_INFO = "/rest/openapi/gw/dsp/series/report/querySeriesInfo";
     public static final String AD_SOCIAL_TASK_LIST = "/rest/openapi/gw/ad_social/v1/quick_task/task/list";
     public static final String AD_SOCIAL_ORDER_LIST = "/rest/openapi/gw/ad_social/v1/quick_task/order/list";

+ 4 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IKuaiShouDramaService.java

@@ -9,8 +9,12 @@ public interface IKuaiShouDramaService {
 
     void queryOrderDetail(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend);
 
+    void querySalerOrderDetail(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend);
+
     void querySalerCopyRightData(String accessToken, Long advertiserId, Integer seriesType, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend);
 
+    void querySalerData(String accessToken, Long advertiserId, Integer seriesType, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend);
+
     void querySeriesInfo(String accessToken, Long advertiserId, Integer isLog, Long errId, Integer isSend);
 
     List<JSONObject> queryAdminAdvertiserToken(Long adminAdvertiserId);

+ 133 - 6
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/KuaiShouDramaServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.job.kuaishou.data.utils.AlertUtils;
 import cn.com.ctop.job.kuaishou.data.utils.Check;
 import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
 import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
+import cn.com.ctop.job.kuaishou.utils.doris.sink.DorisMultiTableStreamLoadManager;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -27,6 +28,8 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
     private KuaiShouDramaMapper kuaiShouDramaMapper;
     @Autowired
     private IKuaiShouErrorLogService errorLogService;
+    @Autowired
+    private DorisMultiTableStreamLoadManager dorisStreamLoadManager;
 
     @Override
     public void queryAdReportDetail(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
@@ -80,8 +83,8 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
             kuaiShouDramaMapper.insertAdReportDetail(addList);
             try {
                 kuaiShouDramaMapper.insertAdReportDetailSD(addList);
-            }catch (Exception e) {
-                log.error("insertAdReportDetailSD",e);
+            } catch (Exception e) {
+                log.error("insertAdReportDetailSD", e);
             }
         }
         if (page < totalPage) {
@@ -97,6 +100,7 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
         }
     }
 
+    // 自投订单
     @Override
     public void queryOrderDetail(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
         String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.DRAMA_ORDER_DETAIL;
@@ -153,8 +157,8 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
             kuaiShouDramaMapper.insertDramaOrder(addList);
             try {
                 kuaiShouDramaMapper.insertDramaOrderSD(addList);
-            }catch (Exception e) {
-                log.error("insertDramaOrderSD",e);
+            } catch (Exception e) {
+                log.error("insertDramaOrderSD", e);
             }
         }
         if (page < totalPage) {
@@ -170,6 +174,68 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
         }
     }
 
+    // 分销第三方订单
+    @Override
+    public void querySalerOrderDetail(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
+        String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.DRAMA_SALER_ORDER_DETAIL;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", accessToken);
+        Map<String, Object> param = new HashMap<>();
+        int pageSize = 1000;
+        param.put("start_date", DateUtils.timeToStamp(startDate + " 00:00:00"));
+        param.put("end_date", DateUtils.timeToStamp(endDate + " 23:59:59"));
+        param.put("user_id", advertiserId);
+        param.put("page_size", pageSize);
+        param.put("page_no", page);
+
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        if (Check.isNull(result)) {
+            log.error("获取快手分销短剧订单接口异常:{},accountId:{}", "返回结果为空", advertiserId);
+            if (isLog != null && isLog == 1) {
+                errorLogService.addError(advertiserId, startDate, endDate, "drama_saler_order", "daily", "返回结果为空", 2);
+            }
+            return;
+        }
+        JSONObject resultJson = JSONObject.parseObject(result);
+        Integer code = resultJson.getInteger("code");
+        String message = resultJson.getString("message");
+        if (null == code || code != 0) {
+            log.error("获取快手分销短剧订单接口异常:{},accountId:{}", message, advertiserId);
+            if (isLog != null && isLog == 1) {
+                errorLogService.addError(advertiserId, startDate, endDate, "drama_saler_order", "daily", message, 2);
+            }
+            return;
+        }
+        JSONObject data = resultJson.getJSONObject("data");
+        int totalCount = data.getIntValue("total_count");
+        int totalPage = (int) Math.ceil(totalCount * 1.0 / pageSize);
+        JSONArray details = data.getJSONArray("core_data_list");
+        if (!Check.isNull(details)) {
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject detailJson = details.getJSONObject(i);
+                detailJson.put("order_type", 2);
+                detailJson.put("stat_date", DateUtils.stampToIntDate(detailJson.getLong("create_time")));
+                detailJson.put("admin_advertiser_id", advertiserId);
+                detailJson.put("series_name", getSeriesName(advertiserId, detailJson.getLong("series_id"), accessToken));
+            }
+            dorisStreamLoadManager.add("media_api", "kuaishou_drama_order", details);
+        }
+
+        if (page < totalPage) {
+            querySalerOrderDetail(accessToken, advertiserId, startDate, endDate, page + 1, isLog, errId, isSend);
+        } else {
+            log.info("【{}】录入快手分销短剧订单数据完成 {} {} page: {}", advertiserId, startDate, endDate, page);
+            if (errId != null) {
+                errorLogService.deleteInfoByErrorId(errId);
+            }
+            if (isSend != null && isSend == 1) {
+                AlertUtils.sendMessage(advertiserId, startDate, endDate, 2, "daily", 1, "drama_saler_order");
+            }
+        }
+    }
+
+    // 版权商短剧分销数据
     @Override
     public void querySalerCopyRightData(String accessToken, Long advertiserId, Integer seriesType, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
         String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.DRAMA_SALER_COPY_RIGHT_DATA;
@@ -222,8 +288,8 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
             kuaiShouDramaMapper.insertSalerCopyRightData(addList);
             try {
                 kuaiShouDramaMapper.insertSalerCopyRightDataSD(addList);
-            }catch (Exception e) {
-                log.error("insertSalerCopyRightDataSD",e);
+            } catch (Exception e) {
+                log.error("insertSalerCopyRightDataSD", e);
             }
         }
         if (page < totalPage) {
@@ -239,6 +305,67 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
         }
     }
 
+    //分销商短剧分销数据
+    @Override
+    public void querySalerData(String accessToken, Long advertiserId, Integer seriesType, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
+        String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.DRAMA_SALER_DATA;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", accessToken);
+        Map<String, Object> param = new HashMap<>();
+        int pageSize = 100;
+        param.put("start_date", DateUtils.timeToStamp(startDate + " 00:00:00"));
+        param.put("end_date", DateUtils.timeToStamp(endDate + " 23:59:59"));
+        param.put("role_type", 2);
+        param.put("series_type", seriesType);
+        param.put("advertiser_id", advertiserId);
+        param.put("page_size", pageSize);
+        param.put("current_page", page);
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        if (Check.isNull(result)) {
+            log.error("获取快手分销商短剧分销数据查询接口异常:{},accountId:{}", "返回结果为空", advertiserId);
+            if (isLog != null && isLog == 1) {
+                errorLogService.addError(advertiserId, startDate, endDate, "drama_saler_data", "daily", new JSONObject().fluentPut("msg", "返回结果为空").fluentPut("seriesType", seriesType).toJSONString(), 2);
+            }
+            return;
+        }
+        JSONObject resultJson = JSONObject.parseObject(result);
+        Integer code = resultJson.getInteger("code");
+        String message = resultJson.getString("message");
+        if (null == code || code != 0) {
+            log.error("获取快手分销商短剧分销数据查询接口异常:{},accountId:{}", message, advertiserId);
+            if (isLog != null && isLog == 1 && (null == code || code != 3)) {
+                errorLogService.addError(advertiserId, startDate, endDate, "drama_saler_data", "daily", new JSONObject().fluentPut("msg", message).fluentPut("seriesType", seriesType).toJSONString(), 2);
+            }
+            return;
+        }
+        JSONObject data = resultJson.getJSONObject("data");
+        int totalCount = data.getIntValue("total_count");
+        int totalPage = (int) Math.ceil(totalCount * 1.0 / pageSize);
+        JSONArray details = data.getJSONArray("data_list");
+        if (!Check.isNull(details)) {
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject detailJson = details.getJSONObject(i);
+                detailJson.put("stat_date", DateUtils.getDateInteger(detailJson.getString("report_date")));
+                detailJson.put("admin_advertiser_id", advertiserId);
+                detailJson.put("series_type", seriesType);
+            }
+            dorisStreamLoadManager.add("media_api", "kuaishou_drama_saler_data", details);
+        }
+
+        if (page < totalPage) {
+            querySalerData(accessToken, advertiserId, seriesType, startDate, endDate, page + 1, isLog, errId, isSend);
+        } else {
+            log.info("【{}】录入快手分销商短剧分销数据完成 {} {} page: {}", advertiserId, startDate, endDate, page);
+            if (errId != null) {
+                errorLogService.deleteInfoByErrorId(errId);
+            }
+            if (isSend != null && isSend == 1) {
+                AlertUtils.sendMessage(advertiserId, startDate, endDate, 2, "daily", 1, "drama_saler_data");
+            }
+        }
+    }
+
     public void querySeriesInfo(String accessToken, Long advertiserId, Integer isLog, Long errId, Integer isSend) {
         String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.DRAMA_SERIES_INFO;
         Map<String, String> headers = new HashMap<>();