|
|
@@ -3,6 +3,7 @@ package cn.com.ctop.job.kuaishou.data.service.impl;
|
|
|
import cn.com.ctop.job.kuaishou.data.constant.KuaishouLinkConstants;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaAdReportDetail;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaEpisodeInfo;
|
|
|
+import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaEpisodeReport;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaOrder;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaSalerCopyRightData;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaSeriesInfo;
|
|
|
@@ -544,4 +545,91 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
|
|
|
}
|
|
|
return seriesName;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void queryEpisodeReport(String accessToken, Long advertiserId, String startDate, String endDate, Integer isLog, Long errId, Integer isSend) {
|
|
|
+ Integer statDate = DateUtils.getIntegerDate(startDate);
|
|
|
+ List<Long> seriesIds = kuaiShouDramaMapper.querySeriesIdsByDate(advertiserId, statDate);
|
|
|
+ if (Check.isNull(seriesIds)) {
|
|
|
+ log.info("【{}】无需查询的短剧剧集报表 {} {}", advertiserId, startDate, endDate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int batchSize = 20;
|
|
|
+ for (int i = 0; i < seriesIds.size(); i += batchSize) {
|
|
|
+ List<Long> batchSeriesIds = seriesIds.subList(i, Math.min(i + batchSize, seriesIds.size()));
|
|
|
+ queryEpisodeReportBySeriesIds(accessToken, advertiserId, startDate, endDate, batchSeriesIds, 1, isLog, errId, isSend);
|
|
|
+ }
|
|
|
+ log.info("【{}】录入快手短剧剧集报表数据完成 {} {}", advertiserId, startDate, endDate);
|
|
|
+ if (errId != null) {
|
|
|
+ errorLogService.deleteInfoByErrorId(errId);
|
|
|
+ }
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
+ AlertUtils.sendMessage(advertiserId, startDate, endDate, 2, "daily", 1, "drama_episode_report");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void queryEpisodeReportBySeriesIds(String accessToken, Long advertiserId, String startDate, String endDate, List<Long> seriesIds, int page, Integer isLog, Long errId, Integer isSend) {
|
|
|
+ String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.DRAMA_EPISODE_REPORT;
|
|
|
+ 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("advertiser_id", advertiserId);
|
|
|
+ param.put("start_date", DateUtils.timeToStamp(startDate + " 00:00:00"));
|
|
|
+ param.put("end_date", DateUtils.timeToStamp(endDate + " 23:59:59"));
|
|
|
+ param.put("series_ids", seriesIds);
|
|
|
+ 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_episode_report", "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_episode_report", "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("data_list");
|
|
|
+ List<KuaiShouDramaEpisodeReport> addList = new ArrayList<>();
|
|
|
+ if (!Check.isNull(details)) {
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
+ KuaiShouDramaEpisodeReport report = new KuaiShouDramaEpisodeReport();
|
|
|
+ report.setAdminAdvertiserId(advertiserId);
|
|
|
+ report.setStatDate(DateUtils.getIntegerDate(detailJson.getString("report_date")));
|
|
|
+ report.setSeriesId(detailJson.getLong("series_id"));
|
|
|
+ report.setEpisodeId(detailJson.getLong("episode_id"));
|
|
|
+ report.setAccountId(detailJson.getString("account_id"));
|
|
|
+ report.setResourceType(detailJson.getString("resource_type"));
|
|
|
+ report.setIsPayEpisode(detailJson.getInteger("is_pay_episode"));
|
|
|
+ report.setSeriesPayTemplateId(detailJson.getString("series_pay_template_id"));
|
|
|
+ report.setShowCnt(detailJson.getInteger("show_cnt"));
|
|
|
+ report.setPlayCnt(detailJson.getInteger("play_cnt"));
|
|
|
+ report.setCompletePlayCnt(detailJson.getInteger("complete_play_cnt"));
|
|
|
+ report.setPayPanelShowCnt(detailJson.getInteger("pay_panel_show_cnt"));
|
|
|
+ report.setPayPanelClickCnt(detailJson.getInteger("pay_panel_click_cnt"));
|
|
|
+ report.setPayAmt(detailJson.getDouble("pay_amt"));
|
|
|
+ addList.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(addList)) {
|
|
|
+ kuaiShouDramaMapper.insertEpisodeReport(addList);
|
|
|
+ }
|
|
|
+ if (page < totalPage) {
|
|
|
+ queryEpisodeReportBySeriesIds(accessToken, advertiserId, startDate, endDate, seriesIds, page + 1, isLog, errId, isSend);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|