|
|
@@ -1,11 +1,10 @@
|
|
|
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.AlertUtils;
|
|
|
import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
import cn.com.ctop.job.adq.data.utils.FieldsConfig;
|
|
|
import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
@@ -32,8 +31,7 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
private static String sendUrl = "http://172.16.0.108:8765/webhook/media_report";
|
|
|
private static ExecutorService sendExecutorService = Executors.newFixedThreadPool(5);
|
|
|
@Autowired
|
|
|
- private AdqErrorLogMapper adqErrorLogMapper;
|
|
|
-
|
|
|
+ private AdqAccountReportMapper accountReportMapper;
|
|
|
|
|
|
@Override
|
|
|
public void getCreativeHourRetry(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isSend) {
|
|
|
@@ -57,7 +55,6 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
paramsMap.put("group_by", group_by);
|
|
|
JSONArray fieldsList = FieldsConfig.getCreativeHourFieldsList();
|
|
|
paramsMap.put("fields", fieldsList);
|
|
|
- Integer totalNumber = 0;
|
|
|
List<AdqCreativeReportHour> hourList = new ArrayList<>();
|
|
|
String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/hourly_reports/get", paramsMap, null);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
@@ -66,10 +63,7 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
if (code == 0) {
|
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
|
if (!Check.isNull(data)) {
|
|
|
- JSONObject pageInfo = data.getJSONObject("page_info");
|
|
|
- if (!Check.isNull(pageInfo)) {
|
|
|
- totalNumber = pageInfo.getInteger("total_number");
|
|
|
- }
|
|
|
+
|
|
|
JSONArray list = data.getJSONArray("list");
|
|
|
if (!Check.isNull(list)) {
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
@@ -89,13 +83,13 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
if (!Check.isNull(hourList)) {
|
|
|
adqReportMapper.addsHourList(hourList);
|
|
|
}
|
|
|
- if (totalNumber >= 1000) {
|
|
|
+ if (hourList.size() >= 1000) {
|
|
|
getCreativeHourRetry(errorId, advertiserId, accessToken, startDate, endDate, page + 1, isSend);
|
|
|
} else {
|
|
|
log.error("请求创意时报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errorId);
|
|
|
+ adqReportMapper.deleteInfoByErrorId(errorId);
|
|
|
if (isSend == 1) {
|
|
|
- AlertUtils.sendMessage(advertiserId, startDate, endDate, 3, "hour", 1);
|
|
|
+ sendMessage(advertiserId, startDate, endDate, 3, "hour", 1, "creative");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -124,7 +118,6 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
paramsMap.put("group_by", group_by);
|
|
|
JSONArray fieldsList = FieldsConfig.getCreativeDailyFieldsList();
|
|
|
paramsMap.put("fields", fieldsList);
|
|
|
- Integer totalNumber = 0;
|
|
|
List<AdqCreativeReportDaily> dailies = new ArrayList<>();
|
|
|
String s = HttpUtils.httpGet("https://api.e.qq.com/v3.0/daily_reports/get", paramsMap, null);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
@@ -133,10 +126,6 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
if (code == 0) {
|
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
|
if (!Check.isNull(data)) {
|
|
|
- JSONObject pageInfo = data.getJSONObject("page_info");
|
|
|
- if (!Check.isNull(pageInfo)) {
|
|
|
- totalNumber = pageInfo.getInteger("total_number");
|
|
|
- }
|
|
|
JSONArray list = data.getJSONArray("list");
|
|
|
if (!Check.isNull(list)) {
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
@@ -156,13 +145,138 @@ public class AdqRetryReportServiceImpl implements IAdqRetryReportService {
|
|
|
if (!Check.isNull(dailies)) {
|
|
|
adqReportMapper.addsDaily(dailies);
|
|
|
}
|
|
|
- if (totalNumber >= 1000) {
|
|
|
+ if (dailies.size() >= 1000) {
|
|
|
getCreativeDailyRetry(errorId, advertiserId, accessToken, startDate, endDate, page + 1, isSend);
|
|
|
} else {
|
|
|
log.error("请求创意日报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errorId);
|
|
|
+ adqReportMapper.deleteInfoByErrorId(errorId);
|
|
|
+ if (isSend == 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) {
|
|
|
- AlertUtils.sendMessage(advertiserId, startDate, endDate, 3, "daily", 1);
|
|
|
+ sendMessage(advertiserId, startDate, endDate, 3, "daily", 1, "account");
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -171,4 +285,33 @@ 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, String dimension) {
|
|
|
+ if (count > 5) {
|
|
|
+ log.error("超过最大次数,account_id:{}", count);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sendExecutorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("account_id", account_id);
|
|
|
+ param.put("start_date", start_date);
|
|
|
+ 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)) {
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 200) {
|
|
|
+ log.info("请求数据清洗服务成功,account_id:{}", account_id);
|
|
|
+ } else {
|
|
|
+ sendMessage(account_id, start_date, end_date, media_type, type, count + 1, dimension);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|