告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
|
||||
abstract class DroneStationDataSource {
|
||||
Future<List<DroneStationEntity>> getDroneStationList(int siteId);
|
||||
Future<UAVDetailEntity> getUAVDetail(String gatewaySn, String deviceSn);
|
||||
Future<VideoStreamEntity> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
String qualityType = 'adaptive',
|
||||
int videoExpire = 7200,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import '../datasources/drone_station_datasource.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
|
||||
class DroneStationDataSourceImpl implements DroneStationDataSource {
|
||||
final Dio dio;
|
||||
|
||||
DroneStationDataSourceImpl(this.dio);
|
||||
|
||||
@override
|
||||
Future<List<DroneStationEntity>> getDroneStationList(int siteId) async {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getSiteUAVList,
|
||||
queryParameters: {'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) => DroneStationEntity.fromJson(item)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UAVDetailEntity> getUAVDetail(
|
||||
String gatewaySn,
|
||||
String deviceSn,
|
||||
) async {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getUAVState,
|
||||
queryParameters: {'sn': gatewaySn, 'droneSn': deviceSn},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
return UAVDetailEntity.fromJson(responseData['data']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<VideoStreamEntity> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
String qualityType = 'adaptive',
|
||||
int videoExpire = 7200,
|
||||
}) async {
|
||||
final response = await dio.post(
|
||||
HttpApiConsts.changeCamera,
|
||||
data: {
|
||||
'sn': sn,
|
||||
'cameraIndex': cameraIndex,
|
||||
'cameraPosition': cameraPosition,
|
||||
'qualityType': qualityType,
|
||||
'videoExpire': videoExpire,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
return VideoStreamEntity.fromJson(responseData['data']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/// 机器人数据模型
|
||||
class RobotDataModel {
|
||||
final String name;
|
||||
final String id;
|
||||
final String type;
|
||||
final String status;
|
||||
final double battery;
|
||||
final String task;
|
||||
|
||||
const RobotDataModel({
|
||||
required this.name,
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.battery,
|
||||
required this.task,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建数据模型
|
||||
factory RobotDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return RobotDataModel(
|
||||
name: json['deviceName'] ?? json['name'] ?? '',
|
||||
id: json['deviceId']?.toString() ?? json['id']?.toString() ?? '',
|
||||
type: json['deviceTypeName'] ?? json['type'] ?? '未知类型',
|
||||
status: _getStatusText(json['status'] ?? 0),
|
||||
battery: (json['battery'] as num?)?.toDouble() ??
|
||||
(json['capacity_percent'] as num?)?.toDouble() ?? 0.0,
|
||||
task: json['task'] ?? json['currentTask'] ?? '待机中',
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'id': id,
|
||||
'type': type,
|
||||
'status': status,
|
||||
'battery': battery,
|
||||
'task': task,
|
||||
};
|
||||
}
|
||||
|
||||
/// 状态码转换
|
||||
static String _getStatusText(int status) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '在线';
|
||||
case 2:
|
||||
return '离线';
|
||||
case 3:
|
||||
return '异常';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../core/error/failure.dart';
|
||||
import '../datasources/drone_station_datasource.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
import '../../domain/repositories/drone_station_repository.dart';
|
||||
|
||||
class DroneStationRepositoryImpl implements DroneStationRepository {
|
||||
final DroneStationDataSource dataSource;
|
||||
|
||||
DroneStationRepositoryImpl(this.dataSource);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<DroneStationEntity>>> getDroneStationList(
|
||||
int siteId,
|
||||
) async {
|
||||
try {
|
||||
final stations = await dataSource.getDroneStationList(siteId);
|
||||
return Right(stations);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, UAVDetailEntity>> getUAVDetail(
|
||||
String gatewaySn,
|
||||
String deviceSn,
|
||||
) async {
|
||||
try {
|
||||
final detail = await dataSource.getUAVDetail(gatewaySn, deviceSn);
|
||||
return Right(detail);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, VideoStreamEntity>> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
}) async {
|
||||
try {
|
||||
final videoStream = await dataSource.getVideoStream(
|
||||
sn: sn,
|
||||
cameraIndex: cameraIndex,
|
||||
cameraPosition: cameraPosition,
|
||||
);
|
||||
return Right(videoStream);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user