@cpzxrobot/sdk 1.3.79 → 1.3.81

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
@@ -9,6 +9,7 @@ import type {
9
9
  Supplier,
10
10
  DeviceAlarmStatsResponse,
11
11
  DeviceAlarmStatisticsResponse,
12
+ AlarmStatisticsByTypeResponse,
12
13
  } from ".";
13
14
 
14
15
  class DeviceFault {
@@ -78,14 +79,14 @@ export class DeviceGateway extends Object {
78
79
  public normalFilter: NormalGateway;
79
80
  context: Cpzxrobot;
80
81
  public categories = [
81
- { id: 0, name: '网关',order: 4 }, //排序时网关优先级不高
82
- { id: 1, name: '传感器',order: 1 },
83
- { id: 2, name: '执行器',order: 2 },
84
- { id: 3, name: 'AI设备',order: 3 },
85
- { id: 4, name: '业务数据',order: 5 },
86
- { id: 5, name: '设备参数',order: 6 },
87
- { id: 8, name: '生产设备',order: 7 },
88
- { id: 9, name: '设备部件',order: 8 },
82
+ { id: 0, name: '网关', order: 4 }, //排序时网关优先级不高
83
+ { id: 1, name: '传感器', order: 1 },
84
+ { id: 2, name: '执行器', order: 2 },
85
+ { id: 3, name: 'AI设备', order: 3 },
86
+ { id: 4, name: '业务数据', order: 5 },
87
+ { id: 5, name: '设备参数', order: 6 },
88
+ { id: 8, name: '生产设备', order: 7 },
89
+ { id: 9, name: '设备部件', order: 8 },
89
90
  ];
90
91
 
91
92
  get v2() {
@@ -1083,4 +1084,79 @@ export class DeviceGateway extends Object {
1083
1084
  });
1084
1085
  }
1085
1086
 
1087
+ /**
1088
+ * 获取报警具体信息分类统计
1089
+ * @param factoryId 工厂ID
1090
+ * @param topN 查询发生次数从多到少排名的top几(不传则默认对所有种类的报警信息进行统计)
1091
+ * @param fromDate 查询起始时间(格式:YYYY-MM-DD HH:mm:ss,不传则默认对所有的报警信息进行归类统计)
1092
+ * @param toDate 查询终止时间(格式:YYYY-MM-DD HH:mm:ss,不传则默认对所有的报警信息进行归类统计)
1093
+ * @returns Promise 包含报警分类统计数据
1094
+ */
1095
+ async getAlarmStatisticsByType(
1096
+ fromDate?: string,
1097
+ toDate?: string,
1098
+ factoryId?: number,
1099
+ topN?: number
1100
+ ): Promise<AlarmStatisticsByTypeResponse> {
1101
+ const axios = await this.context.ready;
1102
+ var _factoryId = factoryId || 0;
1103
+ if (!factoryId) {
1104
+ const farm = await this.context.user.getSelectedFarm();
1105
+ _factoryId = farm?.id || 0;
1106
+ }
1107
+
1108
+ // 参数验证
1109
+ if (!_factoryId) {
1110
+ throw new Error('工厂ID不能为空');
1111
+ }
1112
+ if (topN !== undefined && topN <= 0) {
1113
+ throw new Error('topN参数必须大于0');
1114
+ }
1115
+ if (fromDate && !this.isValidDateTime(fromDate)) {
1116
+ throw new Error('fromDate参数格式错误,应为YYYY-MM-DD HH:mm:ss格式');
1117
+ }
1118
+ if (toDate && !this.isValidDateTime(toDate)) {
1119
+ throw new Error('toDate参数格式错误,应为YYYY-MM-DD HH:mm:ss格式');
1120
+ }
1121
+ if (fromDate && toDate && fromDate > toDate) {
1122
+ throw new Error('fromDate不能晚于toDate');
1123
+ }
1124
+
1125
+ // 构建请求参数
1126
+ const params: any = { factoryId: _factoryId };
1127
+ if (topN !== undefined) {
1128
+ params.topN = topN;
1129
+ }
1130
+ if (fromDate) {
1131
+ params.fromDate = fromDate;
1132
+ }
1133
+ if (toDate) {
1134
+ params.toDate = toDate;
1135
+ }
1136
+
1137
+ return axios.get(`/api/v2/device/stat/alarms/statistics-by-type`, {
1138
+ params: params
1139
+ }).then((res) => {
1140
+ if (res.data.code !== 200) {
1141
+ throw new Error(res.data.message || '获取报警分类统计信息失败');
1142
+ }
1143
+ return res.data;
1144
+ });
1145
+ }
1146
+
1147
+ /**
1148
+ * 验证日期时间格式(YYYY-MM-DD HH:mm:ss)
1149
+ * @param dateTime 日期时间字符串
1150
+ * @returns 是否有效
1151
+ */
1152
+ private isValidDateTime(dateTime: string): boolean {
1153
+ const regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
1154
+ if (!regex.test(dateTime)) {
1155
+ return false;
1156
+ }
1157
+
1158
+ const date = new Date(dateTime);
1159
+ return !isNaN(date.getTime());
1160
+ }
1161
+
1086
1162
  }
@@ -869,5 +869,71 @@ class DeviceGateway extends Object {
869
869
  });
870
870
  });
871
871
  }
872
+ /**
873
+ * 获取报警具体信息分类统计
874
+ * @param factoryId 工厂ID
875
+ * @param topN 查询发生次数从多到少排名的top几(不传则默认对所有种类的报警信息进行统计)
876
+ * @param fromDate 查询起始时间(格式:YYYY-MM-DD HH:mm:ss,不传则默认对所有的报警信息进行归类统计)
877
+ * @param toDate 查询终止时间(格式:YYYY-MM-DD HH:mm:ss,不传则默认对所有的报警信息进行归类统计)
878
+ * @returns Promise 包含报警分类统计数据
879
+ */
880
+ getAlarmStatisticsByType(fromDate, toDate, factoryId, topN) {
881
+ return __awaiter(this, void 0, void 0, function* () {
882
+ const axios = yield this.context.ready;
883
+ var _factoryId = factoryId || 0;
884
+ if (!factoryId) {
885
+ const farm = yield this.context.user.getSelectedFarm();
886
+ _factoryId = (farm === null || farm === void 0 ? void 0 : farm.id) || 0;
887
+ }
888
+ // 参数验证
889
+ if (!_factoryId) {
890
+ throw new Error('工厂ID不能为空');
891
+ }
892
+ if (topN !== undefined && topN <= 0) {
893
+ throw new Error('topN参数必须大于0');
894
+ }
895
+ if (fromDate && !this.isValidDateTime(fromDate)) {
896
+ throw new Error('fromDate参数格式错误,应为YYYY-MM-DD HH:mm:ss格式');
897
+ }
898
+ if (toDate && !this.isValidDateTime(toDate)) {
899
+ throw new Error('toDate参数格式错误,应为YYYY-MM-DD HH:mm:ss格式');
900
+ }
901
+ if (fromDate && toDate && fromDate > toDate) {
902
+ throw new Error('fromDate不能晚于toDate');
903
+ }
904
+ // 构建请求参数
905
+ const params = { factoryId: _factoryId };
906
+ if (topN !== undefined) {
907
+ params.topN = topN;
908
+ }
909
+ if (fromDate) {
910
+ params.fromDate = fromDate;
911
+ }
912
+ if (toDate) {
913
+ params.toDate = toDate;
914
+ }
915
+ return axios.get(`/api/v2/device/stat/alarms/statistics-by-type`, {
916
+ params: params
917
+ }).then((res) => {
918
+ if (res.data.code !== 200) {
919
+ throw new Error(res.data.message || '获取报警分类统计信息失败');
920
+ }
921
+ return res.data;
922
+ });
923
+ });
924
+ }
925
+ /**
926
+ * 验证日期时间格式(YYYY-MM-DD HH:mm:ss)
927
+ * @param dateTime 日期时间字符串
928
+ * @returns 是否有效
929
+ */
930
+ isValidDateTime(dateTime) {
931
+ const regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
932
+ if (!regex.test(dateTime)) {
933
+ return false;
934
+ }
935
+ const date = new Date(dateTime);
936
+ return !isNaN(date.getTime());
937
+ }
872
938
  }
873
939
  exports.DeviceGateway = DeviceGateway;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.79",
3
+ "version": "1.3.81",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types.d.ts CHANGED
@@ -483,6 +483,32 @@ interface DeviceAlarmStatisticsResponse {
483
483
  message: string;
484
484
  }
485
485
 
486
+ /**
487
+ * 报警分类统计项接口
488
+ */
489
+ interface AlarmStatisticsByTypeItem {
490
+ /** 报警类型(0,1,2等) */
491
+ category: number;
492
+ /** 时间范围内的指定种类的报警数量 */
493
+ count: number;
494
+ /** 上次发生此类报警的时间 */
495
+ lastOccurred: string;
496
+ /** 此类报警还没恢复的总数 */
497
+ unresolvedCount: number;
498
+ }
499
+
500
+ /**
501
+ * 报警分类统计响应接口
502
+ */
503
+ interface AlarmStatisticsByTypeResponse {
504
+ /** 响应码 */
505
+ code: number;
506
+ /** 报警分类统计数据 */
507
+ data: AlarmStatisticsByTypeItem[];
508
+ /** 响应消息 */
509
+ message: string;
510
+ }
511
+
486
512
  declare class Cpzxrobot {
487
513
  transport: TransportGateway;
488
514
  ready: Promise<MyAxiosInstance>;
@@ -571,6 +597,8 @@ declare module "@cpzxrobot/sdk" {
571
597
  DeviceAlarmStatisticsItem,
572
598
  DeviceAlarmStatisticsPage,
573
599
  DeviceAlarmStatisticsResponse,
600
+ AlarmStatisticsByTypeItem,
601
+ AlarmStatisticsByTypeResponse,
574
602
  ElectricMeterRate,
575
603
  DevicePurpose,
576
604
  };