@cpzxrobot/sdk 1.3.115 → 1.3.116
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 +196 -1
- package/aiform_gateway.ts +2 -6
- package/dist/aiform_gateway.js +1 -5
- package/dist/production_gateway.js +2 -0
- package/package.json +1 -1
- package/production_gateway.ts +2 -0
package/AIFORM_GATEWAY.md
CHANGED
|
@@ -12,6 +12,8 @@ AI报表模板接口用于管理工厂的AI报表模板,包括查询模板列
|
|
|
12
12
|
|
|
13
13
|
通过 `cpzxrobot().aiform.template` 访问AI报表模板相关功能。
|
|
14
14
|
|
|
15
|
+
通过 `cpzxrobot().aiform.record` 访问文件上传和记录相关功能。
|
|
16
|
+
|
|
15
17
|
## 可用方法
|
|
16
18
|
|
|
17
19
|
### 1. 查询模板列表
|
|
@@ -130,6 +132,180 @@ if (response.code === 200) {
|
|
|
130
132
|
}
|
|
131
133
|
```
|
|
132
134
|
|
|
135
|
+
### 3. 上传表格图片
|
|
136
|
+
|
|
137
|
+
**方法**: `upload(file: File, templateId: number): Promise<AiformFileUploadResponse>`
|
|
138
|
+
|
|
139
|
+
**接口路径**: `POST /api/v2/aiform/file/upload`
|
|
140
|
+
|
|
141
|
+
**功能**: 上传表格图片到 MinIO,并关联到指定的模板。上传成功后自动异步触发大模型解析。
|
|
142
|
+
|
|
143
|
+
**参数**:
|
|
144
|
+
- `file` (File): 表格图片文件,必填
|
|
145
|
+
- `templateId` (number): 关联的模板ID,必填
|
|
146
|
+
|
|
147
|
+
**返回值**:
|
|
148
|
+
```typescript
|
|
149
|
+
interface AiformFileUploadResponse {
|
|
150
|
+
code: number; // 状态码
|
|
151
|
+
message: string; // 提示信息
|
|
152
|
+
data: File; // 文件记录
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface File {
|
|
156
|
+
id: number; // 文件记录ID
|
|
157
|
+
code?: string; // 业务编码
|
|
158
|
+
tableKey: number; // 关联业务ID(模板ID)
|
|
159
|
+
tableName: string; // 关联业务表名(固定值 aiform_template)
|
|
160
|
+
fileName: string; // 原始文件名
|
|
161
|
+
storageName: string; // 存储文件名
|
|
162
|
+
fileUrl: string; // MinIO存储路径
|
|
163
|
+
accessUrl: string; // 预签名访问链接
|
|
164
|
+
fileExt: string; // 文件扩展名
|
|
165
|
+
server: string; // 存储服务(minio)
|
|
166
|
+
type: string; // 文件类型(image)
|
|
167
|
+
status: number; // 状态:0-已上传 1-解析中 2-已解析
|
|
168
|
+
createTime: string; // 创建时间
|
|
169
|
+
updateTime: string; // 更新时间
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**使用示例**:
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
// HTML文件输入示例
|
|
177
|
+
<input type="file" id="fileInput" accept="image/*">
|
|
178
|
+
|
|
179
|
+
// 上传文件
|
|
180
|
+
async function uploadFile() {
|
|
181
|
+
const fileInput = document.getElementById('fileInput');
|
|
182
|
+
const file = fileInput.files[0];
|
|
183
|
+
const templateId = 1; // 模板ID
|
|
184
|
+
|
|
185
|
+
if (!file) {
|
|
186
|
+
alert('请选择文件');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const response = await cpzxrobot().aiform.record.upload(file, templateId);
|
|
192
|
+
console.log('上传成功:', response.data);
|
|
193
|
+
console.log('文件状态:', getFileStatusText(response.data.status));
|
|
194
|
+
console.log('访问链接:', response.data.accessUrl);
|
|
195
|
+
|
|
196
|
+
// 可以开始轮询状态
|
|
197
|
+
trackFileStatus(templateId, response.data.id);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error('上传失败:', error.message);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function getFileStatusText(status) {
|
|
204
|
+
const statusMap = {
|
|
205
|
+
0: '已上传',
|
|
206
|
+
1: '解析中',
|
|
207
|
+
2: '已解析'
|
|
208
|
+
};
|
|
209
|
+
return statusMap[status] || '未知';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 绑定事件
|
|
213
|
+
document.getElementById('fileInput').addEventListener('change', uploadFile);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 4. 根据模板ID查询上传记录
|
|
217
|
+
|
|
218
|
+
**方法**: `list(templateId: number): Promise<AiformFileListResponse>`
|
|
219
|
+
|
|
220
|
+
**接口路径**: `GET /api/v2/aiform/file/list/{templateId}`
|
|
221
|
+
|
|
222
|
+
**功能**: 根据模板ID查询该模板下所有上传的文件记录,按创建时间倒序排列。
|
|
223
|
+
|
|
224
|
+
**参数**:
|
|
225
|
+
- `templateId` (number): 模板ID,必填
|
|
226
|
+
|
|
227
|
+
**返回值**:
|
|
228
|
+
```typescript
|
|
229
|
+
interface AiformFileListResponse {
|
|
230
|
+
code: number; // 状态码
|
|
231
|
+
message: string; // 提示信息
|
|
232
|
+
data: File[]; // 文件记录列表
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**使用示例**:
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
// 获取模板的上传记录
|
|
240
|
+
async function getTemplateRecords(templateId) {
|
|
241
|
+
try {
|
|
242
|
+
const response = await cpzxrobot().aiform.record.list(templateId);
|
|
243
|
+
|
|
244
|
+
if (response.code === 200) {
|
|
245
|
+
const records = response.data;
|
|
246
|
+
console.log(`找到 ${records.length} 条上传记录:`);
|
|
247
|
+
|
|
248
|
+
records.forEach((record, index) => {
|
|
249
|
+
console.log(`\n记录 ${index + 1}:`);
|
|
250
|
+
console.log(`文件名: ${record.fileName}`);
|
|
251
|
+
console.log(`状态: ${getFileStatusText(record.status)}`);
|
|
252
|
+
console.log(`创建时间: ${record.createTime}`);
|
|
253
|
+
console.log(`访问链接: ${record.accessUrl}`);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.error('获取记录失败:', error.message);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 调用示例
|
|
262
|
+
getTemplateRecords(1); // 查询模板ID为1的上传记录
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 5. 轮询文件解析状态
|
|
266
|
+
|
|
267
|
+
**功能**: 上传文件后,需要轮询文件状态以确认解析进度。
|
|
268
|
+
|
|
269
|
+
**使用示例**:
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
async function trackFileStatus(templateId, fileId) {
|
|
273
|
+
let status = 0; // 初始状态
|
|
274
|
+
let attempts = 0;
|
|
275
|
+
const maxAttempts = 30; // 最多轮询30次
|
|
276
|
+
|
|
277
|
+
console.log('开始跟踪文件解析状态...');
|
|
278
|
+
|
|
279
|
+
while (status !== 2 && attempts < maxAttempts) {
|
|
280
|
+
try {
|
|
281
|
+
const response = await cpzxrobot().aiform.record.list(templateId);
|
|
282
|
+
const fileRecord = response.data.find(record => record.id === fileId);
|
|
283
|
+
|
|
284
|
+
if (fileRecord) {
|
|
285
|
+
status = fileRecord.status;
|
|
286
|
+
console.log(`当前状态: ${getFileStatusText(status)}`);
|
|
287
|
+
|
|
288
|
+
if (status === 2) {
|
|
289
|
+
console.log('文件已成功解析!');
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
await new Promise(resolve => setTimeout(resolve, 5000)); // 每5秒轮询一次
|
|
295
|
+
attempts++;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.error('轮询失败:', error.message);
|
|
298
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
299
|
+
attempts++;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (attempts >= maxAttempts) {
|
|
304
|
+
console.log('解析超时,请稍后手动检查状态');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
133
309
|
## 错误处理
|
|
134
310
|
|
|
135
311
|
### 常见错误
|
|
@@ -138,6 +314,8 @@ if (response.code === 200) {
|
|
|
138
314
|
- `工厂ID不能为空` - 未提供factoryId参数
|
|
139
315
|
- `模板名称不能为空` - 未提供name参数
|
|
140
316
|
- `模板内容不能为空` - 未提供content参数
|
|
317
|
+
- `文件不能为空` - 未提供file参数
|
|
318
|
+
- `模板ID不能为空` - 未提供templateId参数
|
|
141
319
|
|
|
142
320
|
2. **API错误**:
|
|
143
321
|
- 当API返回非200状态码时,会抛出包含错误信息的异常
|
|
@@ -164,6 +342,23 @@ try {
|
|
|
164
342
|
} catch (error) {
|
|
165
343
|
console.error('保存失败:', error.message);
|
|
166
344
|
}
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
// 尝试上传文件
|
|
348
|
+
const file = document.getElementById('fileInput').files[0];
|
|
349
|
+
const response = await cpzxrobot().aiform.record.upload(file, 1);
|
|
350
|
+
console.log('上传成功:', response.data);
|
|
351
|
+
} catch (error) {
|
|
352
|
+
console.error('上传失败:', error.message);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
// 尝试获取上传记录
|
|
357
|
+
const response = await cpzxrobot().aiform.record.list(1);
|
|
358
|
+
console.log('上传记录:', response.data);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.error('获取记录失败:', error.message);
|
|
361
|
+
}
|
|
167
362
|
```
|
|
168
363
|
|
|
169
364
|
## 完整使用示例
|
|
@@ -250,5 +445,5 @@ manageAITemplates();
|
|
|
250
445
|
|
|
251
446
|
## 版本信息
|
|
252
447
|
|
|
253
|
-
- **SDK版本**: 1.3.
|
|
448
|
+
- **SDK版本**: 1.3.114+
|
|
254
449
|
- **接口版本**: v2
|
package/aiform_gateway.ts
CHANGED
|
@@ -77,17 +77,13 @@ export class AiformGateway extends Object {
|
|
|
77
77
|
* @param templateId 关联的模板ID
|
|
78
78
|
* @returns Promise 包含文件记录信息
|
|
79
79
|
*/
|
|
80
|
-
upload: async (
|
|
80
|
+
upload: async (templateId: number): Promise<AiformFileUploadResponse> => {
|
|
81
81
|
const axios = await this.context.ready;
|
|
82
82
|
|
|
83
|
-
// 参数验证
|
|
84
|
-
if (!file) {
|
|
85
|
-
throw new Error('文件不能为空');
|
|
86
|
-
}
|
|
87
83
|
if (!templateId) {
|
|
88
84
|
throw new Error('模板ID不能为空');
|
|
89
85
|
}
|
|
90
|
-
|
|
86
|
+
|
|
91
87
|
return axios.upload(`/api/v2/aiform/file/upload`,{
|
|
92
88
|
title: "请选择要解析的表格图片",
|
|
93
89
|
data: {
|
package/dist/aiform_gateway.js
CHANGED
|
@@ -71,12 +71,8 @@ class AiformGateway extends Object {
|
|
|
71
71
|
* @param templateId 关联的模板ID
|
|
72
72
|
* @returns Promise 包含文件记录信息
|
|
73
73
|
*/
|
|
74
|
-
upload: (
|
|
74
|
+
upload: (templateId) => __awaiter(this, void 0, void 0, function* () {
|
|
75
75
|
const axios = yield this.context.ready;
|
|
76
|
-
// 参数验证
|
|
77
|
-
if (!file) {
|
|
78
|
-
throw new Error('文件不能为空');
|
|
79
|
-
}
|
|
80
76
|
if (!templateId) {
|
|
81
77
|
throw new Error('模板ID不能为空');
|
|
82
78
|
}
|
package/package.json
CHANGED