浏览代码

修改文件上传设置

syh 5 年之前
父节点
当前提交
b57112af04

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

@@ -15,8 +15,8 @@ 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) {
+        return reportService.getAdvertiserReport(conditions);
     }
 
     @GetMapping("campaign")
@@ -24,6 +24,11 @@ public class ReportController {
         return reportService.getCampaignReport(conditions);
     }
 
+    @GetMapping("ad")
+    public Map<String, Object> adReport(@RequestBody JSONObject conditions) {
+        return reportService.getAdReport(conditions);
+    }
+
     @Autowired
     private IReportService reportService;
 }

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

@@ -5,7 +5,9 @@ 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);
 }

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

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

@@ -24,22 +24,178 @@ 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);
+    public Map<String, Object> getAdvertiserReport(JSONObject conditions) {
+        Long accountId = conditions.getLong("accountId");
+        CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId + "");
+        JSONObject getObject = getAdvertiserStat(token, conditions);
         return null;
     }
 
     @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 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/";
+
+        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(open_api_url_prefix + uri));
+            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 +205,9 @@ 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("startDate"));
+                put("end_date", conditions.getString("endDate"));
+                put("time_granularity", conditions.getString("timeGranularity"));
             }
         };