@cpzxrobot/sdk 1.3.78 → 1.3.80

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 {
@@ -1060,4 +1061,102 @@ export class DeviceGateway extends Object {
1060
1061
  });
1061
1062
  }
1062
1063
 
1064
+ /**
1065
+ * 获取报警具体信息
1066
+ * @param logId 报警日志ID
1067
+ * @returns Promise 包含报警具体信息的数据
1068
+ */
1069
+ async getAlarmDetails(logId: number): Promise<any> {
1070
+ const axios = await this.context.ready;
1071
+
1072
+ // 参数验证
1073
+ if (!logId || logId <= 0) {
1074
+ throw new Error('报警日志ID不能为空且必须大于0');
1075
+ }
1076
+
1077
+ return axios.get(`/api/v2/device/stat/alarms/details`, {
1078
+ params: { logId }
1079
+ }).then((res) => {
1080
+ if (res.data.code !== 200) {
1081
+ throw new Error(res.data.message || '获取报警具体信息失败');
1082
+ }
1083
+ return res.data;
1084
+ });
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
+ factoryId: number | undefined = undefined,
1097
+ topN?: number,
1098
+ fromDate?: string,
1099
+ toDate?: string
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
+
1063
1162
  }
@@ -847,5 +847,93 @@ class DeviceGateway extends Object {
847
847
  });
848
848
  });
849
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
+ }
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() {
881
+ return __awaiter(this, arguments, void 0, function* (factoryId = undefined, topN, fromDate, toDate) {
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
+ }
850
938
  }
851
939
  exports.DeviceGateway = DeviceGateway;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.78",
3
+ "version": "1.3.80",
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
  };