@cpzxrobot/sdk 1.3.22 → 1.3.24

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/device_gateway.ts CHANGED
@@ -386,10 +386,49 @@ export class DeviceGateway extends Object {
386
386
 
387
387
  get ctrl() {
388
388
  return {
389
- // 获取设备控制参数
390
- get: (deviceId: number, type: string, no: any): Promise<any> => {
389
+ // 获取设备可控制参数
390
+ get: (deviceId: number): Promise<any> => {
391
391
  return this.context.ready.then(() => {
392
- return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${type}/${no}`)
392
+ return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/paramType`)
393
+ .then((res) => {
394
+ if (res.data.code != 200) {
395
+ throw res.data.message;
396
+ }
397
+ return res.data;
398
+ });
399
+ });
400
+ },
401
+
402
+ // 获取设备控制部件列表
403
+ parts: (deviceId: number, paramType: string): Promise<any> => {
404
+ return this.context.ready.then(() => {
405
+ return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${paramType}/parts`)
406
+ .then((res) => {
407
+ if (res.data.code != 200) {
408
+ throw res.data.message;
409
+ }
410
+ return res.data;
411
+ });
412
+ });
413
+ },
414
+
415
+ // 获取部件下的控制点
416
+ points: (deviceId: number, paramType: string, partName: string): Promise<any> => {
417
+ return this.context.ready.then(() => {
418
+ return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${paramType}/${partName}/points`)
419
+ .then((res) => {
420
+ if (res.data.code != 200) {
421
+ throw res.data.message;
422
+ }
423
+ return res.data;
424
+ });
425
+ });
426
+ },
427
+
428
+ // 设置控制点值
429
+ setPoint: (deviceId: number, paramType: string, partName: string, pointId: string, value: any): Promise<any> => {
430
+ return this.context.ready.then(() => {
431
+ return this.context.axios.post(`/api/v2/device/ctrl/${deviceId}/${paramType}/${partName}/point/${pointId}`, { value })
393
432
  .then((res) => {
394
433
  if (res.data.code != 200) {
395
434
  throw res.data.message;
@@ -412,7 +451,7 @@ export class DeviceGateway extends Object {
412
451
  });
413
452
  },
414
453
 
415
- //GET /api/v2/device/ctrl/{id}/{paramType}/configs
454
+ // 获取设备控制参数配置
416
455
  configs: (deviceId: number, type: string): Promise<any> => {
417
456
  return this.context.ready.then(() => {
418
457
  return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${type}/configs`)
@@ -284,10 +284,46 @@ class DeviceGateway extends Object {
284
284
  }
285
285
  get ctrl() {
286
286
  return {
287
- // 获取设备控制参数
288
- get: (deviceId, type, no) => {
287
+ // 获取设备可控制参数
288
+ get: (deviceId) => {
289
289
  return this.context.ready.then(() => {
290
- return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${type}/${no}`)
290
+ return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/paramType`)
291
+ .then((res) => {
292
+ if (res.data.code != 200) {
293
+ throw res.data.message;
294
+ }
295
+ return res.data;
296
+ });
297
+ });
298
+ },
299
+ // 获取设备控制部件列表
300
+ parts: (deviceId, paramType) => {
301
+ return this.context.ready.then(() => {
302
+ return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${paramType}/parts`)
303
+ .then((res) => {
304
+ if (res.data.code != 200) {
305
+ throw res.data.message;
306
+ }
307
+ return res.data;
308
+ });
309
+ });
310
+ },
311
+ // 获取部件下的控制点
312
+ points: (deviceId, paramType, partName) => {
313
+ return this.context.ready.then(() => {
314
+ return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${paramType}/${partName}/points`)
315
+ .then((res) => {
316
+ if (res.data.code != 200) {
317
+ throw res.data.message;
318
+ }
319
+ return res.data;
320
+ });
321
+ });
322
+ },
323
+ // 设置控制点值
324
+ setPoint: (deviceId, paramType, partName, pointId, value) => {
325
+ return this.context.ready.then(() => {
326
+ return this.context.axios.post(`/api/v2/device/ctrl/${deviceId}/${paramType}/${partName}/point/${pointId}`, { value })
291
327
  .then((res) => {
292
328
  if (res.data.code != 200) {
293
329
  throw res.data.message;
@@ -308,7 +344,7 @@ class DeviceGateway extends Object {
308
344
  });
309
345
  });
310
346
  },
311
- //GET /api/v2/device/ctrl/{id}/{paramType}/configs
347
+ // 获取设备控制参数配置
312
348
  configs: (deviceId, type) => {
313
349
  return this.context.ready.then(() => {
314
350
  return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${type}/configs`)
@@ -11,7 +11,7 @@ class ProductionGateway extends Object {
11
11
  * 添加产品类型
12
12
  * @param productName 产品名称
13
13
  */
14
- async addType(productName) {
14
+ async add(productName) {
15
15
  const axios = await this.context.ready;
16
16
  const factory = await this.context.user.getSelectedFarm();
17
17
  return axios.post('/api/v3/production/add', {
@@ -22,45 +22,34 @@ class ProductionGateway extends Object {
22
22
  /**
23
23
  * 获取所有产品类型列表
24
24
  */
25
- async listTypes() {
25
+ async list() {
26
26
  const axios = await this.context.ready;
27
27
  const factory = await this.context.user.getSelectedFarm();
28
28
  return axios.get(`/api/v3/production/list/${factory.id}`);
29
29
  }
30
- /**
31
- * 录入产量统计数据
32
- * @param request 统计请求参数
33
- */
34
- async createStat(request) {
35
- if (!request.factory_id) {
36
- const factory = await this.context.user.getSelectedFarm();
37
- request.factory_id = factory.id;
38
- }
39
- const axios = await this.context.ready;
40
- return axios.post('/api/v3/production/stat', {
41
- factory_id: request.factory_id,
42
- time: request.time.toISOString(),
43
- period: request.period,
44
- products: request.products
45
- });
46
- }
47
- /**
48
- * 查询产量统计数据
49
- * @param period 统计周期(month|quater|year)
50
- * @param factoryId 工厂ID
51
- */
52
- async getStats(period, factoryId) {
53
- if (!factoryId) {
54
- const factory = await this.context.user.getSelectedFarm();
55
- factoryId = factory.id;
56
- }
57
- const axios = await this.context.ready;
58
- return axios.get('/api/v3/production/stat', {
59
- params: {
60
- period,
61
- factory_id: factoryId
30
+ get stat() {
31
+ return {
32
+ get: async (type, period, factoryId) => {
33
+ if (!factoryId) {
34
+ const factory = await this.context.user.getSelectedFarm();
35
+ factoryId = factory.id;
36
+ }
37
+ const axios = await this.context.ready;
38
+ return axios.get(`/api/v3/production/stat/${type}/${period}`, {
39
+ params: {
40
+ factory_id: factoryId
41
+ }
42
+ });
43
+ },
44
+ create: async (request) => {
45
+ if (!request.factory_id) {
46
+ const factory = await this.context.user.getSelectedFarm();
47
+ request.factory_id = factory.id;
48
+ }
49
+ const axios = await this.context.ready;
50
+ return axios.post('/api/v3/production/stat', request);
62
51
  }
63
- });
52
+ };
64
53
  }
65
54
  }
66
55
  exports.ProductionGateway = ProductionGateway;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.22",
3
+ "version": "1.3.24",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { Factory, MyAxiosInstance, Unit } from "./types";
1
+ import { type Factory, type MyAxiosInstance, type Unit } from "./types";
2
2
 
3
3
  export abstract class PlatformInterface {
4
4
  appCode: string;
@@ -13,7 +13,7 @@ export class ProductionGateway extends Object {
13
13
  * 添加产品类型
14
14
  * @param productName 产品名称
15
15
  */
16
- async addType(productName: string): Promise<{ code: number; message: string }> {
16
+ async add(productName: string): Promise<{ code: number; message: string }> {
17
17
  const axios = await this.context.ready;
18
18
  const factory = await this.context.user.getSelectedFarm();
19
19
  return axios.post('/api/v3/production/add', {
@@ -25,54 +25,46 @@ export class ProductionGateway extends Object {
25
25
  /**
26
26
  * 获取所有产品类型列表
27
27
  */
28
- async listTypes(): Promise<{ types: Production[] }> {
28
+ async list(): Promise<{ types: Production[] }> {
29
29
  const axios = await this.context.ready;
30
30
  const factory = await this.context.user.getSelectedFarm();
31
31
  return axios.get(`/api/v3/production/list/${factory.id}`);
32
32
  }
33
33
 
34
- /**
35
- * 录入产量统计数据
36
- * @param request 统计请求参数
37
- */
38
- async createStat(request: {
39
- factory_id?: number;
40
- time: Date;
41
- period: number; // 1:月度, 2:季度, 3:年度
42
- products: Record<number, number>; // 产品名称到产量的映射
43
- }): Promise<void> {
44
- if (!request.factory_id) {
45
- const factory = await this.context.user.getSelectedFarm();
46
- request.factory_id = factory.id;
34
+ get stat() {
35
+ return {
36
+ get: async (
37
+ type: 'sale' | 'order' | 'production' | 'manufacture',
38
+ period: 'month' | 'quater' | 'year', factoryId?: number): Promise<Array<{
39
+ time: string;
40
+ products: Record<number, number>;
41
+ }>> => {
42
+ if (!factoryId) {
43
+ const factory = await this.context.user.getSelectedFarm();
44
+ factoryId = factory.id;
45
+ }
46
+ const axios = await this.context.ready;
47
+ return axios.get(`/api/v3/production/stat/${type}/${period}`, {
48
+ params: {
49
+ factory_id: factoryId
50
+ }
51
+ });
52
+ },
53
+ create: async (request: {
54
+ factory_id?: number;
55
+ time: Date;
56
+ period: number; // 1:月度, 2:季度, 3:年度
57
+ type: 'sale' | 'order' | 'production' | 'manufacture'
58
+ products: Record<number, number>; // 产品名称到产量的映射
59
+ }) => {
60
+ if (!request.factory_id) {
61
+ const factory = await this.context.user.getSelectedFarm();
62
+ request.factory_id = factory.id;
63
+ }
64
+ const axios = await this.context.ready;
65
+ return axios.post('/api/v3/production/stat', request);
66
+ }
47
67
  }
48
- const axios = await this.context.ready;
49
- return axios.post('/api/v3/production/stat', {
50
- factory_id: request.factory_id,
51
- time: request.time.toISOString(),
52
- period: request.period,
53
- products: request.products
54
- });
55
68
  }
56
69
 
57
- /**
58
- * 查询产量统计数据
59
- * @param period 统计周期(month|quater|year)
60
- * @param factoryId 工厂ID
61
- */
62
- async getStats(period: 'month' | 'quater' | 'year', factoryId?: number): Promise<Array<{
63
- time: string;
64
- products: Record<number, number>;
65
- }>> {
66
- if (!factoryId) {
67
- const factory = await this.context.user.getSelectedFarm();
68
- factoryId = factory.id;
69
- }
70
- const axios = await this.context.ready;
71
- return axios.get('/api/v3/production/stat', {
72
- params: {
73
- period,
74
- factory_id: factoryId
75
- }
76
- });
77
- }
78
70
  }