|
@@ -2,6 +2,8 @@ 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.constant.KuaishouLinkConstants;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaAdReportDetail;
|
|
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.KuaiShouDramaOrder;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaSalerCopyRightData;
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaSalerCopyRightData;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaSeriesInfo;
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaiShouDramaSeriesInfo;
|
|
@@ -267,7 +269,7 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
|
|
|
if (isLog != null && isLog == 1 && (null == code || code != 3)) {
|
|
if (isLog != null && isLog == 1 && (null == code || code != 3)) {
|
|
|
errorLogService.addError(advertiserId, startDate, endDate, "drama_saler_cr_data", "daily", new JSONObject().fluentPut("msg", message).fluentPut("seriesType", seriesType).toJSONString(), 2);
|
|
errorLogService.addError(advertiserId, startDate, endDate, "drama_saler_cr_data", "daily", new JSONObject().fluentPut("msg", message).fluentPut("seriesType", seriesType).toJSONString(), 2);
|
|
|
}
|
|
}
|
|
|
- if (code != null && code == 3 && errId != null){
|
|
|
|
|
|
|
+ if (code != null && code == 3 && errId != null) {
|
|
|
errorLogService.deleteInfoByErrorId(errId);
|
|
errorLogService.deleteInfoByErrorId(errId);
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
@@ -437,7 +439,7 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
|
|
|
if (!Check.isNull(seriesIds)) {
|
|
if (!Check.isNull(seriesIds)) {
|
|
|
updateSeriesEpisodeNum(advertiserId, accessToken, seriesIds);
|
|
updateSeriesEpisodeNum(advertiserId, accessToken, seriesIds);
|
|
|
}
|
|
}
|
|
|
- log.error("批量获取快手短剧剧集信息完成 accountId:{}", advertiserId);
|
|
|
|
|
|
|
+ log.info("批量获取快手短剧剧集信息完成 accountId:{}", advertiserId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -456,31 +458,49 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
|
|
|
Integer code = resultJson.getInteger("code");
|
|
Integer code = resultJson.getInteger("code");
|
|
|
String message = resultJson.getString("message");
|
|
String message = resultJson.getString("message");
|
|
|
if (null == code || code != 0) {
|
|
if (null == code || code != 0) {
|
|
|
- log.error("批量获取快手短剧剧集信息查询接口异常:{},accountId:{}", message, advertiserId);
|
|
|
|
|
- }
|
|
|
|
|
- JSONArray data = resultJson.getJSONArray("data");
|
|
|
|
|
- List<KuaiShouDramaSeriesInfo> seriesInfos = new ArrayList<>();
|
|
|
|
|
- for (Object datum : data) {
|
|
|
|
|
- JSONObject seriesInfo = JSONObject.parseObject(datum.toString());
|
|
|
|
|
- JSONArray episodeList = seriesInfo.getJSONArray("episode_list");
|
|
|
|
|
- String seriesName = seriesInfo.getString("mini_series_name");
|
|
|
|
|
- Long seriesId = seriesInfo.getLong("mini_series_id");
|
|
|
|
|
- Integer episodeNum = null;
|
|
|
|
|
- if (!Check.isNull(episodeList)) {
|
|
|
|
|
- episodeNum = episodeList.size();
|
|
|
|
|
|
|
+ log.error("批量获取快手短剧剧集信息查询接口异常:{},accountId:{},seriesIds:{}", message, advertiserId, param.get("mini_series_ids"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ JSONArray data = resultJson.getJSONArray("data");
|
|
|
|
|
+ List<KuaiShouDramaSeriesInfo> seriesInfos = new ArrayList<>();
|
|
|
|
|
+ List<KuaiShouDramaEpisodeInfo> episodeInfos = new ArrayList<>();
|
|
|
|
|
+ for (Object datum : data) {
|
|
|
|
|
+ JSONObject seriesInfo = JSONObject.parseObject(datum.toString());
|
|
|
|
|
+ JSONArray episodeList = seriesInfo.getJSONArray("episode_list");
|
|
|
|
|
+ String seriesName = seriesInfo.getString("mini_series_name");
|
|
|
|
|
+ Long seriesId = seriesInfo.getLong("mini_series_id");
|
|
|
|
|
+ Integer episodeNum = null;
|
|
|
|
|
+ if (!Check.isNull(episodeList)) {
|
|
|
|
|
+ episodeNum = episodeList.size();
|
|
|
|
|
+ for (int i = 0; i < episodeList.size(); i++) {
|
|
|
|
|
+ JSONObject episodeJson = episodeList.getJSONObject(i);
|
|
|
|
|
+ KuaiShouDramaEpisodeInfo episodeInfo = new KuaiShouDramaEpisodeInfo();
|
|
|
|
|
+ episodeInfo.setAdminAdvertiserId(advertiserId);
|
|
|
|
|
+ episodeInfo.setSeriesId(seriesId);
|
|
|
|
|
+ episodeInfo.setSeriesName(seriesName);
|
|
|
|
|
+ episodeInfo.setEpisodeId(episodeJson.getLong("episode_id"));
|
|
|
|
|
+ episodeInfo.setEpisodeName(episodeJson.getString("episode_name"));
|
|
|
|
|
+ episodeInfo.setOrderNo(episodeJson.getInteger("order_no"));
|
|
|
|
|
+ episodeInfo.setFreeEpisode(episodeJson.getBoolean("free_episode"));
|
|
|
|
|
+ episodeInfos.add(episodeInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ KuaiShouDramaSeriesInfo kuaiShouDramaSeriesInfo = new KuaiShouDramaSeriesInfo(advertiserId, seriesId, seriesName, null, null, episodeNum);
|
|
|
|
|
+ seriesInfos.add(kuaiShouDramaSeriesInfo);
|
|
|
}
|
|
}
|
|
|
- KuaiShouDramaSeriesInfo kuaiShouDramaSeriesInfo = new KuaiShouDramaSeriesInfo(advertiserId, seriesId, seriesName, null, null, episodeNum);
|
|
|
|
|
- seriesInfos.add(kuaiShouDramaSeriesInfo);
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(seriesInfos)) {
|
|
|
|
|
- kuaiShouDramaMapper.insertSeriesInfo(seriesInfos);
|
|
|
|
|
|
|
+ if (!Check.isNull(seriesInfos)) {
|
|
|
|
|
+ kuaiShouDramaMapper.insertSeriesInfo(seriesInfos);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(episodeInfos)) {
|
|
|
|
|
+ kuaiShouDramaMapper.insertEpisodeInfo(episodeInfos);
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("批量获取快手短剧剧集信息查询接口成功:{},accountId:{},seriesIds:{}", message, advertiserId, param.get("mini_series_ids"));
|
|
|
}
|
|
}
|
|
|
if (size > 20) {
|
|
if (size > 20) {
|
|
|
List<Long> longs = new ArrayList<>(seriesIds.subList(20, size));
|
|
List<Long> longs = new ArrayList<>(seriesIds.subList(20, size));
|
|
|
updateSeriesEpisodeNum(advertiserId, accessToken, longs);
|
|
updateSeriesEpisodeNum(advertiserId, accessToken, longs);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.error("updateSeriesEpisodeNum error, advertiserId:{}", advertiserId, e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -525,4 +545,91 @@ public class KuaiShouDramaServiceImpl implements IKuaiShouDramaService {
|
|
|
}
|
|
}
|
|
|
return seriesName;
|
|
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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|