@cpzxrobot/sdk 1.3.118 → 1.3.120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AIFORM_GATEWAY.md +414 -321
- package/aiform_gateway.ts +29 -0
- package/company_gateway.ts +211 -207
- package/dist/aiform_gateway.js +25 -0
- package/dist/company_gateway.js +7 -3
- package/package.json +1 -1
- package/types.d.ts +4 -0
package/AIFORM_GATEWAY.md
CHANGED
|
@@ -1,399 +1,492 @@
|
|
|
1
|
-
# AI
|
|
1
|
+
# AI报表模板接口使用说明
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 概述
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
AI报表模板接口用于管理工厂的AI报表模板,包括查询模板列表、新增和修改模板等功能。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 接口基础信息
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**Base URL**: `/api/v2/aiform/template`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## 如何使用
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|--------|------|------|------|------|
|
|
15
|
-
| factoryId | path | Long | 是 | 工厂ID |
|
|
13
|
+
通过 `cpzxrobot().aiform.template` 访问AI报表模板相关功能。
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
通过 `cpzxrobot().aiform.record` 访问文件上传和记录相关功能。
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
## 可用方法
|
|
18
|
+
|
|
19
|
+
### 1. 查询模板列表
|
|
20
|
+
|
|
21
|
+
**方法**: `list(factoryId: number): Promise<AiformTemplateListResponse>`
|
|
22
|
+
|
|
23
|
+
**接口路径**: `GET /api/v2/aiform/template/list/{factoryId}`
|
|
24
|
+
|
|
25
|
+
**功能**: 根据工厂ID查询该工厂下的所有AI报表模板
|
|
26
|
+
|
|
27
|
+
**参数**:
|
|
28
|
+
- `factoryId` (number): 工厂ID,必填
|
|
29
|
+
|
|
30
|
+
**返回值**:
|
|
31
|
+
```typescript
|
|
32
|
+
interface AiformTemplateListResponse {
|
|
33
|
+
code: number; // 状态码
|
|
34
|
+
message: string; // 提示信息
|
|
35
|
+
data: AiformTemplate[]; // 模板列表
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface AiformTemplate {
|
|
39
|
+
id: number; // 模板ID
|
|
40
|
+
factoryId: number; // 工厂ID
|
|
41
|
+
name: string; // 模板名称
|
|
42
|
+
content: string; // 模板内容
|
|
43
|
+
attention?: string; // 注意事项
|
|
44
|
+
}
|
|
21
45
|
```
|
|
22
46
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
| content | String | 模板内容 |
|
|
39
|
-
| attention | TemplateAttention | 注意事项(对象) |
|
|
40
|
-
|
|
41
|
-
**attention 字段(TemplateAttention)**:
|
|
42
|
-
|
|
43
|
-
| 参数名 | 类型 | 说明 |
|
|
44
|
-
|--------|------|------|
|
|
45
|
-
| hasFixedContent | Boolean | 是否有固定内容 |
|
|
46
|
-
| fixedContentList | Array\<String\> | 固定内容列表 |
|
|
47
|
-
| hasFixedRowContent | Boolean | 是否有固定行内容 |
|
|
48
|
-
| rowContent | String | 行内容 |
|
|
49
|
-
| hasFixedColumnContent | Boolean | 是否有固定列内容 |
|
|
50
|
-
| columnContent | String | 列内容 |
|
|
51
|
-
| otherNotes | String | 其他备注 |
|
|
52
|
-
|
|
53
|
-
**响应示例**:
|
|
54
|
-
|
|
55
|
-
```json
|
|
56
|
-
{
|
|
57
|
-
"code": 200,
|
|
58
|
-
"message": "SUCCESS",
|
|
59
|
-
"data": [
|
|
60
|
-
{
|
|
61
|
-
"id": 1,
|
|
62
|
-
"factoryId": 17231604990917,
|
|
63
|
-
"name": "栋舍巡检报表",
|
|
64
|
-
"content": "进行分娩舍的巡检记录",
|
|
65
|
-
"attention": {
|
|
66
|
-
"hasFixedContent": false,
|
|
67
|
-
"fixedContentList": [],
|
|
68
|
-
"hasFixedRowContent": true,
|
|
69
|
-
"rowContent": "每头母猪和仔猪的日常记录情况",
|
|
70
|
-
"hasFixedColumnContent": false,
|
|
71
|
-
"columnContent": "",
|
|
72
|
-
"otherNotes": ""
|
|
73
|
-
}
|
|
47
|
+
**使用示例**:
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// 查询工厂1001的模板列表
|
|
51
|
+
const response = await cpzxrobot().aiform.template.list(1001);
|
|
52
|
+
|
|
53
|
+
if (response.code === 200) {
|
|
54
|
+
const templates = response.data;
|
|
55
|
+
console.log(`找到 ${templates.length} 个模板:`);
|
|
56
|
+
|
|
57
|
+
templates.forEach(template => {
|
|
58
|
+
console.log(`ID: ${template.id}, 名称: ${template.name}`);
|
|
59
|
+
console.log(`内容: ${template.content.substring(0, 100)}...`);
|
|
60
|
+
if (template.attention) {
|
|
61
|
+
console.log(`注意事项: ${template.attention}`);
|
|
74
62
|
}
|
|
75
|
-
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
console.error('获取模板列表失败:', response.message);
|
|
76
66
|
}
|
|
77
67
|
```
|
|
78
68
|
|
|
79
|
-
|
|
69
|
+
### 2. 新增或修改模板
|
|
80
70
|
|
|
81
|
-
|
|
71
|
+
**方法**: `save(request: AiformTemplateSaveRequest): Promise<AiformTemplateSaveResponse>`
|
|
82
72
|
|
|
83
73
|
**接口路径**: `POST /api/v2/aiform/template/save`
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
| 参数名 | 类型 | 必填 | 说明 |
|
|
96
|
-
|--------|------|------|------|
|
|
97
|
-
| id | Long | 否 | 模板ID(传则修改,不传则新增) |
|
|
98
|
-
| factoryId | Long | 是 | 工厂ID |
|
|
99
|
-
| name | String | 是 | 模板名称 |
|
|
100
|
-
| content | String | 是 | 模板内容 |
|
|
101
|
-
| attention | TemplateAttention | 否 | 注意事项(对象) |
|
|
102
|
-
|
|
103
|
-
**attention 字段(TemplateAttention)**:
|
|
104
|
-
|
|
105
|
-
| 参数名 | 类型 | 必填 | 说明 |
|
|
106
|
-
|--------|------|------|------|
|
|
107
|
-
| hasFixedContent | Boolean | 否 | 是否有固定内容 |
|
|
108
|
-
| fixedContentList | Array\<String\> | 否 | 固定内容列表 |
|
|
109
|
-
| hasFixedRowContent | Boolean | 否 | 是否有固定行内容 |
|
|
110
|
-
| rowContent | String | 否 | 行内容 |
|
|
111
|
-
| hasFixedColumnContent | Boolean | 否 | 是否有固定列内容 |
|
|
112
|
-
| columnContent | String | 否 | 列内容 |
|
|
113
|
-
| otherNotes | String | 否 | 其他备注 |
|
|
114
|
-
|
|
115
|
-
**新增请求示例**:
|
|
116
|
-
|
|
117
|
-
```json
|
|
118
|
-
{
|
|
119
|
-
"factoryId": 17231604990917,
|
|
120
|
-
"name": "栋舍巡检报表",
|
|
121
|
-
"content": "进行分娩舍的巡检记录",
|
|
122
|
-
"attention": {
|
|
123
|
-
"hasFixedContent": false,
|
|
124
|
-
"fixedContentList": [],
|
|
125
|
-
"hasFixedRowContent": true,
|
|
126
|
-
"rowContent": "每头母猪和仔猪的日常记录情况",
|
|
127
|
-
"hasFixedColumnContent": false,
|
|
128
|
-
"columnContent": "",
|
|
129
|
-
"otherNotes": ""
|
|
130
|
-
}
|
|
75
|
+
**功能**: 新增或修改AI报表模板。当请求体中包含 `id` 时执行修改操作,不包含 `id` 时执行新增操作。
|
|
76
|
+
|
|
77
|
+
**请求参数**:
|
|
78
|
+
```typescript
|
|
79
|
+
interface AiformTemplateSaveRequest {
|
|
80
|
+
id?: number; // 模板ID(传则修改,不传则新增)
|
|
81
|
+
factoryId: number; // 工厂ID,必填
|
|
82
|
+
name: string; // 模板名称,必填
|
|
83
|
+
content: string; // 模板内容,必填
|
|
84
|
+
attention?: string; // 注意事项,可选
|
|
131
85
|
}
|
|
132
86
|
```
|
|
133
87
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
"factoryId": 17231604990917,
|
|
140
|
-
"name": "栋舍巡检报表(修改)",
|
|
141
|
-
"content": "修改后的巡检记录内容",
|
|
142
|
-
"attention": {
|
|
143
|
-
"hasFixedContent": true,
|
|
144
|
-
"fixedContentList": ["温度", "湿度"],
|
|
145
|
-
"hasFixedRowContent": true,
|
|
146
|
-
"rowContent": "每头母猪和仔猪的日常记录情况",
|
|
147
|
-
"hasFixedColumnContent": false,
|
|
148
|
-
"columnContent": "",
|
|
149
|
-
"otherNotes": "需关注异常情况"
|
|
150
|
-
}
|
|
88
|
+
**返回值**:
|
|
89
|
+
```typescript
|
|
90
|
+
interface AiformTemplateSaveResponse {
|
|
91
|
+
code: number; // 状态码
|
|
92
|
+
message: string; // 提示信息
|
|
151
93
|
}
|
|
152
94
|
```
|
|
153
95
|
|
|
154
|
-
|
|
96
|
+
**使用示例**:
|
|
155
97
|
|
|
156
|
-
|
|
157
|
-
|--------|------|------|
|
|
158
|
-
| code | int | 状态码 |
|
|
159
|
-
| message | String | 提示信息 |
|
|
98
|
+
#### 新增模板
|
|
160
99
|
|
|
161
|
-
|
|
100
|
+
```javascript
|
|
101
|
+
// 新增模板
|
|
102
|
+
const response = await cpzxrobot().aiform.template.save({
|
|
103
|
+
factoryId: 1001,
|
|
104
|
+
name: "生产日报模板",
|
|
105
|
+
content: "## 生产日报\n\n日期: {{date}}\n\n产量: {{production}}\n\n质量: {{quality}}",
|
|
106
|
+
attention: "请确保填写真实数据"
|
|
107
|
+
});
|
|
162
108
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
109
|
+
if (response.code === 200) {
|
|
110
|
+
console.log('模板创建成功');
|
|
111
|
+
} else {
|
|
112
|
+
console.error('模板创建失败:', response.message);
|
|
167
113
|
}
|
|
168
114
|
```
|
|
169
115
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
116
|
+
#### 修改模板
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
// 修改模板
|
|
120
|
+
const response = await cpzxrobot().aiform.template.save({
|
|
121
|
+
id: 1, // 模板ID
|
|
122
|
+
factoryId: 1001,
|
|
123
|
+
name: "生产日报模板(更新版)",
|
|
124
|
+
content: "## 生产日报\n\n日期: {{date}}\n\n产量: {{production}}\n\n质量: {{quality}}\n\n备注: {{remark}}",
|
|
125
|
+
attention: "请确保填写真实数据,新增加了备注字段"
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (response.code === 200) {
|
|
129
|
+
console.log('模板更新成功');
|
|
130
|
+
} else {
|
|
131
|
+
console.error('模板更新失败:', response.message);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
177
134
|
|
|
178
|
-
|
|
135
|
+
### 3. 上传表格图片
|
|
179
136
|
|
|
180
|
-
|
|
137
|
+
**方法**: `upload(templateId: number): Promise<AiformFileUploadResponse>`
|
|
181
138
|
|
|
182
139
|
**接口路径**: `POST /api/v2/aiform/file/upload`
|
|
183
140
|
|
|
184
|
-
|
|
141
|
+
**功能**: 上传表格图片到 MinIO,并关联到指定的模板。上传成功后自动异步触发大模型解析。
|
|
185
142
|
|
|
186
|
-
|
|
143
|
+
**参数**:
|
|
144
|
+
- `templateId` (number): 关联的模板ID,必填
|
|
187
145
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
146
|
+
**返回值**:
|
|
147
|
+
```typescript
|
|
148
|
+
interface AiformFileUploadResponse {
|
|
149
|
+
code: number; // 状态码
|
|
150
|
+
message: string; // 提示信息
|
|
151
|
+
data: File; // 文件记录
|
|
152
|
+
}
|
|
191
153
|
|
|
192
|
-
|
|
154
|
+
interface File {
|
|
155
|
+
id: number; // 文件记录ID
|
|
156
|
+
code?: string; // 业务编码
|
|
157
|
+
tableKey: number; // 关联业务ID(模板ID)
|
|
158
|
+
tableName: string; // 关联业务表名(固定值 aiform_template)
|
|
159
|
+
fileName: string; // 原始文件名
|
|
160
|
+
storageName: string; // 存储文件名
|
|
161
|
+
fileUrl: string; // MinIO存储路径
|
|
162
|
+
accessUrl: string; // 预签名访问链接
|
|
163
|
+
fileExt: string; // 文件扩展名
|
|
164
|
+
server: string; // 存储服务(minio)
|
|
165
|
+
type: string; // 文件类型(image)
|
|
166
|
+
status: number; // 状态:0-已上传 1-解析中 2-已解析
|
|
167
|
+
createTime: string; // 创建时间
|
|
168
|
+
updateTime: string; // 更新时间
|
|
169
|
+
}
|
|
170
|
+
```
|
|
193
171
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
| id | Long | 文件记录ID |
|
|
212
|
-
| code | String | 业务编码(用于调用详情接口) |
|
|
213
|
-
| tableKey | Long | 关联业务ID(此处为模板ID) |
|
|
214
|
-
| tableName | String | 关联业务表名(固定值 `aiform_template`) |
|
|
215
|
-
| fileName | String | 原始文件名 |
|
|
216
|
-
| storageName | String | 存储文件名(系统统一生成) |
|
|
217
|
-
| fileUrl | String | MinIO存储路径 |
|
|
218
|
-
| fileExt | String | 文件扩展名 |
|
|
219
|
-
| server | String | 存储服务(minio) |
|
|
220
|
-
| type | String | 文件类型(image) |
|
|
221
|
-
| status | Integer | 状态:0-已上传 1-解析中 2-已解析 |
|
|
222
|
-
| createUserId | Long | 创建用户ID |
|
|
223
|
-
| createTime | String | 创建时间 |
|
|
224
|
-
| updateTime | String | 更新时间 |
|
|
225
|
-
|
|
226
|
-
**响应示例**:
|
|
227
|
-
|
|
228
|
-
```json
|
|
229
|
-
{
|
|
230
|
-
"code": 200,
|
|
231
|
-
"message": "SUCCESS",
|
|
232
|
-
"data": {
|
|
233
|
-
"id": 1,
|
|
234
|
-
"code": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
235
|
-
"tableKey": 1,
|
|
236
|
-
"tableName": "aiform_template",
|
|
237
|
-
"fileName": "巡检报表20260301.png",
|
|
238
|
-
"storageName": "20260301120000000123.png",
|
|
239
|
-
"fileUrl": "aiform/1/20260301120000000123.png",
|
|
240
|
-
"fileExt": "png",
|
|
241
|
-
"server": "minio",
|
|
242
|
-
"type": "image",
|
|
243
|
-
"status": 0,
|
|
244
|
-
"createUserId": 100,
|
|
245
|
-
"createTime": "2026-03-01 12:00:00",
|
|
246
|
-
"updateTime": "2026-03-01 12:00:00"
|
|
172
|
+
**使用示例**:
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
// 上传文件
|
|
176
|
+
async function uploadFile() {
|
|
177
|
+
const templateId = 1; // 模板ID
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
const response = await cpzxrobot().aiform.record.upload(templateId);
|
|
181
|
+
console.log('上传成功:', response.data);
|
|
182
|
+
console.log('文件状态:', getFileStatusText(response.data.status));
|
|
183
|
+
console.log('访问链接:', response.data.accessUrl);
|
|
184
|
+
|
|
185
|
+
// 可以开始轮询状态
|
|
186
|
+
trackFileStatus(templateId, response.data.id);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error('上传失败:', error.message);
|
|
247
189
|
}
|
|
248
190
|
}
|
|
249
|
-
```
|
|
250
191
|
|
|
251
|
-
|
|
192
|
+
function getFileStatusText(status) {
|
|
193
|
+
const statusMap = {
|
|
194
|
+
0: '已上传',
|
|
195
|
+
1: '解析中',
|
|
196
|
+
2: '已解析'
|
|
197
|
+
};
|
|
198
|
+
return statusMap[status] || '未知';
|
|
199
|
+
}
|
|
252
200
|
|
|
253
|
-
|
|
201
|
+
// 调用示例
|
|
202
|
+
uploadFile();
|
|
203
|
+
```
|
|
254
204
|
|
|
255
|
-
|
|
205
|
+
### 4. 根据模板ID查询上传记录
|
|
256
206
|
|
|
257
|
-
|
|
207
|
+
**方法**: `list(templateId: number): Promise<AiformFileListResponse>`
|
|
258
208
|
|
|
259
|
-
|
|
209
|
+
**接口路径**: `GET /api/v2/aiform/file/list/{templateId}`
|
|
260
210
|
|
|
261
|
-
|
|
262
|
-
|--------|------|------|------|------|
|
|
263
|
-
| templateId | path | Long | 是 | 模板ID |
|
|
211
|
+
**功能**: 根据模板ID查询该模板下所有上传的文件记录,按创建时间倒序排列(返回精简版记录)。
|
|
264
212
|
|
|
265
|
-
|
|
213
|
+
**参数**:
|
|
214
|
+
- `templateId` (number): 模板ID,必填
|
|
266
215
|
|
|
267
|
-
|
|
268
|
-
|
|
216
|
+
**返回值**:
|
|
217
|
+
```typescript
|
|
218
|
+
interface AiformFileListResponse {
|
|
219
|
+
code: number; // 状态码
|
|
220
|
+
message: string; // 提示信息
|
|
221
|
+
data: File[]; // 文件记录列表(精简版)
|
|
222
|
+
}
|
|
269
223
|
```
|
|
270
224
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
**status 状态说明**:
|
|
291
|
-
|
|
292
|
-
| 值 | 含义 |
|
|
293
|
-
|----|------|
|
|
294
|
-
| 0 | 已上传 |
|
|
295
|
-
| 1 | 解析中 |
|
|
296
|
-
| 2 | 已解析 |
|
|
297
|
-
|
|
298
|
-
**响应示例**:
|
|
299
|
-
|
|
300
|
-
```json
|
|
301
|
-
{
|
|
302
|
-
"code": 200,
|
|
303
|
-
"message": "SUCCESS",
|
|
304
|
-
"data": [
|
|
305
|
-
{
|
|
306
|
-
"code": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
307
|
-
"storageName": "20260302100000000456.png",
|
|
308
|
-
"status": 2,
|
|
309
|
-
"createUserId": 100,
|
|
310
|
-
"createTime": "2026-03-02T10:00:00+08:00",
|
|
311
|
-
"updateTime": "2026-03-02T10:05:00+08:00"
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
"code": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
|
|
315
|
-
"storageName": "20260301120000000123.png",
|
|
316
|
-
"status": 0,
|
|
317
|
-
"createUserId": 100,
|
|
318
|
-
"createTime": "2026-03-01T12:00:00+08:00",
|
|
319
|
-
"updateTime": "2026-03-01T12:00:00+08:00"
|
|
225
|
+
**使用示例**:
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
// 获取模板的上传记录
|
|
229
|
+
async function getTemplateRecords(templateId) {
|
|
230
|
+
try {
|
|
231
|
+
const response = await cpzxrobot().aiform.record.list(templateId);
|
|
232
|
+
|
|
233
|
+
if (response.code === 200) {
|
|
234
|
+
const records = response.data;
|
|
235
|
+
console.log(`找到 ${records.length} 条上传记录:`);
|
|
236
|
+
|
|
237
|
+
records.forEach((record, index) => {
|
|
238
|
+
console.log(`\n记录 ${index + 1}:`);
|
|
239
|
+
console.log(`文件名: ${record.fileName}`);
|
|
240
|
+
console.log(`状态: ${getFileStatusText(record.status)}`);
|
|
241
|
+
console.log(`创建时间: ${record.createTime}`);
|
|
242
|
+
console.log(`访问链接: ${record.accessUrl}`);
|
|
243
|
+
});
|
|
320
244
|
}
|
|
321
|
-
|
|
245
|
+
} catch (error) {
|
|
246
|
+
console.error('获取记录失败:', error.message);
|
|
247
|
+
}
|
|
322
248
|
}
|
|
249
|
+
|
|
250
|
+
// 调用示例
|
|
251
|
+
getTemplateRecords(1); // 查询模板ID为1的上传记录
|
|
323
252
|
```
|
|
324
253
|
|
|
325
|
-
|
|
254
|
+
### 5. 根据文件业务编码获取详情
|
|
326
255
|
|
|
327
|
-
|
|
256
|
+
**方法**: `detail(code: string): Promise<AiformFileDetailResponse>`
|
|
328
257
|
|
|
329
258
|
**接口路径**: `GET /api/v2/aiform/file/detail/{code}`
|
|
330
259
|
|
|
331
|
-
|
|
260
|
+
**功能**: 根据文件业务编码获取解析结果详情。
|
|
332
261
|
|
|
333
|
-
|
|
262
|
+
**参数**:
|
|
263
|
+
- `code` (string): 文件业务编码,必填
|
|
334
264
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
265
|
+
**返回值**:
|
|
266
|
+
```typescript
|
|
267
|
+
interface AiformFileDetailResponse {
|
|
268
|
+
code: number; // 状态码
|
|
269
|
+
message: string; // 提示信息
|
|
270
|
+
data: any; // 解析结果详情
|
|
271
|
+
}
|
|
272
|
+
```
|
|
338
273
|
|
|
339
|
-
|
|
274
|
+
**使用示例**:
|
|
340
275
|
|
|
341
|
-
```
|
|
342
|
-
|
|
276
|
+
```javascript
|
|
277
|
+
// 获取文件详情
|
|
278
|
+
async function getFileDetail(code) {
|
|
279
|
+
try {
|
|
280
|
+
const response = await cpzxrobot().aiform.record.detail(code);
|
|
281
|
+
|
|
282
|
+
if (response.code === 200) {
|
|
283
|
+
console.log('文件详情:', response.data);
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error('获取文件详情失败:', error.message);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 调用示例
|
|
291
|
+
getFileDetail('FILE_20240101_001'); // 查询业务编码为FILE_20240101_001的文件详情
|
|
343
292
|
```
|
|
344
293
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
{
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
294
|
+
### 6. 轮询文件解析状态
|
|
295
|
+
|
|
296
|
+
**功能**: 上传文件后,需要轮询文件状态以确认解析进度。
|
|
297
|
+
|
|
298
|
+
**使用示例**:
|
|
299
|
+
|
|
300
|
+
```javascript
|
|
301
|
+
async function trackFileStatus(templateId, fileId) {
|
|
302
|
+
let status = 0; // 初始状态
|
|
303
|
+
let attempts = 0;
|
|
304
|
+
const maxAttempts = 30; // 最多轮询30次
|
|
305
|
+
|
|
306
|
+
console.log('开始跟踪文件解析状态...');
|
|
307
|
+
|
|
308
|
+
while (status !== 2 && attempts < maxAttempts) {
|
|
309
|
+
try {
|
|
310
|
+
const response = await cpzxrobot().aiform.record.list(templateId);
|
|
311
|
+
const fileRecord = response.data.find(record => record.id === fileId);
|
|
312
|
+
|
|
313
|
+
if (fileRecord) {
|
|
314
|
+
status = fileRecord.status;
|
|
315
|
+
console.log(`当前状态: ${getFileStatusText(status)}`);
|
|
316
|
+
|
|
317
|
+
if (status === 2) {
|
|
318
|
+
console.log('文件已成功解析!');
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
await new Promise(resolve => setTimeout(resolve, 5000)); // 每5秒轮询一次
|
|
324
|
+
attempts++;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error('轮询失败:', error.message);
|
|
327
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
328
|
+
attempts++;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (attempts >= maxAttempts) {
|
|
333
|
+
console.log('解析超时,请稍后手动检查状态');
|
|
375
334
|
}
|
|
376
335
|
}
|
|
377
336
|
```
|
|
378
337
|
|
|
379
|
-
|
|
338
|
+
## 错误处理
|
|
380
339
|
|
|
381
|
-
|
|
340
|
+
### 常见错误
|
|
382
341
|
|
|
383
|
-
|
|
342
|
+
1. **参数验证错误**:
|
|
343
|
+
- `工厂ID不能为空` - 未提供factoryId参数
|
|
344
|
+
- `模板名称不能为空` - 未提供name参数
|
|
345
|
+
- `模板内容不能为空` - 未提供content参数
|
|
346
|
+
- `文件不能为空` - 未提供file参数
|
|
347
|
+
- `模板ID不能为空` - 未提供templateId参数
|
|
348
|
+
|
|
349
|
+
2. **API错误**:
|
|
350
|
+
- 当API返回非200状态码时,会抛出包含错误信息的异常
|
|
351
|
+
|
|
352
|
+
### 错误处理示例
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
try {
|
|
356
|
+
// 尝试获取模板列表
|
|
357
|
+
const response = await cpzxrobot().aiform.template.list(1001);
|
|
358
|
+
console.log('模板列表:', response.data);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.error('操作失败:', error.message);
|
|
361
|
+
}
|
|
384
362
|
|
|
385
|
-
|
|
386
|
-
|
|
363
|
+
try {
|
|
364
|
+
// 尝试保存模板
|
|
365
|
+
const response = await cpzxrobot().aiform.template.save({
|
|
366
|
+
factoryId: 1001,
|
|
367
|
+
name: "测试模板",
|
|
368
|
+
content: "模板内容"
|
|
369
|
+
});
|
|
370
|
+
console.log('保存成功:', response.message);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error('保存失败:', error.message);
|
|
373
|
+
}
|
|
387
374
|
|
|
388
|
-
|
|
375
|
+
try {
|
|
376
|
+
// 尝试上传文件
|
|
377
|
+
const file = document.getElementById('fileInput').files[0];
|
|
378
|
+
const response = await cpzxrobot().aiform.record.upload(file, 1);
|
|
379
|
+
console.log('上传成功:', response.data);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
console.error('上传失败:', error.message);
|
|
382
|
+
}
|
|
389
383
|
|
|
390
|
-
|
|
384
|
+
try {
|
|
385
|
+
// 尝试获取上传记录
|
|
386
|
+
const response = await cpzxrobot().aiform.record.list(1);
|
|
387
|
+
console.log('上传记录:', response.data);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
console.error('获取记录失败:', error.message);
|
|
390
|
+
}
|
|
391
391
|
|
|
392
|
-
|
|
392
|
+
try {
|
|
393
|
+
// 尝试获取文件详情
|
|
394
|
+
const response = await cpzxrobot().aiform.record.detail('FILE_20240101_001');
|
|
395
|
+
console.log('文件详情:', response.data);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
console.error('获取文件详情失败:', error.message);
|
|
398
|
+
}
|
|
399
|
+
```
|
|
393
400
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
401
|
+
## 完整使用示例
|
|
402
|
+
|
|
403
|
+
```javascript
|
|
404
|
+
async function manageAITemplates() {
|
|
405
|
+
try {
|
|
406
|
+
const aiform = cpzxrobot().aiform.template;
|
|
407
|
+
const factoryId = 1001;
|
|
408
|
+
|
|
409
|
+
console.log('=== 管理AI报表模板 ===');
|
|
410
|
+
|
|
411
|
+
// 1. 获取模板列表
|
|
412
|
+
console.log('\n1. 获取模板列表:');
|
|
413
|
+
const listResponse = await aiform.list(factoryId);
|
|
414
|
+
if (listResponse.code === 200) {
|
|
415
|
+
console.log(`找到 ${listResponse.data.length} 个模板:`);
|
|
416
|
+
listResponse.data.forEach((template, index) => {
|
|
417
|
+
console.log(` ${index + 1}. ${template.name} (ID: ${template.id})`);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// 2. 新增模板
|
|
422
|
+
console.log('\n2. 新增模板:');
|
|
423
|
+
const createResponse = await aiform.save({
|
|
424
|
+
factoryId: factoryId,
|
|
425
|
+
name: "新增测试模板",
|
|
426
|
+
content: "## 测试模板\n\n这是一个测试模板",
|
|
427
|
+
attention: "测试用模板"
|
|
428
|
+
});
|
|
429
|
+
console.log(`新增结果: ${createResponse.message}`);
|
|
430
|
+
|
|
431
|
+
// 3. 再次获取模板列表
|
|
432
|
+
console.log('\n3. 再次获取模板列表:');
|
|
433
|
+
const updatedListResponse = await aiform.list(factoryId);
|
|
434
|
+
if (updatedListResponse.code === 200) {
|
|
435
|
+
console.log(`现在有 ${updatedListResponse.data.length} 个模板:`);
|
|
436
|
+
updatedListResponse.data.forEach((template, index) => {
|
|
437
|
+
console.log(` ${index + 1}. ${template.name} (ID: ${template.id})`);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// 4. 修改最后一个模板
|
|
442
|
+
if (updatedListResponse.data.length > 0) {
|
|
443
|
+
const lastTemplate = updatedListResponse.data[updatedListResponse.data.length - 1];
|
|
444
|
+
console.log(`\n4. 修改模板: ${lastTemplate.name}`);
|
|
445
|
+
|
|
446
|
+
const updateResponse = await aiform.save({
|
|
447
|
+
id: lastTemplate.id,
|
|
448
|
+
factoryId: factoryId,
|
|
449
|
+
name: `${lastTemplate.name} (已更新)`,
|
|
450
|
+
content: lastTemplate.content + '\n\n更新时间: ' + new Date().toLocaleString(),
|
|
451
|
+
attention: lastTemplate.attention + ' - 已更新'
|
|
452
|
+
});
|
|
453
|
+
console.log(`修改结果: ${updateResponse.message}`);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// 5. 最终模板列表
|
|
457
|
+
console.log('\n5. 最终模板列表:');
|
|
458
|
+
const finalListResponse = await aiform.list(factoryId);
|
|
459
|
+
if (finalListResponse.code === 200) {
|
|
460
|
+
console.log(`最终有 ${finalListResponse.data.length} 个模板:`);
|
|
461
|
+
finalListResponse.data.forEach((template, index) => {
|
|
462
|
+
console.log(` ${index + 1}. ${template.name} (ID: ${template.id})`);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
} catch (error) {
|
|
467
|
+
console.error('操作失败:', error.message);
|
|
468
|
+
}
|
|
398
469
|
}
|
|
470
|
+
|
|
471
|
+
// 执行操作
|
|
472
|
+
manageAITemplates();
|
|
399
473
|
```
|
|
474
|
+
|
|
475
|
+
## 注意事项
|
|
476
|
+
|
|
477
|
+
1. **权限要求**: 使用这些接口需要具有相应的工厂管理权限
|
|
478
|
+
2. **模板内容**: 模板内容支持使用模板变量(如 `{{date}}`),具体变量格式请参考AI报表系统的相关文档
|
|
479
|
+
3. **参数验证**: 所有必填参数必须提供,否则会抛出错误
|
|
480
|
+
4. **错误处理**: 建议使用 try-catch 捕获可能的错误
|
|
481
|
+
5. **网络请求**: 这些接口是异步网络请求,需要使用 `async/await` 或 Promise 处理
|
|
482
|
+
|
|
483
|
+
## 版本信息
|
|
484
|
+
|
|
485
|
+
- **SDK版本**: 1.3.114+
|
|
486
|
+
- **接口版本**: v2
|
|
487
|
+
|
|
488
|
+
## 接口变更说明
|
|
489
|
+
|
|
490
|
+
- **新增接口**: `cpzxrobot().aiform.record.detail(code)` - 根据文件业务编码获取解析结果详情
|
|
491
|
+
- **变更接口**: `cpzxrobot().aiform.record.upload()` - 不再需要传递File参数,改为内部处理文件选择
|
|
492
|
+
- **变更接口**: `cpzxrobot().aiform.record.list()` - 返回精简版文件记录,去掉了内容字段
|