|
@@ -1,32 +1,24 @@
|
|
package org.jeecg.modules.ctop.service.impl;
|
|
package org.jeecg.modules.ctop.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.utils.CsvUtils;
|
|
import cn.com.ctop.common.utils.CsvUtils;
|
|
|
|
+import cn.com.ctop.common.utils.HttpUtils;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import org.apache.http.client.ClientProtocolException;
|
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|
|
|
-import org.apache.http.entity.ContentType;
|
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
-import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
|
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
import org.apache.poi.ss.usermodel.CellStyle;
|
|
import org.apache.poi.ss.usermodel.CellStyle;
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.jeecg.common.constant.CtopAdConstant;
|
|
import org.jeecg.common.util.ResultMapUtils;
|
|
import org.jeecg.common.util.ResultMapUtils;
|
|
import org.jeecg.common.util.StatusCode;
|
|
import org.jeecg.common.util.StatusCode;
|
|
-import org.jeecg.modules.ctop.entity.CtopOauthToken;
|
|
|
|
-import org.jeecg.modules.ctop.entity.CustomerPlanStatisticInfo;
|
|
|
|
-import org.jeecg.modules.ctop.entity.PlatformCampaignStatisticInfo;
|
|
|
|
|
|
+import org.jeecg.modules.ctop.entity.*;
|
|
import org.jeecg.modules.ctop.mapper.CustomerPlanStatisticInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.CustomerPlanStatisticInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.PlatformCampaignStatisticInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.PlatformCampaignStatisticInfoMapper;
|
|
-import org.jeecg.modules.ctop.service.ICtopOauthTokenService;
|
|
|
|
-import org.jeecg.modules.ctop.service.ICustomerPlanStatisticInfoService;
|
|
|
|
-import org.jeecg.modules.ctop.service.IPlatformCampaignStatisticInfoService;
|
|
|
|
-import org.jeecg.modules.ctop.service.IReportService;
|
|
|
|
|
|
+import org.jeecg.modules.ctop.service.*;
|
|
import org.jeecg.modules.ctop.vo.StatisticCampaignVo;
|
|
import org.jeecg.modules.ctop.vo.StatisticCampaignVo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -35,7 +27,6 @@ import org.springframework.stereotype.Service;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
-import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -43,6 +34,10 @@ import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @author 宋英豪
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class ReportServiceImpl implements IReportService {
|
|
public class ReportServiceImpl implements IReportService {
|
|
@Value("${jeecg.path.csv-upload}")
|
|
@Value("${jeecg.path.csv-upload}")
|
|
@@ -59,109 +54,177 @@ public class ReportServiceImpl implements IReportService {
|
|
private PlatformCampaignStatisticInfoMapper platformCampaignStatisticInfoMapper;
|
|
private PlatformCampaignStatisticInfoMapper platformCampaignStatisticInfoMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private ICtopOauthTokenService tokenService;
|
|
private ICtopOauthTokenService tokenService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedanceAdvertiserDailyReportService advertiserDailyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedanceAdvertiserHourlyReportService advertiserHourlyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedanceCampaignDailyReportService campaignDailyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedanceCampaignHourlyReportService campaignHourlyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedancePlanDailyReportService planDailyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedancePlanHourlyReportService planHourlyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedanceCreativeDailyReportService creativeDailyReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBytedanceCreativeHourlyReportService creativeHourlyReportService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> getAdvertiserReport(JSONObject conditions) {
|
|
public Map<String, Object> getAdvertiserReport(JSONObject conditions) {
|
|
|
|
+ String time_granularity = "STAT_TIME_GRANULARITY_HOURLY";
|
|
conditions = new JSONObject();
|
|
conditions = new JSONObject();
|
|
- conditions.put("advertiser_id", 74099510334L);
|
|
|
|
|
|
+ conditions.put("advertiser_id", 111463131228L);
|
|
conditions.put("start_date", "2019-06-01");
|
|
conditions.put("start_date", "2019-06-01");
|
|
- conditions.put("end_date", "2019-07-01");
|
|
|
|
- conditions.put("page_size", 50);
|
|
|
|
|
|
+ conditions.put("end_date", "2019-06-10");
|
|
|
|
+ conditions.put("page_size", 1000);
|
|
conditions.put("page", 1);
|
|
conditions.put("page", 1);
|
|
|
|
+ conditions.put("time_granularity", time_granularity);
|
|
Long accountId = conditions.getLong("advertiser_id");
|
|
Long accountId = conditions.getLong("advertiser_id");
|
|
-// Long accountId = 74099510334L;
|
|
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
JSONObject getObject = getAdvertiserStat(token, conditions);
|
|
JSONObject getObject = getAdvertiserStat(token, conditions);
|
|
|
|
+ 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 != time_granularity && time_granularity.equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
|
+ BytedanceAdvertiserHourlyReport hourlyReport = new BytedanceAdvertiserHourlyReport(data);
|
|
|
|
+ advertiserHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
|
+ } else {
|
|
|
|
+ BytedanceAdvertiserDailyReport dailyReport = new BytedanceAdvertiserDailyReport(data);
|
|
|
|
+ advertiserDailyReportService.saveOrUpdate(dailyReport);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return getObject;
|
|
return getObject;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> getCampaignReport(JSONObject conditions) {
|
|
public Map<String, Object> getCampaignReport(JSONObject conditions) {
|
|
- Long accountId = conditions.getLong("accountId");
|
|
|
|
|
|
+ String time_granularity = CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY;
|
|
|
|
+ conditions = new JSONObject();
|
|
|
|
+ conditions.put("advertiser_id", 111463131228L);
|
|
|
|
+ conditions.put("start_date", "2019-06-01");
|
|
|
|
+ conditions.put("end_date", "2019-06-10");
|
|
|
|
+ conditions.put("page_size", 1000);
|
|
|
|
+ conditions.put("page", 1);
|
|
|
|
+ conditions.put("time_granularity", time_granularity);
|
|
|
|
+ Long accountId = conditions.getLong("advertiser_id");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
JSONObject getObject = getAdStat(token, conditions);
|
|
JSONObject getObject = getAdStat(token, conditions);
|
|
- return new HashMap<>();
|
|
|
|
|
|
+ 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 != time_granularity && time_granularity.equals("STAT_TIME_GRANULARITY_HOURLY")) {
|
|
|
|
+ BytedanceCampaignHourlyReport hourlyReport = new BytedanceCampaignHourlyReport(data);
|
|
|
|
+ campaignHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
|
+ } else {
|
|
|
|
+ BytedanceCampaignDailyReport dailyReport = new BytedanceCampaignDailyReport(data);
|
|
|
|
+ campaignDailyReportService.saveOrUpdate(dailyReport);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return getObject;
|
|
}
|
|
}
|
|
|
|
|
|
private JSONObject getAdStat(CtopOauthToken token, JSONObject conditions) {
|
|
private JSONObject getAdStat(CtopOauthToken token, JSONObject conditions) {
|
|
- final Long advertiserId = token.getAccountId();
|
|
|
|
|
|
+ Long advertiserId = token.getAccountId();
|
|
// 请求地址
|
|
// 请求地址
|
|
String url = "https://ad.toutiao.com/open_api/2/report/ad/get/";
|
|
String url = "https://ad.toutiao.com/open_api/2/report/ad/get/";
|
|
- final Map filtering = new HashMap() {
|
|
|
|
- {
|
|
|
|
- put("campaign_id", 1L);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+ Map<String, Object> filtering = new HashMap<>();
|
|
|
|
+ filtering.put("campaign_id", 1L);
|
|
// 请求参数
|
|
// 请求参数
|
|
- final Map data = new HashMap() {
|
|
|
|
- {
|
|
|
|
- put("advertiser_id", advertiserId);
|
|
|
|
- put("start_date", "2018-04-01");
|
|
|
|
- put("end_date", "2018-05-01");
|
|
|
|
- put("time_granularity", "STAT_TIME_GRANULARITY_DAILY");
|
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_FIELD_ID"});
|
|
|
|
- put("filtering", filtering);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // 构造请求
|
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
- @Override
|
|
|
|
- public String getMethod() {
|
|
|
|
- return "GET";
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- httpEntity.setHeader("Access-Token", token.getAccessToken());
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- CloseableHttpClient client = null;
|
|
|
|
- try {
|
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
|
- httpEntity.setURI(URI.create(url));
|
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
-
|
|
|
|
- response = client.execute(httpEntity);
|
|
|
|
- if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
|
- String line = "";
|
|
|
|
- while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
- result.append(line);
|
|
|
|
- }
|
|
|
|
- bufferedReader.close();
|
|
|
|
- return JSONObject.parseObject(result.toString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
|
+ params.put("start_date", "2018-04-01");
|
|
|
|
+ params.put("end_date", "2018-05-01");
|
|
|
|
+ params.put("time_granularity", "STAT_TIME_GRANULARITY_DAILY");
|
|
|
|
+ params.put("group_by", new String[]{"STAT_GROUP_BY_FIELD_ID"});
|
|
|
|
+ params.put("filtering", filtering);
|
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> getAdReport(JSONObject conditions) {
|
|
public Map<String, Object> getAdReport(JSONObject conditions) {
|
|
- Long accountId = conditions.getLong("accountId");
|
|
|
|
|
|
+ String time_granularity = CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY;
|
|
|
|
+ conditions = new JSONObject();
|
|
|
|
+ conditions.put("advertiser_id", 111463131228L);
|
|
|
|
+ conditions.put("start_date", "2019-06-01");
|
|
|
|
+ conditions.put("end_date", "2019-06-10");
|
|
|
|
+ conditions.put("page_size", 1000);
|
|
|
|
+ conditions.put("page", 1);
|
|
|
|
+ conditions.put("time_granularity", time_granularity);
|
|
|
|
+ Long accountId = conditions.getLong("advertiser_id");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
JSONObject getObject = getAdStat(token, conditions);
|
|
JSONObject getObject = getAdStat(token, conditions);
|
|
|
|
+ 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 != time_granularity && time_granularity.equals("STAT_TIME_GRANULARITY_HOURLY")) {
|
|
|
|
+ BytedancePlanHourlyReport hourlyReport = new BytedancePlanHourlyReport(data);
|
|
|
|
+ planHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
|
+ } else {
|
|
|
|
+ BytedancePlanDailyReport dailyReport = new BytedancePlanDailyReport(data);
|
|
|
|
+ planDailyReportService.saveOrUpdate(dailyReport);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return getObject;
|
|
return getObject;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> getCreativeReport(JSONObject conditions) {
|
|
public Map<String, Object> getCreativeReport(JSONObject conditions) {
|
|
- Long accountId = conditions.getLong("accountId");
|
|
|
|
|
|
+ String time_granularity = CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY;
|
|
|
|
+ conditions = new JSONObject();
|
|
|
|
+ conditions.put("advertiser_id", 111463131228L);
|
|
|
|
+ conditions.put("start_date", "2019-06-01");
|
|
|
|
+ conditions.put("end_date", "2019-06-10");
|
|
|
|
+ conditions.put("page_size", 1000);
|
|
|
|
+ conditions.put("page", 1);
|
|
|
|
+ conditions.put("time_granularity", time_granularity);
|
|
|
|
+ Long accountId = conditions.getLong("advertiser_id");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
JSONObject getObject = getCreativeStat(token, conditions);
|
|
JSONObject getObject = getCreativeStat(token, conditions);
|
|
|
|
+ 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 != time_granularity && time_granularity.equals("STAT_TIME_GRANULARITY_HOURLY")) {
|
|
|
|
+ BytedanceCreativeHourlyReport hourlyReport = new BytedanceCreativeHourlyReport(data);
|
|
|
|
+ creativeHourlyReportService.saveOrUpdate(hourlyReport);
|
|
|
|
+ } else {
|
|
|
|
+ BytedanceCreativeDailyReport dailyReport = new BytedanceCreativeDailyReport(data);
|
|
|
|
+ creativeDailyReportService.saveOrUpdate(dailyReport);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return getObject;
|
|
return getObject;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -608,7 +671,7 @@ public class ReportServiceImpl implements IReportService {
|
|
// 请求地址
|
|
// 请求地址
|
|
String url = "https://ad.toutiao.com/open_api/2/report/agent/get/";
|
|
String url = "https://ad.toutiao.com/open_api/2/report/agent/get/";
|
|
// 请求参数
|
|
// 请求参数
|
|
- Map data = new HashMap() {
|
|
|
|
|
|
+ Map params = new HashMap() {
|
|
{
|
|
{
|
|
put("advertiser_id", token.getAccountId());
|
|
put("advertiser_id", token.getAccountId());
|
|
put("start_date", "2018-04-01");
|
|
put("start_date", "2018-04-01");
|
|
@@ -616,46 +679,8 @@ public class ReportServiceImpl implements IReportService {
|
|
put("time_granularity", "STAT_TIME_GRANULARITY_DAILY");
|
|
put("time_granularity", "STAT_TIME_GRANULARITY_DAILY");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- // 构造请求
|
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
- @Override
|
|
|
|
- public String getMethod() {
|
|
|
|
- return "GET";
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- httpEntity.setHeader("Access-Token", token.getAccessToken());
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- CloseableHttpClient client = null;
|
|
|
|
- try {
|
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
|
- httpEntity.setURI(URI.create(url));
|
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
- response = client.execute(httpEntity);
|
|
|
|
- if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
|
- String line = "";
|
|
|
|
- while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
- result.append(line);
|
|
|
|
- }
|
|
|
|
- bufferedReader.close();
|
|
|
|
- return JSONObject.parseObject(result.toString());
|
|
|
|
- }
|
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ JSONObject data = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
|
|
+ return data;
|
|
}
|
|
}
|
|
|
|
|
|
public JSONObject getCreativeStat(CtopOauthToken token, JSONObject conditions) {
|
|
public JSONObject getCreativeStat(CtopOauthToken token, JSONObject conditions) {
|
|
@@ -667,7 +692,7 @@ public class ReportServiceImpl implements IReportService {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
// 请求参数
|
|
// 请求参数
|
|
- final Map data = new HashMap() {
|
|
|
|
|
|
+ final Map params = new HashMap() {
|
|
{
|
|
{
|
|
put("advertiser_id", token.getAccountId());
|
|
put("advertiser_id", token.getAccountId());
|
|
put("start_date", "2018-04-01");
|
|
put("start_date", "2018-04-01");
|
|
@@ -677,47 +702,8 @@ public class ReportServiceImpl implements IReportService {
|
|
put("filtering", filtering);
|
|
put("filtering", filtering);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-
|
|
|
|
- // 构造请求
|
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
- @Override
|
|
|
|
- public String getMethod() {
|
|
|
|
- return "GET";
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- httpEntity.setHeader("Access-Token", token.getAccessToken());
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- CloseableHttpClient client = null;
|
|
|
|
- try {
|
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
|
- httpEntity.setURI(URI.create(url));
|
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
- response = client.execute(httpEntity);
|
|
|
|
- if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
|
- String line = "";
|
|
|
|
- while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
- result.append(line);
|
|
|
|
- }
|
|
|
|
- bufferedReader.close();
|
|
|
|
- return JSONObject.parseObject(result.toString());
|
|
|
|
- }
|
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ JSONObject data = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
|
|
+ return data;
|
|
}
|
|
}
|
|
|
|
|
|
public static JSONObject getCampaignStat(CtopOauthToken token, JSONObject conditions) {
|
|
public static JSONObject getCampaignStat(CtopOauthToken token, JSONObject conditions) {
|
|
@@ -729,7 +715,7 @@ public class ReportServiceImpl implements IReportService {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
// 请求参数
|
|
// 请求参数
|
|
- final Map data = new HashMap() {
|
|
|
|
|
|
+ final Map params = new HashMap() {
|
|
{
|
|
{
|
|
put("page", 1000);
|
|
put("page", 1000);
|
|
put("pageSize", conditions.getInteger("page_size"));
|
|
put("pageSize", conditions.getInteger("page_size"));
|
|
@@ -741,46 +727,8 @@ public class ReportServiceImpl implements IReportService {
|
|
put("filtering", filtering);
|
|
put("filtering", filtering);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- // 构造请求
|
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
- @Override
|
|
|
|
- public String getMethod() {
|
|
|
|
- return "GET";
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- httpEntity.setHeader("Access-Token", token.getAccessToken());
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- CloseableHttpClient client = null;
|
|
|
|
- try {
|
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
|
- httpEntity.setURI(URI.create(url));
|
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
- response = client.execute(httpEntity);
|
|
|
|
- if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
|
- String line = "";
|
|
|
|
- while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
- result.append(line);
|
|
|
|
- }
|
|
|
|
- bufferedReader.close();
|
|
|
|
- return JSONObject.parseObject(result.toString());
|
|
|
|
- }
|
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ JSONObject data = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
|
|
+ return data;
|
|
}
|
|
}
|
|
|
|
|
|
public JSONObject getAdvertiserStat(CtopOauthToken token, JSONObject conditions) {
|
|
public JSONObject getAdvertiserStat(CtopOauthToken token, JSONObject conditions) {
|
|
@@ -788,53 +736,17 @@ public class ReportServiceImpl implements IReportService {
|
|
// 请求地址
|
|
// 请求地址
|
|
String url = "https://ad.toutiao.com/open_api/2/report/advertiser/get/";
|
|
String url = "https://ad.toutiao.com/open_api/2/report/advertiser/get/";
|
|
// 请求参数
|
|
// 请求参数
|
|
- Map data = new HashMap() {
|
|
|
|
|
|
+ Map params = new HashMap() {
|
|
{
|
|
{
|
|
put("advertiser_id", advertiserId);
|
|
put("advertiser_id", advertiserId);
|
|
put("start_date", conditions.getString("start_date"));
|
|
put("start_date", conditions.getString("start_date"));
|
|
put("end_date", conditions.getString("end_date"));
|
|
put("end_date", conditions.getString("end_date"));
|
|
-// put("time_granularity", conditions.getString("timeGranularity"));
|
|
|
|
|
|
+ put("time_granularity", conditions.getString("time_granularity"));
|
|
put("page", conditions.getString("page"));
|
|
put("page", conditions.getString("page"));
|
|
put("page_size", conditions.getString("page_size"));
|
|
put("page_size", conditions.getString("page_size"));
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- // 构造请求
|
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
- @Override
|
|
|
|
- public String getMethod() {
|
|
|
|
- return "GET";
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- httpEntity.setHeader("Access-Token", token.getAccessToken());
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- CloseableHttpClient client = null;
|
|
|
|
- try {
|
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
|
- httpEntity.setURI(URI.create(url));
|
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
- response = client.execute(httpEntity);
|
|
|
|
- if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
- StringBuffer result = new StringBuffer();
|
|
|
|
- String line = "";
|
|
|
|
- while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
- result.append(line);
|
|
|
|
- }
|
|
|
|
- bufferedReader.close();
|
|
|
|
- return JSONObject.parseObject(result.toString());
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- if (response != null) {
|
|
|
|
- response.close();
|
|
|
|
- }
|
|
|
|
- client.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ JSONObject data = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
|
|
+ return data;
|
|
}
|
|
}
|
|
}
|
|
}
|