@cpzxrobot/sdk 1.3.102 → 1.3.104

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
@@ -14,8 +14,11 @@ import type {
14
14
  AlarmHistoryResponse,
15
15
  CreateAlarmRuleRequest,
16
16
  CreateAlarmRuleResponse,
17
+ UpdateAlarmRuleRequest,
18
+ UpdateAlarmRuleResponse,
17
19
  ActiveAlarmRuleRequest,
18
20
  ActiveAlarmRuleResponse,
21
+ ActivatedFactoriesResponse,
19
22
  AlarmRuleListResponse,
20
23
  AlarmRuleDetailResponse,
21
24
  } from ".";
@@ -283,6 +286,40 @@ export class DeviceGateway extends Object {
283
286
  return res.data;
284
287
  });
285
288
  },
289
+
290
+ /**
291
+ * 修改报警规则
292
+ * @param request 修改报警规则的请求参数
293
+ * @returns Promise 包含修改结果
294
+ */
295
+ update: async (request: UpdateAlarmRuleRequest): Promise<UpdateAlarmRuleResponse> => {
296
+ const axios = await this.context.ready;
297
+
298
+ // 参数验证
299
+ if (!request.id) {
300
+ throw new Error('规则ID不能为空');
301
+ }
302
+ if (!request.factoryId) {
303
+ let farm = await this.context.user.getSelectedFarm();
304
+ request.factoryId = farm?.id || 0;
305
+ }
306
+ if (!request.ruleName) {
307
+ throw new Error('规则名称不能为空');
308
+ }
309
+
310
+ // 设置默认值
311
+ const requestData: UpdateAlarmRuleRequest = {
312
+ ...request,
313
+ ruleActive: request.ruleActive !== undefined ? request.ruleActive : true
314
+ };
315
+
316
+ return axios.post(`/api/v2/device/stat/alarms/rule/update`, requestData).then((res) => {
317
+ if (res.data.code !== 200) {
318
+ throw new Error(res.data.message || '修改报警规则失败');
319
+ }
320
+ return res.data;
321
+ });
322
+ },
286
323
  /**
287
324
  * 删除报警规则
288
325
  * @param id - 报警规则ID
@@ -317,6 +354,29 @@ export class DeviceGateway extends Object {
317
354
  return res.data;
318
355
  });
319
356
  },
357
+
358
+ /**
359
+ * 获取已激活工厂列表
360
+ * @param ruleId 规则ID
361
+ * @returns Promise 包含已激活的工厂ID列表
362
+ */
363
+ getActivatedFactories: async (ruleId: number): Promise<ActivatedFactoriesResponse> => {
364
+ const axios = await this.context.ready;
365
+
366
+ // 参数验证
367
+ if (!ruleId) {
368
+ throw new Error('规则ID不能为空');
369
+ }
370
+
371
+ return axios.get(`/api/v2/device/stat/alarms/rule/list`, {
372
+ params: { id: ruleId }
373
+ }).then((res) => {
374
+ if (res.data.code !== 200) {
375
+ throw new Error(res.data.message || '获取已激活工厂列表失败');
376
+ }
377
+ return res.data;
378
+ });
379
+ },
320
380
  };
321
381
  }
322
382
 
@@ -212,6 +212,33 @@ class DeviceGateway extends Object {
212
212
  return res.data;
213
213
  });
214
214
  }),
215
+ /**
216
+ * 修改报警规则
217
+ * @param request 修改报警规则的请求参数
218
+ * @returns Promise 包含修改结果
219
+ */
220
+ update: (request) => __awaiter(this, void 0, void 0, function* () {
221
+ const axios = yield this.context.ready;
222
+ // 参数验证
223
+ if (!request.id) {
224
+ throw new Error('规则ID不能为空');
225
+ }
226
+ if (!request.factoryId) {
227
+ let farm = yield this.context.user.getSelectedFarm();
228
+ request.factoryId = (farm === null || farm === void 0 ? void 0 : farm.id) || 0;
229
+ }
230
+ if (!request.ruleName) {
231
+ throw new Error('规则名称不能为空');
232
+ }
233
+ // 设置默认值
234
+ const requestData = Object.assign(Object.assign({}, request), { ruleActive: request.ruleActive !== undefined ? request.ruleActive : true });
235
+ return axios.post(`/api/v2/device/stat/alarms/rule/update`, requestData).then((res) => {
236
+ if (res.data.code !== 200) {
237
+ throw new Error(res.data.message || '修改报警规则失败');
238
+ }
239
+ return res.data;
240
+ });
241
+ }),
215
242
  /**
216
243
  * 删除报警规则
217
244
  * @param id - 报警规则ID
@@ -243,6 +270,26 @@ class DeviceGateway extends Object {
243
270
  return res.data;
244
271
  });
245
272
  }),
273
+ /**
274
+ * 获取已激活工厂列表
275
+ * @param ruleId 规则ID
276
+ * @returns Promise 包含已激活的工厂ID列表
277
+ */
278
+ getActivatedFactories: (ruleId) => __awaiter(this, void 0, void 0, function* () {
279
+ const axios = yield this.context.ready;
280
+ // 参数验证
281
+ if (!ruleId) {
282
+ throw new Error('规则ID不能为空');
283
+ }
284
+ return axios.get(`/api/v2/device/stat/alarms/rule/list`, {
285
+ params: { id: ruleId }
286
+ }).then((res) => {
287
+ if (res.data.code !== 200) {
288
+ throw new Error(res.data.message || '获取已激活工厂列表失败');
289
+ }
290
+ return res.data;
291
+ });
292
+ }),
246
293
  };
247
294
  }
248
295
  constructor(context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.102",
3
+ "version": "1.3.104",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types.d.ts CHANGED
@@ -653,6 +653,50 @@ interface CreateAlarmRuleResponse {
653
653
  message: string;
654
654
  }
655
655
 
656
+ /**
657
+ * 修改报警规则请求接口
658
+ */
659
+ interface UpdateAlarmRuleRequest {
660
+ /** 规则id */
661
+ id: number;
662
+ /** 工厂id */
663
+ factoryId: number;
664
+ /** 规则名称 */
665
+ ruleName: string;
666
+ /** 规则描述 */
667
+ ruleDescription?: string;
668
+ /** 规则是否启用 */
669
+ ruleActive?: boolean;
670
+ /** 单元id列表 */
671
+ unitIds?: number[];
672
+ /** 栋舍id列表 */
673
+ workshopIds?: number[];
674
+ /** 栋舍类型列表 */
675
+ workshopTypes?: number[];
676
+ /** 报警方式 */
677
+ alarmType?: "OFFLINE" | "FAULT" | "THRESHOLD" | "TREND";
678
+ /** 设备类型列表 */
679
+ deviceTypes?: ("GATEWAY" | "SENSOR" | "DEVICE")[];
680
+ /** 阈值配置列表 */
681
+ thresholdConfigs?: AlarmRuleThresholdConfig[];
682
+ /** 报警配置列表 */
683
+ alarmConfigs?: AlarmRuleAlarmConfig[];
684
+ /** 激活规则的工厂数量 */
685
+ upperActiveSum?: number;
686
+ }
687
+
688
+ /**
689
+ * 修改报警规则响应接口
690
+ */
691
+ interface UpdateAlarmRuleResponse {
692
+ /** 响应码 */
693
+ code: number;
694
+ /** 响应数据 */
695
+ data: null;
696
+ /** 响应消息 */
697
+ message: string;
698
+ }
699
+
656
700
  /**
657
701
  * 报警规则详情接口
658
702
  */
@@ -743,6 +787,18 @@ interface ActiveAlarmRuleResponse {
743
787
  message: string;
744
788
  }
745
789
 
790
+ /**
791
+ * 已激活工厂列表响应接口
792
+ */
793
+ interface ActivatedFactoriesResponse {
794
+ /** 响应码 */
795
+ code: number;
796
+ /** 已激活的工厂ID列表 */
797
+ data: number[];
798
+ /** 响应消息 */
799
+ message: string;
800
+ }
801
+
746
802
  declare class Cpzxrobot {
747
803
  transport: TransportGateway;
748
804
  ready: Promise<MyAxiosInstance>;
@@ -841,8 +897,11 @@ declare module "@cpzxrobot/sdk" {
841
897
  AlarmRuleAlarmConfig,
842
898
  CreateAlarmRuleRequest,
843
899
  CreateAlarmRuleResponse,
900
+ UpdateAlarmRuleRequest,
901
+ UpdateAlarmRuleResponse,
844
902
  ActiveAlarmRuleRequest,
845
903
  ActiveAlarmRuleResponse,
904
+ ActivatedFactoriesResponse,
846
905
  AlarmRuleDetail,
847
906
  AlarmRuleListResponse,
848
907
  AlarmRuleDetailResponse,