From ad9a2cce2d444d07482a8a98c377e0204c979980 Mon Sep 17 00:00:00 2001 From: Songzex <2402265378@qq.com> Date: Sat, 28 Feb 2026 09:45:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=88=9B=E5=BB=BA=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8E=A5=E5=8F=A3+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/di/injection.dart | 6 ++++- .../usecases/save_work_record_usecase.dart | 27 +++++++++++++++++++ .../presentation/bloc/devices_cubit.dart | 19 ++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 lib/features/devices/domain/usecases/save_work_record_usecase.dart diff --git a/lib/core/di/injection.dart b/lib/core/di/injection.dart index 715b535e..efb02aa9 100644 --- a/lib/core/di/injection.dart +++ b/lib/core/di/injection.dart @@ -33,6 +33,8 @@ import '../../features/devices/domain/usecases/device_work_hostrirty_usecase.dar import '../../features/devices/domain/usecases/generate_path_usecase.dart'; import '../../features/devices/domain/usecases/get_device_location_usecase.dart'; import '../../features/devices/domain/usecases/get_work_record_usecase.dart'; +import '../../features/devices/domain/usecases/save_work_record_usecase.dart'; +import '../../features/devices/domain/usecases/select_work_record_usecase.dart'; import '../../features/remote_control/presentation/bloc/remote_control_cubit.dart'; import '../app/app_user_cubit.dart'; import '../network/dio_client.dart'; @@ -103,14 +105,16 @@ Future init() async { sl.registerLazySingleton(() => GetUserDeviceUseCase(sl())); sl.registerLazySingleton(() => DiffSteerUseCase()); sl.registerLazySingleton(() => DeviceWorkHostrirty(sl())); + sl.registerLazySingleton(() => SelectWorkRecordUseCase(sl())); sl.registerLazySingleton(() => UnbindDeviceUseCase(sl())); sl.registerLazySingleton(() => UpdateDevicenameUsecase(sl())); + sl.registerLazySingleton(() => SaveWorkRecordUseCase(sl())); /// 5. 状态管理 (Cubit/Bloc) sl.registerLazySingleton(() => AppUserCubit()); // AuthCubit 依赖它,必须先注册 sl.registerLazySingleton(() => GetDeviceLocationUseCase(sl())); sl.registerLazySingleton( - () => DevicesCubit(sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl()), + () => DevicesCubit(sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl()), ); sl.registerFactory(() => RemoteControlCubit(sl())); diff --git a/lib/features/devices/domain/usecases/save_work_record_usecase.dart b/lib/features/devices/domain/usecases/save_work_record_usecase.dart new file mode 100644 index 00000000..1e9749d2 --- /dev/null +++ b/lib/features/devices/domain/usecases/save_work_record_usecase.dart @@ -0,0 +1,27 @@ +// lib/features/devices/domain/usecases/save_work_record_usecase.dart +import 'package:fpdart/fpdart.dart'; +import '../../domain/errors/device_failure.dart'; +import '../../domain/repositories/path_repository.dart'; + +class SaveWorkRecordUseCase { + final PathRepository repository; + + SaveWorkRecordUseCase(this.repository); + + Future>> call({ + required String workName, + required String userId, + required String jsonData, + }) async { + try { + final result = await repository.saveWorkRecord( + workName: workName, + userId: userId, + jsonData: jsonData, + ); + return Right(result); + } catch (e) { + return Left(DeviceFailure.networkError(message: e.toString())); + } + } +} diff --git a/lib/features/devices/presentation/bloc/devices_cubit.dart b/lib/features/devices/presentation/bloc/devices_cubit.dart index 327d77d1..e7f949b7 100644 --- a/lib/features/devices/presentation/bloc/devices_cubit.dart +++ b/lib/features/devices/presentation/bloc/devices_cubit.dart @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart'; import 'package:maibu_satabot_v2/features/devices/domain/repositories/device_repository.dart'; import 'package:maibu_satabot_v2/features/devices/domain/usecases/get_user_device_usecase.dart'; +import 'package:maibu_satabot_v2/features/devices/domain/usecases/save_work_record_usecase.dart'; import 'package:maibu_satabot_v2/features/devices/domain/usecases/select_work_record_usecase.dart'; import 'package:maibu_satabot_v2/features/devices/domain/usecases/unbind_device_usecase.dart'; import 'package:maibu_satabot_v2/features/devices/domain/usecases/update_devicename_usecase.dart'; @@ -21,6 +22,7 @@ class DevicesCubit extends Cubit { final UnbindDeviceUseCase _unbindDeviceUseCase; final UpdateDevicenameUsecase _updateDevicename; final SelectWorkRecordUseCase _selectWorkRecordUseCase; + final SaveWorkRecordUseCase _saveWorkRecordUseCase; DevicesCubit( this.repository, @@ -30,7 +32,8 @@ class DevicesCubit extends Cubit { this._deleteWorkRecordUseCase, this._unbindDeviceUseCase, this._updateDevicename, - this._selectWorkRecordUseCase + this._selectWorkRecordUseCase, + this._saveWorkRecordUseCase, ) : super(const DevicesState()); Future unbindDevice(String deviceId, String deviceName) async { @@ -275,5 +278,19 @@ class DevicesCubit extends Cubit { emit(state.copyWith(isLoading: false, errorMessage: e.toString())); } } + /// 保存路径数据 + Future saveWorkRecord(String workName, String userId, String jsonData) async { + emit(state.copyWith(isLoading: true)); + final result = await _saveWorkRecordUseCase.call( + workName: workName, + userId: userId, + jsonData: jsonData, + ); + result.fold( + (failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message)), + (data) => emit(state.copyWith(isLoading: false)), + ); + } + }