|
@@ -13,6 +13,7 @@ import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
|
|
import org.jeecg.modules.ctop.service.IReportService;
|
|
import org.jeecg.modules.ctop.service.IReportService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import retrofit2.http.Url;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -25,10 +26,17 @@ import java.util.Map;
|
|
public class ReportServiceImpl implements IReportService {
|
|
public class ReportServiceImpl implements IReportService {
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> getAdvertiserReport(JSONObject conditions) {
|
|
public Map<String, Object> getAdvertiserReport(JSONObject conditions) {
|
|
- Long accountId = conditions.getLong("accountId");
|
|
|
|
|
|
+ conditions = new JSONObject();
|
|
|
|
+ conditions.put("advertiser_id", 74099510334L);
|
|
|
|
+ conditions.put("start_date", "2019-06-01");
|
|
|
|
+ conditions.put("end_date", "2019-07-01");
|
|
|
|
+ conditions.put("page_size", 50);
|
|
|
|
+ conditions.put("page", 1);
|
|
|
|
+ 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);
|
|
- return null;
|
|
|
|
|
|
+ return getObject;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -116,13 +124,156 @@ public class ReportServiceImpl implements IReportService {
|
|
Long accountId = conditions.getLong("accountId");
|
|
Long accountId = conditions.getLong("accountId");
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
|
|
JSONObject getObject = getAdStat(token, conditions);
|
|
JSONObject getObject = getAdStat(token, conditions);
|
|
|
|
+ return getObject;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> getCreativeReport(JSONObject conditions) {
|
|
|
|
+ Long accountId = conditions.getLong("accountId");
|
|
|
|
+ CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
|
|
|
|
+ JSONObject getObject = getCreativeStat(token, conditions);
|
|
|
|
+ return getObject;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> getAgentReport(JSONObject conditions) {
|
|
|
|
+ Long accountId = conditions.getLong("accountId");
|
|
|
|
+ CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
|
|
|
|
+ JSONObject getObject = getCreativeStat(token, conditions);
|
|
|
|
+ return getObject;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject getAgentStat(CTopOauthToken token, JSONObject conditions) {
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.toutiao.com/open_api/2/report/agent/get/";
|
|
|
|
+ // 请求参数
|
|
|
|
+ Map data = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("advertiser_id", token.getAccountId());
|
|
|
|
+ put("start_date", "2018-04-01");
|
|
|
|
+ put("end_date", "2018-05-01");
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject getCreativeStat(CTopOauthToken token, JSONObject conditions) {
|
|
|
|
+
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.toutiao.com/open_api/2/report/creative/get/";
|
|
|
|
+
|
|
|
|
+ final Map filtering = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("campaign_id", 1L);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 请求参数
|
|
|
|
+ final Map data = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("advertiser_id", token.getAccountId());
|
|
|
|
+ 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;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public static JSONObject getCampaignStat(CTopOauthToken token, JSONObject conditions) {
|
|
public static JSONObject getCampaignStat(CTopOauthToken token, JSONObject conditions) {
|
|
// 请求地址
|
|
// 请求地址
|
|
- String open_api_url_prefix = "https://ad.toutiao.com/open_api/2/";
|
|
|
|
- String uri = "report/campaign/get/";
|
|
|
|
|
|
+ String url = "https://ad.toutiao.com/open_api/2/report/campaign/get/";
|
|
|
|
|
|
final Map filtering = new HashMap() {
|
|
final Map filtering = new HashMap() {
|
|
{
|
|
{
|
|
@@ -160,7 +311,7 @@ public class ReportServiceImpl implements IReportService {
|
|
|
|
|
|
try {
|
|
try {
|
|
client = HttpClientBuilder.create().build();
|
|
client = HttpClientBuilder.create().build();
|
|
- httpEntity.setURI(URI.create(open_api_url_prefix + uri));
|
|
|
|
|
|
+ httpEntity.setURI(URI.create(url));
|
|
httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
|
|
response = client.execute(httpEntity);
|
|
response = client.execute(httpEntity);
|
|
@@ -205,9 +356,11 @@ public class ReportServiceImpl implements IReportService {
|
|
Map data = new HashMap() {
|
|
Map data = new HashMap() {
|
|
{
|
|
{
|
|
put("advertiser_id", advertiserId);
|
|
put("advertiser_id", advertiserId);
|
|
- put("start_date", conditions.getString("startDate"));
|
|
|
|
- put("end_date", conditions.getString("endDate"));
|
|
|
|
- put("time_granularity", conditions.getString("timeGranularity"));
|
|
|
|
|
|
+ put("start_date", conditions.getString("start_date"));
|
|
|
|
+ put("end_date", conditions.getString("end_date"));
|
|
|
|
+// put("time_granularity", conditions.getString("timeGranularity"));
|
|
|
|
+ put("page", conditions.getString("page"));
|
|
|
|
+ put("page_size", conditions.getString("page_size"));
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|