@cpzxrobot/sdk 1.3.118 → 1.3.119

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 CHANGED
@@ -1,399 +1,492 @@
1
- # AI报表 接口文档
1
+ # AI报表模板接口使用说明
2
2
 
3
- ---
3
+ ## 概述
4
4
 
5
- ## 1. 按 factoryId 查询模板列表
5
+ AI报表模板接口用于管理工厂的AI报表模板,包括查询模板列表、新增和修改模板等功能。
6
6
 
7
- **接口路径**: `GET /api/v2/aiform/template/list/{factoryId}`
7
+ ## 接口基础信息
8
8
 
9
- **接口描述**: 根据工厂ID查询该工厂下的所有AI报表模板
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
- GET /api/v2/aiform/template/list/17231604990917
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
- | code | int | 状态码 |
28
- | message | String | 提示信息 |
29
- | data | Array\<AiformTemplateVO\> | 模板列表 |
30
-
31
- **data 数组元素字段(AiformTemplateVO)**:
32
-
33
- | 参数名 | 类型 | 说明 |
34
- |--------|------|------|
35
- | id | Long | 模板ID |
36
- | factoryId | Long | 工厂ID |
37
- | name | String | 模板名称 |
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
- ## 2. 新增或修改模板
71
+ **方法**: `save(request: AiformTemplateSaveRequest): Promise<AiformTemplateSaveResponse>`
82
72
 
83
73
  **接口路径**: `POST /api/v2/aiform/template/save`
84
74
 
85
- **接口描述**: 新增或修改AI报表模板。当请求体中包含 `id` 时执行修改操作,不包含 `id` 时执行新增操作。
86
-
87
- **请求头**:
88
-
89
- | Header | 值 |
90
- |--------|----|
91
- | Content-Type | application/json |
92
-
93
- **请求体参数(AiformTemplateVO)**:
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
- ```json
137
- {
138
- "id": 1,
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
- ```json
164
- {
165
- "code": 200,
166
- "message": "SUCCESS"
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
- # AI报表文件 接口
175
-
176
- **Base URL**: `/api/v2/aiform/file`
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
- ## 3. 上传表格图片
137
+ **方法**: `upload(templateId: number): Promise<AiformFileUploadResponse>`
181
138
 
182
139
  **接口路径**: `POST /api/v2/aiform/file/upload`
183
140
 
184
- **接口描述**: 上传表格图片到 MinIO,并关联到指定的模板。上传成功后自动触发大模型解析。返回文件记录(含 code),可通过接口4轮询文件状态,通过接口5根据 code 获取解析结果和预签名访问链接。
141
+ **功能**: 上传表格图片到 MinIO,并关联到指定的模板。上传成功后自动异步触发大模型解析。
185
142
 
186
- **请求头**:
143
+ **参数**:
144
+ - `templateId` (number): 关联的模板ID,必填
187
145
 
188
- | Header | 值 |
189
- |--------|----|
190
- | Content-Type | multipart/form-data |
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
- | file | form-data | MultipartFile | 是 | 表格图片文件 |
197
- | templateId | form-data | Long | 是 | 关联的模板ID |
198
-
199
- **响应参数**:
200
-
201
- | 参数名 | 类型 | 说明 |
202
- |--------|------|------|
203
- | code | int | 状态码 |
204
- | message | String | 提示信息 |
205
- | data | File | 文件记录 |
206
-
207
- **data 字段(File,通用文件表 `app_v2_file`)**:
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
- ## 4. 根据模板ID查询上传记录
201
+ // 调用示例
202
+ uploadFile();
203
+ ```
254
204
 
255
- **接口路径**: `GET /api/v2/aiform/file/list/{templateId}`
205
+ ### 4. 根据模板ID查询上传记录
256
206
 
257
- **接口描述**: 根据模板ID查询该模板下所有上传的文件记录,按创建时间倒序排列。返回精简的文件列表(FileVO),如需解析结果或预签名访问链接请调用接口5。
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
- GET /api/v2/aiform/file/list/1
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
- | code | int | 状态码 |
276
- | message | String | 提示信息 |
277
- | data | Array\<FileVO\> | 文件记录列表 |
278
-
279
- **data 数组元素字段(FileVO)**:
280
-
281
- | 参数名 | 类型 | 说明 |
282
- |--------|------|------|
283
- | code | String | 业务编码(用于调用详情接口) |
284
- | storageName | String | 存储文件名 |
285
- | status | Integer | 状态:0-已上传 1-解析中 2-已解析 |
286
- | createUserId | Long | 创建用户ID |
287
- | createTime | String | 创建时间(RFC 3339 格式,如 `2026-03-02T10:00:00+08:00`) |
288
- | updateTime | String | 更新时间(RFC 3339 格式,如 `2026-03-02T10:05:00+08:00`) |
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
- ## 5. 根据文件code获取详情
256
+ **方法**: `detail(code: string): Promise<AiformFileDetailResponse>`
328
257
 
329
258
  **接口路径**: `GET /api/v2/aiform/file/detail/{code}`
330
259
 
331
- **接口描述**: 根据文件业务编码(code)获取解析结果和预签名访问链接。需在列表接口中获取 code 后调用。
260
+ **功能**: 根据文件业务编码获取解析结果详情。
332
261
 
333
- **请求参数**:
262
+ **参数**:
263
+ - `code` (string): 文件业务编码,必填
334
264
 
335
- | 参数名 | 位置 | 类型 | 必填 | 说明 |
336
- |--------|------|------|------|------|
337
- | code | path | String | 是 | 文件业务编码(上传或列表接口返回) |
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
- GET /api/v2/aiform/file/detail/a1b2c3d4-e5f6-7890-abcd-ef1234567890
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
- | code | int | 状态码 |
350
- | message | String | 提示信息 |
351
- | data | AiformParseResultVO | 解析结果详情 |
352
-
353
- **data 字段(AiformParseResultVO)**:
354
-
355
- | 参数名 | 类型 | 说明 |
356
- |--------|------|------|
357
- | content | String | markdown 解析的表格内容 |
358
- | unclears | Array\<String\> | 疑似不清晰处的描述说明 |
359
- | description | String | 整体解析说明 |
360
- | parseResult | String | 解析结果(兼容旧数据或解析失败时的原始结果) |
361
- | accessUrl | String | 预签名访问链接(有效期7天) |
362
-
363
- **响应示例**:
364
-
365
- ```json
366
- {
367
- "code": 200,
368
- "message": "SUCCESS",
369
- "data": {
370
- "content": "| 列1 | 列2 |\n|-----|-----|\n| 值1 | 值2 |",
371
- "unclears": ["第3行第2列字迹模糊"],
372
- "description": "表格共3行2列,已完整解析",
373
- "parseResult": null,
374
- "accessUrl": "https://minio.cpzxrobot.com/app/aiform/1/20260302100000000456.png?X-Amz-..."
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
- 上传成功后系统自动异步调用大模型(Qwen3-VL-235B)解析图片,文件状态流转如下:
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
- - `0`(已上传)→ `1`(解析中)→ `2`(已解析)
386
- - 解析失败时回退为 `0`(已上传)
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
- 解析结果持久化到 `aiform_parse_result` 表,按 `content`(表格内容)、`unclears`(疑似不清晰处)、`description`(整体说明)三个字段存储,可通过接口5根据文件 code 获取。
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
- ```json
395
- {
396
- "code": 400,
397
- "message": "FAIL"
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()` - 返回精简版文件记录,去掉了内容字段
@@ -1,207 +1,211 @@
1
- import { Cpzxrobot } from "./types";
2
- import { WarzoneGateway } from "./warzone_gateway";
3
-
4
- export class CompanyGateway extends Object {
5
- context: Cpzxrobot;
6
- warzone!: WarzoneGateway;
7
- constructor(context: Cpzxrobot) {
8
- super();
9
- this.context = context;
10
- this.warzone = new WarzoneGateway(context);
11
- }
12
-
13
- async list(pageNo: number, pageSize: number, pid: number, companyName: string) {
14
- var axios = await this.context.ready;
15
- return axios
16
- .get(`/api/v2/company/list?current=${pageNo}&size=${pageSize}&pid=${pid}&companyName=${companyName}`)
17
- }
18
-
19
- async detail(id: number) {
20
- var axios = await this.context.ready;
21
- return axios.get(`/api/v2/company/get?id=${id}`);
22
- }
23
-
24
- async create(data: any) {
25
- var axios = await this.context.ready;
26
- return axios.post(`/api/v2/company/add`, data);
27
- }
28
-
29
- async update(id: number, data: any) {
30
- var axios = await this.context.ready;
31
- data.id = id;
32
- return axios.post(`/api/v2/company/update`, data);
33
- }
34
-
35
- async delete(id: number) {
36
- var axios = await this.context.ready;
37
- return axios.get(`/api/v2/company/delete?id=${id}`);
38
- }
39
-
40
- get data() {
41
- return {
42
- export: async (companyId: string, supplier?: string,modelId?: string, startDate?: string, endDate?: string) => {
43
- var axios = await this.context.ready;
44
- return axios.getAndSave(`/api/v2/company/${companyId}/data/export`, {
45
- params: {
46
- supplier,
47
- startDate,
48
- endDate,
49
- model: modelId,
50
- }
51
- });
52
- }
53
- }
54
- }
55
-
56
- get rank() {
57
- return {
58
- byRevenue: async () => {
59
- var axios = await this.context.ready;
60
- return axios.get(`/api/v2/coremde-sale/company/revenue/rank/list`);
61
- },
62
- byProfit: async () => {
63
- var axios = await this.context.ready;
64
- return axios.get(`/api/v2/coremde-sale/company/profit/rank/list`);
65
- },
66
- byOrder: async () => {
67
- var axios = await this.context.ready;
68
- return axios.get(`/api/v2/coremde-sale/company/order/rank/list`);
69
- },
70
- }
71
- }
72
-
73
- async attribute(key: string, companyId: number | undefined = undefined) {
74
- let axios = await this.context.ready;
75
- if (!companyId) {
76
- var selectedFarm = await this.context.user.getSelectedFarm();
77
- companyId = selectedFarm.id;
78
- }
79
- return axios.get(`/api/v2/company/${companyId}/attribute?key=${key}`);
80
- }
81
-
82
- get department() {
83
- return {
84
- list: async (pid: string) => {
85
- var axios = await this.context.ready;
86
- return axios.get(`/api/v3/enterprise/department/${pid}`);
87
- },
88
- detail: async (id: string|number) => {
89
- var axios = await this.context.ready;
90
- return axios.get(`/api/v3/enterprise/department/${id}/detail`);
91
- },
92
- create: async (data: any) => {
93
- var axios = await this.context.ready;
94
- return axios.post(`/api/v3/enterprise/department`, data);
95
- },
96
- mark: async (factoryId: string, departmentId: string, kind: "maintenance") => {
97
- var axios = await this.context.ready;
98
- return axios.post(`/api/v3/enterprise/department/${factoryId}/mark`, { departmentId, kind });
99
- },
100
- users: async (id: number) => {
101
- var axios = await this.context.ready;
102
- return axios.get("/api/v2/factory/" + id + "/users");
103
- }
104
- }
105
- }
106
-
107
- get cost() {
108
- return {
109
- byMonth: async (companyId: number) => {
110
- var axios = await this.context.ready;
111
- return axios.get(`/api/v2/coremde-sale/company/cost/month/get?companyId=${companyId}`);
112
- },
113
- byYear: async (companyId: number) => {
114
- var axios = await this.context.ready;
115
- return axios.get(`/api/v2/coremde-sale/company/cost/year/get?companyId=${companyId}`);
116
- }
117
- }
118
- }
119
-
120
- get enterprise() {
121
- return {
122
- userCount: async () => {
123
- var axios = await this.context.ready;
124
- return axios.get(`/api/v2/coremde-sale/company/enterprise/count/user`);
125
- },
126
- revenue: async () => {
127
- var axios = await this.context.ready;
128
- return axios.get(`/api/v2/coremde-sale/company/enterprise/revenue/get`);
129
- }
130
- }
131
- }
132
-
133
- get revenue() {
134
- return {
135
- //按类型统计
136
- groupSummary: {
137
- byMonth: async (companyId: number, pageNo: number | undefined = undefined, pageSize: number | undefined = undefined) => {
138
- var axios = await this.context.ready;
139
- var params = {
140
- pageNo: pageNo,
141
- pageSize: pageSize,
142
- companyId: companyId
143
- }
144
- return axios.get(`/api/v2/coremde-sale/company/revenue/month/list`, {
145
- params: params
146
- });
147
- },
148
- byYear: async (companyId: number, pageNo: number | undefined = undefined, pageSize: number | undefined = undefined) => {
149
- var axios = await this.context.ready;
150
- var params = {
151
- pageNo: pageNo,
152
- pageSize: pageSize,
153
- companyId: companyId
154
- }
155
- return axios.get(`/api/v2/coremde-sale/company/revenue/year/list`, {
156
- params: params
157
- });
158
- },
159
- },
160
- //最新情况统计,最近一个月,最近十天,最近一天
161
- recentSummary: {
162
- byDay: async (companyId: number) => {
163
- var axios = await this.context.ready;
164
- return axios.get(`/api/v2/coremde-sale/company/revenue/day/get?companyId=${companyId}`);
165
- },
166
- byDecade: async (companyId: number) => {
167
- var axios = await this.context.ready;
168
- return axios.get(`/api/v2/coremde-sale/company/revenue/decade/get?companyId=${companyId}`);
169
- },
170
- byMonth: async (companyId: number) => {
171
- var axios = await this.context.ready;
172
- return axios.get(`/api/v2/coremde-sale/company/revenue/month/get?companyId=${companyId}`);
173
- },
174
- },
175
- list: async (companyId: number, pageNo: number | undefined = undefined, pageSize: number | undefined = undefined) => {
176
- var axios = await this.context.ready;
177
- var params = {
178
- pageNo: pageNo,
179
- pageSize: pageSize,
180
- companyId: companyId
181
- }
182
- return axios.get(`/api/v2/coremde-sale/company/revenue/list`, {
183
- params: params
184
- });
185
- },
186
- enterprise: async () => {
187
- var axios = await this.context.ready;
188
- return axios.get(`/api/v2/coremde-sale/company/enterprise/revenue/get`);
189
- }
190
- }
191
- }
192
-
193
- async search(args: any) {
194
- var axios = await this.context.ready;
195
- return axios.post(`/api/v2/company/query`, args);
196
- }
197
-
198
- //用于获得父节点的子节点列表,用于树形结构展示
199
- async treenode(pid: number | undefined) {
200
- var axios = await this.context.ready;
201
- if (pid == undefined) {
202
- return axios.get(`/api/tenant/groups`);
203
- }
204
- return axios.post(`/api/tenant/groups/${pid}/children`);
205
- }
206
-
207
- }
1
+ import { Cpzxrobot } from "./types";
2
+ import { WarzoneGateway } from "./warzone_gateway";
3
+
4
+ export class CompanyGateway extends Object {
5
+ context: Cpzxrobot;
6
+ warzone!: WarzoneGateway;
7
+ constructor(context: Cpzxrobot) {
8
+ super();
9
+ this.context = context;
10
+ this.warzone = new WarzoneGateway(context);
11
+ }
12
+
13
+ async list(pageNo: number, pageSize: number, pid: number,
14
+ companyName: string, type?: string) {
15
+ var params: any = {
16
+ current: pageNo, size: pageSize, pid: pid, companyName: companyName
17
+ };
18
+ var axios = await this.context.ready;
19
+ if (type) params.type = type; // 新增:可选的 type 参数
20
+ return axios.get(`/api/v2/company/list`, { params });
21
+ }
22
+
23
+ async detail(id: number) {
24
+ var axios = await this.context.ready;
25
+ return axios.get(`/api/v2/company/get?id=${id}`);
26
+ }
27
+
28
+ async create(data: any) {
29
+ var axios = await this.context.ready;
30
+ return axios.post(`/api/v2/company/add`, data);
31
+ }
32
+
33
+ async update(id: number, data: any) {
34
+ var axios = await this.context.ready;
35
+ data.id = id;
36
+ return axios.post(`/api/v2/company/update`, data);
37
+ }
38
+
39
+ async delete(id: number) {
40
+ var axios = await this.context.ready;
41
+ return axios.get(`/api/v2/company/delete?id=${id}`);
42
+ }
43
+
44
+ get data() {
45
+ return {
46
+ export: async (companyId: string, supplier?: string,modelId?: string, startDate?: string, endDate?: string) => {
47
+ var axios = await this.context.ready;
48
+ return axios.getAndSave(`/api/v2/company/${companyId}/data/export`, {
49
+ params: {
50
+ supplier,
51
+ startDate,
52
+ endDate,
53
+ model: modelId,
54
+ }
55
+ });
56
+ }
57
+ }
58
+ }
59
+
60
+ get rank() {
61
+ return {
62
+ byRevenue: async () => {
63
+ var axios = await this.context.ready;
64
+ return axios.get(`/api/v2/coremde-sale/company/revenue/rank/list`);
65
+ },
66
+ byProfit: async () => {
67
+ var axios = await this.context.ready;
68
+ return axios.get(`/api/v2/coremde-sale/company/profit/rank/list`);
69
+ },
70
+ byOrder: async () => {
71
+ var axios = await this.context.ready;
72
+ return axios.get(`/api/v2/coremde-sale/company/order/rank/list`);
73
+ },
74
+ }
75
+ }
76
+
77
+ async attribute(key: string, companyId: number | undefined = undefined) {
78
+ let axios = await this.context.ready;
79
+ if (!companyId) {
80
+ var selectedFarm = await this.context.user.getSelectedFarm();
81
+ companyId = selectedFarm.id;
82
+ }
83
+ return axios.get(`/api/v2/company/${companyId}/attribute?key=${key}`);
84
+ }
85
+
86
+ get department() {
87
+ return {
88
+ list: async (pid: string) => {
89
+ var axios = await this.context.ready;
90
+ return axios.get(`/api/v3/enterprise/department/${pid}`);
91
+ },
92
+ detail: async (id: string|number) => {
93
+ var axios = await this.context.ready;
94
+ return axios.get(`/api/v3/enterprise/department/${id}/detail`);
95
+ },
96
+ create: async (data: any) => {
97
+ var axios = await this.context.ready;
98
+ return axios.post(`/api/v3/enterprise/department`, data);
99
+ },
100
+ mark: async (factoryId: string, departmentId: string, kind: "maintenance") => {
101
+ var axios = await this.context.ready;
102
+ return axios.post(`/api/v3/enterprise/department/${factoryId}/mark`, { departmentId, kind });
103
+ },
104
+ users: async (id: number) => {
105
+ var axios = await this.context.ready;
106
+ return axios.get("/api/v2/factory/" + id + "/users");
107
+ }
108
+ }
109
+ }
110
+
111
+ get cost() {
112
+ return {
113
+ byMonth: async (companyId: number) => {
114
+ var axios = await this.context.ready;
115
+ return axios.get(`/api/v2/coremde-sale/company/cost/month/get?companyId=${companyId}`);
116
+ },
117
+ byYear: async (companyId: number) => {
118
+ var axios = await this.context.ready;
119
+ return axios.get(`/api/v2/coremde-sale/company/cost/year/get?companyId=${companyId}`);
120
+ }
121
+ }
122
+ }
123
+
124
+ get enterprise() {
125
+ return {
126
+ userCount: async () => {
127
+ var axios = await this.context.ready;
128
+ return axios.get(`/api/v2/coremde-sale/company/enterprise/count/user`);
129
+ },
130
+ revenue: async () => {
131
+ var axios = await this.context.ready;
132
+ return axios.get(`/api/v2/coremde-sale/company/enterprise/revenue/get`);
133
+ }
134
+ }
135
+ }
136
+
137
+ get revenue() {
138
+ return {
139
+ //按类型统计
140
+ groupSummary: {
141
+ byMonth: async (companyId: number, pageNo: number | undefined = undefined, pageSize: number | undefined = undefined) => {
142
+ var axios = await this.context.ready;
143
+ var params = {
144
+ pageNo: pageNo,
145
+ pageSize: pageSize,
146
+ companyId: companyId
147
+ }
148
+ return axios.get(`/api/v2/coremde-sale/company/revenue/month/list`, {
149
+ params: params
150
+ });
151
+ },
152
+ byYear: async (companyId: number, pageNo: number | undefined = undefined, pageSize: number | undefined = undefined) => {
153
+ var axios = await this.context.ready;
154
+ var params = {
155
+ pageNo: pageNo,
156
+ pageSize: pageSize,
157
+ companyId: companyId
158
+ }
159
+ return axios.get(`/api/v2/coremde-sale/company/revenue/year/list`, {
160
+ params: params
161
+ });
162
+ },
163
+ },
164
+ //最新情况统计,最近一个月,最近十天,最近一天
165
+ recentSummary: {
166
+ byDay: async (companyId: number) => {
167
+ var axios = await this.context.ready;
168
+ return axios.get(`/api/v2/coremde-sale/company/revenue/day/get?companyId=${companyId}`);
169
+ },
170
+ byDecade: async (companyId: number) => {
171
+ var axios = await this.context.ready;
172
+ return axios.get(`/api/v2/coremde-sale/company/revenue/decade/get?companyId=${companyId}`);
173
+ },
174
+ byMonth: async (companyId: number) => {
175
+ var axios = await this.context.ready;
176
+ return axios.get(`/api/v2/coremde-sale/company/revenue/month/get?companyId=${companyId}`);
177
+ },
178
+ },
179
+ list: async (companyId: number, pageNo: number | undefined = undefined, pageSize: number | undefined = undefined) => {
180
+ var axios = await this.context.ready;
181
+ var params = {
182
+ pageNo: pageNo,
183
+ pageSize: pageSize,
184
+ companyId: companyId
185
+ }
186
+ return axios.get(`/api/v2/coremde-sale/company/revenue/list`, {
187
+ params: params
188
+ });
189
+ },
190
+ enterprise: async () => {
191
+ var axios = await this.context.ready;
192
+ return axios.get(`/api/v2/coremde-sale/company/enterprise/revenue/get`);
193
+ }
194
+ }
195
+ }
196
+
197
+ async search(args: any) {
198
+ var axios = await this.context.ready;
199
+ return axios.post(`/api/v2/company/query`, args);
200
+ }
201
+
202
+ //用于获得父节点的子节点列表,用于树形结构展示
203
+ async treenode(pid: number | undefined) {
204
+ var axios = await this.context.ready;
205
+ if (pid == undefined) {
206
+ return axios.get(`/api/tenant/groups`);
207
+ }
208
+ return axios.post(`/api/tenant/groups/${pid}/children`);
209
+ }
210
+
211
+ }
@@ -17,11 +17,15 @@ class CompanyGateway extends Object {
17
17
  this.context = context;
18
18
  this.warzone = new warzone_gateway_1.WarzoneGateway(context);
19
19
  }
20
- list(pageNo, pageSize, pid, companyName) {
20
+ list(pageNo, pageSize, pid, companyName, type) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
+ var params = {
23
+ current: pageNo, size: pageSize, pid: pid, companyName: companyName
24
+ };
22
25
  var axios = yield this.context.ready;
23
- return axios
24
- .get(`/api/v2/company/list?current=${pageNo}&size=${pageSize}&pid=${pid}&companyName=${companyName}`);
26
+ if (type)
27
+ params.type = type; // 新增:可选的 type 参数
28
+ return axios.get(`/api/v2/company/list`, { params });
25
29
  });
26
30
  }
27
31
  detail(id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.118",
3
+ "version": "1.3.119",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {