|
@@ -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;
|
|
@@ -24,22 +25,328 @@ import java.util.Map;
|
|
@Service
|
|
@Service
|
|
public class ReportServiceImpl implements IReportService {
|
|
public class ReportServiceImpl implements IReportService {
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> getAdvertiserReport(String accountId, String startDate, String endDate, String timeGranularity) {
|
|
|
|
- CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
|
|
- JSONObject getObject = getAdvertiserStat(token, startDate, endDate, timeGranularity);
|
|
|
|
- return null;
|
|
|
|
|
|
+ public Map<String, Object> getAdvertiserReport(JSONObject conditions) {
|
|
|
|
+ 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 + "");
|
|
|
|
+ JSONObject getObject = getAdvertiserStat(token, conditions);
|
|
|
|
+ return getObject;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> getCampaignReport(JSONObject conditions) {
|
|
public Map<String, Object> getCampaignReport(JSONObject conditions) {
|
|
|
|
+ Long accountId = conditions.getLong("accountId");
|
|
|
|
+ CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
|
|
|
|
+ JSONObject getObject = getAdStat(token, conditions);
|
|
|
|
+ return new HashMap<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONObject getAdStat(CTopOauthToken token, JSONObject conditions) {
|
|
|
|
+ final Long advertiser_id = token.getAccountId();
|
|
|
|
+
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.toutiao.com/open_api/2/report/ad/get/";
|
|
|
|
+
|
|
|
|
+ final Map filtering = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("campaign_id", 1L);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 请求参数
|
|
|
|
+ final Map data = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("advertiser_id", advertiser_id);
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> getAdReport(JSONObject conditions) {
|
|
|
|
+ Long accountId = conditions.getLong("accountId");
|
|
|
|
+ CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static JSONObject getCampaignStat(CTopOauthToken token, JSONObject conditions) {
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.toutiao.com/open_api/2/report/campaign/get/";
|
|
|
|
+
|
|
|
|
+ final Map filtering = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("campaign_ids", new Long[]{1L, 2L});
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 请求参数
|
|
|
|
+ final Map data = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("page", 1000);
|
|
|
|
+ put("pageSize", conditions.getInteger("page_size"));
|
|
|
|
+ put("advertiser_id", token.getAccountId());
|
|
|
|
+ put("start_date", conditions.getString("startDate"));
|
|
|
|
+ put("end_date", conditions.getString("endDate"));
|
|
|
|
+ put("time_granularity", conditions.getString("timeGranularity"));
|
|
|
|
+ put("group_by", conditions.getJSONArray("groupBy"));
|
|
|
|
+ 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;
|
|
}
|
|
}
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ICTopOauthTokenService tokenService;
|
|
private ICTopOauthTokenService tokenService;
|
|
|
|
|
|
- public JSONObject getAdvertiserStat(CTopOauthToken token, String startDate, String endDate, String timeGranularity) {
|
|
|
|
- String accessToken = token.getAccessToken();
|
|
|
|
|
|
+ public JSONObject getAdvertiserStat(CTopOauthToken token, JSONObject conditions) {
|
|
final Long advertiserId = token.getAccountId();
|
|
final Long advertiserId = token.getAccountId();
|
|
|
|
|
|
// 请求地址
|
|
// 请求地址
|
|
@@ -49,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", startDate);
|
|
|
|
- put("end_date", endDate);
|
|
|
|
- put("time_granularity", 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"));
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|