|
|
|
# API数据源使用示例
|
|
|
|
|
|
|
|
**注意:** 数据源表的数据更新的时候,会根据实际情况启动使用该数据源表的分析表的更新,最小更新间隔为1个小时。
|
|
|
|
|
|
|
|
*举例:当10点更新了一张数据源表,当表数据写入完成后,会立即更新到九数云中,如果10点10分再次更新这张表,则需要在11点的时候,才会将最新的数据更新到九数云中,13点15的时候再次更新这张表的数据,则在数据写入完成后,会立即更新到九数云中。*
|
|
|
|
|
|
|
|
## 调用示例代码
|
|
|
|
|
|
|
|
```Authentication```表示的是传入accessKeyId和accessKeySecret参数,获取临时令牌的操作,可以自行调用其中的RestApi,不是必须使用该类。
|
|
|
|
|
|
|
|
```DatasourceOperation```表示的是可以对API数据源进行的若干操作的集合,可以自行调用其中的RestApi,不是必须使用该类。
|
|
|
|
|
|
|
|
### 开启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 groupId = operation.createGroup("我的分组");
|
|
|
|
```
|
|
|
|
|
|
|
|
### 创建表
|
|
|
|
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
// 创建表并返回表id
|
|
|
|
String tableId = operation.createTable("HelloTable", "#分组Id(可选)");
|
|
|
|
```
|
|
|
|
|
|
|
|
### 更新表数据
|
|
|
|
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
// 创建表并返回表id
|
|
|
|
String tableId = "上一步获取到表id";
|
|
|
|
// 获取给该表提供数据的文件的上传地址
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
### 删除表
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
String tableId = "#待删除的表id";
|
|
|
|
operation.deleteTable(tableId);
|
|
|
|
```
|
|
|
|
|
|
|
|
### 删除所有表
|
|
|
|
```java
|
|
|
|
Authentication authentication = new Authentication("#key", "#secret");
|
|
|
|
DatasourceOperation operation = new DatasourceOperation(authentication);
|
|
|
|
operation.reset();
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 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
|
|
|
|
|
|
|
|
请求参数:```{"groupName":"#分组名"}```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success":true,
|
|
|
|
"code":"200",
|
|
|
|
"data":"#groupId"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 读取所有分组
|
|
|
|
请求地址:```/api/v1/datasource/group/list```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200",
|
|
|
|
"data": [{"id":"#groupId", "name": "#groupName"}]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 读取分组下的所有表
|
|
|
|
请求地址:```/api/v1/datasource/group/table/list```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数:```{"groupId":"#分组Id"}```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200",
|
|
|
|
"data": [{"id":"#tableId","name":"#tableName"}]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 修改分组名
|
|
|
|
请求地址:```/api/v1/datasource/group/modify```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数: ``` {"groupId":"#分组Id","groupName":"#新的分组名"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 表管理
|
|
|
|
#### 创建数据源表
|
|
|
|
请求地址:```/api/v1/datasource/table/create```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数: ``` {"tableName":"#表名","groupId":"#分组Id(可选)"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200",
|
|
|
|
"data":"#tableId"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 获取表数据上传地址
|
|
|
|
请求地址:```/api/v1/datasource/table/upload/url```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数:``` {"tableId":"#表Id"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200",
|
|
|
|
"data":"#file_upload_url"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 标记表数据已上传完成
|
|
|
|
请求地址:```/api/v1/datasource/table/upload/finish```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数:``` {"tableId":"#表Id"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 修改数据源表名(暂未启用)
|
|
|
|
请求地址:```/api/v1/datasource/table/modify```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数: ``` {"tableId":"#表Id","tableName":"#新的表名"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 删除数据源表
|
|
|
|
请求地址:```/api/v1/datasource/table/delete```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
请求参数: ``` {"tableId":"#表Id"} ```
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 重置整个数据源
|
|
|
|
请求地址:```/api/v1/datasource/reset```
|
|
|
|
|
|
|
|
请求类型:POST
|
|
|
|
|
|
|
|
返回值:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"success": true,
|
|
|
|
"code": "200"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|