完善路线返航和障碍物显示
This commit is contained in:
@@ -7,6 +7,12 @@ import '../../domain/entities/device_schedule_plan_entity.dart';
|
||||
import '../models/device_task_model.dart';
|
||||
|
||||
abstract class DeviceTaskDatasource {
|
||||
Future<void> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
});
|
||||
|
||||
Future<List<DeviceTaskModel>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
required int siteId,
|
||||
@@ -48,6 +54,50 @@ class DeviceTaskDatasourceImpl implements DeviceTaskDatasource {
|
||||
|
||||
DeviceTaskDatasourceImpl(this.dio);
|
||||
|
||||
@override
|
||||
Future<void> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
}) async {
|
||||
final body = {
|
||||
'deviceId': deviceId,
|
||||
'orgId': orgId,
|
||||
'siteId': siteId,
|
||||
};
|
||||
final url = HttpApiConsts.backToRestPoint;
|
||||
_logger.logWithLevel(
|
||||
'[机器人返航] 请求: POST $url, 参数: ${jsonEncode(body)}',
|
||||
shouldLog: true,
|
||||
);
|
||||
final response = await dio.post(
|
||||
url,
|
||||
data: body,
|
||||
options: Options(contentType: Headers.jsonContentType),
|
||||
);
|
||||
dynamic data = response.data;
|
||||
if (data is String) {
|
||||
try {
|
||||
data = jsonDecode(data);
|
||||
} on FormatException {
|
||||
throw Exception('返航接口响应格式异常');
|
||||
}
|
||||
}
|
||||
if (response.statusCode != 200 || data is! Map) {
|
||||
throw Exception('返航请求失败(HTTP ${response.statusCode})');
|
||||
}
|
||||
if ('${data['code']}' != '200') {
|
||||
final message = (data['msg'] ?? data['message'])?.toString().trim();
|
||||
throw Exception(
|
||||
message == null || message.isEmpty ? '返航请求未成功' : message,
|
||||
);
|
||||
}
|
||||
if (data['data'] == false) {
|
||||
throw Exception('返航请求未成功,请确认车辆状态后重试');
|
||||
}
|
||||
_logger.logWithLevel('[机器人返航] 服务端已接受请求', shouldLog: true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DeviceTaskModel>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
|
||||
@@ -10,6 +10,24 @@ class DeviceTaskRepositoryImpl implements DeviceTaskRepository {
|
||||
|
||||
DeviceTaskRepositoryImpl({required this.datasource});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Unit>> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
}) async {
|
||||
try {
|
||||
await datasource.backToRestPoint(
|
||||
deviceId: deviceId,
|
||||
orgId: orgId,
|
||||
siteId: siteId,
|
||||
);
|
||||
return const Right(unit);
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<DeviceTaskEntity>>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
|
||||
Reference in New Issue
Block a user