|
|
@@ -1,7 +1,7 @@
|
|
|
package cn.com.ctop.job.adq.data.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.job.adq.data.entity.AdqAccountReportHour;
|
|
|
-import cn.com.ctop.job.adq.data.entity.AdqCreativeReportHour;
|
|
|
+import cn.com.ctop.job.adq.data.entity.AdqAdvertiserReportDaily;
|
|
|
+import cn.com.ctop.job.adq.data.entity.AdqAdvertiserReportHour;
|
|
|
import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
|
|
|
import cn.com.ctop.job.adq.data.mapper.AdqAccountReportMapper;
|
|
|
import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
|
|
|
@@ -27,6 +27,8 @@ import java.util.Map;
|
|
|
public class AdqAccountReportServiceImpl implements IAdqAccountReportService {
|
|
|
@Autowired
|
|
|
private AdqErrorLogMapper adqErrorLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private AdqAccountReportMapper accountReportMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -46,15 +48,15 @@ public class AdqAccountReportServiceImpl implements IAdqAccountReportService {
|
|
|
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.getFieldsList();
|
|
|
+ JSONArray fieldsList = FieldsConfig.getAccountHourFieldsList();
|
|
|
paramsMap.put("fields", fieldsList);
|
|
|
Integer totalNumber = 0;
|
|
|
- List<AdqAccountReportHour> hourList = new ArrayList<>();
|
|
|
+ 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);
|
|
|
- System.err.println(jsonObject);
|
|
|
if (!Check.isNull(jsonObject)) {
|
|
|
Integer code = jsonObject.getInteger("code");
|
|
|
if (code == 0) {
|
|
|
@@ -68,7 +70,7 @@ public class AdqAccountReportServiceImpl implements IAdqAccountReportService {
|
|
|
if (!Check.isNull(list)) {
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
JSONObject dataJson = list.getJSONObject(i);
|
|
|
- AdqAccountReportHour hourReport = JSONObject.parseObject(dataJson.toJSONString(), AdqAccountReportHour.class);
|
|
|
+ AdqAdvertiserReportHour hourReport = JSONObject.parseObject(dataJson.toJSONString(), AdqAdvertiserReportHour.class);
|
|
|
hourReport.setAdvertiserId(advertiserId);
|
|
|
hourReport.setStatTimeDay(Long.valueOf(startDate.replace("-", "")));
|
|
|
hourList.add(hourReport);
|
|
|
@@ -76,26 +78,98 @@ public class AdqAccountReportServiceImpl implements IAdqAccountReportService {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- log.error("请求创意时报失败,account_id:{},返回信息:{}", advertiserId, jsonObject);
|
|
|
+ log.error("请求账户时报失败,account_id:{},返回信息:{}", advertiserId, jsonObject);
|
|
|
if (isLog == 1) {
|
|
|
AdqErrorLog errorInfo = new AdqErrorLog();
|
|
|
errorInfo.setAdvertiserId(advertiserId);
|
|
|
errorInfo.setStartDate(startDate);
|
|
|
errorInfo.setEndDate(endDate);
|
|
|
- errorInfo.setDataDimension("creative");
|
|
|
+ errorInfo.setDataDimension("account");
|
|
|
errorInfo.setDataType("hour");
|
|
|
- // adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
+ adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (!Check.isNull(hourList)) {
|
|
|
- // accountReportMapper.addsHourList(hourList);
|
|
|
+ accountReportMapper.addAccountHourList(hourList);
|
|
|
+ }
|
|
|
+ if (totalNumber >= 1000) {
|
|
|
+ getAdqAccountHour(advertiserId, accessToken, startDate, endDate, page + 1, isLog);
|
|
|
+ } else {
|
|
|
+ log.error("请求账户时报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAdqAccountDaily(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {
|
|
|
+ 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);
|
|
|
+ Integer totalNumber = 0;
|
|
|
+ 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)) {
|
|
|
+ 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++) {
|
|
|
+ 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);
|
|
|
+ if (isLog == 1) {
|
|
|
+ AdqErrorLog errorInfo = new AdqErrorLog();
|
|
|
+ errorInfo.setAdvertiserId(advertiserId);
|
|
|
+ errorInfo.setStartDate(startDate);
|
|
|
+ errorInfo.setEndDate(endDate);
|
|
|
+ errorInfo.setDataDimension("account");
|
|
|
+ errorInfo.setDataType("daily");
|
|
|
+ adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(dailyList)) {
|
|
|
+ accountReportMapper.addAccountDailyList(dailyList);
|
|
|
}
|
|
|
if (totalNumber >= 1000) {
|
|
|
getAdqAccountHour(advertiserId, accessToken, startDate, endDate, page + 1, isLog);
|
|
|
} else {
|
|
|
- log.error("请求创意时报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
+ log.error("请求账户日报完成,account_id:{},日期:{}", advertiserId, startDate);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|