@cpzxrobot/sdk 1.3.77 → 1.3.79

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
@@ -8,6 +8,7 @@ import type {
8
8
  Factory,
9
9
  Supplier,
10
10
  DeviceAlarmStatsResponse,
11
+ DeviceAlarmStatisticsResponse,
11
12
  } from ".";
12
13
 
13
14
  class DeviceFault {
@@ -1009,4 +1010,77 @@ export class DeviceGateway extends Object {
1009
1010
  });
1010
1011
  }
1011
1012
 
1013
+ /**
1014
+ * 获取设备分类报警统计列表
1015
+ * @param factoryId 工厂ID
1016
+ * @param resolveType 报警类型(0为还没恢复的报警;1为今日已恢复的报警;2为今日所有报警)
1017
+ * @param pageNum 页码(默认为1)
1018
+ * @param pageSize 页面尺寸(默认为10)
1019
+ * @returns Promise 包含设备报警统计列表分页数据
1020
+ */
1021
+ async getAlarmStatistics(
1022
+ factoryId: number | undefined = undefined,
1023
+ resolveType: number = 2,
1024
+ pageNum: number = 1,
1025
+ pageSize: number = 10
1026
+ ): Promise<DeviceAlarmStatisticsResponse> {
1027
+ const axios = await this.context.ready;
1028
+ var _factoryId = factoryId || 0;
1029
+ if (!factoryId) {
1030
+ const farm = await this.context.user.getSelectedFarm();
1031
+ _factoryId = farm?.id || 0;
1032
+ }
1033
+
1034
+ // 参数验证
1035
+ if (!_factoryId) {
1036
+ throw new Error('工厂ID不能为空');
1037
+ }
1038
+ if (resolveType < 0 || resolveType > 2) {
1039
+ throw new Error('报警类型参数错误,必须是0、1或2');
1040
+ }
1041
+ if (pageNum < 1) {
1042
+ throw new Error('页码不能小于1');
1043
+ }
1044
+ if (pageSize < 1 || pageSize > 100) {
1045
+ throw new Error('页面尺寸必须在1-100之间');
1046
+ }
1047
+
1048
+ return axios.get(`/api/v2/device/stat/alarms/statistics`, {
1049
+ params: {
1050
+ factoryId: _factoryId,
1051
+ resolveType: resolveType,
1052
+ pageNum: pageNum,
1053
+ pageSize: pageSize
1054
+ }
1055
+ }).then((res) => {
1056
+ if (res.data.code !== 200) {
1057
+ throw new Error(res.data.message || '获取设备报警统计列表失败');
1058
+ }
1059
+ return res.data;
1060
+ });
1061
+ }
1062
+
1063
+ /**
1064
+ * 获取报警具体信息
1065
+ * @param logId 报警日志ID
1066
+ * @returns Promise 包含报警具体信息的数据
1067
+ */
1068
+ async getAlarmDetails(logId: number): Promise<any> {
1069
+ const axios = await this.context.ready;
1070
+
1071
+ // 参数验证
1072
+ if (!logId || logId <= 0) {
1073
+ throw new Error('报警日志ID不能为空且必须大于0');
1074
+ }
1075
+
1076
+ return axios.get(`/api/v2/device/stat/alarms/details`, {
1077
+ params: { logId }
1078
+ }).then((res) => {
1079
+ if (res.data.code !== 200) {
1080
+ throw new Error(res.data.message || '获取报警具体信息失败');
1081
+ }
1082
+ return res.data;
1083
+ });
1084
+ }
1085
+
1012
1086
  }
@@ -803,5 +803,71 @@ class DeviceGateway extends Object {
803
803
  });
804
804
  });
805
805
  }
806
+ /**
807
+ * 获取设备分类报警统计列表
808
+ * @param factoryId 工厂ID
809
+ * @param resolveType 报警类型(0为还没恢复的报警;1为今日已恢复的报警;2为今日所有报警)
810
+ * @param pageNum 页码(默认为1)
811
+ * @param pageSize 页面尺寸(默认为10)
812
+ * @returns Promise 包含设备报警统计列表分页数据
813
+ */
814
+ getAlarmStatistics() {
815
+ return __awaiter(this, arguments, void 0, function* (factoryId = undefined, resolveType = 2, pageNum = 1, pageSize = 10) {
816
+ const axios = yield this.context.ready;
817
+ var _factoryId = factoryId || 0;
818
+ if (!factoryId) {
819
+ const farm = yield this.context.user.getSelectedFarm();
820
+ _factoryId = (farm === null || farm === void 0 ? void 0 : farm.id) || 0;
821
+ }
822
+ // 参数验证
823
+ if (!_factoryId) {
824
+ throw new Error('工厂ID不能为空');
825
+ }
826
+ if (resolveType < 0 || resolveType > 2) {
827
+ throw new Error('报警类型参数错误,必须是0、1或2');
828
+ }
829
+ if (pageNum < 1) {
830
+ throw new Error('页码不能小于1');
831
+ }
832
+ if (pageSize < 1 || pageSize > 100) {
833
+ throw new Error('页面尺寸必须在1-100之间');
834
+ }
835
+ return axios.get(`/api/v2/device/stat/alarms/statistics`, {
836
+ params: {
837
+ factoryId: _factoryId,
838
+ resolveType: resolveType,
839
+ pageNum: pageNum,
840
+ pageSize: pageSize
841
+ }
842
+ }).then((res) => {
843
+ if (res.data.code !== 200) {
844
+ throw new Error(res.data.message || '获取设备报警统计列表失败');
845
+ }
846
+ return res.data;
847
+ });
848
+ });
849
+ }
850
+ /**
851
+ * 获取报警具体信息
852
+ * @param logId 报警日志ID
853
+ * @returns Promise 包含报警具体信息的数据
854
+ */
855
+ getAlarmDetails(logId) {
856
+ return __awaiter(this, void 0, void 0, function* () {
857
+ const axios = yield this.context.ready;
858
+ // 参数验证
859
+ if (!logId || logId <= 0) {
860
+ throw new Error('报警日志ID不能为空且必须大于0');
861
+ }
862
+ return axios.get(`/api/v2/device/stat/alarms/details`, {
863
+ params: { logId }
864
+ }).then((res) => {
865
+ if (res.data.code !== 200) {
866
+ throw new Error(res.data.message || '获取报警具体信息失败');
867
+ }
868
+ return res.data;
869
+ });
870
+ });
871
+ }
806
872
  }
807
873
  exports.DeviceGateway = DeviceGateway;
@@ -151,7 +151,13 @@ class FactoryGateway extends Object {
151
151
  id = farm.id;
152
152
  }
153
153
  const response = yield axios.get(`/api/v2/factory/${id}/units`);
154
- return response.data;
154
+ const body = response.data;
155
+ if (body.code === 200) {
156
+ return body.data;
157
+ }
158
+ else {
159
+ throw new Error(body.message);
160
+ }
155
161
  });
156
162
  }
157
163
  //获得工厂的业务类型
@@ -135,7 +135,12 @@ export class FactoryGateway extends Object {
135
135
  id = farm.id;
136
136
  }
137
137
  const response = await axios.get(`/api/v2/factory/${id}/units`);
138
- return response.data;
138
+ const body = response.data;
139
+ if (body.code === 200) {
140
+ return body.data;
141
+ }else{
142
+ throw new Error(body.message);
143
+ }
139
144
  }
140
145
 
141
146
  //获得工厂的业务类型
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.77",
3
+ "version": "1.3.79",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types.d.ts CHANGED
@@ -399,6 +399,90 @@ interface DeviceAlarmStatsResponse {
399
399
  message: string;
400
400
  }
401
401
 
402
+ /**
403
+ * 设备报警统计列表项接口
404
+ */
405
+ interface DeviceAlarmStatisticsItem {
406
+ /** 报警类型(0,1,2等) */
407
+ category: number;
408
+ /** 点位Id */
409
+ deviceId: string;
410
+ /** 从开始报警到恢复的时间间隔,以秒计 */
411
+ durationSeconds: number;
412
+ /** 报警结束时间,如果还没恢复就是null */
413
+ endTime: string | null;
414
+ /** 工厂id */
415
+ factoryId: number;
416
+ /** 故障种类(online、CO2-54等) */
417
+ field: string;
418
+ /** 主键id */
419
+ id: number;
420
+ /** 报警是否已解决 */
421
+ resolved: boolean;
422
+ /** 报警开始时间 */
423
+ startTime: string;
424
+ }
425
+
426
+ /**
427
+ * 设备报警统计列表分页数据接口
428
+ */
429
+ interface DeviceAlarmStatisticsPage {
430
+ /** 结束行号 */
431
+ endRow: number;
432
+ /** 第一页 */
433
+ firstPage: number;
434
+ /** 是否有下一页 */
435
+ hasNextPage: boolean;
436
+ /** 是否有上一页 */
437
+ hasPreviousPage: boolean;
438
+ /** 是否第一页 */
439
+ isFirstPage: boolean;
440
+ /** 是否最后一页 */
441
+ isLastPage: boolean;
442
+ /** 最后一页 */
443
+ lastPage: number;
444
+ /** 报警统计列表 */
445
+ list: DeviceAlarmStatisticsItem[];
446
+ /** 导航第一页 */
447
+ navigateFirstPage: number;
448
+ /** 导航最后一页 */
449
+ navigateLastPage: number;
450
+ /** 导航页数 */
451
+ navigatePages: number;
452
+ /** 导航页码数组 */
453
+ navigatepageNums: number[];
454
+ /** 下一页 */
455
+ nextPage: number;
456
+ /** 排序字段 */
457
+ orderBy: string | null;
458
+ /** 当前页码 */
459
+ pageNum: number;
460
+ /** 页面尺寸 */
461
+ pageSize: number;
462
+ /** 总页数 */
463
+ pages: number;
464
+ /** 上一页 */
465
+ prePage: number;
466
+ /** 当前页数量 */
467
+ size: number;
468
+ /** 开始行号 */
469
+ startRow: number;
470
+ /** 总记录数 */
471
+ total: number;
472
+ }
473
+
474
+ /**
475
+ * 设备报警统计列表响应接口
476
+ */
477
+ interface DeviceAlarmStatisticsResponse {
478
+ /** 响应码 */
479
+ code: number;
480
+ /** 报警统计分页数据 */
481
+ data: DeviceAlarmStatisticsPage;
482
+ /** 响应消息 */
483
+ message: string;
484
+ }
485
+
402
486
  declare class Cpzxrobot {
403
487
  transport: TransportGateway;
404
488
  ready: Promise<MyAxiosInstance>;
@@ -484,6 +568,9 @@ declare module "@cpzxrobot/sdk" {
484
568
  FieldDatas,
485
569
  DeviceAlarmStats,
486
570
  DeviceAlarmStatsResponse,
571
+ DeviceAlarmStatisticsItem,
572
+ DeviceAlarmStatisticsPage,
573
+ DeviceAlarmStatisticsResponse,
487
574
  ElectricMeterRate,
488
575
  DevicePurpose,
489
576
  };