@cpzxrobot/sdk 1.3.20 → 1.3.21

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
@@ -204,8 +204,8 @@ export class DeviceGateway extends Object {
204
204
 
205
205
  //获取设备详情
206
206
  //ID:点位ID,设备UUID,当type是device时,为设备ID(UUID);当type是datapoint时,为点位ID(number)
207
- show(id: any, type: "device"|"datapoint" = "datapoint"){
208
- this.context.platform.showInDeviceManager(id,type);
207
+ show(id: any, type: "device" | "datapoint" = "datapoint") {
208
+ this.context.platform.showInDeviceManager(id, type);
209
209
  }
210
210
 
211
211
  async watch(
@@ -367,9 +367,9 @@ export class DeviceGateway extends Object {
367
367
  }
368
368
 
369
369
  // 设备生产商 GET /api/v2/device/manufacturers
370
- manufacturers(category: string|undefined = undefined): Promise<any> {
370
+ manufacturers(category: string | undefined = undefined): Promise<any> {
371
371
  return this.context.ready.then(() => {
372
- return this.context.axios.get("/api/v2/device/manufacturers",{
372
+ return this.context.axios.get("/api/v2/device/manufacturers", {
373
373
  params: {
374
374
  category
375
375
  }
@@ -382,7 +382,7 @@ export class DeviceGateway extends Object {
382
382
  });
383
383
  });
384
384
  }
385
-
385
+
386
386
 
387
387
  get ctrl() {
388
388
  return {
@@ -426,4 +426,123 @@ export class DeviceGateway extends Object {
426
426
  }
427
427
  };
428
428
  }
429
+
430
+ get v3() {
431
+ //v1的设备实际是点位,v3的设备才是真正的设备
432
+ return {
433
+ list: (args: {
434
+ limit?: number;
435
+ offset?: number;
436
+ factoryId?: number;
437
+ } = {}): Promise<any> => {
438
+ return this.context.ready.then(async () => {
439
+
440
+ if (args.factoryId == undefined) {
441
+ var farm = await this.context.user.getSelectedFarm();
442
+ args.factoryId = farm.id;
443
+ }
444
+
445
+ return this.context.axios.get(`/api/v3/device/list`, {
446
+ params: {
447
+ limit: args.limit,
448
+ offset: args.offset,
449
+ factory_id: args.factoryId
450
+ }
451
+ });
452
+ });
453
+ },
454
+ detail: (id: number): Promise<any> => {
455
+ return this.context.ready.then(() => {
456
+ return this.context.axios.get(`/api/v3/device/detail/${id}`);
457
+ });
458
+ },
459
+ manufacturer: (id: number): Promise<any> => {
460
+ return this.context.ready.then(() => {
461
+ return this.context.axios.get(`/api/v3/device/manufacturer/${id}`);
462
+ });
463
+ },
464
+ manufacturers: (): Promise<any> => {
465
+ return this.context.ready.then(() => {
466
+ return this.context.axios.get(`/api/v3/device/manufacturer/list`);
467
+ });
468
+ }
469
+ }
470
+ }
471
+
472
+ get purpose() {
473
+ return {
474
+ list: (parentId: number | undefined): Promise<any> => {
475
+ return this.context.ready.then(() => {
476
+ if (parentId == undefined) {
477
+ return this.context.axios.get(`/api/v3/device/purpose`);
478
+ } else {
479
+ return this.context.axios.get(`/api/v3/device/purpose/${parentId}`);
480
+ }
481
+ });
482
+ },
483
+
484
+ create: (data: {
485
+ name: string;
486
+ code: string;
487
+ parts?: string[];
488
+ faultCategories?: string[];
489
+ isImportant?: boolean;
490
+ importantParams?: string;
491
+ parentId?: number;
492
+ path?: string;
493
+ }): Promise<any> => {
494
+ return this.context.ready.then(() => {
495
+ return this.context.axios.post(`/api/v3/device/purpose`, data);
496
+ });
497
+ },
498
+
499
+ delete: (id: number): Promise<any> => {
500
+ return this.context.ready.then(() => {
501
+ return this.context.axios.delete(`/api/v3/device/purpose/${id}`);
502
+ });
503
+ }
504
+ }
505
+ }
506
+
507
+ get model() {
508
+ return {
509
+ list: async (manufacturerId: Number | undefined): Promise<any> => {
510
+ var axios = await this.context.ready;
511
+ if (manufacturerId === undefined) {
512
+ return axios.get('/api/v3/device/model');
513
+ } else {
514
+ return axios.get('/api/v3/device/model', { params: { manufacturerId } });
515
+ }
516
+ },
517
+
518
+ create: async (data: {
519
+ name: string;
520
+ code: string;
521
+ category?: string;
522
+ manufacturerId?: number;
523
+ connectionCategory?: number;
524
+ connectionType?: number;
525
+ }): Promise<any> => {
526
+ var axios = await this.context.ready;
527
+ return axios.post('/api/v3/device/model', data);
528
+ },
529
+
530
+ update: async (id: number, data: {
531
+ name?: string;
532
+ code?: string;
533
+ category?: string;
534
+ manufacturerId?: number;
535
+ connectionCategory?: number;
536
+ connectionType?: number;
537
+ }): Promise<any> => {
538
+ var axios = await this.context.ready;
539
+ return axios.put(`/api/v3/device/model/${id}`, data);
540
+ },
541
+
542
+ delete: async (id: number): Promise<any> => {
543
+ var axios = await this.context.ready;
544
+ return axios.delete(`/api/v3/device/model/${id}`);
545
+ }
546
+ }
547
+ }
429
548
  }
@@ -322,5 +322,89 @@ class DeviceGateway extends Object {
322
322
  }
323
323
  };
324
324
  }
325
+ get v3() {
326
+ //v1的设备实际是点位,v3的设备才是真正的设备
327
+ return {
328
+ list: (args = {}) => {
329
+ return this.context.ready.then(async () => {
330
+ if (args.factoryId == undefined) {
331
+ var farm = await this.context.user.getSelectedFarm();
332
+ args.factoryId = farm.id;
333
+ }
334
+ return this.context.axios.get(`/api/v3/device/list`, {
335
+ params: {
336
+ limit: args.limit,
337
+ offset: args.offset,
338
+ factory_id: args.factoryId
339
+ }
340
+ });
341
+ });
342
+ },
343
+ detail: (id) => {
344
+ return this.context.ready.then(() => {
345
+ return this.context.axios.get(`/api/v3/device/detail/${id}`);
346
+ });
347
+ },
348
+ manufacturer: (id) => {
349
+ return this.context.ready.then(() => {
350
+ return this.context.axios.get(`/api/v3/device/manufacturer/${id}`);
351
+ });
352
+ },
353
+ manufacturers: () => {
354
+ return this.context.ready.then(() => {
355
+ return this.context.axios.get(`/api/v3/device/manufacturer/list`);
356
+ });
357
+ }
358
+ };
359
+ }
360
+ get purpose() {
361
+ return {
362
+ list: (parentId) => {
363
+ return this.context.ready.then(() => {
364
+ if (parentId == undefined) {
365
+ return this.context.axios.get(`/api/v3/device/purpose`);
366
+ }
367
+ else {
368
+ return this.context.axios.get(`/api/v3/device/purpose/${parentId}`);
369
+ }
370
+ });
371
+ },
372
+ create: (data) => {
373
+ return this.context.ready.then(() => {
374
+ return this.context.axios.post(`/api/v3/device/purpose`, data);
375
+ });
376
+ },
377
+ delete: (id) => {
378
+ return this.context.ready.then(() => {
379
+ return this.context.axios.delete(`/api/v3/device/purpose/${id}`);
380
+ });
381
+ }
382
+ };
383
+ }
384
+ get model() {
385
+ return {
386
+ list: async (manufacturerId) => {
387
+ var axios = await this.context.ready;
388
+ if (manufacturerId === undefined) {
389
+ return axios.get('/api/v3/device/model');
390
+ }
391
+ else {
392
+ return axios.get('/api/v3/device/model', { params: { manufacturerId } });
393
+ }
394
+ },
395
+ create: async (data) => {
396
+ var axios = await this.context.ready;
397
+ return axios.post('/api/v3/device/model', data);
398
+ },
399
+ update: async (id, data) => {
400
+ var axios = await this.context.ready;
401
+ return axios.put(`/api/v3/device/model/${id}`, data);
402
+ },
403
+ delete: async (id) => {
404
+ var axios = await this.context.ready;
405
+ return axios.delete(`/api/v3/device/model/${id}`);
406
+ }
407
+ };
408
+ }
325
409
  }
326
410
  exports.DeviceGateway = DeviceGateway;
package/dist/index.js CHANGED
@@ -51,6 +51,7 @@ const construction_gateway_1 = require("./construction_gateway");
51
51
  const system_gateway_1 = require("./system_gateway");
52
52
  const mobile_platform_1 = require("./mobile_platform");
53
53
  const web_platform_1 = require("./web_platform");
54
+ const production_gateway_1 = require("./production_gateway");
54
55
  class Cpzxrobot {
55
56
  constructor(appCode, baseUrl, initSelectedFactory, initSelectedUnit) {
56
57
  this.pigfarm = new pigfarm_gateway_1.PigfarmGateway(this);
@@ -71,6 +72,7 @@ class Cpzxrobot {
71
72
  this.ai = new ai_gateway_1.AiGateway(this);
72
73
  this.construction = new construction_gateway_1.ConstructionGateway(this);
73
74
  this.system = new system_gateway_1.SystemGateway(this);
75
+ this.production = new production_gateway_1.ProductionGateway(this);
74
76
  this.sseCallbacks = {};
75
77
  //获取当前浏览器的域名
76
78
  this.ready = new Promise((resolve, reject) => {
@@ -65,6 +65,12 @@ class MobilePlatform {
65
65
  getAndSave: function (url, config) {
66
66
  return that.platform.callHandler("axios_getAndSave", url, config);
67
67
  },
68
+ delete: function (url, data) {
69
+ return that.platform.callHandler("axios_exec", "DELETE", url, data);
70
+ },
71
+ put: function (url, data) {
72
+ return that.platform.callHandler("axios_exec", "PUT", url, data);
73
+ },
68
74
  getAndPreview: function (url, config) {
69
75
  if (config == undefined) {
70
76
  config = {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProductionGateway = void 0;
4
+ // 产量统计网关,管理工厂产量数据
5
+ class ProductionGateway extends Object {
6
+ constructor(context) {
7
+ super();
8
+ this.context = context;
9
+ }
10
+ /**
11
+ * 添加产品类型
12
+ * @param productName 产品名称
13
+ */
14
+ async addType(productName) {
15
+ const axios = await this.context.ready;
16
+ return axios.post('/api/v3/production/add', {
17
+ product_name: productName
18
+ });
19
+ }
20
+ /**
21
+ * 获取所有产品类型列表
22
+ */
23
+ async listTypes() {
24
+ const axios = await this.context.ready;
25
+ return axios.get('/api/v3/production/list');
26
+ }
27
+ /**
28
+ * 录入产量统计数据
29
+ * @param request 统计请求参数
30
+ */
31
+ async createStat(request) {
32
+ if (!request.factory_id) {
33
+ const factory = await this.context.user.getSelectedFarm();
34
+ request.factory_id = factory.id;
35
+ }
36
+ const axios = await this.context.ready;
37
+ return axios.post('/api/v3/production/stat', {
38
+ factory_id: request.factory_id,
39
+ time: request.time.toISOString(),
40
+ period: request.period,
41
+ products: request.products
42
+ });
43
+ }
44
+ /**
45
+ * 查询产量统计数据
46
+ * @param period 统计周期(month|quater|year)
47
+ * @param factoryId 工厂ID
48
+ */
49
+ async getStats(period, factoryId) {
50
+ if (!factoryId) {
51
+ const factory = await this.context.user.getSelectedFarm();
52
+ factoryId = factory.id;
53
+ }
54
+ const axios = await this.context.ready;
55
+ return axios.get('/api/v3/production/stat', {
56
+ params: {
57
+ period,
58
+ factory_id: factoryId
59
+ }
60
+ });
61
+ }
62
+ }
63
+ exports.ProductionGateway = ProductionGateway;
@@ -126,6 +126,21 @@ class WebPlatform {
126
126
  return response.blob();
127
127
  }
128
128
  },
129
+ delete: async (url, data, config) => {
130
+ const response = await this.fetchWithAuth(url, {
131
+ method: 'DELETE',
132
+ headers: config === null || config === void 0 ? void 0 : config.headers
133
+ });
134
+ return { data: await response.json() };
135
+ },
136
+ put: async (url, data, config) => {
137
+ const response = await this.fetchWithAuth(url, {
138
+ method: 'PUT',
139
+ headers: Object.assign({ 'Content-Type': 'application/json' }, config === null || config === void 0 ? void 0 : config.headers),
140
+ body: JSON.stringify(data)
141
+ });
142
+ return { data: await response.json() };
143
+ },
129
144
  post: async (url, data, config) => {
130
145
  const response = await this.fetchWithAuth(url, {
131
146
  method: 'POST',
package/index.ts CHANGED
@@ -26,6 +26,7 @@ import { ConstructionGateway } from "./construction_gateway";
26
26
  import { SystemGateway } from "./system_gateway";
27
27
  import { MobilePlatform } from "./mobile_platform";
28
28
  import { WebPlatform } from "./web_platform";
29
+ import { ProductionGateway } from "./production_gateway";
29
30
 
30
31
  export class Cpzxrobot {
31
32
  private static factorySelectorLoaded = false;
@@ -66,6 +67,7 @@ export class Cpzxrobot {
66
67
  ai: AiGateway = new AiGateway(this);
67
68
  construction: ConstructionGateway = new ConstructionGateway(this);
68
69
  system: SystemGateway = new SystemGateway(this);
70
+ production: ProductionGateway = new ProductionGateway(this);
69
71
  sseCallbacks: {
70
72
  [key: string]: (data: any) => void;
71
73
  } = {};
@@ -77,6 +77,12 @@ export class MobilePlatform implements PlatformInterface {
77
77
  getAndSave: function (url, config) {
78
78
  return that.platform.callHandler("axios_getAndSave", url, config);
79
79
  },
80
+ delete: function (url, data) {
81
+ return that.platform.callHandler("axios_exec", "DELETE", url, data);
82
+ },
83
+ put: function (url, data) {
84
+ return that.platform.callHandler("axios_exec", "PUT", url, data);
85
+ },
80
86
  getAndPreview: function (url, config) {
81
87
  if (config == undefined) {
82
88
  config = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,75 @@
1
+ import { Cpzxrobot, Production } from ".";
2
+
3
+ // 产量统计网关,管理工厂产量数据
4
+ export class ProductionGateway extends Object {
5
+ context: Cpzxrobot;
6
+
7
+ constructor(context: Cpzxrobot) {
8
+ super();
9
+ this.context = context;
10
+ }
11
+
12
+ /**
13
+ * 添加产品类型
14
+ * @param productName 产品名称
15
+ */
16
+ async addType(productName: string): Promise<{ code: number; message: string }> {
17
+ const axios = await this.context.ready;
18
+ return axios.post('/api/v3/production/add', {
19
+ product_name: productName
20
+ });
21
+ }
22
+
23
+ /**
24
+ * 获取所有产品类型列表
25
+ */
26
+ async listTypes(): Promise<{ types: Production[] }> {
27
+ const axios = await this.context.ready;
28
+ return axios.get('/api/v3/production/list');
29
+ }
30
+
31
+ /**
32
+ * 录入产量统计数据
33
+ * @param request 统计请求参数
34
+ */
35
+ async createStat(request: {
36
+ factory_id?: number;
37
+ time: Date;
38
+ period: number; // 1:月度, 2:季度, 3:年度
39
+ products: Record<number, number>; // 产品名称到产量的映射
40
+ }): Promise<void> {
41
+ if (!request.factory_id) {
42
+ const factory = await this.context.user.getSelectedFarm();
43
+ request.factory_id = factory.id;
44
+ }
45
+ const axios = await this.context.ready;
46
+ return axios.post('/api/v3/production/stat', {
47
+ factory_id: request.factory_id,
48
+ time: request.time.toISOString(),
49
+ period: request.period,
50
+ products: request.products
51
+ });
52
+ }
53
+
54
+ /**
55
+ * 查询产量统计数据
56
+ * @param period 统计周期(month|quater|year)
57
+ * @param factoryId 工厂ID
58
+ */
59
+ async getStats(period: 'month' | 'quater' | 'year', factoryId?: number): Promise<Array<{
60
+ time: string;
61
+ products: Record<number, number>;
62
+ }>> {
63
+ if (!factoryId) {
64
+ const factory = await this.context.user.getSelectedFarm();
65
+ factoryId = factory.id;
66
+ }
67
+ const axios = await this.context.ready;
68
+ return axios.get('/api/v3/production/stat', {
69
+ params: {
70
+ period,
71
+ factory_id: factoryId
72
+ }
73
+ });
74
+ }
75
+ }
package/types.d.ts CHANGED
@@ -263,6 +263,11 @@ type FeedTowerV2 = {
263
263
  buildTime: string;
264
264
  };
265
265
 
266
+ type Production = {
267
+ id: number;
268
+ name: string;
269
+ };
270
+
266
271
  type FeedTower = {
267
272
  id: number;
268
273
  name: string;
@@ -284,6 +289,7 @@ type FeedTower = {
284
289
  interface MyAxiosInstance {
285
290
  get: (url: string, config?: any) => Promise<any>;
286
291
  post: (url: string, data?: any, config?: any) => Promise<any>;
292
+ put: (url: string, data?: any, config?: any) => Promise<any>;
287
293
  getAndSave: (url: string, data?: {
288
294
  fileName?: string;
289
295
  params?: any;
@@ -302,6 +308,7 @@ interface MyAxiosInstance {
302
308
  //option.data:上传的数据,例如{id:123,name:"xxx"},文件会被附加到data中,作为文件字段上传
303
309
  upload: (url: string, option?: {}) => Promise<any>;
304
310
  getAsSse: (url: string, fn: any, config?: any) => Promise<any>;
311
+ delete: (url: string, data?: any, config?: any) => Promise<any>;
305
312
  }
306
313
 
307
314
  interface Assistant {
@@ -315,6 +322,19 @@ interface ElectricMeter extends Device {
315
322
  status: string;
316
323
  }
317
324
 
325
+ interface DevicePurpose {
326
+ id?: number;
327
+ name: string;
328
+ code: string;
329
+ parts?: string[];
330
+ faultCategories?: string[];
331
+ isImportant?: boolean;
332
+ importantParams?: string;
333
+ parentId?: number;
334
+ path?: string;
335
+ children?: DevicePurpose[];
336
+ }
337
+
318
338
  interface DataQueryArgs {
319
339
  start?: string;
320
340
  stop?: string;
@@ -362,6 +382,7 @@ class Cpzxrobot {
362
382
  system: SystemGateway;
363
383
  dict: (key: string) => any;
364
384
  platform: PlatformInterface;
385
+ production: ProductionGateway;
365
386
  // _getSelectedFarmFromMiniApp: () => Promise<Factory>;
366
387
  // _getSelectedUnitFromMiniApp: () => Promise<Unit>;
367
388
  openMiniApp: (url: string) => void;
@@ -431,6 +452,7 @@ declare module "@cpzxrobot/sdk" {
431
452
  DeviceV2,
432
453
  FieldDatas,
433
454
  SensorDatas,
434
- ElectricMeterRate
455
+ ElectricMeterRate,
456
+ DevicePurpose,
435
457
  };
436
458
  }
package/web_platform.ts CHANGED
@@ -132,6 +132,24 @@ export class WebPlatform implements PlatformInterface {
132
132
  return response.blob();
133
133
  }
134
134
  },
135
+ delete: async (url: string, data?: any, config?: any) => {
136
+ const response = await this.fetchWithAuth(url, {
137
+ method: 'DELETE',
138
+ headers: config?.headers
139
+ });
140
+ return { data: await response.json() };
141
+ },
142
+ put: async (url: string, data?: any, config?: any) => {
143
+ const response = await this.fetchWithAuth(url, {
144
+ method: 'PUT',
145
+ headers: {
146
+ 'Content-Type': 'application/json',
147
+ ...config?.headers
148
+ },
149
+ body: JSON.stringify(data)
150
+ });
151
+ return { data: await response.json() };
152
+ },
135
153
  post: async (url: string, data?: any, config?: any) => {
136
154
  const response = await this.fetchWithAuth(url, {
137
155
  method: 'POST',