diff --git a/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java b/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java index ffb6938..bd9ff94 100644 --- a/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java +++ b/src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java @@ -25,7 +25,10 @@ public class DatasourceOperation { JSONObject body = new JSONObject(); body.put("status", "1"); HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); - HttpKits.post(String.format("%s/api/v1/datasource/status/modify", ProjectConstants.BASE_URI), headers(), entity); + Map params = new HashMap<>(); + params.put("status", "1"); + String r = HttpKits.post(String.format("%s/api/v1/datasource/status/modify", ProjectConstants.BASE_URI), headers(), params); + System.out.println("result=" + r); } public void createGroup(String groupName) throws Exception { @@ -35,6 +38,15 @@ public class DatasourceOperation { HttpKits.post(String.format("%s/api/v1/datasource/group/create", ProjectConstants.BASE_URI), headers(), entity); } + public String createTable(String tableName) throws Exception { + JSONObject body = new JSONObject(); + body.put("tableName", tableName); + HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); + String res = HttpKits.post(String.format("%s/api/v1/datasource/table/create", ProjectConstants.BASE_URI), headers(), entity); + JSONObject data = new JSONObject(res); + return data.getString("data"); + } + public String createTable(String tableName, String groupName) throws Exception { JSONObject body = new JSONObject(); body.put("name", tableName); @@ -47,7 +59,9 @@ public class DatasourceOperation { JSONObject body = new JSONObject(); body.put("tableId", tableId); HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); - return HttpKits.post(String.format("%s/api/v1/datasource/table/upload/url", ProjectConstants.BASE_URI), headers(), entity); + String res = HttpKits.post(String.format("%s/api/v1/datasource/table/upload/url", ProjectConstants.BASE_URI), headers(), entity); + JSONObject data = new JSONObject(res); + return data.getString("data"); } public void markAsFinish(String tableId) throws Exception { diff --git a/src/main/java/com/fanruan/hihidata/datasource/server/ProjectConstants.java b/src/main/java/com/fanruan/hihidata/datasource/server/ProjectConstants.java index af18b72..9940774 100644 --- a/src/main/java/com/fanruan/hihidata/datasource/server/ProjectConstants.java +++ b/src/main/java/com/fanruan/hihidata/datasource/server/ProjectConstants.java @@ -6,5 +6,5 @@ package com.fanruan.hihidata.datasource.server; */ public class ProjectConstants { - public static final String BASE_URI = "https://work.jiushuyun.com/decision"; + public static final String BASE_URI = "https://test.jiushuyun.com/decision"; } diff --git a/src/main/java/com/fanruan/hihidata/datasource/server/ServerApplication.java b/src/main/java/com/fanruan/hihidata/datasource/server/ServerApplication.java index e647051..3e60a04 100644 --- a/src/main/java/com/fanruan/hihidata/datasource/server/ServerApplication.java +++ b/src/main/java/com/fanruan/hihidata/datasource/server/ServerApplication.java @@ -11,13 +11,13 @@ import java.io.File; public class ServerApplication { public static void main(String... args) throws Exception { - Authentication authentication = new Authentication(args[0], args[1]); + Authentication authentication = new Authentication("ZDdjOWJhZGI5OTBjNDI3ZWE2MzAzYWYwY2UyMTI1Zjg=", "103d4522039be2d17588882b7ae5ba12"); DatasourceOperation operation = new DatasourceOperation(authentication); - operation.open(); + //operation.open(); // 创建一个分组,如果已经存在,则直接跳过 - operation.createGroup("TestGroup"); + //operation.createGroup("TestGroup"); // 在分组下创建一个表,返回创建的表的ID,如果表已经存在,则直接返回表ID - String tableId = operation.createTable("HelloTable", "TestGroup"); + String tableId = operation.createTable("HelloTable"); // 获取上传文件的url String fileUploadUrl = operation.requestUploadUrl(tableId); // 将数据文件上传 diff --git a/src/main/java/com/fanruan/hihidata/datasource/server/http/HttpKits.java b/src/main/java/com/fanruan/hihidata/datasource/server/http/HttpKits.java index 194cb21..29f8e7d 100644 --- a/src/main/java/com/fanruan/hihidata/datasource/server/http/HttpKits.java +++ b/src/main/java/com/fanruan/hihidata/datasource/server/http/HttpKits.java @@ -206,6 +206,22 @@ public class HttpKits { .build()); } + /** + * 发起POST请求并获取返回的文本 + * + * @param url 响应请求的的服务器地址 + * @param headers POST请求的参数 + * @return 服务器返回的文本内容 + */ + public static String post(String url, Map headers, Map params) throws IOException { + return executeAndParse(HttpRequest + .custom() + .url(url) + .headers(headers) + .post(params) + .build()); + } + /** * 上传文件到指定的服务器 *