Files
MES/yawei-mes/.tasks/2025-10-14_IOT_Labview_数据库配置API文档V1.6.md
2026-04-02 10:39:03 +08:00

350 lines
7.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# IOT Labview 数据库配置 API 接口文档
## 基本信息
- **基础路径**: `/iot/labview`
- **接口总数**: 12个
- **认证方式**: 无需认证
- **数据格式**: JSON
---
## 文档中实际场景应用
- **localhost**实际服务器ip地址
- **端口号**:实际服务器后端端口地址
---
## 接口列表
| 序号 | 接口地址 | 请求方式 | 功能说明 |
|------|----------|----------|----------|
| 1 | `/iot/labview/list` | GET | 查询配置列表 |
| 2 | `/iot/labview/{id}` | GET | 查询配置详情 |
| 3 | `/iot/labview` | POST | 新增配置 |
| 4 | `/iot/labview` | PUT | 修改配置 |
| 5 | `/iot/labview/{ids}` | DELETE | 删除配置(支持批量) |
| 6 | `/iot/labview/device/{iotDeviceId}` | GET | 根据设备ID查询配置 |
| 7 | `/iot/labview/targetTable/{id}` | GET | 获取目标表配置JSON |
| 8 | `/iot/labview/testConnection` | POST | 测试数据库连接 |
| 9 | `/iot/labview/deviceIds` | GET | 获取所有设备ID列表 |
| 10 | `/iot/labview/deviceIds/tenant` | GET | 根据租户查询设备ID列表 |
| 11 | `/iot/labview/tenant/device` | POST | 根据租户和设备ID查询配置 |
| 12 | `/iot/labview/export` | POST | 导出Excel |
---
## 接口测试Apifox
### 1. 查询配置列表(分页)
- **方法**: GET
- **URL**: `http://localhost:8080/iot/labview/list`
- **Query参数**:
- `pageNum`: 1
- `pageSize`: 10
- `iotDeviceId`: 1001 (可选)
- `iotDbIp`: 192.168 (可选,模糊查询)
- `iotDbName`: test (可选,模糊查询)
---
### 2. 查询配置详情
- **方法**: GET
- **URL**: `http://localhost:8080/iot/labview/1`
---
### 3. 新增配置
- **方法**: POST
- **URL**: `http://localhost:8080/iot/labview`
- **Headers**: `Content-Type: application/json`
- **Body (JSON)**:
```json
{
"iotDeviceId": 1004,
"iotDbIp": "192.168.1.103",
"iotDbPort": 3306,
"iotDbName": "test_db",
"Object": "root",
"Class": "123456",
"iotTargetTable": "{\"temperature\":\"ymes_iiot_temperature\"}",
"iotRemark": "测试配置",
"tenantId": 1
}
```
---
### 4. 修改配置
- **方法**: PUT
- **URL**: `http://localhost:8080/iot/labview`
- **Headers**: `Content-Type: application/json`
- **Body (JSON)**:
```json
{
"id": 1,
"iotDeviceId": 1001,
"iotDbIp": "192.168.1.100",
"iotDbPort": 3306,
"iotDbName": "test_db_new",
"Object": "root",
"Class": "123456",
"iotTargetTable": "{\"temperature\":\"ymes_iiot_temperature\"}",
"tenantId": 1
}
```
---
### 5. 删除配置(支持批量)
- **方法**: DELETE
- **URL**: `http://localhost:8080/iot/labview/1` (删除单个)
- **URL**: `http://localhost:8080/iot/labview/1,2,3` (批量删除)
---
### 6. 根据设备ID查询配置
- **方法**: GET
- **URL**: `http://localhost:8080/iot/labview/device/1001`
---
### 7. 获取目标表配置JSON格式
- **方法**: GET
- **URL**: `http://localhost:8080/iot/labview/targetTable/1`
**返回示例**:
```json
{
"code": 200,
"msg": "操作成功",
"data": {
"temperature": "ymes_iiot_temperature",
"humidity": "ymes_iiot_humidity"
}
}
```
---
### 8. 测试数据库连接
- **方法**: POST
- **URL**: `http://localhost:8080/iot/labview/testConnection`
- **Headers**: `Content-Type: application/json`
- **Body (JSON)**:
```json
{
"iotDbIp": "192.168.1.100",
"iotDbPort": 3306,
"iotDbName": "test_db",
"iotDbUser": "root",
"iotDbPass": "123456"
}
```
---
### 9. 获取所有设备ID列表
- **方法**: GET
- **URL**: `http://localhost:8080/iot/labview/deviceIds`
**返回示例**:
```json
{
"code": 200,
"msg": "操作成功",
"data": [1001, 1002, 1003, 1004]
}
```
**说明**:
- 返回所有已配置的设备ID
- 自动去重和排序
- 数组类型便于LabVIEW处理
---
### 10. 根据租户查询设备ID列表
- **方法**: GET
- **URL**: `http://localhost:8080/iot/labview/deviceIds/tenant`
**Query参数**:
- `tenantId` (可选): 租户ID精确匹配
- `tenantName` (可选): 租户名称,模糊查询
- **注意**: 至少提供一个参数
**使用示例**:
**示例1 - 通过租户ID查询**:
```
http://localhost:8080/iot/labview/deviceIds/tenant?tenantId=1
```
**示例2 - 通过租户名称查询**:
```
http://localhost:8080/iot/labview/deviceIds/tenant?tenantName=测试租户
```
**示例3 - 同时使用两个条件AND关系**:
```
http://localhost:8080/iot/labview/deviceIds/tenant?tenantId=1&tenantName=测试
```
**返回示例**:
```json
{
"code": 200,
"msg": "操作成功",
"data": [1001, 1002, 1003]
}
```
**错误示例**(未提供参数):
```json
{
"code": 500,
"msg": "请提供租户ID或租户名称"
}
```
**说明**:
- 支持按租户ID精确查询
- 支持按租户名称模糊查询(包含匹配)
- 两个参数可以同时使用AND关系
- 返回该租户下的所有设备ID去重、排序
---
### 11. 根据租户和设备ID查询配置
- **方法**: POST
- **URL**: `http://localhost:8080/iot/labview/tenant/device`
**请求体参数** (JSON):
- `tenantId` (必填): 租户ID
- `iotDeviceId` (必填): 设备ID
**使用示例**:
**查询租户1的设备1001配置**:
```json
POST http://localhost:8080/iot/labview/tenant/device
请求体:
{
"tenantId": 1,
"iotDeviceId": 1001
}
```
**返回示例(成功)**:
```json
{
"code": 200,
"msg": "操作成功",
"data": {
"id": 1,
"iotDeviceId": 1001,
"iotDbIp": "192.168.1.100",
"iotDbPort": 3306,
"iotDbName": "mes_db",
"Object": "root",
"Class": "123456",
"iotTargetTable": "{\"data\":\"ymes_iiot_data\",\"config\":\"ymes_iiot_config\"}",
"iotRemark": "测试设备",
"tenantId": 1,
"tenantName": "测试租户A",
"createBy": "admin",
"createTime": "2025-10-14 10:00:00",
"updateBy": null,
"updateTime": "2025-10-14 10:00:00"
}
}
```
**返回示例(未找到)**:
```json
{
"code": 500,
"msg": "未找到该租户下的设备配置"
}
```
**返回示例(参数缺失)**:
```json
{
"code": 500,
"msg": "租户ID和设备ID不能为空"
}
```
**说明**:
- 使用JSON格式的请求体传递参数
- 通过租户ID和设备ID精确查询
- 返回完整的配置对象
- 用于多租户环境下的设备配置隔离
- LabVIEW可通过此接口获取特定租户的设备数据库配置
**LabVIEW调用示例**:
```
LabVIEW HTTP POST请求
URL: http://your-server:8080/mes/iot/labview/tenant/device
Content-Type: application/json
请求体:
{
"tenantId": 1,
"iotDeviceId": 1001
}
```
---
### 12. 导出Excel
- **方法**: POST
- **URL**: `http://localhost:8080/iot/labview/export`
- **Query参数** (可选): `iotDbIp`, `iotDeviceId`, `iotDbName`
- **说明**: 点击 Send and Download 下载Excel文件
---
## 数据字段说明
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| id | Long | - | 主键ID |
| iotDeviceId | Long | ✓ | 设备ID唯一 |
| iotDbIp | String | ✓ | 数据库IP |
| iotDbPort | Integer | ✓ | 端口默认3306 |
| iotDbName | String | ✓ | 数据库名 |
| iotDbUser | String | ✓ | 账号 |
| iotDbPass | String | ✓ | 密码 |
| iotTargetTable | String | ✓ | 目标表JSON字符串 |
| iotRemark | String | - | 备注 |
| tenantId | Long | ✓ | 租户ID |
---
**文档版本**: v1.6
**更新时间**: 2025-10-14
**更新内容**:
- v1.1: 新增获取所有设备ID列表接口
- v1.2: 新增根据租户查询设备ID列表接口
- v1.3: 新增根据租户ID和设备ID查询配置接口
- v1.4: 将根据租户和设备ID查询配置接口改为POST方法
- v1.5: 将租户和设备ID查询接口的参数从路径参数改为请求体JSON格式
- v1.6: 修改JSON返回字段名`iotDbUser`改为`Object``iotDbPass`改为`Class`;移除`params``searchValue`字段