一次大的提交
This commit is contained in:
@@ -5,8 +5,11 @@ abstract class AlarmDetailRemoteDataSource {
|
||||
/// 获取告警详情
|
||||
Future<AlarmDetailModel> getAlarmDetail(String alarmId);
|
||||
|
||||
/// 确认告警
|
||||
Future<bool> confirmAlarm(String alarmId);
|
||||
/// 确认告警(处理中)
|
||||
Future<Map<String, dynamic>> confirmAlarm(String alarmId);
|
||||
|
||||
/// 处理告警(已关闭)
|
||||
Future<Map<String, dynamic>> handleAlarm(Map<String, dynamic> handleData);
|
||||
|
||||
/// AI诊断
|
||||
Future<String> aiDiagnosis(String alarmId);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/error/failure.dart';
|
||||
import '../../domain/entities/alarm_dispatch_entity.dart';
|
||||
|
||||
/// 告警派发远程数据源抽象
|
||||
abstract class AlarmDispatchRemoteDataSource {
|
||||
Future<Either<Failure, bool>> dispatchWorkOrder(AlarmDispatchEntity entity);
|
||||
}
|
||||
@@ -2,9 +2,17 @@ import 'package:maibu_satabot_v2/features/v2/waring_center/data/models/alarm_mod
|
||||
|
||||
/// 告警远程数据源抽象
|
||||
abstract class AlarmRemoteDataSource {
|
||||
/// 获取告警列表
|
||||
Future<List<AlarmModel>> getAlarmList();
|
||||
/// 获取告警列表(支持分页)
|
||||
Future<List<AlarmModel>> getAlarmList({
|
||||
int? siteId,
|
||||
int? configId,
|
||||
int? page,
|
||||
int? pageSize,
|
||||
});
|
||||
|
||||
/// 获取告警统计
|
||||
Future<AlarmCountModel> getAlarmCount();
|
||||
Future<AlarmCountModel> getAlarmCount({int? siteId});
|
||||
|
||||
/// 获取告警工单配置列表
|
||||
Future<List<AlarmOrderConfigModel>> getAlarmOrderConfigList(int siteId);
|
||||
}
|
||||
|
||||
@@ -1,55 +1,118 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/data/datasources/alarm_detail_remote_datasource.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/data/models/alarm_detail_model.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/data/models/alarm_handle_model.dart';
|
||||
|
||||
/// 告警详情远程数据源实现(模拟数据)
|
||||
/// 告警详情远程数据源实现
|
||||
class AlarmDetailRemoteDataSourceImpl implements AlarmDetailRemoteDataSource {
|
||||
AlarmDetailRemoteDataSourceImpl(this._dio);
|
||||
|
||||
final Dio _dio;
|
||||
|
||||
@override
|
||||
Future<AlarmDetailModel> getAlarmDetail(String alarmId) async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
final uri = '${HttpApiConsts.alarmDetail}/$alarmId';
|
||||
debugPrint('=== 告警详情请求 ===');
|
||||
debugPrint('uri: `$uri`');
|
||||
|
||||
return AlarmDetailModel(
|
||||
id: alarmId,
|
||||
title: '逆变器离网告警',
|
||||
level: '严重',
|
||||
deviceInfo: '光伏区A / 逆变器 INV-001',
|
||||
occurTime: '2025-05-19T09:24:30',
|
||||
alarmStatus: '未处理',
|
||||
recoverTime: null,
|
||||
duration: '36分钟',
|
||||
affectRange: '光伏区A(2.6 MW)',
|
||||
description: '逆变器与电网失去连接,功率输出为0。',
|
||||
suggestions: [
|
||||
'检查逆变器侧并网开关状态',
|
||||
'检查电网电压及频率是否异常',
|
||||
],
|
||||
historyData: HistoryDataModel(
|
||||
power: [
|
||||
MetricPointModel(time: '08:24', value: 1050),
|
||||
MetricPointModel(time: '08:54', value: 980),
|
||||
MetricPointModel(time: '09:04', value: 1020),
|
||||
MetricPointModel(time: '09:14', value: 990),
|
||||
MetricPointModel(time: '09:19', value: 1010),
|
||||
MetricPointModel(time: '09:24', value: 100),
|
||||
MetricPointModel(time: '09:24:30', value: 0),
|
||||
],
|
||||
voltage: [],
|
||||
frequency: [],
|
||||
),
|
||||
final response = await _dio.get(uri);
|
||||
|
||||
debugPrint('statusCode: ${response.statusCode}');
|
||||
debugPrint('statusMessage: ${response.statusMessage}');
|
||||
debugPrint('Response Text: ${response.data}');
|
||||
debugPrint('=== 告警详情响应结束 ===');
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '获取告警详情失败');
|
||||
}
|
||||
|
||||
return AlarmDetailModel.fromJson(
|
||||
responseData['data'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> confirmAlarm(String alarmId) async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
return true;
|
||||
Future<Map<String, dynamic>> confirmAlarm(String alarmId) async {
|
||||
final requestData = AlarmHandleModel(alarmId: alarmId, handleStatus: 2);
|
||||
|
||||
debugPrint('=== 确认告警请求 ===');
|
||||
debugPrint('uri: ${HttpApiConsts.alarmHandle}');
|
||||
debugPrint('requestData: ${requestData.toJson()}');
|
||||
|
||||
final response = await _dio.post(
|
||||
HttpApiConsts.alarmHandle,
|
||||
data: requestData.toJson(),
|
||||
);
|
||||
|
||||
debugPrint('statusCode: ${response.statusCode}');
|
||||
debugPrint('statusMessage: ${response.statusMessage}');
|
||||
debugPrint('Response Data: ${response.data}');
|
||||
debugPrint('=== 确认告警响应结束 ===');
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '确认告警失败');
|
||||
}
|
||||
|
||||
return responseData as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> handleAlarm(
|
||||
Map<String, dynamic> handleData,
|
||||
) async {
|
||||
debugPrint('=== 处理告警请求 ===');
|
||||
debugPrint('uri: ${HttpApiConsts.alarmHandle}');
|
||||
debugPrint('requestData: $handleData');
|
||||
|
||||
final response = await _dio.post(
|
||||
HttpApiConsts.alarmHandle,
|
||||
data: handleData,
|
||||
);
|
||||
|
||||
debugPrint('statusCode: ${response.statusCode}');
|
||||
debugPrint('statusMessage: ${response.statusMessage}');
|
||||
debugPrint('Response Data: ${response.data}');
|
||||
debugPrint('=== 处理告警响应结束 ===');
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '处理告警失败');
|
||||
}
|
||||
|
||||
return responseData as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> aiDiagnosis(String alarmId) async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
return 'AI分析结果:\n\n根据历史数据分析,该告警可能是由于以下原因导致:\n1. 电网侧电压波动超过阈值\n2. 逆变器保护机制触发\n3. 并网开关异常断开\n\n建议优先检查并网开关状态和电网电压稳定性。';
|
||||
final response = await _dio.get(
|
||||
'${HttpApiConsts.alarmDetail}/$alarmId/aiDiagnosis',
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? 'AI诊断失败');
|
||||
}
|
||||
|
||||
return responseData['data'] as String? ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../../../../../../core/app/app_user_cubit.dart';
|
||||
import '../../../domain/entities/alarm_dispatch_entity.dart';
|
||||
import '../alarm_dispatch_remote_datasource.dart';
|
||||
|
||||
/// 告警派发远程数据源实现
|
||||
class AlarmDispatchRemoteDataSourceImpl
|
||||
implements AlarmDispatchRemoteDataSource {
|
||||
@override
|
||||
Future<Either<Failure, bool>> dispatchWorkOrder(
|
||||
AlarmDispatchEntity entity,
|
||||
) async {
|
||||
print('========================================');
|
||||
print('[告警派发工单] 开始提交');
|
||||
print('[告警派发工单] 请求URL: ${HttpApiConsts.workOrderAdd}');
|
||||
|
||||
try {
|
||||
// 格式化计划时间
|
||||
String formatDateTime(DateTime? dt) {
|
||||
if (dt == null) return '';
|
||||
return '${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} '
|
||||
'${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:'
|
||||
'${dt.second.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
// 构造 workOrder JSON
|
||||
final workOrder = <String, dynamic>{
|
||||
'siteId': entity.siteId,
|
||||
'siteName': entity.siteName ?? '',
|
||||
'sourceType': 7, // 7=告警关联
|
||||
'orderType': entity.orderType ?? '',
|
||||
'deviceId': entity.deviceId ?? '',
|
||||
'deviceName': entity.deviceName ?? '',
|
||||
'taskDescription': entity.description ?? '',
|
||||
'priorityLevel': entity.problemLevel ?? 'INFO',
|
||||
'orderTitle': '${entity.orderType ?? '告警派发'} - ${entity.deviceName ?? ''}',
|
||||
'orderStatus': 1, // 1=待处理
|
||||
'imgUrl': <String>[],
|
||||
'videoUrl': <String>[],
|
||||
'alarmId': entity.alarmId,
|
||||
'alarmNo': entity.alarmNo ?? '',
|
||||
'planStartTime': formatDateTime(entity.planStartTime),
|
||||
'planEndTime': formatDateTime(entity.planEndTime),
|
||||
};
|
||||
final workOrderJson = jsonEncode(workOrder);
|
||||
print('[告警派发工单] workOrder JSON: $workOrderJson');
|
||||
|
||||
// 分离图片和视频
|
||||
final imagePaths = <String>[];
|
||||
final videoPaths = <String>[];
|
||||
const videoExts = ['mp4', 'mov', 'avi', 'mkv', 'wmv', 'flv', '3gp'];
|
||||
|
||||
if (entity.mediaUrls != null) {
|
||||
for (final path in entity.mediaUrls!) {
|
||||
final ext = path.split('.').last.toLowerCase();
|
||||
if (videoExts.contains(ext)) {
|
||||
videoPaths.add(path);
|
||||
} else {
|
||||
imagePaths.add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
print('[告警派发工单] 图片: ${imagePaths.length}个, 视频: ${videoPaths.length}个');
|
||||
|
||||
// 创建 multipart 请求
|
||||
final request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(HttpApiConsts.workOrderAdd),
|
||||
);
|
||||
|
||||
// Authorization
|
||||
final userToken = GetIt.I<AppUserCubit>().state.user?.token;
|
||||
if (userToken != null) {
|
||||
request.headers['Authorization'] = 'Bearer $userToken';
|
||||
}
|
||||
|
||||
// 图片文件
|
||||
if (imagePaths.isNotEmpty) {
|
||||
final firstImage = imagePaths.first;
|
||||
final file = File(firstImage);
|
||||
if (await file.exists()) {
|
||||
final bytes = await file.readAsBytes();
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'file',
|
||||
bytes,
|
||||
filename: firstImage.split('/').last,
|
||||
contentType: http.MediaType('image', 'jpeg'),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'file',
|
||||
<int>[],
|
||||
filename: 'empty.jpg',
|
||||
contentType: http.MediaType('image', 'jpeg'),
|
||||
));
|
||||
}
|
||||
|
||||
// 视频文件
|
||||
if (videoPaths.isNotEmpty) {
|
||||
final firstVideo = videoPaths.first;
|
||||
final file = File(firstVideo);
|
||||
if (await file.exists()) {
|
||||
final bytes = await file.readAsBytes();
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'video',
|
||||
bytes,
|
||||
filename: firstVideo.split('/').last,
|
||||
contentType: http.MediaType('video', 'mp4'),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'video',
|
||||
<int>[],
|
||||
filename: 'empty.mp4',
|
||||
contentType: http.MediaType('video', 'mp4'),
|
||||
));
|
||||
}
|
||||
|
||||
// workOrder JSON
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'workOrder',
|
||||
utf8.encode(workOrderJson),
|
||||
filename: '',
|
||||
contentType: http.MediaType('application', 'json'),
|
||||
));
|
||||
|
||||
print('[告警派发工单] 开始发送请求...');
|
||||
|
||||
final http.StreamedResponse response = await request.send();
|
||||
final String responseBody = await response.stream.bytesToString();
|
||||
|
||||
print('[告警派发工单] 响应状态码: ${response.statusCode}');
|
||||
print('[告警派发工单] 响应体: $responseBody');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final respJson = jsonDecode(responseBody) as Map<String, dynamic>;
|
||||
final code = respJson['code'];
|
||||
if (code != null && code.toString() == '200') {
|
||||
print('[告警派发工单] 提交成功');
|
||||
print('========================================');
|
||||
return right(true);
|
||||
} else {
|
||||
final msg = respJson['msg'] ?? respJson['message'] ?? '提交失败';
|
||||
print('[告警派发工单] 业务失败: $msg');
|
||||
print('========================================');
|
||||
return left(Failure(msg.toString()));
|
||||
}
|
||||
} else {
|
||||
print('[告警派发工单] HTTP错误: ${response.statusCode}');
|
||||
print('========================================');
|
||||
return left(
|
||||
Failure('服务器错误: HTTP ${response.statusCode}'),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('[告警派发工单] 异常: $e');
|
||||
print('========================================');
|
||||
return left(Failure('提交失败: $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +1,56 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/data/datasources/alarm_remote_datasource.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/data/models/alarm_model.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警远程数据源实现(模拟数据)
|
||||
/// 告警远程数据源实现
|
||||
class AlarmRemoteDataSourceImpl implements AlarmRemoteDataSource {
|
||||
@override
|
||||
Future<List<AlarmModel>> getAlarmList() async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
AlarmRemoteDataSourceImpl(this._dio);
|
||||
|
||||
return [
|
||||
AlarmModel(
|
||||
id: '1',
|
||||
title: '逆变器INV-001通讯异常',
|
||||
area: 'A区',
|
||||
device: 'INV-001',
|
||||
time: '05-21 10:23',
|
||||
level: AlarmLevel.danger,
|
||||
status: AlarmStatus.unconfirmed,
|
||||
aiDiagnosis: 'INV-001通讯异常可能由网络波动或采集器故障引起,建议检查网络连接。',
|
||||
),
|
||||
AlarmModel(
|
||||
id: '2',
|
||||
title: '汇流箱SCB-003过温告警',
|
||||
area: 'B区',
|
||||
device: 'SCB-003',
|
||||
time: '05-21 09:45',
|
||||
level: AlarmLevel.warning,
|
||||
status: AlarmStatus.unconfirmed,
|
||||
),
|
||||
AlarmModel(
|
||||
id: '3',
|
||||
title: '组件串STR-024功率异常',
|
||||
area: 'C区',
|
||||
device: 'STR-024',
|
||||
time: '05-21 08:32',
|
||||
level: AlarmLevel.low,
|
||||
status: AlarmStatus.confirmed,
|
||||
),
|
||||
AlarmModel(
|
||||
id: '4',
|
||||
title: '环境辐照度传感器离线',
|
||||
area: 'D区',
|
||||
device: 'SEN-001',
|
||||
time: '05-21 07:15',
|
||||
level: AlarmLevel.info,
|
||||
status: AlarmStatus.confirmed,
|
||||
),
|
||||
];
|
||||
final Dio _dio;
|
||||
|
||||
@override
|
||||
Future<List<AlarmModel>> getAlarmList({
|
||||
int? siteId,
|
||||
int? configId,
|
||||
int? page,
|
||||
int? pageSize,
|
||||
}) async {
|
||||
final queryParams = <String, dynamic>{};
|
||||
if (siteId != null) queryParams['siteId'] = siteId;
|
||||
if (configId != null) queryParams['configId'] = configId;
|
||||
if (page != null) queryParams['page'] = page;
|
||||
if (pageSize != null) queryParams['pageSize'] = pageSize;
|
||||
|
||||
debugPrint('=== 获取告警列表请求 ===');
|
||||
debugPrint('uri: ${HttpApiConsts.alarmList}');
|
||||
debugPrint('queryParams: $queryParams');
|
||||
|
||||
final response = await _dio.get(
|
||||
HttpApiConsts.alarmList,
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '获取告警列表失败');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
return rows
|
||||
.map((item) => AlarmModel.fromJson(item as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AlarmCountModel> getAlarmCount() async {
|
||||
Future<AlarmCountModel> getAlarmCount({int? siteId}) async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
|
||||
@@ -62,4 +61,31 @@ class AlarmRemoteDataSourceImpl implements AlarmRemoteDataSource {
|
||||
todayNew: 12,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<AlarmOrderConfigModel>> getAlarmOrderConfigList(
|
||||
int siteId,
|
||||
) async {
|
||||
final response = await _dio.post(
|
||||
HttpApiConsts.alarmOrderConfigList,
|
||||
data: {'siteId': siteId},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '获取告警工单配置失败');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
return rows
|
||||
.map(
|
||||
(item) =>
|
||||
AlarmOrderConfigModel.fromJson(item as Map<String, dynamic>),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,24 @@ class AlarmDetailModel {
|
||||
required this.description,
|
||||
required this.suggestions,
|
||||
required this.historyData,
|
||||
this.alarmNo,
|
||||
this.alarmType,
|
||||
this.deviceId,
|
||||
this.deviceType,
|
||||
this.createTime,
|
||||
this.updateTime,
|
||||
this.handleUserId,
|
||||
this.handleUserName,
|
||||
this.handleTime,
|
||||
this.handleRemark,
|
||||
this.rootCause,
|
||||
this.handleSuggestion,
|
||||
this.siteId,
|
||||
this.orgId,
|
||||
this.notifySms,
|
||||
this.notifyTelegram,
|
||||
this.notifyEmail,
|
||||
this.handleResult,
|
||||
});
|
||||
|
||||
final String id;
|
||||
@@ -30,29 +48,99 @@ class AlarmDetailModel {
|
||||
final String description;
|
||||
final List<String> suggestions;
|
||||
final HistoryDataModel historyData;
|
||||
final String? alarmNo;
|
||||
final int? alarmType;
|
||||
final String? deviceId;
|
||||
final String? deviceType;
|
||||
final String? createTime;
|
||||
final String? updateTime;
|
||||
final String? handleUserId;
|
||||
final String? handleUserName;
|
||||
final String? handleTime;
|
||||
final String? handleRemark;
|
||||
final String? rootCause;
|
||||
final String? handleSuggestion;
|
||||
final int? siteId;
|
||||
final int? orgId;
|
||||
final int? notifySms;
|
||||
final int? notifyTelegram;
|
||||
final int? notifyEmail;
|
||||
final String? handleResult;
|
||||
|
||||
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() ??
|
||||
[],
|
||||
id: json['id'].toString(),
|
||||
title: json['alarmTitle']?.toString() ?? '',
|
||||
level: json['alarmLevel']?.toString() ?? '',
|
||||
deviceInfo:
|
||||
(json['deviceName']?.toString() ??
|
||||
json['deviceId']?.toString() ??
|
||||
'') +
|
||||
(json['deviceType'] != null ? ' (${json['deviceType']})' : ''),
|
||||
occurTime: json['alarmTime']?.toString() ?? '',
|
||||
alarmStatus: _parseStatus(json['handleStatus']),
|
||||
recoverTime: json['recoverTime']?.toString(),
|
||||
duration: json['duration']?.toString() ?? '',
|
||||
affectRange: json['siteId'] != null ? '站点${json['siteId']}' : '',
|
||||
description: json['alarmContent']?.toString() ?? '',
|
||||
suggestions: _parseSuggestions(json['handleSuggestion']),
|
||||
historyData: HistoryDataModel.fromJson(
|
||||
json['historyData'] as Map<String, dynamic>,
|
||||
json['historyData'] as Map<String, dynamic>? ?? {},
|
||||
),
|
||||
alarmNo: json['alarmNo']?.toString(),
|
||||
alarmType: json['alarmType'] is int ? json['alarmType'] as int : null,
|
||||
deviceId: json['deviceId']?.toString(),
|
||||
deviceType: json['deviceType']?.toString(),
|
||||
createTime: json['createTime']?.toString(),
|
||||
updateTime: json['updateTime']?.toString(),
|
||||
handleUserId: json['handleUserId']?.toString(),
|
||||
handleUserName: json['handleUserName']?.toString(),
|
||||
handleTime: json['handleTime']?.toString(),
|
||||
handleRemark: json['handleRemark']?.toString(),
|
||||
rootCause: json['rootCause']?.toString(),
|
||||
handleSuggestion: json['handleSuggestion']?.toString(),
|
||||
siteId: json['siteId'] is int ? json['siteId'] as int : null,
|
||||
orgId: json['orgId'] is int ? json['orgId'] as int : null,
|
||||
notifySms: json['notifySms'] is int ? json['notifySms'] as int : null,
|
||||
notifyTelegram: json['notifyTelegram'] is int
|
||||
? json['notifyTelegram'] as int
|
||||
: null,
|
||||
notifyEmail: json['notifyEmail'] is int
|
||||
? json['notifyEmail'] as int
|
||||
: null,
|
||||
handleResult: json['handleResult']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
static String _parseStatus(dynamic status) {
|
||||
if (status is int) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '待处理';
|
||||
case 2:
|
||||
return '已关闭';
|
||||
case 3:
|
||||
return '已关闭';
|
||||
case 4:
|
||||
return '已忽略';
|
||||
default:
|
||||
return '待处理';
|
||||
}
|
||||
}
|
||||
return status as String? ?? '待处理';
|
||||
}
|
||||
|
||||
static List<String> _parseSuggestions(dynamic suggestion) {
|
||||
if (suggestion == null) return [];
|
||||
if (suggestion is String) {
|
||||
return suggestion.split('\n').where((s) => s.trim().isNotEmpty).toList();
|
||||
}
|
||||
if (suggestion is List) {
|
||||
return suggestion.map((e) => e.toString()).toList();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
AlarmDetailEntity toEntity() {
|
||||
return AlarmDetailEntity(
|
||||
id: id,
|
||||
@@ -67,23 +155,45 @@ class AlarmDetailModel {
|
||||
description: description,
|
||||
suggestions: suggestions,
|
||||
historyData: historyData.toEntity(),
|
||||
alarmNo: alarmNo,
|
||||
alarmType: alarmType,
|
||||
deviceId: deviceId,
|
||||
deviceType: deviceType,
|
||||
createTime: createTime,
|
||||
updateTime: updateTime,
|
||||
handleUserId: handleUserId,
|
||||
handleUserName: handleUserName,
|
||||
handleTime: handleTime,
|
||||
handleRemark: handleRemark,
|
||||
rootCause: rootCause,
|
||||
handleSuggestion: handleSuggestion,
|
||||
siteId: siteId,
|
||||
orgId: orgId,
|
||||
notifySms: notifySms,
|
||||
notifyTelegram: notifyTelegram,
|
||||
notifyEmail: notifyEmail,
|
||||
handleResult: handleResult,
|
||||
);
|
||||
}
|
||||
|
||||
AlarmLevel _parseLevel(String level) {
|
||||
switch (level) {
|
||||
final lowerLevel = level.toLowerCase();
|
||||
switch (lowerLevel) {
|
||||
case 'danger':
|
||||
case '严重':
|
||||
return AlarmLevel.danger;
|
||||
case '高危':
|
||||
return AlarmLevel.danger;
|
||||
case 'warning':
|
||||
case '中危':
|
||||
return AlarmLevel.warning;
|
||||
case 'low':
|
||||
case '低危':
|
||||
return AlarmLevel.low;
|
||||
case 'info':
|
||||
case '提示':
|
||||
return AlarmLevel.info;
|
||||
default:
|
||||
return AlarmLevel.info;
|
||||
return AlarmLevel.warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,15 +212,18 @@ class HistoryDataModel {
|
||||
|
||||
factory HistoryDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return HistoryDataModel(
|
||||
power: (json['power'] as List<dynamic>?)
|
||||
power:
|
||||
(json['power'] as List<dynamic>?)
|
||||
?.map((e) => MetricPointModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
voltage: (json['voltage'] as List<dynamic>?)
|
||||
voltage:
|
||||
(json['voltage'] as List<dynamic>?)
|
||||
?.map((e) => MetricPointModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
frequency: (json['frequency'] as List<dynamic>?)
|
||||
frequency:
|
||||
(json['frequency'] as List<dynamic>?)
|
||||
?.map((e) => MetricPointModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
@@ -128,10 +241,7 @@ class HistoryDataModel {
|
||||
|
||||
/// 指标点模型
|
||||
class MetricPointModel {
|
||||
MetricPointModel({
|
||||
required this.time,
|
||||
required this.value,
|
||||
});
|
||||
MetricPointModel({required this.time, required this.value});
|
||||
|
||||
final String time;
|
||||
final num value;
|
||||
@@ -144,9 +254,6 @@ class MetricPointModel {
|
||||
}
|
||||
|
||||
MetricDataPoint toEntity() {
|
||||
return MetricDataPoint(
|
||||
time: time,
|
||||
value: value.toDouble(),
|
||||
);
|
||||
return MetricDataPoint(time: time, value: value.toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
class AlarmHandleModel {
|
||||
AlarmHandleModel({
|
||||
required this.alarmId,
|
||||
required this.handleStatus,
|
||||
this.handleRemark,
|
||||
this.rootCause,
|
||||
this.handleResult,
|
||||
});
|
||||
|
||||
final String alarmId;
|
||||
final int handleStatus;
|
||||
final String? handleRemark;
|
||||
final String? rootCause;
|
||||
final String? handleResult;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'alarmId': alarmId,
|
||||
'handleStatus': handleStatus,
|
||||
'handleRemark': handleRemark,
|
||||
'rootCause': rootCause,
|
||||
'handleResult': handleResult,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -27,14 +27,15 @@ class AlarmModel {
|
||||
/// 从 JSON 创建
|
||||
factory AlarmModel.fromJson(Map<String, dynamic> json) {
|
||||
return AlarmModel(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
area: json['area'] as String,
|
||||
device: json['device'] as String,
|
||||
time: json['time'] as String,
|
||||
level: _parseLevel(json['level'] as String),
|
||||
status: _parseStatus(json['status'] as String),
|
||||
aiDiagnosis: json['aiDiagnosis'] as String?,
|
||||
id: json['id'].toString(),
|
||||
title: json['alarmTitle']?.toString() ?? '',
|
||||
area: json['siteId'] != null ? '站点${json['siteId']}' : '',
|
||||
device:
|
||||
json['deviceName']?.toString() ?? json['deviceId']?.toString() ?? '',
|
||||
time: json['alarmTime']?.toString() ?? '',
|
||||
level: _parseLevel(json['alarmLevel']?.toString() ?? ''),
|
||||
status: _parseStatus(json['handleStatus']),
|
||||
aiDiagnosis: json['aiDiagnosis']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,7 +82,8 @@ class AlarmModel {
|
||||
}
|
||||
|
||||
static AlarmLevel _parseLevel(String level) {
|
||||
switch (level) {
|
||||
final lowerLevel = level.toLowerCase();
|
||||
switch (lowerLevel) {
|
||||
case 'danger':
|
||||
return AlarmLevel.danger;
|
||||
case 'warning':
|
||||
@@ -91,21 +93,40 @@ class AlarmModel {
|
||||
case 'info':
|
||||
return AlarmLevel.info;
|
||||
default:
|
||||
return AlarmLevel.info;
|
||||
return AlarmLevel.warning;
|
||||
}
|
||||
}
|
||||
|
||||
static AlarmStatus _parseStatus(String status) {
|
||||
switch (status) {
|
||||
case 'unconfirmed':
|
||||
return AlarmStatus.unconfirmed;
|
||||
case 'confirmed':
|
||||
return AlarmStatus.confirmed;
|
||||
case 'recovered':
|
||||
return AlarmStatus.recovered;
|
||||
default:
|
||||
return AlarmStatus.unconfirmed;
|
||||
static AlarmStatus _parseStatus(dynamic status) {
|
||||
if (status is int) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return AlarmStatus.pending;
|
||||
case 2:
|
||||
return AlarmStatus.closed;
|
||||
case 3:
|
||||
return AlarmStatus.closed;
|
||||
case 4:
|
||||
return AlarmStatus.ignored;
|
||||
default:
|
||||
return AlarmStatus.pending;
|
||||
}
|
||||
}
|
||||
if (status is String) {
|
||||
switch (status) {
|
||||
case 'pending':
|
||||
return AlarmStatus.pending;
|
||||
case 'processing':
|
||||
return AlarmStatus.closed;
|
||||
case 'closed':
|
||||
return AlarmStatus.closed;
|
||||
case 'ignored':
|
||||
return AlarmStatus.ignored;
|
||||
default:
|
||||
return AlarmStatus.pending;
|
||||
}
|
||||
}
|
||||
return AlarmStatus.pending;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,3 +174,31 @@ class AlarmCountModel {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 告警工单配置数据模型
|
||||
class AlarmOrderConfigModel {
|
||||
AlarmOrderConfigModel({required this.id, required this.name, this.code});
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
final String? code;
|
||||
|
||||
/// 从 JSON 创建
|
||||
factory AlarmOrderConfigModel.fromJson(Map<String, dynamic> json) {
|
||||
return AlarmOrderConfigModel(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String? ?? '',
|
||||
code: json['code'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'id': id, 'name': name, 'code': code};
|
||||
}
|
||||
|
||||
/// 转换为实体
|
||||
AlarmOrderConfigEntity toEntity() {
|
||||
return AlarmOrderConfigEntity(id: id, name: name, code: code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ class AlarmDetailRepositoryImpl implements AlarmDetailRepository {
|
||||
final AlarmDetailRemoteDataSource _remoteDataSource;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, AlarmDetailEntity>> getAlarmDetail(String alarmId) async {
|
||||
Future<Either<Failure, AlarmDetailEntity>> getAlarmDetail(
|
||||
String alarmId,
|
||||
) async {
|
||||
try {
|
||||
final model = await _remoteDataSource.getAlarmDetail(alarmId);
|
||||
return right(model.toEntity());
|
||||
@@ -21,7 +23,9 @@ class AlarmDetailRepositoryImpl implements AlarmDetailRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> confirmAlarm(String alarmId) async {
|
||||
Future<Either<Failure, Map<String, dynamic>>> confirmAlarm(
|
||||
String alarmId,
|
||||
) async {
|
||||
try {
|
||||
final result = await _remoteDataSource.confirmAlarm(alarmId);
|
||||
return right(result);
|
||||
@@ -30,6 +34,18 @@ class AlarmDetailRepositoryImpl implements AlarmDetailRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Map<String, dynamic>>> handleAlarm(
|
||||
Map<String, dynamic> handleData,
|
||||
) async {
|
||||
try {
|
||||
final result = await _remoteDataSource.handleAlarm(handleData);
|
||||
return right(result);
|
||||
} catch (e) {
|
||||
return left(ServerFailure('处理告警失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, String>> aiDiagnosis(String alarmId) async {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/error/failure.dart';
|
||||
import '../../domain/entities/alarm_dispatch_entity.dart';
|
||||
import '../../domain/usecases/dispatch_workorder_usecase.dart';
|
||||
import '../datasources/alarm_dispatch_remote_datasource.dart';
|
||||
|
||||
/// 告警派发仓储实现
|
||||
class AlarmDispatchRepositoryImpl implements AlarmDispatchRepository {
|
||||
final AlarmDispatchRemoteDataSource remoteDataSource;
|
||||
|
||||
AlarmDispatchRepositoryImpl({required this.remoteDataSource});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> dispatchWorkOrder(
|
||||
AlarmDispatchEntity entity,
|
||||
) async {
|
||||
return await remoteDataSource.dispatchWorkOrder(entity);
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,18 @@ class AlarmRepositoryImpl implements AlarmRepository {
|
||||
@override
|
||||
Future<Either<Failure, List<AlarmEntity>>> getAlarmList({
|
||||
AlarmFilterTab? filter,
|
||||
int? siteId,
|
||||
int? configId,
|
||||
int? page,
|
||||
int? pageSize,
|
||||
}) async {
|
||||
try {
|
||||
final models = await _remoteDataSource.getAlarmList();
|
||||
final models = await _remoteDataSource.getAlarmList(
|
||||
siteId: siteId,
|
||||
configId: configId,
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
final entities = models.map((model) => model.toEntity()).toList();
|
||||
|
||||
// 根据筛选条件过滤
|
||||
@@ -34,24 +43,46 @@ class AlarmRepositoryImpl implements AlarmRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, AlarmCountEntity>> getAlarmCount() async {
|
||||
Future<Either<Failure, AlarmCountEntity>> getAlarmCount({int? siteId}) async {
|
||||
try {
|
||||
final model = await _remoteDataSource.getAlarmCount();
|
||||
final model = await _remoteDataSource.getAlarmCount(siteId: siteId);
|
||||
return right(model.toEntity());
|
||||
} catch (e) {
|
||||
return left(core_error.ServerFailure('获取告警统计失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<AlarmOrderConfigEntity>>> getAlarmOrderConfigList(
|
||||
int siteId,
|
||||
) async {
|
||||
try {
|
||||
final models = await _remoteDataSource.getAlarmOrderConfigList(siteId);
|
||||
final entities = models.map((model) => model.toEntity()).toList();
|
||||
return right(entities);
|
||||
} catch (e) {
|
||||
return left(core_error.ServerFailure('获取告警工单配置失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// 筛选告警
|
||||
List<AlarmEntity> _filterAlarms(List<AlarmEntity> alarms, AlarmFilterTab filter) {
|
||||
List<AlarmEntity> _filterAlarms(
|
||||
List<AlarmEntity> alarms,
|
||||
AlarmFilterTab filter,
|
||||
) {
|
||||
switch (filter) {
|
||||
case AlarmFilterTab.unprocessed:
|
||||
return alarms.where((alarm) => alarm.status == AlarmStatus.unconfirmed).toList();
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.pending)
|
||||
.toList();
|
||||
case AlarmFilterTab.confirmed:
|
||||
return alarms.where((alarm) => alarm.status == AlarmStatus.confirmed).toList();
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.processing)
|
||||
.toList();
|
||||
case AlarmFilterTab.recovered:
|
||||
return alarms.where((alarm) => alarm.status == AlarmStatus.recovered).toList();
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.closed)
|
||||
.toList();
|
||||
case AlarmFilterTab.all:
|
||||
return alarms;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// 告警工单配置实体
|
||||
class AlarmOrderConfigEntity extends Equatable {
|
||||
const AlarmOrderConfigEntity({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.code,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
final String? code;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, name, code];
|
||||
}
|
||||
|
||||
/// 告警统计实体
|
||||
class AlarmCountEntity extends Equatable {
|
||||
const AlarmCountEntity({
|
||||
|
||||
@@ -46,6 +46,24 @@ class AlarmDetailEntity extends Equatable {
|
||||
required this.description,
|
||||
required this.suggestions,
|
||||
required this.historyData,
|
||||
this.alarmNo,
|
||||
this.alarmType,
|
||||
this.deviceId,
|
||||
this.deviceType,
|
||||
this.createTime,
|
||||
this.updateTime,
|
||||
this.handleUserId,
|
||||
this.handleUserName,
|
||||
this.handleTime,
|
||||
this.handleRemark,
|
||||
this.rootCause,
|
||||
this.handleSuggestion,
|
||||
this.siteId,
|
||||
this.orgId,
|
||||
this.notifySms,
|
||||
this.notifyTelegram,
|
||||
this.notifyEmail,
|
||||
this.handleResult,
|
||||
});
|
||||
|
||||
/// 告警ID
|
||||
@@ -84,6 +102,60 @@ class AlarmDetailEntity extends Equatable {
|
||||
/// 历史指标数据
|
||||
final HistoryMetrics historyData;
|
||||
|
||||
/// 告警编号
|
||||
final String? alarmNo;
|
||||
|
||||
/// 告警类型
|
||||
final int? alarmType;
|
||||
|
||||
/// 设备ID
|
||||
final String? deviceId;
|
||||
|
||||
/// 设备类型
|
||||
final String? deviceType;
|
||||
|
||||
/// 创建时间
|
||||
final String? createTime;
|
||||
|
||||
/// 更新时间
|
||||
final String? updateTime;
|
||||
|
||||
/// 处理人ID
|
||||
final String? handleUserId;
|
||||
|
||||
/// 处理人名称
|
||||
final String? handleUserName;
|
||||
|
||||
/// 处理时间
|
||||
final String? handleTime;
|
||||
|
||||
/// 处理备注
|
||||
final String? handleRemark;
|
||||
|
||||
/// 根因
|
||||
final String? rootCause;
|
||||
|
||||
/// 处理建议(原始字符串)
|
||||
final String? handleSuggestion;
|
||||
|
||||
/// 站点ID
|
||||
final int? siteId;
|
||||
|
||||
/// 组织ID
|
||||
final int? orgId;
|
||||
|
||||
/// 是否短信通知
|
||||
final int? notifySms;
|
||||
|
||||
/// 是否电报通知
|
||||
final int? notifyTelegram;
|
||||
|
||||
/// 是否邮件通知
|
||||
final int? notifyEmail;
|
||||
|
||||
/// 处理结果
|
||||
final String? handleResult;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
@@ -98,6 +170,24 @@ class AlarmDetailEntity extends Equatable {
|
||||
description,
|
||||
suggestions,
|
||||
historyData,
|
||||
alarmNo,
|
||||
alarmType,
|
||||
deviceId,
|
||||
deviceType,
|
||||
createTime,
|
||||
updateTime,
|
||||
handleUserId,
|
||||
handleUserName,
|
||||
handleTime,
|
||||
handleRemark,
|
||||
rootCause,
|
||||
handleSuggestion,
|
||||
siteId,
|
||||
orgId,
|
||||
notifySms,
|
||||
notifyTelegram,
|
||||
notifyEmail,
|
||||
handleResult,
|
||||
];
|
||||
|
||||
AlarmDetailEntity copyWith({
|
||||
@@ -113,6 +203,24 @@ class AlarmDetailEntity extends Equatable {
|
||||
String? description,
|
||||
List<String>? suggestions,
|
||||
HistoryMetrics? historyData,
|
||||
String? alarmNo,
|
||||
int? alarmType,
|
||||
String? deviceId,
|
||||
String? deviceType,
|
||||
String? createTime,
|
||||
String? updateTime,
|
||||
String? handleUserId,
|
||||
String? handleUserName,
|
||||
String? handleTime,
|
||||
String? handleRemark,
|
||||
String? rootCause,
|
||||
String? handleSuggestion,
|
||||
int? siteId,
|
||||
int? orgId,
|
||||
int? notifySms,
|
||||
int? notifyTelegram,
|
||||
int? notifyEmail,
|
||||
String? handleResult,
|
||||
}) {
|
||||
return AlarmDetailEntity(
|
||||
id: id ?? this.id,
|
||||
@@ -127,6 +235,24 @@ class AlarmDetailEntity extends Equatable {
|
||||
description: description ?? this.description,
|
||||
suggestions: suggestions ?? this.suggestions,
|
||||
historyData: historyData ?? this.historyData,
|
||||
alarmNo: alarmNo ?? this.alarmNo,
|
||||
alarmType: alarmType ?? this.alarmType,
|
||||
deviceId: deviceId ?? this.deviceId,
|
||||
deviceType: deviceType ?? this.deviceType,
|
||||
createTime: createTime ?? this.createTime,
|
||||
updateTime: updateTime ?? this.updateTime,
|
||||
handleUserId: handleUserId ?? this.handleUserId,
|
||||
handleUserName: handleUserName ?? this.handleUserName,
|
||||
handleTime: handleTime ?? this.handleTime,
|
||||
handleRemark: handleRemark ?? this.handleRemark,
|
||||
rootCause: rootCause ?? this.rootCause,
|
||||
handleSuggestion: handleSuggestion ?? this.handleSuggestion,
|
||||
siteId: siteId ?? this.siteId,
|
||||
orgId: orgId ?? this.orgId,
|
||||
notifySms: notifySms ?? this.notifySms,
|
||||
notifyTelegram: notifyTelegram ?? this.notifyTelegram,
|
||||
notifyEmail: notifyEmail ?? this.notifyEmail,
|
||||
handleResult: handleResult ?? this.handleResult,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/// 告警派发工单实体
|
||||
class AlarmDispatchEntity {
|
||||
/// 告警ID
|
||||
final String alarmId;
|
||||
|
||||
/// 告警编号
|
||||
final String? alarmNo;
|
||||
|
||||
/// 告警原始设备类型(如 UAV, MOWER),用于映射 orderType
|
||||
final String? deviceType;
|
||||
|
||||
/// 映射后的工单类型(如 UAV_ERROR, MOWER_ERROR)
|
||||
final String? orderType;
|
||||
|
||||
/// 场站ID
|
||||
final int? siteId;
|
||||
|
||||
/// 场站名称
|
||||
final String? siteName;
|
||||
|
||||
/// 设备ID
|
||||
final String? deviceId;
|
||||
|
||||
/// 设备名称
|
||||
final String? deviceName;
|
||||
|
||||
/// 任务描述
|
||||
final String? description;
|
||||
|
||||
/// 问题等级
|
||||
final String? problemLevel;
|
||||
|
||||
/// 媒体文件路径列表
|
||||
final List<String>? mediaUrls;
|
||||
|
||||
/// 计划开始时间
|
||||
final DateTime? planStartTime;
|
||||
|
||||
/// 计划结束时间
|
||||
final DateTime? planEndTime;
|
||||
|
||||
const AlarmDispatchEntity({
|
||||
required this.alarmId,
|
||||
this.alarmNo,
|
||||
this.deviceType,
|
||||
this.orderType,
|
||||
this.siteId,
|
||||
this.siteName,
|
||||
this.deviceId,
|
||||
this.deviceName,
|
||||
this.description,
|
||||
this.problemLevel,
|
||||
this.mediaUrls,
|
||||
this.planStartTime,
|
||||
this.planEndTime,
|
||||
});
|
||||
|
||||
AlarmDispatchEntity copyWith({
|
||||
String? alarmId,
|
||||
String? alarmNo,
|
||||
String? deviceType,
|
||||
String? orderType,
|
||||
int? siteId,
|
||||
String? siteName,
|
||||
String? deviceId,
|
||||
String? deviceName,
|
||||
String? description,
|
||||
String? problemLevel,
|
||||
List<String>? mediaUrls,
|
||||
DateTime? planStartTime,
|
||||
DateTime? planEndTime,
|
||||
}) {
|
||||
return AlarmDispatchEntity(
|
||||
alarmId: alarmId ?? this.alarmId,
|
||||
alarmNo: alarmNo ?? this.alarmNo,
|
||||
deviceType: deviceType ?? this.deviceType,
|
||||
orderType: orderType ?? this.orderType,
|
||||
siteId: siteId ?? this.siteId,
|
||||
siteName: siteName ?? this.siteName,
|
||||
deviceId: deviceId ?? this.deviceId,
|
||||
deviceName: deviceName ?? this.deviceName,
|
||||
description: description ?? this.description,
|
||||
problemLevel: problemLevel ?? this.problemLevel,
|
||||
mediaUrls: mediaUrls ?? this.mediaUrls,
|
||||
planStartTime: planStartTime ?? this.planStartTime,
|
||||
planEndTime: planEndTime ?? this.planEndTime,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,13 @@ abstract class AlarmDetailRepository {
|
||||
/// 获取告警详情
|
||||
Future<Either<Failure, AlarmDetailEntity>> getAlarmDetail(String alarmId);
|
||||
|
||||
/// 确认告警
|
||||
Future<Either<Failure, bool>> confirmAlarm(String alarmId);
|
||||
/// 确认告警(处理中)
|
||||
Future<Either<Failure, Map<String, dynamic>>> confirmAlarm(String alarmId);
|
||||
|
||||
/// 处理告警(已关闭)
|
||||
Future<Either<Failure, Map<String, dynamic>>> handleAlarm(
|
||||
Map<String, dynamic> handleData,
|
||||
);
|
||||
|
||||
/// AI诊断
|
||||
Future<Either<Failure, String>> aiDiagnosis(String alarmId);
|
||||
|
||||
@@ -6,12 +6,21 @@ import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constant
|
||||
|
||||
/// 告警仓储接口
|
||||
abstract class AlarmRepository {
|
||||
/// 获取告警列表
|
||||
/// 获取告警列表(支持分页)
|
||||
/// [filter] 筛选条件
|
||||
Future<Either<Failure, List<AlarmEntity>>> getAlarmList({
|
||||
AlarmFilterTab? filter,
|
||||
int? siteId,
|
||||
int? configId,
|
||||
int? page,
|
||||
int? pageSize,
|
||||
});
|
||||
|
||||
/// 获取告警统计
|
||||
Future<Either<Failure, AlarmCountEntity>> getAlarmCount();
|
||||
Future<Either<Failure, AlarmCountEntity>> getAlarmCount({int? siteId});
|
||||
|
||||
/// 获取告警工单配置列表
|
||||
Future<Either<Failure, List<AlarmOrderConfigEntity>>> getAlarmOrderConfigList(
|
||||
int siteId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,24 @@ class ConfirmAlarmUseCase {
|
||||
|
||||
final AlarmDetailRepository _repository;
|
||||
|
||||
Future<Either<Failure, bool>> call(String alarmId) async {
|
||||
Future<Either<Failure, Map<String, dynamic>>> call(String alarmId) async {
|
||||
return await _repository.confirmAlarm(alarmId);
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理告警用例
|
||||
class HandleAlarmUseCase {
|
||||
HandleAlarmUseCase(this._repository);
|
||||
|
||||
final AlarmDetailRepository _repository;
|
||||
|
||||
Future<Either<Failure, Map<String, dynamic>>> call(
|
||||
Map<String, dynamic> handleData,
|
||||
) async {
|
||||
return await _repository.handleAlarm(handleData);
|
||||
}
|
||||
}
|
||||
|
||||
/// AI诊断用例
|
||||
class AIDiagnosisUseCase {
|
||||
AIDiagnosisUseCase(this._repository);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/error/failure.dart';
|
||||
import '../entities/alarm_dispatch_entity.dart';
|
||||
|
||||
/// 派发工单用例
|
||||
abstract class AlarmDispatchRepository {
|
||||
Future<Either<Failure, bool>> dispatchWorkOrder(
|
||||
AlarmDispatchEntity entity,
|
||||
);
|
||||
}
|
||||
|
||||
class DispatchWorkOrderUseCase {
|
||||
final AlarmDispatchRepository repository;
|
||||
|
||||
DispatchWorkOrderUseCase(this.repository);
|
||||
|
||||
Future<Either<Failure, bool>> execute(AlarmDispatchEntity entity) async {
|
||||
if (entity.siteId == null) {
|
||||
return left(Failure('请选择场站'));
|
||||
}
|
||||
if (entity.orderType == null || entity.orderType!.isEmpty) {
|
||||
return left(Failure('请选择上报类型'));
|
||||
}
|
||||
if (entity.deviceId == null || entity.deviceId!.isEmpty) {
|
||||
return left(Failure('请选择设备'));
|
||||
}
|
||||
if (entity.description == null || entity.description!.isEmpty) {
|
||||
return left(Failure('请填写问题描述'));
|
||||
}
|
||||
if (entity.problemLevel == null || entity.problemLevel!.isEmpty) {
|
||||
return left(Failure('请选择问题等级'));
|
||||
}
|
||||
if (entity.planStartTime == null) {
|
||||
return left(Failure('请选择计划开始时间'));
|
||||
}
|
||||
|
||||
return await repository.dispatchWorkOrder(entity);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class GetAlarmCountUseCase {
|
||||
final AlarmRepository _repository;
|
||||
|
||||
/// 执行用例
|
||||
Future<Either<Failure, AlarmCountEntity>> call() async {
|
||||
return await _repository.getAlarmCount();
|
||||
Future<Either<Failure, AlarmCountEntity>> call({int? siteId}) async {
|
||||
return await _repository.getAlarmCount(siteId: siteId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,21 @@ class GetAlarmListUseCase {
|
||||
|
||||
/// 执行用例
|
||||
/// [filter] 筛选条件
|
||||
/// [page] 页码
|
||||
/// [pageSize] 每页条数
|
||||
Future<Either<Failure, List<AlarmEntity>>> call({
|
||||
AlarmFilterTab? filter,
|
||||
int? siteId,
|
||||
int? configId,
|
||||
int? page,
|
||||
int? pageSize,
|
||||
}) async {
|
||||
return await _repository.getAlarmList(filter: filter);
|
||||
return await _repository.getAlarmList(
|
||||
filter: filter,
|
||||
siteId: siteId,
|
||||
configId: configId,
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:maibu_satabot_v2/core/error/failure.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_count_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/repositories/alarm_repository.dart';
|
||||
|
||||
/// 获取告警工单配置列表用例
|
||||
class GetAlarmOrderConfigUseCase {
|
||||
GetAlarmOrderConfigUseCase(this._repository);
|
||||
|
||||
final AlarmRepository _repository;
|
||||
|
||||
/// 执行用例
|
||||
Future<Either<Failure, List<AlarmOrderConfigEntity>>> call(int siteId) async {
|
||||
return await _repository.getAlarmOrderConfigList(siteId);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,232 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_count_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/get_alarm_count_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/get_alarm_list_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警中心 Cubit
|
||||
const int _pageSize = 50;
|
||||
const int _countPageSize = 500;
|
||||
|
||||
class AlarmCubit extends Cubit<AlarmState> {
|
||||
AlarmCubit({
|
||||
required GetAlarmListUseCase getAlarmListUseCase,
|
||||
required GetAlarmCountUseCase getAlarmCountUseCase,
|
||||
}) : _getAlarmListUseCase = getAlarmListUseCase,
|
||||
_getAlarmCountUseCase = getAlarmCountUseCase,
|
||||
super(AlarmInitial());
|
||||
}) : _getAlarmListUseCase = getAlarmListUseCase,
|
||||
super(AlarmInitial());
|
||||
|
||||
final GetAlarmListUseCase _getAlarmListUseCase;
|
||||
final GetAlarmCountUseCase _getAlarmCountUseCase;
|
||||
int _loadRequestId = 0;
|
||||
|
||||
int? get _siteId {
|
||||
try {
|
||||
return GetIt.I<SiteCubit>().state.selectedSite?.id;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 加载告警数据
|
||||
Future<void> loadAlarms({AlarmFilterTab? filter}) async {
|
||||
// 如果不是初始加载,保留旧数据
|
||||
final isInitialLoad = state is AlarmInitial;
|
||||
if (isInitialLoad) {
|
||||
emit(AlarmLoading());
|
||||
}
|
||||
|
||||
try {
|
||||
// 并行获取告警列表和统计
|
||||
final alarmsResult = await _getAlarmListUseCase(filter: filter);
|
||||
final countResult = await _getAlarmCountUseCase();
|
||||
final siteId = _siteId;
|
||||
final requestId = ++_loadRequestId;
|
||||
|
||||
final alarms = alarmsResult.fold(
|
||||
try {
|
||||
final alarmsResult = await _getAlarmListUseCase(
|
||||
siteId: siteId,
|
||||
page: 1,
|
||||
pageSize: _pageSize,
|
||||
);
|
||||
|
||||
final allAlarms = alarmsResult.fold(
|
||||
(failure) => <AlarmEntity>[],
|
||||
(alarms) => alarms,
|
||||
);
|
||||
|
||||
final count = countResult.fold(
|
||||
(failure) => null,
|
||||
(count) => count,
|
||||
final selectedFilter = filter ?? AlarmFilterTab.all;
|
||||
final filteredAlarms = _filterAlarms(allAlarms, selectedFilter);
|
||||
|
||||
emit(
|
||||
AlarmLoaded(
|
||||
allAlarms: allAlarms,
|
||||
alarms: filteredAlarms,
|
||||
count: const AlarmCountEntity(
|
||||
unprocessed: 0,
|
||||
processing: 0,
|
||||
confirmed: 0,
|
||||
todayNew: 0,
|
||||
),
|
||||
selectedFilter: selectedFilter,
|
||||
currentPage: 1,
|
||||
hasMore: allAlarms.length >= _pageSize,
|
||||
isCountLoading: true,
|
||||
),
|
||||
);
|
||||
|
||||
if (count == null) {
|
||||
emit(const AlarmError('获取告警统计失败'));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(AlarmLoaded(
|
||||
alarms: alarms,
|
||||
count: count,
|
||||
selectedFilter: filter ?? AlarmFilterTab.all,
|
||||
));
|
||||
_loadAndCalculateCounts(siteId, requestId);
|
||||
} catch (e) {
|
||||
emit(AlarmError('加载告警数据失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// 切换筛选标签
|
||||
Future<void> changeFilter(AlarmFilterTab filter) async {
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(selectedFilter: filter));
|
||||
await loadAlarms(filter: filter);
|
||||
Future<void> _loadAndCalculateCounts(
|
||||
int? siteId,
|
||||
int requestId,
|
||||
) async {
|
||||
try {
|
||||
final result = await _getAlarmListUseCase(
|
||||
siteId: siteId,
|
||||
page: 1,
|
||||
pageSize: _countPageSize,
|
||||
);
|
||||
|
||||
if (requestId != _loadRequestId) return;
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
if (requestId != _loadRequestId) return;
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(
|
||||
isCountLoading: false,
|
||||
count: const AlarmCountEntity(
|
||||
unprocessed: 0,
|
||||
processing: 0,
|
||||
confirmed: 0,
|
||||
todayNew: 0,
|
||||
),
|
||||
));
|
||||
}
|
||||
},
|
||||
(alarms) {
|
||||
if (requestId != _loadRequestId) return;
|
||||
final count = _calculateCounts(alarms);
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(
|
||||
isCountLoading: false,
|
||||
count: count,
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
if (requestId != _loadRequestId) return;
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(
|
||||
isCountLoading: false,
|
||||
count: const AlarmCountEntity(
|
||||
unprocessed: 0,
|
||||
processing: 0,
|
||||
confirmed: 0,
|
||||
todayNew: 0,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AlarmCountEntity _calculateCounts(List<AlarmEntity> alarms) {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
int unprocessed = 0;
|
||||
int confirmed = 0;
|
||||
int todayNew = 0;
|
||||
|
||||
for (final alarm in alarms) {
|
||||
if (alarm.status == AlarmStatus.pending) {
|
||||
unprocessed++;
|
||||
}
|
||||
if (alarm.status == AlarmStatus.closed) {
|
||||
confirmed++;
|
||||
}
|
||||
|
||||
try {
|
||||
final alarmTime = DateTime.parse(alarm.time);
|
||||
final alarmDate = DateTime(
|
||||
alarmTime.year,
|
||||
alarmTime.month,
|
||||
alarmTime.day,
|
||||
);
|
||||
if (alarmDate == today) {
|
||||
todayNew++;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
return AlarmCountEntity(
|
||||
unprocessed: unprocessed,
|
||||
processing: 0,
|
||||
confirmed: confirmed,
|
||||
todayNew: todayNew,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmLoaded) return;
|
||||
if (currentState.isLoadingMore || !currentState.hasMore) return;
|
||||
|
||||
emit(currentState.copyWith(isLoadingMore: true));
|
||||
|
||||
final siteId = _siteId;
|
||||
final nextPage = currentState.currentPage + 1;
|
||||
|
||||
try {
|
||||
final alarmsResult = await _getAlarmListUseCase(
|
||||
siteId: siteId,
|
||||
page: nextPage,
|
||||
pageSize: _pageSize,
|
||||
);
|
||||
|
||||
final newAlarms = alarmsResult.fold(
|
||||
(failure) => <AlarmEntity>[],
|
||||
(alarms) => alarms,
|
||||
);
|
||||
|
||||
final updatedAllAlarms = [
|
||||
...currentState.allAlarms,
|
||||
...newAlarms,
|
||||
];
|
||||
final filteredAlarms = _filterAlarms(
|
||||
updatedAllAlarms,
|
||||
currentState.selectedFilter,
|
||||
);
|
||||
|
||||
emit(
|
||||
AlarmLoaded(
|
||||
allAlarms: updatedAllAlarms,
|
||||
alarms: filteredAlarms,
|
||||
count: currentState.count,
|
||||
selectedFilter: currentState.selectedFilter,
|
||||
currentPage: nextPage,
|
||||
hasMore: newAlarms.length >= _pageSize,
|
||||
isLoadingMore: false,
|
||||
isCountLoading: currentState.isCountLoading,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(currentState.copyWith(isLoadingMore: false));
|
||||
}
|
||||
}
|
||||
|
||||
void changeFilter(AlarmFilterTab filter) {
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
final filteredAlarms = _filterAlarms(currentState.allAlarms, filter);
|
||||
emit(
|
||||
currentState.copyWith(alarms: filteredAlarms, selectedFilter: filter),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新数据
|
||||
Future<void> refresh() async {
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
@@ -73,4 +235,26 @@ class AlarmCubit extends Cubit<AlarmState> {
|
||||
await loadAlarms();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<AlarmEntity> _filterAlarms(
|
||||
List<AlarmEntity> alarms,
|
||||
AlarmFilterTab filter,
|
||||
) {
|
||||
switch (filter) {
|
||||
case AlarmFilterTab.unprocessed:
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.pending)
|
||||
.toList();
|
||||
case AlarmFilterTab.confirmed:
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.processing)
|
||||
.toList();
|
||||
case AlarmFilterTab.recovered:
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.closed)
|
||||
.toList();
|
||||
case AlarmFilterTab.all:
|
||||
return alarms;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/alarm_actions_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/get_alarm_detail_usecase.dart';
|
||||
@@ -8,14 +9,17 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
AlarmDetailCubit({
|
||||
required GetAlarmDetailUseCase getAlarmDetailUseCase,
|
||||
required ConfirmAlarmUseCase confirmAlarmUseCase,
|
||||
required HandleAlarmUseCase handleAlarmUseCase,
|
||||
required AIDiagnosisUseCase aiDiagnosisUseCase,
|
||||
}) : _getAlarmDetailUseCase = getAlarmDetailUseCase,
|
||||
_confirmAlarmUseCase = confirmAlarmUseCase,
|
||||
_aiDiagnosisUseCase = aiDiagnosisUseCase,
|
||||
super(AlarmDetailInitial());
|
||||
}) : _getAlarmDetailUseCase = getAlarmDetailUseCase,
|
||||
_confirmAlarmUseCase = confirmAlarmUseCase,
|
||||
_handleAlarmUseCase = handleAlarmUseCase,
|
||||
_aiDiagnosisUseCase = aiDiagnosisUseCase,
|
||||
super(AlarmDetailInitial());
|
||||
|
||||
final GetAlarmDetailUseCase _getAlarmDetailUseCase;
|
||||
final ConfirmAlarmUseCase _confirmAlarmUseCase;
|
||||
final HandleAlarmUseCase _handleAlarmUseCase;
|
||||
final AIDiagnosisUseCase _aiDiagnosisUseCase;
|
||||
|
||||
/// 加载告警详情
|
||||
@@ -47,7 +51,12 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmDetailLoaded) return;
|
||||
|
||||
emit(const AlarmDetailActionInProgress('确认告警'));
|
||||
emit(
|
||||
AlarmDetailActionInProgress(
|
||||
'确认告警',
|
||||
alarmDetail: currentState.alarmDetail,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final result = await _confirmAlarmUseCase(alarmId);
|
||||
@@ -56,17 +65,16 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
(failure) {
|
||||
emit(AlarmDetailError(failure.message));
|
||||
},
|
||||
(success) {
|
||||
if (success) {
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
isConfirmed: true,
|
||||
alarmDetail: currentState.alarmDetail.copyWith(
|
||||
alarmStatus: '已处理',
|
||||
),
|
||||
(responseData) {
|
||||
debugPrint('确认告警响应数据: $responseData');
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
isConfirmed: true,
|
||||
alarmDetail: currentState.alarmDetail.copyWith(
|
||||
alarmStatus: '处理中',
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -79,7 +87,12 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmDetailLoaded) return;
|
||||
|
||||
emit(const AlarmDetailActionInProgress('AI诊断'));
|
||||
emit(
|
||||
AlarmDetailActionInProgress(
|
||||
'AI诊断',
|
||||
alarmDetail: currentState.alarmDetail,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final result = await _aiDiagnosisUseCase(alarmId);
|
||||
@@ -96,4 +109,40 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
emit(AlarmDetailError('AI诊断失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理告警(提交处理)
|
||||
Future<void> handleAlarm(Map<String, dynamic> handleData) async {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmDetailLoaded) return;
|
||||
|
||||
emit(
|
||||
AlarmDetailActionInProgress(
|
||||
'提交处理',
|
||||
alarmDetail: currentState.alarmDetail,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final result = await _handleAlarmUseCase(handleData);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
emit(AlarmDetailError(failure.message));
|
||||
},
|
||||
(responseData) {
|
||||
debugPrint('处理告警响应数据: $responseData');
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
alarmDetail: currentState.alarmDetail.copyWith(
|
||||
alarmStatus: '已关闭',
|
||||
),
|
||||
isHandleSuccess: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
emit(AlarmDetailError('处理告警失败: $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,27 +32,31 @@ class AlarmDetailLoaded extends AlarmDetailState {
|
||||
this.selectedMetric = MetricType.power,
|
||||
this.isConfirmed = false,
|
||||
this.aiDiagnosisResult,
|
||||
this.isHandleSuccess = false,
|
||||
});
|
||||
|
||||
final AlarmDetailEntity alarmDetail;
|
||||
final MetricType selectedMetric;
|
||||
final bool isConfirmed;
|
||||
final String? aiDiagnosisResult;
|
||||
final bool isHandleSuccess;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [alarmDetail, selectedMetric, isConfirmed, aiDiagnosisResult];
|
||||
List<Object?> get props => [alarmDetail, selectedMetric, isConfirmed, aiDiagnosisResult, isHandleSuccess];
|
||||
|
||||
AlarmDetailLoaded copyWith({
|
||||
AlarmDetailEntity? alarmDetail,
|
||||
MetricType? selectedMetric,
|
||||
bool? isConfirmed,
|
||||
String? aiDiagnosisResult,
|
||||
bool? isHandleSuccess,
|
||||
}) {
|
||||
return AlarmDetailLoaded(
|
||||
alarmDetail: alarmDetail ?? this.alarmDetail,
|
||||
selectedMetric: selectedMetric ?? this.selectedMetric,
|
||||
isConfirmed: isConfirmed ?? this.isConfirmed,
|
||||
aiDiagnosisResult: aiDiagnosisResult ?? this.aiDiagnosisResult,
|
||||
isHandleSuccess: isHandleSuccess ?? this.isHandleSuccess,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -69,10 +73,14 @@ class AlarmDetailError extends AlarmDetailState {
|
||||
|
||||
/// 操作进行中状态
|
||||
class AlarmDetailActionInProgress extends AlarmDetailState {
|
||||
const AlarmDetailActionInProgress(this.action);
|
||||
const AlarmDetailActionInProgress(
|
||||
this.action, {
|
||||
this.alarmDetail,
|
||||
});
|
||||
|
||||
final String action;
|
||||
final AlarmDetailEntity? alarmDetail;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [action];
|
||||
List<Object?> get props => [action, alarmDetail];
|
||||
}
|
||||
|
||||
@@ -20,27 +20,56 @@ class AlarmLoading extends AlarmState {}
|
||||
/// 加载成功状态
|
||||
class AlarmLoaded extends AlarmState {
|
||||
const AlarmLoaded({
|
||||
required this.allAlarms,
|
||||
required this.alarms,
|
||||
required this.count,
|
||||
this.selectedFilter = AlarmFilterTab.all,
|
||||
this.currentPage = 1,
|
||||
this.hasMore = true,
|
||||
this.isLoadingMore = false,
|
||||
this.isCountLoading = false,
|
||||
});
|
||||
|
||||
final List<AlarmEntity> allAlarms;
|
||||
final List<AlarmEntity> alarms;
|
||||
final AlarmCountEntity count;
|
||||
final AlarmFilterTab selectedFilter;
|
||||
final int currentPage;
|
||||
final bool hasMore;
|
||||
final bool isLoadingMore;
|
||||
final bool isCountLoading;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [alarms, count, selectedFilter];
|
||||
List<Object?> get props => [
|
||||
allAlarms,
|
||||
alarms,
|
||||
count,
|
||||
selectedFilter,
|
||||
currentPage,
|
||||
hasMore,
|
||||
isLoadingMore,
|
||||
isCountLoading,
|
||||
];
|
||||
|
||||
AlarmLoaded copyWith({
|
||||
List<AlarmEntity>? allAlarms,
|
||||
List<AlarmEntity>? alarms,
|
||||
AlarmCountEntity? count,
|
||||
AlarmFilterTab? selectedFilter,
|
||||
int? currentPage,
|
||||
bool? hasMore,
|
||||
bool? isLoadingMore,
|
||||
bool? isCountLoading,
|
||||
}) {
|
||||
return AlarmLoaded(
|
||||
allAlarms: allAlarms ?? this.allAlarms,
|
||||
alarms: alarms ?? this.alarms,
|
||||
count: count ?? this.count,
|
||||
selectedFilter: selectedFilter ?? this.selectedFilter,
|
||||
currentPage: currentPage ?? this.currentPage,
|
||||
hasMore: hasMore ?? this.hasMore,
|
||||
isLoadingMore: isLoadingMore ?? this.isLoadingMore,
|
||||
isCountLoading: isCountLoading ?? this.isCountLoading,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,14 +90,17 @@ enum AlarmLevel {
|
||||
|
||||
/// 告警状态枚举
|
||||
enum AlarmStatus {
|
||||
/// 未确认
|
||||
unconfirmed('未确认'),
|
||||
/// 待处理
|
||||
pending('待处理'),
|
||||
|
||||
/// 已确认
|
||||
confirmed('已确认'),
|
||||
/// 处理中
|
||||
processing('处理中'),
|
||||
|
||||
/// 已恢复
|
||||
recovered('已恢复');
|
||||
/// 已关闭
|
||||
closed('已关闭'),
|
||||
|
||||
/// 已忽略
|
||||
ignored('已忽略');
|
||||
|
||||
const AlarmStatus(this.label);
|
||||
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/entities/alarm_dispatch_entity.dart';
|
||||
import '../../domain/entities/alarm_detail_entity.dart';
|
||||
import '../../domain/usecases/dispatch_workorder_usecase.dart';
|
||||
import '../states/alarm_dispatch_state.dart';
|
||||
import '../../../report/presentation/constants/report_constants.dart';
|
||||
import '../../../home/domain/entities/site_entity.dart';
|
||||
import '../../../home/domain/usecases/get_site_list_usecase.dart';
|
||||
import '../../../home/domain/repositories/site_repository.dart';
|
||||
import '../../../home/data/repositories/site_repository_impl.dart';
|
||||
import '../../../home/data/datasources/site_datasource_impl.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
|
||||
/// deviceType → ReportType 映射配置(方便后续修改)
|
||||
const Map<String, ReportType> deviceTypeToReportType = {
|
||||
'UAV': ReportType.uavError,
|
||||
'DRONE': ReportType.uavError,
|
||||
'MOWER': ReportType.mowerError,
|
||||
'ROBOT': ReportType.mowerError,
|
||||
};
|
||||
|
||||
class AlarmDispatchCubit extends Cubit<AlarmDispatchState> {
|
||||
final DispatchWorkOrderUseCase dispatchUseCase;
|
||||
final AlarmDetailEntity alarmDetail;
|
||||
final Dio dio;
|
||||
final AppUserCubit appUserCubit;
|
||||
final UserStorage userStorage;
|
||||
|
||||
AlarmDispatchCubit({
|
||||
required this.dispatchUseCase,
|
||||
required this.alarmDetail,
|
||||
required this.dio,
|
||||
required this.appUserCubit,
|
||||
required this.userStorage,
|
||||
}) : super(AlarmDispatchLoading()) {
|
||||
_init();
|
||||
}
|
||||
|
||||
Future<void> _init() async {
|
||||
_initFromAlarm();
|
||||
await _loadSiteName();
|
||||
}
|
||||
|
||||
/// 从告警数据初始化表单
|
||||
void _initFromAlarm() {
|
||||
final deviceType = alarmDetail.deviceType?.toUpperCase() ?? '';
|
||||
final reportType = deviceTypeToReportType[deviceType] ?? ReportType.other;
|
||||
final now = DateTime.now();
|
||||
|
||||
final entity = AlarmDispatchEntity(
|
||||
alarmId: alarmDetail.id,
|
||||
alarmNo: alarmDetail.alarmNo,
|
||||
deviceType: alarmDetail.deviceType,
|
||||
orderType: reportType.orderType,
|
||||
siteId: alarmDetail.siteId,
|
||||
siteName: null,
|
||||
deviceId: alarmDetail.deviceId,
|
||||
deviceName: alarmDetail.deviceInfo,
|
||||
description: alarmDetail.description,
|
||||
problemLevel: _mapAlarmLevelToProblemLevel(alarmDetail.level),
|
||||
planStartTime: now,
|
||||
planEndTime: now.add(const Duration(hours: 4)),
|
||||
);
|
||||
|
||||
emit(AlarmDispatchFormState(
|
||||
alarmId: alarmDetail.id,
|
||||
alarmNo: alarmDetail.alarmNo,
|
||||
entity: entity,
|
||||
selectedReportType: reportType,
|
||||
selectedDevice: alarmDetail.deviceInfo,
|
||||
selectedDeviceId: alarmDetail.deviceId,
|
||||
planStartTime: now,
|
||||
planEndTime: now.add(const Duration(hours: 4)),
|
||||
siteId: alarmDetail.siteId,
|
||||
));
|
||||
}
|
||||
|
||||
/// 加载场站列表,根据 siteId 找到场站名称
|
||||
Future<void> _loadSiteName() async {
|
||||
if (state is! AlarmDispatchFormState) return;
|
||||
final currentState = state as AlarmDispatchFormState;
|
||||
final siteId = currentState.siteId;
|
||||
if (siteId == null) return;
|
||||
|
||||
try {
|
||||
final siteDataSource = SiteDataSourceImpl(
|
||||
dio,
|
||||
userStorage,
|
||||
appUserCubit,
|
||||
);
|
||||
final siteRepository = SiteRepositoryImpl(siteDataSource);
|
||||
final getSiteListUseCase = GetSiteListUseCase(siteRepository);
|
||||
|
||||
final user = appUserCubit.state.user;
|
||||
if (user == null) return;
|
||||
|
||||
final result = await getSiteListUseCase(user.userId);
|
||||
result.fold(
|
||||
(failure) {},
|
||||
(sites) {
|
||||
final matches = sites.where((s) => s.id == siteId);
|
||||
if (matches.isNotEmpty) {
|
||||
final matchedSite = matches.first;
|
||||
emit(currentState.copyWith(
|
||||
siteName: matchedSite.siteName,
|
||||
entity: currentState.entity.copyWith(siteName: matchedSite.siteName),
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
// 加载失败不影响表单使用
|
||||
}
|
||||
}
|
||||
|
||||
/// 告警等级 → 问题等级映射
|
||||
String _mapAlarmLevelToProblemLevel(dynamic level) {
|
||||
final label = level.label?.toUpperCase() ?? level.toString().toUpperCase();
|
||||
if (label.contains('DANGER') || label.contains('严重') || label.contains('高危')) {
|
||||
return 'ERROR';
|
||||
}
|
||||
if (label.contains('WARNING') || label.contains('中危')) {
|
||||
return 'WARNING';
|
||||
}
|
||||
return 'INFO';
|
||||
}
|
||||
|
||||
/// 选择上报类型
|
||||
void selectReportType(ReportType type) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
selectedReportType: type,
|
||||
entity: s.entity.copyWith(orderType: type.orderType),
|
||||
));
|
||||
}
|
||||
|
||||
/// 选择问题等级
|
||||
void selectProblemLevel(ProblemLevel level) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
selectedProblemLevel: level,
|
||||
entity: s.entity.copyWith(problemLevel: level.level),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新描述
|
||||
void updateDescription(String description) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
entity: s.entity.copyWith(description: description),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新设备
|
||||
void updateDevice(String deviceName, String deviceId) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
selectedDevice: deviceName,
|
||||
selectedDeviceId: deviceId,
|
||||
entity: s.entity.copyWith(deviceId: deviceId, deviceName: deviceName),
|
||||
));
|
||||
}
|
||||
|
||||
/// 添加媒体文件
|
||||
void addMediaFile(String filePath) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
final updatedFiles = List<String>.from(s.mediaFiles)..add(filePath);
|
||||
emit(s.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
entity: s.entity.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
|
||||
/// 移除媒体文件
|
||||
void removeMediaFile(int index) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
final updatedFiles = List<String>.from(s.mediaFiles)..removeAt(index);
|
||||
emit(s.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
entity: s.entity.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新计划开始时间
|
||||
void updatePlanStartTime(DateTime time) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
planStartTime: time,
|
||||
entity: s.entity.copyWith(planStartTime: time),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新计划结束时间
|
||||
void updatePlanEndTime(DateTime time) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
planEndTime: time,
|
||||
entity: s.entity.copyWith(planEndTime: time),
|
||||
));
|
||||
}
|
||||
|
||||
/// 提交派发
|
||||
Future<void> submitDispatch() async {
|
||||
final s = state;
|
||||
if (s is! AlarmDispatchFormState) return;
|
||||
|
||||
emit(AlarmDispatchSubmitting());
|
||||
|
||||
final result = await dispatchUseCase.execute(s.entity);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
emit(s.copyWith(toastMessage: failure.message, isSuccess: false));
|
||||
},
|
||||
(success) {
|
||||
emit(s.copyWith(toastMessage: '工单派发成功', isSuccess: true));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 清除 toast 消息
|
||||
void clearToast() {
|
||||
final s = state;
|
||||
if (s is AlarmDispatchFormState) {
|
||||
emit(s.copyWith(toastMessage: null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/alarm_item_card.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/alarm_tab_bar.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/ai_diagnosis_card.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/widgets/site_selector_widget.dart';
|
||||
|
||||
/// 告警中心页面
|
||||
class AlarmCenterPage extends StatefulWidget {
|
||||
@@ -21,17 +22,33 @@ class AlarmCenterPage extends StatefulWidget {
|
||||
|
||||
class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
late AlarmCubit _cubit;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cubit = context.read<AlarmCubit>();
|
||||
// 首次加载数据
|
||||
_scrollController.addListener(_onScroll);
|
||||
|
||||
if (_cubit.state is AlarmInitial) {
|
||||
_cubit.loadAlarms();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
final maxScroll = _scrollController.position.maxScrollExtent;
|
||||
final currentScroll = _scrollController.position.pixels;
|
||||
if (currentScroll >= maxScroll - 200) {
|
||||
_cubit.loadMore();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
@@ -88,35 +105,33 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
await _cubit.refresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
controller: _scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: AlarmDimensions.moduleSpacing,
|
||||
bottom: 40,
|
||||
),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
//const SizedBox(height: AlarmDimensions.moduleSpacing),
|
||||
// 告警统计卡片
|
||||
AlarmCountCard(count: state.count),
|
||||
AlarmCountCard(count: state.count, isCountLoading: state.isCountLoading),
|
||||
const SizedBox(
|
||||
height: AlarmDimensions.moduleSpacing,
|
||||
),
|
||||
// 告警列表
|
||||
...state.alarms.map((alarm) {
|
||||
return AlarmItemCard(
|
||||
alarm: alarm,
|
||||
onTap: () {
|
||||
context.push(
|
||||
'/alarm_center/detail/${alarm.id}',
|
||||
);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
if (state.alarms.isNotEmpty)
|
||||
...state.alarms.map((alarm) {
|
||||
return AlarmItemCard(
|
||||
alarm: alarm,
|
||||
onTap: () async {
|
||||
await context.push(
|
||||
'/alarm_center/detail/${alarm.id}',
|
||||
);
|
||||
_cubit.loadAlarms();
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
const SizedBox(
|
||||
height: AlarmDimensions.moduleSpacing,
|
||||
),
|
||||
// AI 诊断建议(仅当有 AI 诊断内容时显示)
|
||||
if (state.alarms.any(
|
||||
(alarm) => alarm.aiDiagnosis != null,
|
||||
))
|
||||
@@ -130,10 +145,10 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
.aiDiagnosis ??
|
||||
'',
|
||||
onViewDetails: () {
|
||||
// TODO: 查看详情
|
||||
debugPrint('查看 AI 诊断详情');
|
||||
},
|
||||
),
|
||||
_buildLoadMoreIndicator(state),
|
||||
]),
|
||||
),
|
||||
),
|
||||
@@ -262,15 +277,24 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('alarm_center.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
const Flexible(child: SiteSelectorWidget(compact: true)),
|
||||
const SizedBox(width: 8),
|
||||
Container(width: 1, height: 20, color: const Color(0xFFE5E6EB)),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('alarm_center.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// 铃铛图标(消息通知)
|
||||
Stack(
|
||||
children: [
|
||||
@@ -323,6 +347,48 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadMoreIndicator(AlarmLoaded state) {
|
||||
if (state.isLoadingMore) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
CircularProgressIndicator(strokeWidth: 2),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'加载中...',
|
||||
style: TextStyle(fontSize: 12, color: AlarmColors.textTertiary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!state.hasMore) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'已加载全部数据',
|
||||
style: TextStyle(fontSize: 12, color: AlarmColors.textTertiary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'上滑加载更多',
|
||||
style: TextStyle(fontSize: 12, color: AlarmColors.textTertiary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterOption(String title, List<String> options) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -12,10 +12,7 @@ import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/
|
||||
class AlarmDetailPage extends StatefulWidget {
|
||||
final String alarmId;
|
||||
|
||||
const AlarmDetailPage({
|
||||
super.key,
|
||||
required this.alarmId,
|
||||
});
|
||||
const AlarmDetailPage({super.key, required this.alarmId});
|
||||
|
||||
@override
|
||||
State<AlarmDetailPage> createState() => _AlarmDetailPageState();
|
||||
@@ -23,6 +20,7 @@ class AlarmDetailPage extends StatefulWidget {
|
||||
|
||||
class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
late AlarmDetailCubit _cubit;
|
||||
AlarmDetailLoaded? _lastLoadedState;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -48,19 +46,14 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
_showAIDiagnosisDialog(state.aiDiagnosisResult!);
|
||||
}
|
||||
|
||||
// 确认告警成功后返回
|
||||
// 确认告警成功后显示提示
|
||||
if (state is AlarmDetailLoaded && state.isConfirmed) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('告警已确认'),
|
||||
content: Text('告警已确认,正在处理中'),
|
||||
backgroundColor: AlarmColors.success,
|
||||
),
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
@@ -73,10 +66,19 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
}
|
||||
|
||||
if (state is AlarmDetailLoaded) {
|
||||
_lastLoadedState = state;
|
||||
return _buildContent(state);
|
||||
}
|
||||
|
||||
if (state is AlarmDetailActionInProgress) {
|
||||
if (_lastLoadedState != null) {
|
||||
return Stack(
|
||||
children: [
|
||||
_buildContent(_lastLoadedState!),
|
||||
_buildLoadingOverlay(state.action),
|
||||
],
|
||||
);
|
||||
}
|
||||
return _buildLoadingOverlay(state.action);
|
||||
}
|
||||
|
||||
@@ -106,7 +108,10 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share_outlined, color: AlarmColors.textPrimary),
|
||||
icon: const Icon(
|
||||
Icons.share_outlined,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
onPressed: () {
|
||||
// TODO: 分享功能
|
||||
},
|
||||
@@ -140,9 +145,7 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AlarmColors.primary,
|
||||
),
|
||||
child: CircularProgressIndicator(color: AlarmColors.primary),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -193,9 +196,7 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: AlarmColors.primary,
|
||||
),
|
||||
CircularProgressIndicator(color: AlarmColors.primary),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'$action...',
|
||||
@@ -229,15 +230,17 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
// 告警详情信息列表
|
||||
_buildAlarmInfoList(alarm),
|
||||
const SizedBox(height: 16),
|
||||
// 指标趋势图
|
||||
MetricTrendChart(
|
||||
historyData: alarm.historyData,
|
||||
selectedMetric: state.selectedMetric,
|
||||
onMetricChanged: (metric) => _cubit.changeMetricType(metric),
|
||||
),
|
||||
// 指标趋势图(仅当有历史数据时显示)
|
||||
if (_hasHistoryData(alarm.historyData))
|
||||
MetricTrendChart(
|
||||
historyData: alarm.historyData,
|
||||
selectedMetric: state.selectedMetric,
|
||||
onMetricChanged: (metric) => _cubit.changeMetricType(metric),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 处理建议
|
||||
_buildSuggestionsCard(alarm.suggestions),
|
||||
// 处理建议(仅当有建议时显示)
|
||||
if (alarm.suggestions.isNotEmpty)
|
||||
_buildSuggestionsCard(alarm.suggestions),
|
||||
const SizedBox(height: 100), // 为底部按钮留出空间
|
||||
],
|
||||
),
|
||||
@@ -323,6 +326,61 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
|
||||
/// 告警详情信息列表
|
||||
Widget _buildAlarmInfoList(AlarmDetailEntity alarm) {
|
||||
final List<Widget> infoRows = [];
|
||||
|
||||
void addRow(String label, dynamic value, {Color? valueColor}) {
|
||||
if (value == null || value == '' || value == 0) return;
|
||||
final displayValue = value is bool
|
||||
? (value ? '是' : '否')
|
||||
: value.toString();
|
||||
infoRows.add(_buildInfoRow(label, displayValue, valueColor: valueColor));
|
||||
}
|
||||
|
||||
addRow('告警编号', alarm.alarmNo);
|
||||
addRow(
|
||||
'告警状态',
|
||||
alarm.alarmStatus,
|
||||
valueColor: alarm.alarmStatus == '待处理'
|
||||
? AlarmColors.danger
|
||||
: AlarmColors.success,
|
||||
);
|
||||
addRow('发生时间', alarm.occurTime);
|
||||
addRow('恢复时间', alarm.recoverTime);
|
||||
addRow('持续时长', alarm.duration);
|
||||
addRow(
|
||||
'设备名称',
|
||||
alarm.deviceInfo.isNotEmpty ? alarm.deviceInfo : alarm.deviceId,
|
||||
);
|
||||
addRow(
|
||||
'告警类型',
|
||||
alarm.deviceType != null ? _mapDeviceType(alarm.deviceType!) : null,
|
||||
);
|
||||
addRow('告警描述', alarm.description);
|
||||
addRow('创建时间', alarm.createTime);
|
||||
addRow('更新时间', alarm.updateTime);
|
||||
addRow('处理人', alarm.handleUserName);
|
||||
addRow('处理时间', alarm.handleTime);
|
||||
addRow('处理备注', alarm.handleRemark);
|
||||
addRow('根因分析', alarm.rootCause);
|
||||
addRow('处理建议', alarm.handleSuggestion);
|
||||
addRow('处理结果', alarm.handleResult);
|
||||
addRow(
|
||||
'短信通知',
|
||||
alarm.notifySms != null ? (alarm.notifySms == 1 ? '是' : '否') : null,
|
||||
);
|
||||
addRow(
|
||||
'电报通知',
|
||||
alarm.notifyTelegram != null
|
||||
? (alarm.notifyTelegram == 1 ? '是' : '否')
|
||||
: null,
|
||||
);
|
||||
addRow(
|
||||
'邮件通知',
|
||||
alarm.notifyEmail != null ? (alarm.notifyEmail == 1 ? '是' : '否') : null,
|
||||
);
|
||||
|
||||
if (infoRows.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
@@ -331,25 +389,55 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
boxShadow: [AlarmDimensions.cardShadow],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildInfoRow('告警状态', alarm.alarmStatus,
|
||||
valueColor: alarm.alarmStatus == '未处理' ? AlarmColors.danger : AlarmColors.success),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('发生时间', alarm.occurTime),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('恢复时间', alarm.recoverTime ?? '--'),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('持续时长', alarm.duration),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('影响范围', alarm.affectRange),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('告警描述', alarm.description, isLast: true),
|
||||
],
|
||||
children: infoRows
|
||||
.asMap()
|
||||
.entries
|
||||
.map(
|
||||
(entry) => [
|
||||
entry.value,
|
||||
if (entry.key < infoRows.length - 1) _buildDivider(),
|
||||
],
|
||||
)
|
||||
.expand((e) => e)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value, {Color? valueColor, bool isLast = false}) {
|
||||
String _mapDeviceType(String type) {
|
||||
final lowerType = type.toLowerCase();
|
||||
switch (lowerType) {
|
||||
case 'uav_fault':
|
||||
case 'uav':
|
||||
return '无人机故障';
|
||||
case 'mower_fault':
|
||||
case 'mower':
|
||||
return '割草机故障';
|
||||
case 'other_device_fault':
|
||||
case 'other_device':
|
||||
return '其他设备故障';
|
||||
case 'server_failure':
|
||||
case 'server':
|
||||
return '服务器故障';
|
||||
case 'system_error':
|
||||
case 'system':
|
||||
return '系统错误';
|
||||
default:
|
||||
if (lowerType.contains('uav')) return '无人机故障';
|
||||
if (lowerType.contains('mower')) return '割草机故障';
|
||||
if (lowerType.contains('other_device')) return '其他设备故障';
|
||||
if (lowerType.contains('server')) return '服务器故障';
|
||||
if (lowerType.contains('system')) return '系统错误';
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(
|
||||
String label,
|
||||
String value, {
|
||||
Color? valueColor,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: isLast ? 0 : 12),
|
||||
child: Row(
|
||||
@@ -381,11 +469,13 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return const Divider(
|
||||
height: 24,
|
||||
thickness: 0.5,
|
||||
color: Color(0xFFE5E6EB),
|
||||
);
|
||||
return const Divider(height: 24, thickness: 0.5, color: Color(0xFFE5E6EB));
|
||||
}
|
||||
|
||||
bool _hasHistoryData(HistoryMetrics historyData) {
|
||||
return historyData.power.isNotEmpty ||
|
||||
historyData.voltage.isNotEmpty ||
|
||||
historyData.frequency.isNotEmpty;
|
||||
}
|
||||
|
||||
/// 处理建议卡片
|
||||
@@ -444,9 +534,10 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
|
||||
/// 底部按钮
|
||||
Widget _buildBottomButtons(AlarmDetailLoaded state) {
|
||||
final isConfirmed = state.isConfirmed;
|
||||
final alarmStatus = state.alarmDetail.alarmStatus;
|
||||
final isInProgress = _cubit.state is AlarmDetailActionInProgress;
|
||||
final isDisabled = isConfirmed || isInProgress;
|
||||
final isPending = alarmStatus == '待处理';
|
||||
final isDisabled = !isPending || isInProgress;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),
|
||||
@@ -467,26 +558,68 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
child: _buildButton(
|
||||
text: 'AI诊断',
|
||||
isPrimary: false,
|
||||
isLoading: isInProgress && _cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action == 'AI诊断',
|
||||
isDisabled: isDisabled,
|
||||
onPressed: isDisabled
|
||||
isLoading:
|
||||
isInProgress &&
|
||||
_cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action ==
|
||||
'AI诊断',
|
||||
isDisabled: isInProgress,
|
||||
onPressed: isInProgress
|
||||
? null
|
||||
: () => _cubit.aiDiagnosis(widget.alarmId),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 12),
|
||||
// 确认告警按钮
|
||||
Expanded(
|
||||
child: _buildButton(
|
||||
text: '确认告警',
|
||||
text: isPending ? '确认告警' : '已确认',
|
||||
isPrimary: true,
|
||||
isLoading: isInProgress && _cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action == '确认告警',
|
||||
isDisabled: isDisabled,
|
||||
onPressed: isDisabled
|
||||
? null
|
||||
: () => _cubit.confirmAlarm(widget.alarmId),
|
||||
isLoading:
|
||||
isInProgress &&
|
||||
_cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action ==
|
||||
'确认告警',
|
||||
isDisabled: true,
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('暂未开放'),
|
||||
backgroundColor: AlarmColors.warning,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 去处理按钮
|
||||
SizedBox(
|
||||
width: 88,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
await context.push(
|
||||
'/alarm_center/detail/${widget.alarmId}/handle',
|
||||
);
|
||||
_cubit.loadAlarmDetail(widget.alarmId);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: AlarmColors.primary,
|
||||
elevation: 0,
|
||||
side: const BorderSide(color: AlarmColors.primary),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 6),
|
||||
),
|
||||
child: Text(
|
||||
alarmStatus == '已关闭' ? '已处理' : '去处理',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -510,9 +643,7 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
foregroundColor: isPrimary ? Colors.white : AlarmColors.primary,
|
||||
elevation: 0,
|
||||
side: isPrimary ? null : const BorderSide(color: AlarmColors.primary),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
@@ -526,8 +657,8 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -542,25 +673,16 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
return AlertDialog(
|
||||
title: const Text(
|
||||
'AI诊断结果',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
result,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.6,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, height: 1.6),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: const Text('关闭'),
|
||||
),
|
||||
TextButton(onPressed: () => context.pop(), child: const Text('关闭')),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,560 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../../domain/entities/alarm_detail_entity.dart';
|
||||
import '../../domain/usecases/dispatch_workorder_usecase.dart';
|
||||
import '../../data/datasources/alarm_dispatch_remote_datasource.dart';
|
||||
import '../../data/datasources/impl/alarm_dispatch_remote_datasource_impl.dart';
|
||||
import '../../data/repositories/alarm_dispatch_repository_impl.dart';
|
||||
import '../cubit/alarm_dispatch_cubit.dart';
|
||||
import '../states/alarm_dispatch_state.dart';
|
||||
import '../../../report/presentation/constants/report_constants.dart';
|
||||
import '../../../report/presentation/widgets/report_type_selector.dart';
|
||||
import '../../../report/presentation/widgets/device_selector.dart';
|
||||
import '../../../report/presentation/widgets/description_input.dart';
|
||||
import '../../../report/presentation/widgets/media_uploader.dart';
|
||||
import '../../../report/presentation/widgets/level_selector.dart';
|
||||
import '../../../report/presentation/pages/media_preview_page.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
|
||||
/// 告警派发工单页面
|
||||
class AlarmDispatchPage extends StatelessWidget {
|
||||
final AlarmDetailEntity alarmDetail;
|
||||
|
||||
const AlarmDispatchPage({super.key, required this.alarmDetail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => _createCubit(alarmDetail),
|
||||
child: _AlarmDispatchPageContent(),
|
||||
);
|
||||
}
|
||||
|
||||
AlarmDispatchCubit _createCubit(AlarmDetailEntity alarmDetail) {
|
||||
final sl = GetIt.I;
|
||||
final datasource = AlarmDispatchRemoteDataSourceImpl();
|
||||
final repository = AlarmDispatchRepositoryImpl(
|
||||
remoteDataSource: datasource,
|
||||
);
|
||||
final useCase = DispatchWorkOrderUseCase(repository);
|
||||
return AlarmDispatchCubit(
|
||||
dispatchUseCase: useCase,
|
||||
alarmDetail: alarmDetail,
|
||||
dio: sl<Dio>(),
|
||||
appUserCubit: sl<AppUserCubit>(),
|
||||
userStorage: sl<UserStorage>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AlarmDispatchPageContent extends StatelessWidget {
|
||||
const _AlarmDispatchPageContent();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.cardBackground,
|
||||
appBar: _buildAppBar(context),
|
||||
body: BlocConsumer<AlarmDispatchCubit, AlarmDispatchState>(
|
||||
listener: (context, state) {
|
||||
if (state is AlarmDispatchFormState && state.toastMessage != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.toastMessage!),
|
||||
backgroundColor: state.isSuccess ? Colors.green : Colors.red,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
context.read<AlarmDispatchCubit>().clearToast();
|
||||
if (state.isSuccess) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is AlarmDispatchSubmitting) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmDispatchLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmDispatchFormState) {
|
||||
return _buildForm(context, state);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildAppBar(BuildContext context) {
|
||||
return AppBar(
|
||||
backgroundColor: AppColors.background,
|
||||
elevation: 0,
|
||||
title: const Text(
|
||||
'告警派发工单',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios, size: 20, color: Colors.black),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.read<AlarmDispatchCubit>().submitDispatch(),
|
||||
child: const Text(
|
||||
'提交',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildForm(BuildContext context, AlarmDispatchFormState state) {
|
||||
final cubit = context.read<AlarmDispatchCubit>();
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 场站信息
|
||||
_buildSiteInfoCard(state),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 告警关联信息条
|
||||
_buildAlarmInfoBar(state),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 上报类型选择
|
||||
ReportTypeSelector(
|
||||
selectedType: state.selectedReportType,
|
||||
onSelected: (type) => cubit.selectReportType(type),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 设备选择
|
||||
DeviceSelector(
|
||||
selectedDevice: state.selectedDevice,
|
||||
onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('设备已从告警自动关联,暂不支持修改'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 问题描述
|
||||
DescriptionInput(
|
||||
description: state.entity.description,
|
||||
onChanged: (value) => cubit.updateDescription(value),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 媒体上传
|
||||
MediaUploader(
|
||||
mediaFiles: state.mediaFiles,
|
||||
onCameraTap: () => _pickImage(cubit),
|
||||
onVideoTap: () => _pickVideo(cubit),
|
||||
onAddFromGallery: () => _pickFromGallery(context, cubit),
|
||||
onTap: (index) {
|
||||
_previewMedia(context, state.mediaFiles, index);
|
||||
},
|
||||
onRemove: (index) => cubit.removeMediaFile(index),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 计划时间
|
||||
_buildPlanTimeSection(context, state, cubit),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 问题等级
|
||||
LevelSelector(
|
||||
selectedLevel: state.selectedProblemLevel,
|
||||
onSelected: (level) => cubit.selectProblemLevel(level),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 场站信息卡片
|
||||
Widget _buildSiteInfoCard(AlarmDispatchFormState state) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x0D000000),
|
||||
blurRadius: AppDimensions.cardShadowBlur,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(Icons.location_on, size: 18, color: AppColors.primary),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
'场站信息',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
// _buildInfoLabel('场站ID'),
|
||||
// const SizedBox(width: 8),
|
||||
// Text(
|
||||
// state.siteId != null ? '${state.siteId}' : '--',
|
||||
// style: const TextStyle(
|
||||
// fontSize: 14,
|
||||
// color: AppColors.textPrimary,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(width: 24),
|
||||
_buildInfoLabel('场站名称'),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.siteName ?? '加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: state.siteName != null
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textHint,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoLabel('告警编号'),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.alarmNo ?? state.alarmId,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textPrimary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoLabel(String label) {
|
||||
return Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.textHint),
|
||||
);
|
||||
}
|
||||
|
||||
/// 告警关联信息条
|
||||
Widget _buildAlarmInfoBar(AlarmDispatchFormState state) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF7E6),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(color: const Color(0xFFFFD591)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
color: Color(0xFFFA8C16),
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'关联告警: ${state.alarmNo ?? state.alarmId}',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF8C6E1F),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, size: 18, color: Color(0xFFFA8C16)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 计划时间区域
|
||||
Widget _buildPlanTimeSection(
|
||||
BuildContext context,
|
||||
AlarmDispatchFormState state,
|
||||
AlarmDispatchCubit cubit,
|
||||
) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x0D000000),
|
||||
blurRadius: AppDimensions.cardShadowBlur,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'计划时间',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildTimeRow(
|
||||
label: '计划开始',
|
||||
time: state.planStartTime,
|
||||
onTap: () => _pickDateTime(context, (time) {
|
||||
cubit.updatePlanStartTime(time);
|
||||
}),
|
||||
required: true,
|
||||
),
|
||||
// const SizedBox(height: 8),
|
||||
// _buildTimeRow(
|
||||
// label: '计划结束',
|
||||
// time: state.planEndTime,
|
||||
// onTap: () => _pickDateTime(context, (time) {
|
||||
// cubit.updatePlanEndTime(time);
|
||||
// }),
|
||||
// required: true,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTimeRow({
|
||||
required String label,
|
||||
required DateTime? time,
|
||||
required VoidCallback onTap,
|
||||
required bool required,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(color: AppColors.borderColor),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'$label${required ? ' *' : ''}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
time != null
|
||||
? '${time.year}-${time.month.toString().padLeft(2, '0')}-${time.day.toString().padLeft(2, '0')} '
|
||||
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}'
|
||||
: '请选择',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: time != null
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textHint,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickDateTime(
|
||||
BuildContext context,
|
||||
Function(DateTime) onPicked,
|
||||
) async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 30)),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
helpText: '选择日期',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
);
|
||||
if (date == null || !context.mounted) return;
|
||||
|
||||
final time = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
helpText: '选择时间',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
);
|
||||
if (time == null) return;
|
||||
|
||||
final dateTime = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
onPicked(dateTime);
|
||||
}
|
||||
|
||||
Future<void> _pickImage(AlarmDispatchCubit cubit) async {
|
||||
final picker = ImagePicker();
|
||||
try {
|
||||
final image = await picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
maxWidth: 1920,
|
||||
maxHeight: 1080,
|
||||
imageQuality: 85,
|
||||
);
|
||||
if (image != null) {
|
||||
cubit.addMediaFile(image.path);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickVideo(AlarmDispatchCubit cubit) async {
|
||||
final picker = ImagePicker();
|
||||
try {
|
||||
final video = await picker.pickVideo(
|
||||
source: ImageSource.camera,
|
||||
maxDuration: const Duration(minutes: 5),
|
||||
);
|
||||
if (video != null) {
|
||||
cubit.addMediaFile(video.path);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
void _previewMedia(BuildContext context, List<String> mediaFiles, int index) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
MediaPreviewPage(mediaFiles: mediaFiles, initialIndex: index),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickFromGallery(
|
||||
BuildContext context,
|
||||
AlarmDispatchCubit cubit,
|
||||
) async {
|
||||
final picker = ImagePicker();
|
||||
try {
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.image),
|
||||
title: const Text('选择图片'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
final image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxWidth: 1920,
|
||||
maxHeight: 1080,
|
||||
imageQuality: 85,
|
||||
);
|
||||
if (image != null) cubit.addMediaFile(image.path);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.video_library),
|
||||
title: const Text('选择视频'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
final video = await picker.pickVideo(
|
||||
source: ImageSource.gallery,
|
||||
);
|
||||
if (video != null) cubit.addMediaFile(video.path);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,639 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
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/bloc/alarm_detail_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_detail_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
class AlarmHandlePage extends StatelessWidget {
|
||||
final String alarmId;
|
||||
|
||||
const AlarmHandlePage({super.key, required this.alarmId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => sl<AlarmDetailCubit>()..loadAlarmDetail(alarmId),
|
||||
child: _AlarmHandlePageContent(alarmId: alarmId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AlarmHandlePageContent extends StatefulWidget {
|
||||
final String alarmId;
|
||||
|
||||
const _AlarmHandlePageContent({required this.alarmId});
|
||||
|
||||
@override
|
||||
State<_AlarmHandlePageContent> createState() =>
|
||||
_AlarmHandlePageContentState();
|
||||
}
|
||||
|
||||
class _AlarmHandlePageContentState extends State<_AlarmHandlePageContent> {
|
||||
final TextEditingController _handlerController = TextEditingController();
|
||||
final TextEditingController _remarkController = TextEditingController();
|
||||
final TextEditingController _rootCauseController = TextEditingController();
|
||||
String _handleStatus = '已关闭';
|
||||
String _handleResult = '';
|
||||
String _currentAlarmStatus = '待处理';
|
||||
int? _selectedActionIndex;
|
||||
|
||||
final Map<String, String> _handleResultMap = {
|
||||
'Handled': '已处理',
|
||||
'Restored': '已恢复',
|
||||
'Ignored': '已忽略',
|
||||
'UnableToHandle': '无法处理',
|
||||
'ManufacturerHandling': '厂家处理中',
|
||||
'FalseAlarm': '误报',
|
||||
};
|
||||
|
||||
final List<Map<String, dynamic>> _actionButtons = [
|
||||
{
|
||||
'label': '确认告警',
|
||||
'icon': Icons.check_circle_outline,
|
||||
'color': const Color(0xFF52C41A),
|
||||
'bgColor': const Color(0xFFF6FFED),
|
||||
'confirmedLabel': '已确认告警',
|
||||
'confirmedTip': '确认无需',
|
||||
'unconfirmedTip': '确认无需',
|
||||
},
|
||||
{
|
||||
'label': '派发工单',
|
||||
'icon': Icons.file_copy_outlined,
|
||||
'color': const Color(0xFF1890FF),
|
||||
'bgColor': const Color(0xFFE6F7FF),
|
||||
'tip': '请填下方表格',
|
||||
},
|
||||
{
|
||||
'label': '联系负责人',
|
||||
'icon': Icons.person_outline,
|
||||
'color': const Color(0xFFFA8C16),
|
||||
'bgColor': const Color(0xFFFFF7E6),
|
||||
'tip': '暂无功能',
|
||||
},
|
||||
{
|
||||
'label': '拍照取证',
|
||||
'icon': Icons.camera_alt_outlined,
|
||||
'color': const Color(0xFF722ED1),
|
||||
'bgColor': const Color(0xFFF9F0FF),
|
||||
'tip': '暂不支持',
|
||||
},
|
||||
{
|
||||
'label': '备注记录',
|
||||
'icon': Icons.edit_note_outlined,
|
||||
'color': const Color(0xFF13C2C2),
|
||||
'bgColor': const Color(0xFFE6FFFB),
|
||||
'tip': '请填下方表格',
|
||||
},
|
||||
{
|
||||
'label': '更多操作',
|
||||
'icon': Icons.more_horiz,
|
||||
'color': const Color(0xFF8C8C8C),
|
||||
'bgColor': const Color(0xFFF5F5F5),
|
||||
'tip': '暂未开发',
|
||||
},
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF5F5F5),
|
||||
appBar: _buildAppBar(),
|
||||
body: BlocConsumer<AlarmDetailCubit, AlarmDetailState>(
|
||||
listener: (context, state) {
|
||||
if (state is AlarmDetailLoaded && state.isHandleSuccess) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('处理成功'),
|
||||
backgroundColor: Color(0xFF52C41A),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
context.pop();
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is AlarmDetailLoaded) {
|
||||
_currentAlarmStatus = state.alarmDetail.alarmStatus;
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildAlarmInfoCard(state.alarmDetail),
|
||||
const SizedBox(height: 16),
|
||||
_buildActionButtons(),
|
||||
const SizedBox(height: 16),
|
||||
_buildFormCard(),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmDetailError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: Color(0xFFBFBFBF),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
state.message,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF8C8C8C),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => context
|
||||
.read<AlarmDetailCubit>()
|
||||
.loadAlarmDetail(widget.alarmId),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('重试'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF1890FF),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
bottomNavigationBar: _buildBottomSubmitButton(),
|
||||
);
|
||||
}
|
||||
|
||||
AppBar _buildAppBar() {
|
||||
return AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios, color: Colors.black, size: 20),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: const Text(
|
||||
'告警处理',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAlarmInfoCard(AlarmDetailEntity alarm) {
|
||||
final levelColor = alarm.level == AlarmLevel.danger
|
||||
? const Color(0xFFFF4D4F)
|
||||
: alarm.level == AlarmLevel.warning
|
||||
? const Color(0xFFFA8C16)
|
||||
: alarm.level == AlarmLevel.low
|
||||
? const Color(0xFF1890FF)
|
||||
: const Color(0xFF52C41A);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: levelColor, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
alarm.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: levelColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
alarm.level.label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: levelColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'${alarm.alarmNo ?? alarm.id} | ${alarm.deviceInfo} | ${alarm.occurTime}',
|
||||
style: const TextStyle(fontSize: 13, color: Color(0xFF8C8C8C)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButtons() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
childAspectRatio: 1,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 16,
|
||||
),
|
||||
itemCount: _actionButtons.length,
|
||||
itemBuilder: (context, index) {
|
||||
final button = _actionButtons[index];
|
||||
return _buildActionButton(button, index);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButton(Map<String, dynamic> button, int index) {
|
||||
final isConfirmed = _currentAlarmStatus != '待处理';
|
||||
final isSelected = _selectedActionIndex == index;
|
||||
String displayLabel = button['label'] as String;
|
||||
|
||||
if (index == 0 && isConfirmed && button.containsKey('confirmedLabel')) {
|
||||
displayLabel = button['confirmedLabel'] as String;
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _onActionButtonTap(button, index),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? (button['color'] as Color)
|
||||
: (button['bgColor'] as Color),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: isSelected
|
||||
? Border.all(color: button['color'] as Color, width: 2)
|
||||
: Border.all(color: Colors.transparent),
|
||||
),
|
||||
child: Icon(
|
||||
button['icon'] as IconData,
|
||||
color: isSelected ? Colors.white : (button['color'] as Color),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
displayLabel,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: button['color'] as Color,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onActionButtonTap(Map<String, dynamic> button, int index) {
|
||||
setState(() {
|
||||
_selectedActionIndex = index;
|
||||
});
|
||||
|
||||
// 确认告警:暂未开放
|
||||
if (index == 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('暂未开放'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 派发工单:跳转到告警派发页面
|
||||
if (index == 1) {
|
||||
final cubitState = context.read<AlarmDetailCubit>().state;
|
||||
if (cubitState is AlarmDetailLoaded) {
|
||||
context.push(
|
||||
'/alarm_center/detail/${widget.alarmId}/handle/dispatch',
|
||||
extra: cubitState.alarmDetail,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String tip = button['tip'] as String? ?? '';
|
||||
|
||||
if (tip.isNotEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(tip),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildFormCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildFormRow(
|
||||
label: '处理状态',
|
||||
child: _buildDropdown(
|
||||
value: _handleStatus,
|
||||
items: const ['已关闭'],
|
||||
onChanged: (value) {
|
||||
setState(() => _handleStatus = value!);
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildFormRow(label: '处理结果', child: _buildHandleResultDropdown()),
|
||||
_buildDivider(),
|
||||
_buildFormRow(
|
||||
label: '根因分析',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _rootCauseController,
|
||||
maxLines: 4,
|
||||
maxLength: 200,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入根因分析,最多200字',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Text(
|
||||
'${_rootCauseController.text.length}/200',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFBFBFBF),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildFormRow(
|
||||
label: '处理人',
|
||||
child: TextField(
|
||||
controller: _handlerController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入处理人',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildFormRow(
|
||||
label: '备注说明',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _remarkController,
|
||||
maxLines: 4,
|
||||
maxLength: 200,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入处理备注,最多200字',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Text(
|
||||
'${_remarkController.text.length}/200',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFBFBFBF),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFormRow({required String label, required Widget child}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 72,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF8C8C8C)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdown({
|
||||
required String value,
|
||||
required List<String> items,
|
||||
String? hintText,
|
||||
required ValueChanged<String?> onChanged,
|
||||
}) {
|
||||
return DropdownButtonFormField<String>(
|
||||
value: value.isEmpty ? null : value,
|
||||
items: items.map((item) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(
|
||||
item.isEmpty ? hintText ?? '' : item,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: item.isEmpty ? const Color(0xFFBFBFBF) : Colors.black,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: onChanged,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
icon: const Icon(Icons.keyboard_arrow_down, color: Color(0xFFBFBFBF)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHandleResultDropdown() {
|
||||
return DropdownButtonFormField<String>(
|
||||
value: _handleResult.isEmpty ? null : _handleResult,
|
||||
items: [
|
||||
const DropdownMenuItem<String>(
|
||||
value: '',
|
||||
child: Text(
|
||||
'请选择处理结果',
|
||||
style: TextStyle(fontSize: 14, color: Color(0xFFBFBFBF)),
|
||||
),
|
||||
),
|
||||
..._handleResultMap.entries.map((entry) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: entry.key,
|
||||
child: Text(
|
||||
entry.value,
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() => _handleResult = value ?? '');
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
icon: const Icon(Icons.keyboard_arrow_down, color: Color(0xFFBFBFBF)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return const Divider(height: 1, color: Color(0xFFF0F0F0));
|
||||
}
|
||||
|
||||
Widget _buildBottomSubmitButton() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 56,
|
||||
child: ElevatedButton(
|
||||
onPressed: _submitHandle,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF1890FF),
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'提交处理',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _submitHandle() {
|
||||
int handleStatusValue = 2;
|
||||
debugPrint('提交处理 - handleStatus: $handleStatusValue');
|
||||
|
||||
final handleData = {
|
||||
'alarmId': widget.alarmId,
|
||||
'handleStatus': handleStatusValue,
|
||||
'handleRemark': _remarkController.text,
|
||||
'rootCause': _rootCauseController.text,
|
||||
'handleResult': _handleResult,
|
||||
};
|
||||
|
||||
context.read<AlarmDetailCubit>().handleAlarm(handleData);
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,59 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/message_center/presentation/pages/message_center_page.dart';
|
||||
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/bloc/alarm_detail_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_center_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_detail_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_handle_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_dispatch_page.dart';
|
||||
|
||||
/// 告警中心路由配置
|
||||
class AlarmCenterRoutes {
|
||||
static List<RouteBase> get routes => [
|
||||
GoRoute(
|
||||
path: '/alarm_center',
|
||||
name: 'alarmCenter',
|
||||
builder: (context, state) => const AlarmCenterPage(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/alarm_center',
|
||||
name: 'alarmCenter',
|
||||
builder: (context, state) => const AlarmCenterPage(),
|
||||
path: 'detail/:alarmId',
|
||||
name: 'alarmDetail',
|
||||
builder: (context, state) {
|
||||
final alarmId = state.pathParameters['alarmId']!;
|
||||
return BlocProvider(
|
||||
create: (_) => sl<AlarmDetailCubit>(),
|
||||
child: AlarmDetailPage(alarmId: alarmId),
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'detail/:alarmId',
|
||||
name: 'alarmDetail',
|
||||
path: 'handle',
|
||||
name: 'alarmHandle',
|
||||
builder: (context, state) {
|
||||
final alarmId = state.pathParameters['alarmId']!;
|
||||
return BlocProvider(
|
||||
create: (_) => sl<AlarmDetailCubit>(),
|
||||
child: AlarmDetailPage(alarmId: alarmId),
|
||||
);
|
||||
return AlarmHandlePage(alarmId: alarmId);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'dispatch',
|
||||
name: 'alarmDispatch',
|
||||
builder: (context, state) {
|
||||
final alarmDetail = state.extra as AlarmDetailEntity;
|
||||
return AlarmDispatchPage(alarmDetail: alarmDetail);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// 消息中心页路由
|
||||
GoRoute(
|
||||
path: '/message_center',
|
||||
name: 'messageCenter',
|
||||
builder: (context, state) => const MessageCenterPage(),
|
||||
),
|
||||
];
|
||||
],
|
||||
),
|
||||
// 消息中心页路由
|
||||
GoRoute(
|
||||
path: '/message_center',
|
||||
name: 'messageCenter',
|
||||
builder: (context, state) => const MessageCenterPage(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/alarm_dispatch_entity.dart';
|
||||
import '../../../report/presentation/constants/report_constants.dart';
|
||||
|
||||
/// 告警派发状态基类
|
||||
abstract class AlarmDispatchState extends Equatable {
|
||||
const AlarmDispatchState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// 加载中
|
||||
class AlarmDispatchLoading extends AlarmDispatchState {}
|
||||
|
||||
/// 提交中
|
||||
class AlarmDispatchSubmitting extends AlarmDispatchState {}
|
||||
|
||||
/// 表单状态
|
||||
class AlarmDispatchFormState extends AlarmDispatchState {
|
||||
/// 关联的告警ID
|
||||
final String alarmId;
|
||||
|
||||
/// 告警编号
|
||||
final String? alarmNo;
|
||||
|
||||
/// 派发实体
|
||||
final AlarmDispatchEntity entity;
|
||||
|
||||
/// 选中的上报类型
|
||||
final ReportType? selectedReportType;
|
||||
|
||||
/// 选中的问题等级
|
||||
final ProblemLevel? selectedProblemLevel;
|
||||
|
||||
/// 选中的设备
|
||||
final String? selectedDevice;
|
||||
|
||||
/// 选中的设备ID
|
||||
final String? selectedDeviceId;
|
||||
|
||||
/// 媒体文件列表
|
||||
final List<String> mediaFiles;
|
||||
|
||||
/// 计划开始时间
|
||||
final DateTime? planStartTime;
|
||||
|
||||
/// 计划结束时间
|
||||
final DateTime? planEndTime;
|
||||
|
||||
/// toast 消息(成功/失败)
|
||||
final String? toastMessage;
|
||||
|
||||
/// 场站ID(展示用)
|
||||
final int? siteId;
|
||||
|
||||
/// 场站名称(展示用)
|
||||
final String? siteName;
|
||||
|
||||
/// 是否为成功消息
|
||||
final bool isSuccess;
|
||||
|
||||
const AlarmDispatchFormState({
|
||||
required this.alarmId,
|
||||
this.alarmNo,
|
||||
required this.entity,
|
||||
this.selectedReportType,
|
||||
this.selectedProblemLevel,
|
||||
this.selectedDevice,
|
||||
this.selectedDeviceId,
|
||||
this.mediaFiles = const [],
|
||||
this.planStartTime,
|
||||
this.planEndTime,
|
||||
this.toastMessage,
|
||||
this.isSuccess = false,
|
||||
this.siteId,
|
||||
this.siteName,
|
||||
});
|
||||
|
||||
AlarmDispatchFormState copyWith({
|
||||
AlarmDispatchEntity? entity,
|
||||
ReportType? selectedReportType,
|
||||
ProblemLevel? selectedProblemLevel,
|
||||
String? selectedDevice,
|
||||
String? selectedDeviceId,
|
||||
List<String>? mediaFiles,
|
||||
DateTime? planStartTime,
|
||||
DateTime? planEndTime,
|
||||
String? toastMessage,
|
||||
bool? isSuccess,
|
||||
int? siteId,
|
||||
String? siteName,
|
||||
}) {
|
||||
return AlarmDispatchFormState(
|
||||
alarmId: alarmId,
|
||||
alarmNo: alarmNo,
|
||||
entity: entity ?? this.entity,
|
||||
selectedReportType: selectedReportType ?? this.selectedReportType,
|
||||
selectedProblemLevel: selectedProblemLevel ?? this.selectedProblemLevel,
|
||||
selectedDevice: selectedDevice ?? this.selectedDevice,
|
||||
selectedDeviceId: selectedDeviceId ?? this.selectedDeviceId,
|
||||
mediaFiles: mediaFiles ?? this.mediaFiles,
|
||||
planStartTime: planStartTime ?? this.planStartTime,
|
||||
planEndTime: planEndTime ?? this.planEndTime,
|
||||
toastMessage: toastMessage,
|
||||
isSuccess: isSuccess ?? this.isSuccess,
|
||||
siteId: siteId ?? this.siteId,
|
||||
siteName: siteName ?? this.siteName,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
alarmId,
|
||||
alarmNo,
|
||||
entity,
|
||||
selectedReportType,
|
||||
selectedProblemLevel,
|
||||
selectedDevice,
|
||||
selectedDeviceId,
|
||||
mediaFiles,
|
||||
planStartTime,
|
||||
planEndTime,
|
||||
toastMessage,
|
||||
isSuccess,
|
||||
siteId,
|
||||
siteName,
|
||||
];
|
||||
}
|
||||
@@ -3,11 +3,15 @@ import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_count_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警统计卡片
|
||||
class AlarmCountCard extends StatelessWidget {
|
||||
const AlarmCountCard({super.key, required this.count});
|
||||
const AlarmCountCard({
|
||||
super.key,
|
||||
required this.count,
|
||||
this.isCountLoading = false,
|
||||
});
|
||||
|
||||
final AlarmCountEntity count;
|
||||
final bool isCountLoading;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -25,9 +29,7 @@ class AlarmCountCard extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildCountItem(
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('alarm_center.unprocessed'),
|
||||
label: '待处理',
|
||||
value: count.unprocessed,
|
||||
color: AlarmColors.danger,
|
||||
bgColor: AlarmColors.unprocessedBg,
|
||||
@@ -37,15 +39,7 @@ class AlarmCountCard extends StatelessWidget {
|
||||
_buildDivider(),
|
||||
Expanded(
|
||||
child: _buildCountItem(
|
||||
label: '处理中',
|
||||
value: count.processing,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
Expanded(
|
||||
child: _buildCountItem(
|
||||
label: '已确认',
|
||||
label: '已关闭',
|
||||
value: count.confirmed,
|
||||
color: const Color(0xFF1D2129),
|
||||
),
|
||||
@@ -88,14 +82,25 @@ class AlarmCountCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
isCountLoading
|
||||
? const SizedBox(
|
||||
height: 24,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
value.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -85,12 +85,10 @@ class AlarmItemCard extends StatelessWidget {
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
_getStatusLabel(context, alarm.status),
|
||||
alarm.status.label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: alarm.status == AlarmStatus.unconfirmed
|
||||
? AlarmColors.warning
|
||||
: AlarmColors.textTertiary,
|
||||
color: _getStatusColor(alarm.status),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
@@ -98,9 +96,7 @@ class AlarmItemCard extends StatelessWidget {
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: alarm.status == AlarmStatus.unconfirmed
|
||||
? AlarmColors.warning
|
||||
: AlarmColors.textTertiary,
|
||||
color: _getStatusColor(alarm.status),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -125,16 +121,14 @@ class AlarmItemCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
String _getStatusLabel(BuildContext context, AlarmStatus status) {
|
||||
Color _getStatusColor(AlarmStatus status) {
|
||||
switch (status) {
|
||||
case AlarmStatus.unconfirmed:
|
||||
return AppLocalizations.of(
|
||||
context,
|
||||
).translate('alarm_center.unconfirmed');
|
||||
case AlarmStatus.confirmed:
|
||||
return AppLocalizations.of(context).translate('alarm_center.confirmed');
|
||||
case AlarmStatus.recovered:
|
||||
return AppLocalizations.of(context).translate('alarm_center.recovered');
|
||||
case AlarmStatus.pending:
|
||||
return AlarmColors.danger;
|
||||
case AlarmStatus.processing:
|
||||
case AlarmStatus.closed:
|
||||
case AlarmStatus.ignored:
|
||||
return AlarmColors.textTertiary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警筛选标签栏
|
||||
/// 告警筛选标签栏 - 全部/未处理/已确认/已恢复
|
||||
class AlarmTabBar extends StatelessWidget {
|
||||
const AlarmTabBar({
|
||||
super.key,
|
||||
@@ -15,6 +15,14 @@ class AlarmTabBar extends StatelessWidget {
|
||||
final ValueChanged<AlarmFilterTab> onFilterChanged;
|
||||
final Color backgroundColor;
|
||||
|
||||
// 待显示的标签列表(已注释掉"已确认"标签)
|
||||
static const List<AlarmFilterTab> _visibleTabs = [
|
||||
AlarmFilterTab.all,
|
||||
AlarmFilterTab.unprocessed,
|
||||
// AlarmFilterTab.confirmed, // 已确认 - 暂不显示
|
||||
AlarmFilterTab.recovered,
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -23,44 +31,14 @@ class AlarmTabBar extends StatelessWidget {
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: AlarmFilterTab.values.length,
|
||||
itemCount: _visibleTabs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final filter = AlarmFilterTab.values[index];
|
||||
final isSelected = selectedFilter == filter;
|
||||
|
||||
return GestureDetector(
|
||||
final filter = _visibleTabs[index];
|
||||
return _buildTabItem(
|
||||
context,
|
||||
label: _getFilterLabel(context, filter),
|
||||
isSelected: selectedFilter == filter,
|
||||
onTap: () => onFilterChanged(filter),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
_getFilterLabel(context, filter),
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: isSelected
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal,
|
||||
color: isSelected
|
||||
? AlarmColors.primary
|
||||
: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
height: 2,
|
||||
width: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AlarmColors.primary
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -72,13 +50,49 @@ class AlarmTabBar extends StatelessWidget {
|
||||
case AlarmFilterTab.all:
|
||||
return AppLocalizations.of(context).translate('alarm_center.all');
|
||||
case AlarmFilterTab.unprocessed:
|
||||
return AppLocalizations.of(
|
||||
context,
|
||||
).translate('alarm_center.unprocessed');
|
||||
return '待处理';
|
||||
case AlarmFilterTab.confirmed:
|
||||
return AppLocalizations.of(context).translate('alarm_center.confirmed');
|
||||
case AlarmFilterTab.recovered:
|
||||
return AppLocalizations.of(context).translate('alarm_center.recovered');
|
||||
return '已关闭(已恢复)';
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildTabItem(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected
|
||||
? AlarmColors.primary
|
||||
: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
height: 2,
|
||||
width: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? AlarmColors.primary : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user