接入设备故障告警和场站实时任务进度

This commit is contained in:
2026-11-21 14:43:24 +08:00
parent 9a8a42a0a1
commit a37c448391
53 changed files with 5033 additions and 489 deletions

View File

@@ -0,0 +1,93 @@
import 'package:equatable/equatable.dart';
import '../../domain/entities/device_alarm.dart';
/// 所有设备与单设备展示只是对场站共享数据的不同投影。
class DeviceAlarmsState extends Equatable {
const DeviceAlarmsState({
this.siteId,
this.isLoading = false,
this.loadFailed = false,
this.alarms = const [],
this.deviceSns = const {},
this.receivedSns = const {},
this.failedSns = const {},
this.handlingIds = const {},
this.handleErrors = const {},
this.closedIds = const {},
});
final int? siteId;
final bool isLoading;
final bool loadFailed;
final List<DeviceAlarm> alarms;
final Set<String> deviceSns;
final Set<String> receivedSns;
final Set<String> failedSns;
final Set<int> handlingIds;
final Map<int, String> handleErrors;
final Set<int> closedIds;
bool get hasReceived =>
siteId != null &&
!isLoading &&
!loadFailed &&
deviceSns.every(receivedSns.contains);
bool get subscriptionFailed => loadFailed || failedSns.isNotEmpty;
int get pendingCount => alarms.where((alarm) => !alarm.isClosed).length;
DeviceAlarmsState forDevice(String? deviceSn) {
if (deviceSn == null) return this;
final sn = deviceSn.trim();
final records = alarms.where((alarm) => alarm.sourceSn == sn).toList();
final ids = records.map((alarm) => alarm.id).toSet();
return copyWith(
alarms: List.unmodifiable(records),
deviceSns: Set.unmodifiable({sn}),
receivedSns: Set.unmodifiable(receivedSns.where((value) => value == sn)),
failedSns: Set.unmodifiable(failedSns.where((value) => value == sn)),
handlingIds: Set.unmodifiable(handlingIds.intersection(ids)),
handleErrors: Map.unmodifiable({
for (final entry in handleErrors.entries)
if (ids.contains(entry.key)) entry.key: entry.value,
}),
);
}
DeviceAlarmsState copyWith({
bool? isLoading,
bool? loadFailed,
List<DeviceAlarm>? alarms,
Set<String>? deviceSns,
Set<String>? receivedSns,
Set<String>? failedSns,
Set<int>? handlingIds,
Map<int, String>? handleErrors,
Set<int>? closedIds,
}) => DeviceAlarmsState(
siteId: siteId,
isLoading: isLoading ?? this.isLoading,
loadFailed: loadFailed ?? this.loadFailed,
alarms: alarms ?? this.alarms,
deviceSns: deviceSns ?? this.deviceSns,
receivedSns: receivedSns ?? this.receivedSns,
failedSns: failedSns ?? this.failedSns,
handlingIds: handlingIds ?? this.handlingIds,
handleErrors: handleErrors ?? this.handleErrors,
closedIds: closedIds ?? this.closedIds,
);
@override
List<Object?> get props => [
siteId,
isLoading,
loadFailed,
alarms,
deviceSns,
receivedSns,
failedSns,
handlingIds,
handleErrors,
closedIds,
];
}