接入设备故障告警和场站实时任务进度
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
|
||||
import '../../../../core/error/failure.dart';
|
||||
import '../../domain/entities/device_alarm.dart';
|
||||
import '../../domain/repositories/device_alarm_repository.dart';
|
||||
import '../datasources/device_alarm_mqtt_datasource.dart';
|
||||
import '../datasources/device_alarm_remote_datasource.dart';
|
||||
|
||||
class DeviceAlarmRepositoryImpl implements DeviceAlarmRepository {
|
||||
const DeviceAlarmRepositoryImpl(this.mqtt, this.remote);
|
||||
final DeviceAlarmMqttDataSource mqtt;
|
||||
final DeviceAlarmRemoteDataSource remote;
|
||||
|
||||
@override
|
||||
Stream<List<DeviceAlarm>> watch(String deviceCode) => mqtt.watch(deviceCode);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Unit>> handle(int alarmId) async {
|
||||
try {
|
||||
await remote.handle(alarmId);
|
||||
return const Right(unit);
|
||||
} on DeviceAlarmRemoteException catch (error) {
|
||||
debugPrint('[设备告警] 处理被拒绝 alarmId=$alarmId msg=${error.message}');
|
||||
return Left(ServerFailure(error.message));
|
||||
} on DioException catch (error) {
|
||||
debugPrint(
|
||||
'[设备告警] 处理请求异常 alarmId=$alarmId type=${error.type} msg=${error.message}',
|
||||
);
|
||||
final body = error.response?.data;
|
||||
return Left(
|
||||
NetworkFailure(body is Map ? body['msg']?.toString() ?? '' : ''),
|
||||
);
|
||||
} catch (error) {
|
||||
debugPrint('[设备告警] 处理失败 alarmId=$alarmId error=$error');
|
||||
return Left(Failure(''));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user