|
|
@@ -1,8 +1,9 @@
|
|
|
package cn.com.ctop.job.adq.data.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.job.adq.data.entity.AdqCreativeReportDaily;
|
|
|
-import cn.com.ctop.job.adq.data.entity.AdqCreativeReportHour;
|
|
|
+import cn.com.ctop.job.adq.data.entity.*;
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdqAccountReportMapper;
|
|
|
import cn.com.ctop.job.adq.data.mapper.AdqCreativeReportMapper;
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
|
|
|
import cn.com.ctop.job.adq.data.service.IAdqRetryReportService;
|
|
|
import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
import cn.com.ctop.job.adq.data.utils.FieldsConfig;
|
|
|
@@ -29,7 +30,8 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
private AdqCreativeReportMapper adqReportMapper;
|
|
|
private static String sendUrl = "http://172.16.0.108:8765/webhook/media_report";
|
|
|
private static ExecutorService sendExecutorService = Executors.newFixedThreadPool(5);
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private AdqAccountReportMapper accountReportMapper;
|
|
|
|
|
|
@Override
|
|
|
public void getCreativeHourRetry(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isSend) {
|
|
|
@@ -87,7 +89,7 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
log.error("请求创意时报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
adqReportMapper.deleteInfoByErrorId(errorId);
|
|
|
if (isSend == 1) {
|
|
|
- sendMessage(advertiserId, startDate, endDate, 3, "hour", 1);
|
|
|
+ sendMessage(advertiserId, startDate, endDate, 3, "hour", 1, "creative");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -149,7 +151,132 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
log.error("请求创意日报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
adqReportMapper.deleteInfoByErrorId(errorId);
|
|
|
if (isSend == 1) {
|
|
|
- sendMessage(advertiserId, startDate, endDate, 3, "daily", 1);
|
|
|
+ sendMessage(advertiserId, startDate, endDate, 3, "daily", 1, "creative");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAccountHourRetry(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isSend) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("access_token", accessToken);
|
|
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
|
+ paramsMap.put("timestamp", String.valueOf(timestamp));
|
|
|
+ paramsMap.put("nonce", RandomStringGenerator.generateRandomString(32));
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", 1000);
|
|
|
+ paramsMap.put("account_id", advertiserId);
|
|
|
+ paramsMap.put("level", "REPORT_LEVEL_ADVERTISER");
|
|
|
+ JSONObject date_range = new JSONObject();
|
|
|
+ date_range.put("start_date", startDate);
|
|
|
+ date_range.put("end_date", endDate);
|
|
|
+ paramsMap.put("date_range", date_range);
|
|
|
+ JSONArray group_by = new JSONArray();
|
|
|
+ group_by.add("date");
|
|
|
+ group_by.add("hour");
|
|
|
+ paramsMap.put("group_by", group_by);
|
|
|
+ JSONArray fieldsList = FieldsConfig.getAccountHourFieldsList();
|
|
|
+ paramsMap.put("fields", fieldsList);
|
|
|
+ List<AdqAdvertiserReportHour> hourList = new ArrayList<>();
|
|
|
+ String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/hourly_reports/get", paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject dataJson = list.getJSONObject(i);
|
|
|
+ AdqAdvertiserReportHour hourReport = JSONObject.parseObject(dataJson.toJSONString(), AdqAdvertiserReportHour.class);
|
|
|
+ hourReport.setAdvertiserId(advertiserId);
|
|
|
+ hourReport.setStatTimeDay(Long.valueOf(startDate.replace("-", "")));
|
|
|
+ hourList.add(hourReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("请求账户时报失败,account_id:{},返回信息:{}", advertiserId, jsonObject);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(hourList)) {
|
|
|
+ accountReportMapper.addAccountHourList(hourList);
|
|
|
+ }
|
|
|
+ if (hourList.size() >= 1000) {
|
|
|
+ getAccountHourRetry(errorId, advertiserId, accessToken, startDate, endDate, page + 1, isSend);
|
|
|
+ } else {
|
|
|
+ log.info("请求账户时报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
+ adqReportMapper.deleteInfoByErrorId(errorId);
|
|
|
+ if (isSend == 1) {
|
|
|
+ sendMessage(advertiserId, startDate, endDate, 3, "daily", 1, "account");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAccountDailyRetry(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isSend) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("access_token", accessToken);
|
|
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
|
+ paramsMap.put("timestamp", String.valueOf(timestamp));
|
|
|
+ paramsMap.put("nonce", RandomStringGenerator.generateRandomString(32));
|
|
|
+ paramsMap.put("page", page);
|
|
|
+ paramsMap.put("page_size", 1000);
|
|
|
+ paramsMap.put("account_id", advertiserId);
|
|
|
+ paramsMap.put("level", "REPORT_LEVEL_ADVERTISER");
|
|
|
+ JSONObject date_range = new JSONObject();
|
|
|
+ date_range.put("start_date", startDate);
|
|
|
+ date_range.put("end_date", endDate);
|
|
|
+ paramsMap.put("date_range", date_range);
|
|
|
+ JSONArray group_by = new JSONArray();
|
|
|
+ group_by.add("date");
|
|
|
+ paramsMap.put("group_by", group_by);
|
|
|
+ JSONArray fieldsList = FieldsConfig.getAccountDailyFieldsList();
|
|
|
+ paramsMap.put("fields", fieldsList);
|
|
|
+ List<AdqAdvertiserReportDaily> dailyList = new ArrayList<>();
|
|
|
+ String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/daily_reports/get", paramsMap, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject dataJson = list.getJSONObject(i);
|
|
|
+ AdqAdvertiserReportDaily dailyReport = JSONObject.parseObject(dataJson.toJSONString(), AdqAdvertiserReportDaily.class);
|
|
|
+ dailyReport.setAdvertiserId(advertiserId);
|
|
|
+ dailyReport.setStatTimeDay(Long.valueOf(dataJson.getString("date").replace("-", "")));
|
|
|
+ dailyList.add(dailyReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("请求账户日报失败,account_id:{},返回信息:{}", advertiserId, jsonObject);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(dailyList)) {
|
|
|
+ accountReportMapper.addAccountDailyList(dailyList);
|
|
|
+ }
|
|
|
+ if (dailyList.size() >= 1000) {
|
|
|
+ getAccountDailyRetry(errorId, advertiserId, accessToken, startDate, endDate, page + 1, isSend);
|
|
|
+ } else {
|
|
|
+ log.error("请求账户日报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
+ adqReportMapper.deleteInfoByErrorId(errorId);
|
|
|
+ if (isSend == 1) {
|
|
|
+ sendMessage(advertiserId, startDate, endDate, 3, "daily", 1, "account");
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -158,7 +285,7 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static void sendMessage(Long account_id, String start_date, String end_date, Integer media_type, String type, Integer count) {
|
|
|
+ private static void sendMessage(Long account_id, String start_date, String end_date, Integer media_type, String type, Integer count, String dimension) {
|
|
|
if (count > 5) {
|
|
|
log.error("超过最大次数,account_id:{}", count);
|
|
|
return;
|
|
|
@@ -172,6 +299,7 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
param.put("end_date", end_date);
|
|
|
param.put("media_type", media_type);
|
|
|
param.put("type", type);
|
|
|
+ param.put("dimension", dimension);
|
|
|
String s = HttpUtils.httpPostRequest(sendUrl, param, new HashMap<>());
|
|
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
if (!Check.isNull(jsonObject)) {
|
|
|
@@ -179,7 +307,7 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
if (code == 200) {
|
|
|
log.info("请求数据清洗服务成功,account_id:{}", account_id);
|
|
|
} else {
|
|
|
- sendMessage(account_id, start_date, end_date, media_type, type, count + 1);
|
|
|
+ sendMessage(account_id, start_date, end_date, media_type, type, count + 1, dimension);
|
|
|
}
|
|
|
}
|
|
|
}
|