Browse Source

Merge remote-tracking branch 'origin/master'

xuzuoyun 5 năm trước cách đây
mục cha
commit
25bacfc748

+ 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");

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

@@ -15,8 +15,10 @@ import java.util.Map;
 @RequestMapping("report")
 public class ReportController {
     @GetMapping("advertiser")
-    public Map<String, Object> advertiserReport(String accountId, String startDate, String endDate, String timeGranularity) {
-        return reportService.getAdvertiserReport(accountId, startDate, endDate, timeGranularity);
+//    public Map<String, Object> advertiserReport(@RequestBody JSONObject conditions) {
+    public Map<String, Object> advertiserReport() {
+        JSONObject conditions = new JSONObject();
+        return reportService.getAdvertiserReport(conditions);
     }
 
     @GetMapping("campaign")
@@ -24,6 +26,22 @@ public class ReportController {
         return reportService.getCampaignReport(conditions);
     }
 
+    @GetMapping("ad")
+    public Map<String, Object> adReport(@RequestBody JSONObject conditions) {
+        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);
     }

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

@@ -5,7 +5,13 @@ import com.alibaba.fastjson.JSONObject;
 import java.util.Map;
 
 public interface IReportService {
-    Map<String, Object> getAdvertiserReport(String accountId, String startDate, String endDate, String timeGranularity);
+    Map<String, Object> getAdvertiserReport(JSONObject conditions);
 
     Map<String, Object> getCampaignReport(JSONObject conditions);
+
+    Map<String, Object> getAdReport(JSONObject conditions);
+
+    Map<String, Object> getCreativeReport(JSONObject conditions);
+
+    Map<String, Object> getAgentReport(JSONObject conditions);
 }

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCreativeServiceImpl.java

@@ -158,7 +158,7 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
                     }
 
                     if (null == horizonVideo) {
-                        Map<String, Object> getVideoResult = fileInfoService.uploadVideoToBytedance(getAccountId, horizonVideoCreativeText);
+                        Map<String, Object> getVideoResult = fileInfoService.uploadVideoToBytedance(getAccountId, horizonVideoUrl);
                         horizonVideo = (String) getVideoResult.get("videoId");
                     }
                     creative.put("image_id", horizonVideoCoverImage);

+ 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");

+ 318 - 9
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;
@@ -24,22 +25,328 @@ import java.util.Map;
 @Service
 public class ReportServiceImpl implements IReportService {
     @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
     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;
     }
 
     @Autowired
     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();
 
         // 请求地址
@@ -49,9 +356,11 @@ public class ReportServiceImpl implements IReportService {
         Map data = new HashMap() {
             {
                 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"));
             }
         };
 

+ 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

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