|
|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedancePromoterReportDaily;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedancePromoterReportHour;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
|
@@ -23,13 +24,14 @@ import java.util.Map;
|
|
|
public class BytedancePromoterReportServiceImpl implements IBytedancePromoterReportService {
|
|
|
@Autowired
|
|
|
private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<JSONObject> getAccountList() {
|
|
|
return promoterReportMapper.getAccountList();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void getBytedancePromoterHourReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page) {
|
|
|
+ public void getBytedanceRetryPromoterHourReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page) {
|
|
|
try {
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/report/custom/get/";
|
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
|
@@ -95,7 +97,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
} catch (InterruptedException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- getBytedancePromoterHourReport(errorId,advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
+ getBytedanceRetryPromoterHourReport(errorId, advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
} else {
|
|
|
log.info("账户ID:{},日期:{},广告时报(最细粒度)数据请求成功", advertiserId, startDate);
|
|
|
promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
@@ -107,7 +109,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void getBytedancePromorteDailyReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page) {
|
|
|
+ public void getBytedancePromoterRetryDailyReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page) {
|
|
|
try {
|
|
|
String url = "https://api.oceanengine.com/open_api/v3.0/report/custom/get/";
|
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
|
@@ -172,7 +174,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
} catch (InterruptedException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- getBytedancePromorteDailyReport(errorId,advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
+ getBytedancePromoterRetryDailyReport(errorId, advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
} else {
|
|
|
log.info("账户ID:{},日期:{},广告日报(最细粒度)数据请求成功", advertiserId, startDate);
|
|
|
promoterReportMapper.deleteInfoByErrorId(errorId);
|
|
|
@@ -188,4 +190,199 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
public List<JSONObject> getChannelInfoList() {
|
|
|
return promoterReportMapper.getChannelInfoList();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getBytedancePromoterHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {
|
|
|
+ try {
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/report/custom/get/";
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("advertiser_id", advertiserId);
|
|
|
+ paramsMap.put("start_time", startDate);
|
|
|
+ paramsMap.put("end_time", endDate);
|
|
|
+ paramsMap.put("data_topic", "BASIC_DATA");
|
|
|
+ paramsMap.put("metrics", FieldsConfig.getpromoterMetrics());
|
|
|
+ paramsMap.put("dimensions", FieldsConfig.getpromoterHoutDimensions());
|
|
|
+ paramsMap.put("order_by", new JSONArray());
|
|
|
+ paramsMap.put("filters", new JSONArray());
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", 100);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(s);
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ log.info("账户id:{},日期:{},广告时报(最细粒度)请求结果返回为空", advertiserId, startDate);
|
|
|
+ if (isLog == 1) {
|
|
|
+ BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
+ errorInfo.setDataDimension("promoter");
|
|
|
+ errorInfo.setDataType("hour");
|
|
|
+ promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedancePromoterReportHour> hours = new ArrayList<>();
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray rows = data.getJSONArray("rows");
|
|
|
+ if (!Check.isNull(rows)) {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject rowJson = rows.getJSONObject(i);
|
|
|
+ JSONObject metricsJson = rowJson.getJSONObject("metrics");
|
|
|
+ JSONObject dimensionsJson = rowJson.getJSONObject("dimensions");
|
|
|
+ Long cdpProjectId = dimensionsJson.getLong("cdp_project_id");
|
|
|
+ String cdpProjectName = dimensionsJson.getString("cdp_project_name");
|
|
|
+ Long cdpPromotionId = dimensionsJson.getLong("cdp_promotion_id");
|
|
|
+ String cdpPromotionName = dimensionsJson.getString("cdp_promotion_name");
|
|
|
+ Integer statTimeDay = Integer.valueOf(dimensionsJson.getString("stat_time_day").replace("-", ""));
|
|
|
+ Integer hour = Integer.valueOf(dimensionsJson.getString("stat_time_hour").substring(11, 13));
|
|
|
+ BytedancePromoterReportHour bytedancePromoterReportHour = JSONObject.parseObject(metricsJson.toJSONString(), BytedancePromoterReportHour.class);
|
|
|
+ bytedancePromoterReportHour.setAdvertiserId(advertiserId);
|
|
|
+ bytedancePromoterReportHour.setCdpProjectId(cdpProjectId);
|
|
|
+ bytedancePromoterReportHour.setCdpProjectName(cdpProjectName);
|
|
|
+ bytedancePromoterReportHour.setCdpPromotionId(cdpPromotionId);
|
|
|
+ bytedancePromoterReportHour.setCdpPromotionName(cdpPromotionName);
|
|
|
+ bytedancePromoterReportHour.setStatTimeDay(statTimeDay);
|
|
|
+ bytedancePromoterReportHour.setHour(hour);
|
|
|
+ hours.add(bytedancePromoterReportHour);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("账户id:{},日期:{}广告时报(最细粒度)请求结果失败,返回数据:{}", advertiserId, startDate, result);
|
|
|
+ if (isLog == 1) {
|
|
|
+ BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
+ errorInfo.setDataDimension("promoter");
|
|
|
+ errorInfo.setDataType("hour");
|
|
|
+ promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!Check.isNull(hours)) {
|
|
|
+ promoterReportMapper.replacePromoterReportHour(hours);
|
|
|
+ }
|
|
|
+ if (hours.size() >= 100) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500L);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ getBytedancePromoterHour(advertiserId, accessToken, startDate, endDate, page + 1, 1);
|
|
|
+ } else {
|
|
|
+ log.info("账户ID:{},日期:{},广告时报(最细粒度)数据请求成功", advertiserId, startDate);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getBytedancePromoterDaily(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {
|
|
|
+ try {
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/report/custom/get/";
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("advertiser_id", advertiserId);
|
|
|
+ paramsMap.put("start_time", startDate);
|
|
|
+ paramsMap.put("end_time", endDate);
|
|
|
+ paramsMap.put("data_topic", "BASIC_DATA");
|
|
|
+ paramsMap.put("metrics", FieldsConfig.getpromoterMetrics());
|
|
|
+ paramsMap.put("dimensions", FieldsConfig.getpromoterDailyDimensions());
|
|
|
+ paramsMap.put("order_by", new JSONArray());
|
|
|
+ paramsMap.put("filters", new JSONArray());
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", 100);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ String s = HttpUtils.httpGet(url, paramsMap, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(s);
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ log.info("账户id:{},广告日报(最细粒度)请求结果返回为空", advertiserId);
|
|
|
+ if (isLog == 1) {
|
|
|
+ BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
+ errorInfo.setDataDimension("promoter");
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
+ promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedancePromoterReportDaily> promoterReportDailies = new ArrayList<>();
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray rows = data.getJSONArray("rows");
|
|
|
+ if (!Check.isNull(rows)) {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject rowJson = rows.getJSONObject(i);
|
|
|
+ JSONObject metricsJson = rowJson.getJSONObject("metrics");
|
|
|
+ JSONObject dimensionsJson = rowJson.getJSONObject("dimensions");
|
|
|
+ Long cdpProjectId = dimensionsJson.getLong("cdp_project_id");
|
|
|
+ String cdpProjectName = dimensionsJson.getString("cdp_project_name");
|
|
|
+ Long cdpPromotionId = dimensionsJson.getLong("cdp_promotion_id");
|
|
|
+ String cdpPromotionName = dimensionsJson.getString("cdp_promotion_name");
|
|
|
+ Integer statTimeDay = Integer.valueOf(dimensionsJson.getString("stat_time_day").replace("-", ""));
|
|
|
+ BytedancePromoterReportDaily promoterReportDaily = JSONObject.parseObject(metricsJson.toJSONString(), BytedancePromoterReportDaily.class);
|
|
|
+ promoterReportDaily.setAdvertiserId(advertiserId);
|
|
|
+ promoterReportDaily.setCdpProjectId(cdpProjectId);
|
|
|
+ promoterReportDaily.setCdpProjectName(cdpProjectName);
|
|
|
+ promoterReportDaily.setCdpPromotionId(cdpPromotionId);
|
|
|
+ promoterReportDaily.setCdpPromotionName(cdpPromotionName);
|
|
|
+ promoterReportDaily.setStatTimeDay(statTimeDay);
|
|
|
+ promoterReportDailies.add(promoterReportDaily);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("账户id:{},日期:{}广告日报(最细粒度)请求结果失败,返回数据:{}", advertiserId, startDate, result);
|
|
|
+ if (isLog == 1) {
|
|
|
+ BytedanceErrorLog errorInfo = new BytedanceErrorLog();
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
+ errorInfo.setDataDimension("promoter");
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
+ promoterReportMapper.replaceErrorInfo(errorInfo);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(promoterReportDailies)) {
|
|
|
+ promoterReportMapper.replacePromoterReportDailies(promoterReportDailies);
|
|
|
+ log.info("账户ID:{},广告日报(最细粒度)数据请求成功", advertiserId);
|
|
|
+ }
|
|
|
+ if (promoterReportDailies.size() >= 100) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500L);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ getBytedancePromoterDaily(advertiserId, accessToken, startDate, endDate, page + 1, 1);
|
|
|
+ } else {
|
|
|
+ log.info("账户ID:{},日期:{},广告日报(最细粒度)数据请求成功", advertiserId, startDate);
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getListBydate(Integer date) {
|
|
|
+ return promoterReportMapper.getListBydate(date);
|
|
|
+ }
|
|
|
}
|