@cpzxrobot/sdk 1.3.115 → 1.3.117
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/mobile_platform.js +5 -0
- package/dist/production_gateway.js +2 -0
- package/dist/user_gateway.js +4 -0
- package/dist/web_platform.js +17 -0
- package/dist/windows_platform.js +7 -0
- package/mobile_platform.ts +4 -0
- package/package.json +1 -1
- package/platform_interface.ts +1 -0
- package/production_gateway.ts +2 -0
- package/user_gateway.ts +5 -0
- package/web_platform.ts +15 -0
- package/windows_platform.ts +5 -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/dist/mobile_platform.js
CHANGED
|
@@ -131,6 +131,11 @@ class MobilePlatform {
|
|
|
131
131
|
return this.platform.callHandler("app.scanQrcode");
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
+
getUserFromCache(userId) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
return this.platform.callHandler("app.getUserFromCache", userId);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
134
139
|
setTitle(title) {
|
|
135
140
|
this.platform.callHandler("app.setTitle", title);
|
|
136
141
|
}
|
package/dist/user_gateway.js
CHANGED
|
@@ -313,6 +313,10 @@ class UserGateway extends Object {
|
|
|
313
313
|
var factory = yield this.context.user.getSelectedFarm();
|
|
314
314
|
var url = '/api/v1/user/info';
|
|
315
315
|
if (userId) {
|
|
316
|
+
var userInCache = yield this.context.platform.getUserFromCache(userId);
|
|
317
|
+
if (userInCache) {
|
|
318
|
+
return userInCache;
|
|
319
|
+
}
|
|
316
320
|
url += `/${userId}`;
|
|
317
321
|
}
|
|
318
322
|
return axios.get(url, {
|
package/dist/web_platform.js
CHANGED
|
@@ -395,6 +395,23 @@ class WebPlatform {
|
|
|
395
395
|
}
|
|
396
396
|
return Promise.resolve(this._selectedUnit);
|
|
397
397
|
}
|
|
398
|
+
getUserFromCache(userId) {
|
|
399
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
// 从本地缓存中获取用户数据
|
|
401
|
+
const userKey = `user_${userId}`;
|
|
402
|
+
const userData = localStorage.getItem(userKey);
|
|
403
|
+
if (userData) {
|
|
404
|
+
try {
|
|
405
|
+
return JSON.parse(userData);
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
console.error('Failed to parse user data from cache:', error);
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
});
|
|
414
|
+
}
|
|
398
415
|
jumpToMiniApp(url) {
|
|
399
416
|
window.location.href = url;
|
|
400
417
|
return Promise.resolve();
|
package/dist/windows_platform.js
CHANGED
|
@@ -148,5 +148,12 @@ class WindwosMiniAppPlatform {
|
|
|
148
148
|
// @ts-ignore
|
|
149
149
|
(_a = window.miniapp) === null || _a === void 0 ? void 0 : _a.aiAssist(args);
|
|
150
150
|
}
|
|
151
|
+
getUserFromCache(userId) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
return yield ((_a = window.miniapp) === null || _a === void 0 ? void 0 : _a.getUserFromCache(userId));
|
|
156
|
+
});
|
|
157
|
+
}
|
|
151
158
|
}
|
|
152
159
|
exports.WindwosMiniAppPlatform = WindwosMiniAppPlatform;
|
package/mobile_platform.ts
CHANGED
|
@@ -130,6 +130,10 @@ export class MobilePlatform implements PlatformInterface {
|
|
|
130
130
|
return this.platform.callHandler("app.scanQrcode");
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
async getUserFromCache(userId: number): Promise<any> {
|
|
134
|
+
return this.platform.callHandler("app.getUserFromCache", userId);
|
|
135
|
+
}
|
|
136
|
+
|
|
133
137
|
setTitle(title: string): void {
|
|
134
138
|
this.platform.callHandler("app.setTitle", title);
|
|
135
139
|
}
|
package/package.json
CHANGED
package/platform_interface.ts
CHANGED
package/production_gateway.ts
CHANGED
package/user_gateway.ts
CHANGED
|
@@ -342,6 +342,11 @@ export class UserGateway extends Object {
|
|
|
342
342
|
var factory = await this.context.user.getSelectedFarm()
|
|
343
343
|
var url = '/api/v1/user/info'
|
|
344
344
|
if (userId) {
|
|
345
|
+
var userInCache = await this.context.platform.getUserFromCache(userId);
|
|
346
|
+
if (userInCache) {
|
|
347
|
+
return userInCache
|
|
348
|
+
}
|
|
349
|
+
|
|
345
350
|
url += `/${userId}`
|
|
346
351
|
}
|
|
347
352
|
return axios.get(url, {
|
package/web_platform.ts
CHANGED
|
@@ -399,6 +399,21 @@ export class WebPlatform implements PlatformInterface {
|
|
|
399
399
|
return Promise.resolve(this._selectedUnit);
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
+
async getUserFromCache(userId: number): Promise<any> {
|
|
403
|
+
// 从本地缓存中获取用户数据
|
|
404
|
+
const userKey = `user_${userId}`;
|
|
405
|
+
const userData = localStorage.getItem(userKey);
|
|
406
|
+
if (userData) {
|
|
407
|
+
try {
|
|
408
|
+
return JSON.parse(userData);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
console.error('Failed to parse user data from cache:', error);
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
|
|
402
417
|
jumpToMiniApp(url: string): Promise<void> {
|
|
403
418
|
window.location.href = url;
|
|
404
419
|
return Promise.resolve();
|
package/windows_platform.ts
CHANGED
|
@@ -139,4 +139,9 @@ export class WindwosMiniAppPlatform implements PlatformInterface {
|
|
|
139
139
|
// @ts-ignore
|
|
140
140
|
window.miniapp?.aiAssist(args);
|
|
141
141
|
}
|
|
142
|
+
|
|
143
|
+
async getUserFromCache(userId: number): Promise<any> {
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
return await window.miniapp?.getUserFromCache(userId);
|
|
146
|
+
}
|
|
142
147
|
}
|