|
@@ -146,12 +146,10 @@ public class ReportServiceImpl implements IReportService {
|
|
|
getCampaignReportByPage(token, conditions, 1);
|
|
|
}
|
|
|
|
|
|
- private void getCampaignReportByPage(CtopOauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
|
|
|
- conditions.setPage(page);
|
|
|
- SerializeConfig config = new SerializeConfig();
|
|
|
- config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
- JSONObject getObject = getCampaignStat(token, jsonObject);
|
|
|
+ @Override
|
|
|
+ public void getCampaignReportByPage(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl, Integer pageNum) {
|
|
|
+ JSONObject getObject = getCampaignStat(token, startDate, endDate, bytedanceReportTypePl, pageNum);
|
|
|
+ System.out.println("返回数据:" + getObject.toJSONString());
|
|
|
Integer code = getObject.getInteger("code");
|
|
|
String message = getObject.getString("message");
|
|
|
if (null == code || code != 0) {
|
|
@@ -165,51 +163,63 @@ public class ReportServiceImpl implements IReportService {
|
|
|
}
|
|
|
for (var i = 0; i < dataArray.size(); i++) {
|
|
|
var data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
+ if (CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(bytedanceReportTypePl)) {
|
|
|
var hourlyReport = new BytedanceCampaignHourlyReport(data, token.getAccountId());
|
|
|
campaignHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
} else {
|
|
|
+ System.out.println(data.toJSONString());
|
|
|
var dailyReport = new BytedanceCampaignDailyReport(data, token.getAccountId());
|
|
|
campaignDailyReportService.saveOrUpdate(dailyReport);
|
|
|
}
|
|
|
}
|
|
|
- getCampaignReportByPage(token, conditions, page + 1);
|
|
|
+ getCampaignReportByPage(token, startDate, endDate, bytedanceReportTypePl, pageNum + 1);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Map<String, Object> getCampaignReport(ByteDanceAdvertiserReportDTO conditions) {
|
|
|
- conditions.setAdvertiserId(111463131228L);
|
|
|
- conditions.setStartDate("2019-06-01");
|
|
|
- conditions.setEndDate("2019-06-10");
|
|
|
- conditions.setPageSize(1000);
|
|
|
- conditions.setPage(1);
|
|
|
- conditions.setTimeGranularity(CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
|
|
|
+ private JSONObject getCampaignStat(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl, Integer pageNum) {
|
|
|
+ // 请求地址
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/report/campaign/get/";
|
|
|
+ // 请求参数
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("page", pageNum);
|
|
|
+ params.put("page_size", 100);
|
|
|
+ params.put("advertiser_id", token.getAccountId());
|
|
|
+ params.put("start_date", DateUtils.formatDate(startDate));
|
|
|
+ params.put("end_date", DateUtils.formatDate(endDate));
|
|
|
+ params.put("time_granularity", bytedanceReportTypePl);
|
|
|
+ params.put("group_by", new String[]{"STAT_GROUP_BY_FIELD_ID", "STAT_GROUP_BY_FIELD_STAT_TIME"});
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getCampaignReportByPage(CtopOauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
|
|
|
+ conditions.setPage(page);
|
|
|
SerializeConfig config = new SerializeConfig();
|
|
|
config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
- Long accountId = conditions.getAdvertiserId();
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
|
- JSONObject getObject = getAdStat(token, jsonObject);
|
|
|
+ System.out.println(jsonObject.toJSONString());
|
|
|
+ JSONObject getObject = getCampaignStat(token, jsonObject);
|
|
|
+ System.out.println(getObject.toJSONString());
|
|
|
Integer code = getObject.getInteger("code");
|
|
|
String message = getObject.getString("message");
|
|
|
if (null == code || code != 0) {
|
|
|
log.error("广告组报表数据获取异常:{}", message);
|
|
|
- } else {
|
|
|
- JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (null != dataArray && dataArray.size() > 0) {
|
|
|
- for (int i = 0; i < dataArray.size(); i++) {
|
|
|
- JSONObject data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
- BytedanceCampaignHourlyReport hourlyReport = new BytedanceCampaignHourlyReport(data, token.getAccountId());
|
|
|
- campaignHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
- } else {
|
|
|
- BytedanceCampaignDailyReport dailyReport = new BytedanceCampaignDailyReport(data, token.getAccountId());
|
|
|
- campaignDailyReportService.saveOrUpdate(dailyReport);
|
|
|
- }
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (null == dataArray || dataArray.size() <= 0) {
|
|
|
+ log.info("广告组报表信息为空=》accountId:{}", token.getAccountId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (var i = 0; i < dataArray.size(); i++) {
|
|
|
+ var data = dataArray.getJSONObject(i);
|
|
|
+ if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
+ var hourlyReport = new BytedanceCampaignHourlyReport(data, token.getAccountId());
|
|
|
+ campaignHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
+ } else {
|
|
|
+ var dailyReport = new BytedanceCampaignDailyReport(data, token.getAccountId());
|
|
|
+ campaignDailyReportService.saveOrUpdate(dailyReport);
|
|
|
}
|
|
|
}
|
|
|
- return getObject;
|
|
|
+ getCampaignReportByPage(token, conditions, page + 1);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -266,42 +276,6 @@ public class ReportServiceImpl implements IReportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> getAdReport(ByteDanceAdvertiserReportDTO conditions) {
|
|
|
- conditions.setAdvertiserId(111463131228L);
|
|
|
- conditions.setStartDate("2019-06-01");
|
|
|
- conditions.setEndDate("2019-06-10");
|
|
|
- conditions.setPageSize(1000);
|
|
|
- conditions.setPage(1);
|
|
|
- conditions.setTimeGranularity(CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
|
|
|
- SerializeConfig config = new SerializeConfig();
|
|
|
- config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
- Long accountId = conditions.getAdvertiserId();
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
|
- JSONObject getObject = getAdStat(token, jsonObject);
|
|
|
- Integer code = getObject.getInteger("code");
|
|
|
- String message = getObject.getString("message");
|
|
|
- if (null == code || code != 0) {
|
|
|
- log.error("广告计划报表数据获取异常:{}", message);
|
|
|
- } else {
|
|
|
- JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (null != dataArray && dataArray.size() > 0) {
|
|
|
- for (int i = 0; i < dataArray.size(); i++) {
|
|
|
- JSONObject data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
- BytedancePlanHourlyReport hourlyReport = new BytedancePlanHourlyReport(data, token.getAccountId());
|
|
|
- planHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
- } else {
|
|
|
- BytedancePlanDailyReport dailyReport = new BytedancePlanDailyReport(data, token.getAccountId());
|
|
|
- planDailyReportService.saveOrUpdate(dailyReport);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return getObject;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public void getAdvertiserCreativeReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {
|
|
|
var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
getCreativeReportByPage(token, conditions, 1);
|
|
@@ -373,42 +347,6 @@ public class ReportServiceImpl implements IReportService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> getCreativeReport(ByteDanceAdvertiserReportDTO conditions) {
|
|
|
- conditions.setAdvertiserId(111463131228L);
|
|
|
- conditions.setStartDate("2019-06-01");
|
|
|
- conditions.setEndDate("2019-06-10");
|
|
|
- conditions.setPageSize(1000);
|
|
|
- conditions.setPage(1);
|
|
|
- conditions.setTimeGranularity(CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
|
|
|
- SerializeConfig config = new SerializeConfig();
|
|
|
- config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
- Long accountId = conditions.getAdvertiserId();
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
|
- JSONObject getObject = getCreativeStat(token, jsonObject);
|
|
|
- Integer code = getObject.getInteger("code");
|
|
|
- String message = getObject.getString("message");
|
|
|
- if (null == code || code != 0) {
|
|
|
- log.error("广告创意报表数据获取异常:{}", message);
|
|
|
- } else {
|
|
|
- JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (null != dataArray && dataArray.size() > 0) {
|
|
|
- for (int i = 0; i < dataArray.size(); i++) {
|
|
|
- JSONObject data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
- BytedanceCreativeHourlyReport hourlyReport = new BytedanceCreativeHourlyReport(data, token.getAccountId());
|
|
|
- creativeHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
- } else {
|
|
|
- BytedanceCreativeDailyReport dailyReport = new BytedanceCreativeDailyReport(data, token.getAccountId());
|
|
|
- creativeDailyReportService.saveOrUpdate(dailyReport);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return getObject;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public Map<String, Object> getAgentReport(JSONObject conditions) {
|
|
|
Long accountId = conditions.getLong("accountId");
|
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|