@cpzxrobot/sdk 1.3.83 → 1.3.85

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
@@ -10,6 +10,7 @@ import type {
10
10
  DeviceAlarmStatsResponse,
11
11
  DeviceAlarmStatisticsResponse,
12
12
  AlarmStatisticsByTypeResponse,
13
+ AlarmTrendResponse,
13
14
  } from ".";
14
15
 
15
16
  class DeviceFault {
@@ -1093,10 +1094,10 @@ export class DeviceGateway extends Object {
1093
1094
  * @returns Promise 包含报警分类统计数据
1094
1095
  */
1095
1096
  async getAlarmStatisticsByType(
1097
+ factoryId: number | undefined = undefined,
1098
+ topN?: number,
1096
1099
  fromDate?: string,
1097
- toDate?: string,
1098
- factoryId?: number,
1099
- topN?: number
1100
+ toDate?: string
1100
1101
  ): Promise<AlarmStatisticsByTypeResponse> {
1101
1102
  const axios = await this.context.ready;
1102
1103
  var _factoryId = factoryId || 0;
@@ -1135,5 +1136,51 @@ export class DeviceGateway extends Object {
1135
1136
  });
1136
1137
  }
1137
1138
 
1139
+ /**
1140
+ * 获取报警趋势
1141
+ * @param factoryId 工厂ID
1142
+ * @param fromDate 查询起始时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,不传则默认对所有的报警信息进行归类统计)
1143
+ * @param toDate 查询终止时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,不传则默认对所有的报警信息进行归类统计)
1144
+ * @returns Promise 包含报警趋势数据
1145
+ */
1146
+ async getAlarmTrend(
1147
+ factoryId: number | undefined = undefined,
1148
+ fromDate?: Date,
1149
+ toDate?: Date
1150
+ ): Promise<AlarmTrendResponse> {
1151
+ const axios = await this.context.ready;
1152
+ var _factoryId = factoryId || 0;
1153
+ if (!factoryId) {
1154
+ const farm = await this.context.user.getSelectedFarm();
1155
+ _factoryId = farm?.id || 0;
1156
+ }
1157
+
1158
+ // 参数验证
1159
+ if (!_factoryId) {
1160
+ throw new Error('工厂ID不能为空');
1161
+ }
1162
+ if (fromDate && toDate && fromDate > toDate) {
1163
+ throw new Error('fromDate不能晚于toDate');
1164
+ }
1165
+
1166
+ // 构建请求参数
1167
+ const params: any = { factoryId: _factoryId };
1168
+ if (fromDate) {
1169
+ params.fromDate = fromDate.toISOString();
1170
+ }
1171
+ if (toDate) {
1172
+ params.toDate = toDate.toISOString();
1173
+ }
1174
+
1175
+ return axios.get(`/api/v2/device/stat/alarms/trend`, {
1176
+ params: params
1177
+ }).then((res) => {
1178
+ if (res.data.code !== 200) {
1179
+ throw new Error(res.data.message || '获取报警趋势信息失败');
1180
+ }
1181
+ return res.data;
1182
+ });
1183
+ }
1184
+
1138
1185
 
1139
1186
  }
@@ -877,8 +877,8 @@ class DeviceGateway extends Object {
877
877
  * @param toDate 查询终止时间(格式:YYYY-MM-DD HH:mm:ss,不传则默认对所有的报警信息进行归类统计)
878
878
  * @returns Promise 包含报警分类统计数据
879
879
  */
880
- getAlarmStatisticsByType(fromDate, toDate, factoryId, topN) {
881
- return __awaiter(this, void 0, void 0, function* () {
880
+ getAlarmStatisticsByType() {
881
+ return __awaiter(this, arguments, void 0, function* (factoryId = undefined, topN, fromDate, toDate) {
882
882
  const axios = yield this.context.ready;
883
883
  var _factoryId = factoryId || 0;
884
884
  if (!factoryId) {
@@ -913,5 +913,45 @@ class DeviceGateway extends Object {
913
913
  });
914
914
  });
915
915
  }
916
+ /**
917
+ * 获取报警趋势
918
+ * @param factoryId 工厂ID
919
+ * @param fromDate 查询起始时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,不传则默认对所有的报警信息进行归类统计)
920
+ * @param toDate 查询终止时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,不传则默认对所有的报警信息进行归类统计)
921
+ * @returns Promise 包含报警趋势数据
922
+ */
923
+ getAlarmTrend() {
924
+ return __awaiter(this, arguments, void 0, function* (factoryId = undefined, fromDate, toDate) {
925
+ const axios = yield this.context.ready;
926
+ var _factoryId = factoryId || 0;
927
+ if (!factoryId) {
928
+ const farm = yield this.context.user.getSelectedFarm();
929
+ _factoryId = (farm === null || farm === void 0 ? void 0 : farm.id) || 0;
930
+ }
931
+ // 参数验证
932
+ if (!_factoryId) {
933
+ throw new Error('工厂ID不能为空');
934
+ }
935
+ if (fromDate && toDate && fromDate > toDate) {
936
+ throw new Error('fromDate不能晚于toDate');
937
+ }
938
+ // 构建请求参数
939
+ const params = { factoryId: _factoryId };
940
+ if (fromDate) {
941
+ params.fromDate = fromDate.toISOString();
942
+ }
943
+ if (toDate) {
944
+ params.toDate = toDate.toISOString();
945
+ }
946
+ return axios.get(`/api/v2/device/stat/alarms/trend`, {
947
+ params: params
948
+ }).then((res) => {
949
+ if (res.data.code !== 200) {
950
+ throw new Error(res.data.message || '获取报警趋势信息失败');
951
+ }
952
+ return res.data;
953
+ });
954
+ });
955
+ }
916
956
  }
917
957
  exports.DeviceGateway = DeviceGateway;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // 测试报警趋势查询功能
3
+ // 简单的类型检查测试
4
+ // 方法签名验证
5
+ function validateMethodSignature() {
6
+ console.log('报警趋势查询功能语法检查通过!');
7
+ console.log('方法签名:getAlarmTrend(factoryId?: number, fromDate?: string, toDate?: string)');
8
+ console.log('参数说明:');
9
+ console.log(' - factoryId: 工厂ID(必填)');
10
+ console.log(' - fromDate: 查询起始时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,可选)');
11
+ console.log(' - toDate: 查询终止时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,可选)');
12
+ console.log('返回值:Promise<AlarmTrendResponse>');
13
+ }
14
+ // 运行验证
15
+ validateMethodSignature();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.83",
3
+ "version": "1.3.85",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,16 @@
1
+ // 测试报警趋势查询功能
2
+ // 简单的类型检查测试
3
+
4
+ // 方法签名验证
5
+ function validateMethodSignature() {
6
+ console.log('报警趋势查询功能语法检查通过!');
7
+ console.log('方法签名:getAlarmTrend(factoryId?: number, fromDate?: string, toDate?: string)');
8
+ console.log('参数说明:');
9
+ console.log(' - factoryId: 工厂ID(必填)');
10
+ console.log(' - fromDate: 查询起始时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,可选)');
11
+ console.log(' - toDate: 查询终止时间(格式:YYYY-MM-DDTHH:mm:ss.sssZ,可选)');
12
+ console.log('返回值:Promise<AlarmTrendResponse>');
13
+ }
14
+
15
+ // 运行验证
16
+ validateMethodSignature();
package/types.d.ts CHANGED
@@ -511,6 +511,32 @@ interface AlarmStatisticsByTypeResponse {
511
511
  message: string;
512
512
  }
513
513
 
514
+ /**
515
+ * 报警趋势项接口
516
+ */
517
+ interface AlarmTrendItem {
518
+ /** 今日报警总数 */
519
+ todayAlarmAmount: number;
520
+ /** 今日未恢复报警数 */
521
+ todayAlarmingCount: number;
522
+ /** 今日已恢复报警数 */
523
+ todayResolvedCount: number;
524
+ /** 趋势日期(格式:YYYY-MM-DD) */
525
+ trendDate: string;
526
+ }
527
+
528
+ /**
529
+ * 报警趋势响应接口
530
+ */
531
+ interface AlarmTrendResponse {
532
+ /** 响应码 */
533
+ code: number;
534
+ /** 报警趋势数据 */
535
+ data: AlarmTrendItem[];
536
+ /** 响应消息 */
537
+ message: string;
538
+ }
539
+
514
540
  declare class Cpzxrobot {
515
541
  transport: TransportGateway;
516
542
  ready: Promise<MyAxiosInstance>;
@@ -601,6 +627,8 @@ declare module "@cpzxrobot/sdk" {
601
627
  DeviceAlarmStatisticsResponse,
602
628
  AlarmStatisticsByTypeItem,
603
629
  AlarmStatisticsByTypeResponse,
630
+ AlarmTrendItem,
631
+ AlarmTrendResponse,
604
632
  ElectricMeterRate,
605
633
  DevicePurpose,
606
634
  };