告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_detail_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警详情数据模型
|
||||
class AlarmDetailModel {
|
||||
AlarmDetailModel({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.level,
|
||||
required this.deviceInfo,
|
||||
required this.occurTime,
|
||||
required this.alarmStatus,
|
||||
this.recoverTime,
|
||||
required this.duration,
|
||||
required this.affectRange,
|
||||
required this.description,
|
||||
required this.suggestions,
|
||||
required this.historyData,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String level;
|
||||
final String deviceInfo;
|
||||
final String occurTime;
|
||||
final String alarmStatus;
|
||||
final String? recoverTime;
|
||||
final String duration;
|
||||
final String affectRange;
|
||||
final String description;
|
||||
final List<String> suggestions;
|
||||
final HistoryDataModel historyData;
|
||||
|
||||
factory AlarmDetailModel.fromJson(Map<String, dynamic> json) {
|
||||
return AlarmDetailModel(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
level: json['level'] as String,
|
||||
deviceInfo: json['deviceInfo'] as String,
|
||||
occurTime: json['occurTime'] as String,
|
||||
alarmStatus: json['alarmStatus'] as String,
|
||||
recoverTime: json['recoverTime'] as String?,
|
||||
duration: json['duration'] as String,
|
||||
affectRange: json['affectRange'] as String,
|
||||
description: json['description'] as String,
|
||||
suggestions: (json['suggestions'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
[],
|
||||
historyData: HistoryDataModel.fromJson(
|
||||
json['historyData'] as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
AlarmDetailEntity toEntity() {
|
||||
return AlarmDetailEntity(
|
||||
id: id,
|
||||
title: title,
|
||||
level: _parseLevel(level),
|
||||
deviceInfo: deviceInfo,
|
||||
occurTime: occurTime,
|
||||
alarmStatus: alarmStatus,
|
||||
recoverTime: recoverTime,
|
||||
duration: duration,
|
||||
affectRange: affectRange,
|
||||
description: description,
|
||||
suggestions: suggestions,
|
||||
historyData: historyData.toEntity(),
|
||||
);
|
||||
}
|
||||
|
||||
AlarmLevel _parseLevel(String level) {
|
||||
switch (level) {
|
||||
case '严重':
|
||||
return AlarmLevel.danger;
|
||||
case '高危':
|
||||
return AlarmLevel.danger;
|
||||
case '中危':
|
||||
return AlarmLevel.warning;
|
||||
case '低危':
|
||||
return AlarmLevel.low;
|
||||
case '提示':
|
||||
return AlarmLevel.info;
|
||||
default:
|
||||
return AlarmLevel.info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 历史数据模型
|
||||
class HistoryDataModel {
|
||||
HistoryDataModel({
|
||||
this.power = const [],
|
||||
this.voltage = const [],
|
||||
this.frequency = const [],
|
||||
});
|
||||
|
||||
final List<MetricPointModel> power;
|
||||
final List<MetricPointModel> voltage;
|
||||
final List<MetricPointModel> frequency;
|
||||
|
||||
factory HistoryDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return HistoryDataModel(
|
||||
power: (json['power'] as List<dynamic>?)
|
||||
?.map((e) => MetricPointModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
voltage: (json['voltage'] as List<dynamic>?)
|
||||
?.map((e) => MetricPointModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
frequency: (json['frequency'] as List<dynamic>?)
|
||||
?.map((e) => MetricPointModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
HistoryMetrics toEntity() {
|
||||
return HistoryMetrics(
|
||||
power: power.map((e) => e.toEntity()).toList(),
|
||||
voltage: voltage.map((e) => e.toEntity()).toList(),
|
||||
frequency: frequency.map((e) => e.toEntity()).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 指标点模型
|
||||
class MetricPointModel {
|
||||
MetricPointModel({
|
||||
required this.time,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
final String time;
|
||||
final num value;
|
||||
|
||||
factory MetricPointModel.fromJson(Map<String, dynamic> json) {
|
||||
return MetricPointModel(
|
||||
time: json['time'] as String,
|
||||
value: json['value'] as num,
|
||||
);
|
||||
}
|
||||
|
||||
MetricDataPoint toEntity() {
|
||||
return MetricDataPoint(
|
||||
time: time,
|
||||
value: value.toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user