|
|
|
# API数据源使用示例
|
|
|
|
|
|
|
|
## 调用示例代码
|
|
|
|
|
|
|
|
### 开启API数据源
|
|
|
|
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
operation.open();
|
|
|
|
```
|
|
|
|
|
|
|
|
在开启后,可以在企业数据的"数据导入"菜单看到如下图所示的API数据源入口
|
|
|
|
![api_datasource](/screenshots/api_datasource.png)
|
|
|
|
|
|
|
|
### 创建表
|
|
|
|
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
// // 创建表并返回表id
|
|
|
|
String tableId = operation.createTable("HelloTable");
|
|
|
|
```
|
|
|
|
|
|
|
|
### 更新表数据
|
|
|
|
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
// // 创建表并返回表id
|
|
|
|
String tableId = "tableIdText;
|
|
|
|
// 获取给该表提供数据的文件的上传地址
|
|
|
|
String fileUploadUrl = operation.requestUploadUrl(tableId);
|
|
|
|
// 将数据文件上传
|
|
|
|
HttpKits.upload(fileUploadUrl, new File(System.getProperty("user.dir") + "/data/地区数据分析.csv"));
|
|
|
|
// 标记该表的数据已经上传完成
|
|
|
|
operation.markAsFinish(tableId);
|
|
|
|
```
|
|
|
|
|
|
|
|
在调用了上述代码后,就可以在API数据源页面看到新增的表和其数据了,这时就可以和其他数据源表一样,添加到项目中使用了:
|
|
|
|
|
|
|
|
![api_datasource_effect](/screenshots/api_datasource_effect.png)
|
|
|
|
|
|
|
|
|
|
|
|
## API文档
|
|
|
|
|
|
|
|
### 开启API数据源
|
|
|
|
#### 查看状态
|
|
|
|
请求地址:```/api/v1/datasource/status```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success":true,
|
|
|
|
"code":"200",
|
|
|
|
"data":{"status":"0"}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 修改状态
|
|
|
|
请求地址:```/api/v1/datasource/status/modify```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数: ``` {"status":"1"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success":true,
|
|
|
|
"code":"200"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 分组管理
|
|
|
|
#### 创建分组(暂未启用)
|
|
|
|
请求地址:```/api/v1/datasource/group/create```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数:```{"name":"#分组名"}```
|
|
|
|
|
|
|
|
#### 读取所有分组(暂未启用)
|
|
|
|
请求地址:```/api/v1/datasource/group/list```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
### 表管理
|
|
|
|
#### 创建数据源表
|
|
|
|
请求地址:```/api/v1/datasource/table/create```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数: ``` {"tableName":"#表名"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200",
|
|
|
|
"data":"2469965eae4d45339448fb1e74d2b733"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 获取表数据上传地址
|
|
|
|
请求地址:```/api/v1/datasource/table/upload/url```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数:``` {"tableId":"#表Id"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200",
|
|
|
|
"data":"upload_url"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 标记表数据已上传完成
|
|
|
|
请求地址:```/api/v1/datasource/table/upload/finish```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数:``` {"tableId":"#表Id"} ```
|