Переглянути джерело

添加报表接口对接代码

syh 5 роки тому
батько
коміт
0c0d768473

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -82,8 +82,8 @@ public class ShiroConfig {
 		filterChainDefinitionMap.put("/actuator/metrics/**", "anon");
 		filterChainDefinitionMap.put("/actuator/httptrace/**", "anon");
 		filterChainDefinitionMap.put("/actuator/redis/**", "anon");
-		filterChainDefinitionMap.put("/test/jeecgDemo/demo3", "anon"); //模板测试
-		filterChainDefinitionMap.put("/test/jeecgDemo/redisDemo/**", "anon"); //redis测试
+        filterChainDefinitionMap.put("/test/**", "anon"); //模板测试
+        filterChainDefinitionMap.put("/report/**", "anon"); //模板测试
 
 		//oauth接口
         filterChainDefinitionMap.put("/auth/**", "anon");

+ 14 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ReportController.java

@@ -15,7 +15,9 @@ import java.util.Map;
 @RequestMapping("report")
 public class ReportController {
     @GetMapping("advertiser")
-    public Map<String, Object> advertiserReport(@RequestBody JSONObject conditions) {
+//    public Map<String, Object> advertiserReport(@RequestBody JSONObject conditions) {
+    public Map<String, Object> advertiserReport() {
+        JSONObject conditions = new JSONObject();
         return reportService.getAdvertiserReport(conditions);
     }
 
@@ -29,6 +31,17 @@ public class ReportController {
         return reportService.getAdReport(conditions);
     }
 
+    @GetMapping("creative")
+    public Map<String, Object> creativeReport(@RequestBody JSONObject conditions) {
+        return reportService.getCreativeReport(conditions);
+    }
+
+    @GetMapping("agent")
+    public Map<String, Object> agentReport(@RequestBody JSONObject conditions) {
+        return reportService.getAgentReport(conditions);
+    }
+
+
     @Autowired
     private IReportService reportService;
 }

+ 4 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -7,6 +7,7 @@ import org.jeecg.modules.ctop.entity.BindAccountAuth;
 import org.jeecg.modules.ctop.service.ICreateInternalService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import retrofit2.http.POST;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -17,8 +18,9 @@ public class TestController {
     @Autowired
     private ICreateInternalService createInternalService;
 
-    @PostMapping(value = "/create")
-    public void authorization(@RequestBody JSONObject json) {
+    @GetMapping(value = "/create")
+    public void authorization() {
+        JSONObject json = new JSONObject();
         System.err.println(json);
         createInternalService.createInternal(json);
     }

+ 4 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IReportService.java

@@ -10,4 +10,8 @@ public interface IReportService {
     Map<String, Object> getCampaignReport(JSONObject conditions);
 
     Map<String, Object> getAdReport(JSONObject conditions);
+
+    Map<String, Object> getCreativeReport(JSONObject conditions);
+
+    Map<String, Object> getAgentReport(JSONObject conditions);
 }

+ 5 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CreateInternalServiceImpl.java

@@ -17,6 +17,7 @@ import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeOptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import sun.misc.BASE64Decoder;
 
@@ -27,12 +28,12 @@ import java.util.*;
 public class CreateInternalServiceImpl implements ICreateInternalService {
     private static final Logger logger = LoggerFactory.getLogger(CreateInternalServiceImpl.class);
 
-
+    @Value("${jeecg.path.chrome-driver}")
+    private String chromeDriver;
     @Override
     public Map<String, Object> createInternal(JSONObject requestJson) {
         String url = "https://ad.oceanengine.com/pages/login/index.html";
-//        System.getProperties().setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
-        System.getProperties().setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
+        System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         ChromeOptions chromeOptions = new ChromeOptions();
         WebDriver webDriver = new ChromeDriver(chromeOptions);
         try {
@@ -63,7 +64,7 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
             param.put("mobile", "");
             param.put("code", "");
             param.put("account", "dcd_ad@bytedance.com");
-            param.put("password", "typdDCD@2018");
+            param.put("password", "typdDCD@20181");
             param.put("captcha", "hqde");
             param.put("is_30_days_no_login", "true");
             param.put("service", "https://ad.oceanengine.com");

+ 161 - 8
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ReportServiceImpl.java

@@ -13,6 +13,7 @@ import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
 import org.jeecg.modules.ctop.service.IReportService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import retrofit2.http.Url;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -25,10 +26,17 @@ import java.util.Map;
 public class ReportServiceImpl implements IReportService {
     @Override
     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 + "");
         JSONObject getObject = getAdvertiserStat(token, conditions);
-        return null;
+        return getObject;
     }
 
     @Override
@@ -116,13 +124,156 @@ public class ReportServiceImpl implements IReportService {
         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 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() {
             {
@@ -160,7 +311,7 @@ public class ReportServiceImpl implements IReportService {
 
         try {
             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));
 
             response = client.execute(httpEntity);
@@ -205,9 +356,11 @@ public class ReportServiceImpl implements IReportService {
         Map data = new HashMap() {
             {
                 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"));
             }
         };
 

+ 3 - 2
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -125,8 +125,8 @@ mybatis-plus:
       # 默认数据库表下划线命名
       table-underline: true
     configuration:
-    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+      # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
+      log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 #jeecg专用配置
 jeecg:
   path:
@@ -136,3 +136,4 @@ jeecg:
     webapp: D://webapp
     video-upload: D://upFiles//video//
     image-upload: D://upFiles//image//
+    chrome-driver: D://chromedriver.exe

+ 1 - 0
jeecg-boot-module-system/src/main/resources/application-prod.yml

@@ -138,4 +138,5 @@ jeecg:
     webapp: /mnt/webapp
     video-upload: /mnt/upload/video/
     image-upload: /mnt/upload/image/
+    chrome-driver: /usr/bin/chromedriver