@cpzxrobot/sdk 1.3.88 → 1.3.90

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
@@ -11,6 +11,10 @@ import type {
11
11
  DeviceAlarmStatisticsResponse,
12
12
  AlarmStatisticsByTypeResponse,
13
13
  AlarmTrendResponse,
14
+ CreateAlarmRuleRequest,
15
+ CreateAlarmRuleResponse,
16
+ AlarmRuleListResponse,
17
+ AlarmRuleDetailResponse,
14
18
  } from ".";
15
19
 
16
20
  class DeviceFault {
@@ -199,6 +203,86 @@ export class DeviceGateway extends Object {
199
203
  };
200
204
  }
201
205
 
206
+ get rule() {
207
+ return {
208
+ /**
209
+ * 按工厂id查询报警规则列表
210
+ * @param factoryId 工厂ID
211
+ * @returns Promise 包含报警规则列表
212
+ */
213
+ list: async (factoryId?: number): Promise<AlarmRuleListResponse> => {
214
+ const axios = await this.context.ready;
215
+
216
+ // 参数验证
217
+ if (!factoryId) {
218
+ let farm = await this.context.user.getSelectedFarm();
219
+ factoryId = farm?.id;
220
+ }
221
+
222
+ return axios.get(`/api/v2/device/stat/alarms/rule`, {
223
+ params: { factoryId }
224
+ }).then((res) => {
225
+ if (res.data.code !== 200) {
226
+ throw new Error(res.data.message || '获取报警规则列表失败');
227
+ }
228
+ return res.data;
229
+ });
230
+ },
231
+
232
+ /**
233
+ * 按规则id查询报警规则详情
234
+ * @param ruleId 规则ID
235
+ * @returns Promise 包含报警规则详情
236
+ */
237
+ get: async (ruleId: number): Promise<AlarmRuleDetailResponse> => {
238
+ const axios = await this.context.ready;
239
+
240
+ // 参数验证
241
+ if (!ruleId || ruleId <= 0) {
242
+ throw new Error('规则ID不能为空且必须大于0');
243
+ }
244
+
245
+ return axios.get(`/api/v2/device/stat/alarms/rule/${ruleId}`).then((res) => {
246
+ if (res.data.code !== 200) {
247
+ throw new Error(res.data.message || '获取报警规则详情失败');
248
+ }
249
+ return res.data;
250
+ });
251
+ },
252
+
253
+ /**
254
+ * 创建报警规则
255
+ * @param request 创建报警规则的请求参数
256
+ * @returns Promise 包含创建结果
257
+ */
258
+ create: async (request: CreateAlarmRuleRequest): Promise<CreateAlarmRuleResponse> => {
259
+ const axios = await this.context.ready;
260
+
261
+ // 参数验证
262
+ if (!request.factoryId) {
263
+ let farm = await this.context.user.getSelectedFarm();
264
+ request.factoryId = farm?.id;
265
+ }
266
+ if (!request.ruleName) {
267
+ throw new Error('规则名称不能为空');
268
+ }
269
+
270
+ // 设置默认值
271
+ const requestData: CreateAlarmRuleRequest = {
272
+ ...request,
273
+ ruleActive: request.ruleActive !== undefined ? request.ruleActive : true
274
+ };
275
+
276
+ return axios.post(`/api/v2/device/stat/alarms/rule`, requestData).then((res) => {
277
+ if (res.data.code !== 200) {
278
+ throw new Error(res.data.message || '创建报警规则失败');
279
+ }
280
+ return res.data;
281
+ });
282
+ },
283
+ };
284
+ }
285
+
202
286
  constructor(context: Cpzxrobot) {
203
287
  super();
204
288
  this.context = context;
@@ -1193,5 +1277,4 @@ export class DeviceGateway extends Object {
1193
1277
  });
1194
1278
  }
1195
1279
 
1196
-
1197
1280
  }
@@ -147,6 +147,73 @@ class DeviceGateway extends Object {
147
147
  }),
148
148
  };
149
149
  }
150
+ get rule() {
151
+ return {
152
+ /**
153
+ * 按工厂id查询报警规则列表
154
+ * @param factoryId 工厂ID
155
+ * @returns Promise 包含报警规则列表
156
+ */
157
+ list: (factoryId) => __awaiter(this, void 0, void 0, function* () {
158
+ const axios = yield this.context.ready;
159
+ // 参数验证
160
+ if (!factoryId) {
161
+ let farm = yield this.context.user.getSelectedFarm();
162
+ factoryId = farm === null || farm === void 0 ? void 0 : farm.id;
163
+ }
164
+ return axios.get(`/api/v2/device/stat/alarms/rule`, {
165
+ params: { factoryId }
166
+ }).then((res) => {
167
+ if (res.data.code !== 200) {
168
+ throw new Error(res.data.message || '获取报警规则列表失败');
169
+ }
170
+ return res.data;
171
+ });
172
+ }),
173
+ /**
174
+ * 按规则id查询报警规则详情
175
+ * @param ruleId 规则ID
176
+ * @returns Promise 包含报警规则详情
177
+ */
178
+ get: (ruleId) => __awaiter(this, void 0, void 0, function* () {
179
+ const axios = yield this.context.ready;
180
+ // 参数验证
181
+ if (!ruleId || ruleId <= 0) {
182
+ throw new Error('规则ID不能为空且必须大于0');
183
+ }
184
+ return axios.get(`/api/v2/device/stat/alarms/rule/${ruleId}`).then((res) => {
185
+ if (res.data.code !== 200) {
186
+ throw new Error(res.data.message || '获取报警规则详情失败');
187
+ }
188
+ return res.data;
189
+ });
190
+ }),
191
+ /**
192
+ * 创建报警规则
193
+ * @param request 创建报警规则的请求参数
194
+ * @returns Promise 包含创建结果
195
+ */
196
+ create: (request) => __awaiter(this, void 0, void 0, function* () {
197
+ const axios = yield this.context.ready;
198
+ // 参数验证
199
+ if (!request.factoryId) {
200
+ let farm = yield this.context.user.getSelectedFarm();
201
+ request.factoryId = farm === null || farm === void 0 ? void 0 : farm.id;
202
+ }
203
+ if (!request.ruleName) {
204
+ throw new Error('规则名称不能为空');
205
+ }
206
+ // 设置默认值
207
+ const requestData = Object.assign(Object.assign({}, request), { ruleActive: request.ruleActive !== undefined ? request.ruleActive : true });
208
+ return axios.post(`/api/v2/device/stat/alarms/rule`, requestData).then((res) => {
209
+ if (res.data.code !== 200) {
210
+ throw new Error(res.data.message || '创建报警规则失败');
211
+ }
212
+ return res.data;
213
+ });
214
+ }),
215
+ };
216
+ }
150
217
  constructor(context) {
151
218
  super();
152
219
  this.categories = [
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * 测试报警规则查询接口
4
+ * 验证rule.list和rule.get方法的语法正确性
5
+ */
6
+ // 验证方法签名
7
+ function validateMethodSignature() {
8
+ console.log("验证报警规则查询接口方法签名...");
9
+ // 模拟方法调用参数验证
10
+ const factoryId = 1830745839850088;
11
+ const ruleId = 1;
12
+ console.log("✅ factoryId参数验证通过:", factoryId);
13
+ console.log("✅ ruleId参数验证通过:", ruleId);
14
+ console.log("✅ 方法签名验证完成");
15
+ }
16
+ // 运行验证
17
+ validateMethodSignature();
18
+ console.log("\n📋 报警规则查询接口使用示例:");
19
+ console.log(`
20
+ // 按工厂ID查询报警规则列表
21
+ const ruleListResult = await deviceGateway.rule.list(1830745839850088);
22
+ console.log("规则列表:", ruleListResult.data);
23
+
24
+ // 按规则ID查询报警规则详情
25
+ const ruleDetailResult = await deviceGateway.rule.get(1);
26
+ console.log("规则详情:", ruleDetailResult.data);
27
+ `);
28
+ console.log("\n📋 与创建报警规则配合使用:");
29
+ console.log(`
30
+ // 1. 创建报警规则
31
+ const createRequest = {
32
+ factoryId: 1830745839850088,
33
+ ruleName: "温度异常报警规则",
34
+ ruleDescription: "监控温度,当超出设定阈值时触发多级报警。",
35
+ ruleActive: true,
36
+ alarmConfigs: [
37
+ {
38
+ alarmLevel: 1,
39
+ alarmMethods: ["SMS"],
40
+ triggerCondition: 0,
41
+ active: true
42
+ }
43
+ ]
44
+ };
45
+
46
+ const createResult = await deviceGateway.createAlarmRule(createRequest);
47
+
48
+ // 2. 查询刚创建的规则
49
+ const newRuleId = 123; // 假设创建成功返回的规则ID
50
+ const ruleDetail = await deviceGateway.rule.get(newRuleId);
51
+
52
+ // 3. 按工厂查询所有规则
53
+ const allRules = await deviceGateway.rule.list(1830745839850088);
54
+ console.log("工厂所有规则:", allRules.data);
55
+ `);
56
+ console.log("\n✅ 报警规则查询接口测试完成");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.88",
3
+ "version": "1.3.90",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 测试报警规则查询接口
3
+ * 验证rule.list和rule.get方法的语法正确性
4
+ */
5
+
6
+ // 验证方法签名
7
+ function validateMethodSignature(): void {
8
+ console.log("验证报警规则查询接口方法签名...");
9
+
10
+ // 模拟方法调用参数验证
11
+ const factoryId = 1830745839850088;
12
+ const ruleId = 1;
13
+
14
+ console.log("✅ factoryId参数验证通过:", factoryId);
15
+ console.log("✅ ruleId参数验证通过:", ruleId);
16
+ console.log("✅ 方法签名验证完成");
17
+ }
18
+
19
+ // 运行验证
20
+ validateMethodSignature();
21
+
22
+ console.log("\n📋 报警规则查询接口使用示例:");
23
+ console.log(`
24
+ // 按工厂ID查询报警规则列表
25
+ const ruleListResult = await deviceGateway.rule.list(1830745839850088);
26
+ console.log("规则列表:", ruleListResult.data);
27
+
28
+ // 按规则ID查询报警规则详情
29
+ const ruleDetailResult = await deviceGateway.rule.get(1);
30
+ console.log("规则详情:", ruleDetailResult.data);
31
+ `);
32
+
33
+ console.log("\n📋 与创建报警规则配合使用:");
34
+ console.log(`
35
+ // 1. 创建报警规则
36
+ const createRequest = {
37
+ factoryId: 1830745839850088,
38
+ ruleName: "温度异常报警规则",
39
+ ruleDescription: "监控温度,当超出设定阈值时触发多级报警。",
40
+ ruleActive: true,
41
+ alarmConfigs: [
42
+ {
43
+ alarmLevel: 1,
44
+ alarmMethods: ["SMS"],
45
+ triggerCondition: 0,
46
+ active: true
47
+ }
48
+ ]
49
+ };
50
+
51
+ const createResult = await deviceGateway.createAlarmRule(createRequest);
52
+
53
+ // 2. 查询刚创建的规则
54
+ const newRuleId = 123; // 假设创建成功返回的规则ID
55
+ const ruleDetail = await deviceGateway.rule.get(newRuleId);
56
+
57
+ // 3. 按工厂查询所有规则
58
+ const allRules = await deviceGateway.rule.list(1830745839850088);
59
+ console.log("工厂所有规则:", allRules.data);
60
+ `);
61
+
62
+ console.log("\n✅ 报警规则查询接口测试完成");
package/types.d.ts CHANGED
@@ -537,6 +537,126 @@ interface AlarmTrendResponse {
537
537
  message: string;
538
538
  }
539
539
 
540
+ /**
541
+ * 报警规则阈值配置接口
542
+ */
543
+ interface AlarmRuleThresholdConfig {
544
+ /** 栋舍类型id */
545
+ unitType?: number;
546
+ /** 设备类型id */
547
+ deviceType?: number;
548
+ /** 报警阈值最小值 */
549
+ thresholdMin?: number;
550
+ /** 阈值最大值 */
551
+ thresholdMax?: number;
552
+ }
553
+
554
+ /**
555
+ * 报警规则报警配置接口
556
+ */
557
+ interface AlarmRuleAlarmConfig {
558
+ /** 报警级别(1级、2级、3级) */
559
+ alarmLevel: number;
560
+ /** 报警方式(短信、邮件等) */
561
+ alarmMethods: ("SMS" | "EMAIL" | "APP" | "PHONE")[];
562
+ /** 报警角色id列表 */
563
+ alarmRoles?: number[];
564
+ /** 触发条件(报警需要持续的时长,以分钟计) */
565
+ triggerCondition?: number;
566
+ /** 分级后的报警是否生效 */
567
+ active?: boolean;
568
+ }
569
+
570
+ /**
571
+ * 创建报警规则请求接口
572
+ */
573
+ interface CreateAlarmRuleRequest {
574
+ /** 工厂id */
575
+ factoryId: number;
576
+ /** 规则名称 */
577
+ ruleName: string;
578
+ /** 规则描述 */
579
+ ruleDescription?: string;
580
+ /** 规则是否启用 */
581
+ ruleActive?: boolean;
582
+ /** 栋舍id */
583
+ unitIds?: number[];
584
+ /** 报警方式id(离线、故障、阈值、变化趋势等) */
585
+ alarmType?: "OFFLINE" | "FAULT" | "THRESHOLD" | "TREND";
586
+ /** 报警设备类型(网关、传感器、生产设备等) */
587
+ deviceTypes?: ("GATEWAY" | "SENSOR" | "DEVICE")[];
588
+ /** 阈值配置列表 */
589
+ thresholdConfigs?: AlarmRuleThresholdConfig[];
590
+ /** 报警配置列表 */
591
+ alarmConfigs?: AlarmRuleAlarmConfig[];
592
+ }
593
+
594
+ /**
595
+ * 创建报警规则响应接口
596
+ */
597
+ interface CreateAlarmRuleResponse {
598
+ /** 响应码 */
599
+ code: number;
600
+ /** 响应数据 */
601
+ data: null;
602
+ /** 响应消息 */
603
+ message: string;
604
+ }
605
+
606
+ /**
607
+ * 报警规则详情接口
608
+ */
609
+ interface AlarmRuleDetail {
610
+ /** 规则id */
611
+ ruleId: number;
612
+ /** 工厂id */
613
+ factoryId: number;
614
+ /** 规则名称 */
615
+ ruleName: string;
616
+ /** 规则描述 */
617
+ ruleDescription?: string;
618
+ /** 规则是否启用 */
619
+ ruleActive: boolean;
620
+ /** 栋舍id列表 */
621
+ unitIds?: number[];
622
+ /** 报警方式 */
623
+ alarmType?: "OFFLINE" | "FAULT" | "THRESHOLD" | "TREND";
624
+ /** 设备类型列表 */
625
+ deviceTypes?: ("GATEWAY" | "SENSOR" | "DEVICE")[];
626
+ /** 创建时间 */
627
+ createTime: string;
628
+ /** 最后修改时间 */
629
+ latestModifyTime: string;
630
+ /** 阈值配置列表 */
631
+ thresholdConfigs?: AlarmRuleThresholdConfig[];
632
+ /** 报警配置列表 */
633
+ alarmConfigs?: AlarmRuleAlarmConfig[];
634
+ }
635
+
636
+ /**
637
+ * 报警规则列表响应接口
638
+ */
639
+ interface AlarmRuleListResponse {
640
+ /** 响应码 */
641
+ code: number;
642
+ /** 报警规则列表 */
643
+ data: AlarmRuleDetail[];
644
+ /** 响应消息 */
645
+ message: string;
646
+ }
647
+
648
+ /**
649
+ * 报警规则详情响应接口
650
+ */
651
+ interface AlarmRuleDetailResponse {
652
+ /** 响应码 */
653
+ code: number;
654
+ /** 报警规则详情 */
655
+ data: AlarmRuleDetail;
656
+ /** 响应消息 */
657
+ message: string;
658
+ }
659
+
540
660
  declare class Cpzxrobot {
541
661
  transport: TransportGateway;
542
662
  ready: Promise<MyAxiosInstance>;
@@ -629,6 +749,13 @@ declare module "@cpzxrobot/sdk" {
629
749
  AlarmStatisticsByTypeResponse,
630
750
  AlarmTrendItem,
631
751
  AlarmTrendResponse,
752
+ AlarmRuleThresholdConfig,
753
+ AlarmRuleAlarmConfig,
754
+ CreateAlarmRuleRequest,
755
+ CreateAlarmRuleResponse,
756
+ AlarmRuleDetail,
757
+ AlarmRuleListResponse,
758
+ AlarmRuleDetailResponse,
632
759
  ElectricMeterRate,
633
760
  DevicePurpose,
634
761
  };
@@ -1,16 +0,0 @@
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();