diff --git a/lib/core/di/injection.dart b/lib/core/di/injection.dart index c5d5ff3a..b7a0c6c9 100644 --- a/lib/core/di/injection.dart +++ b/lib/core/di/injection.dart @@ -34,6 +34,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'; @@ -104,8 +106,10 @@ 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())); sl.registerLazySingleton(() => SelectWorkRecordUseCase(sl())); @@ -113,7 +117,7 @@ Future init() async { 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 186d8927..0b3b2f01 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, @@ -31,6 +33,7 @@ class DevicesCubit extends Cubit { this._unbindDeviceUseCase, this._updateDevicename, this._selectWorkRecordUseCase, + this._saveWorkRecordUseCase, ) : super(const DevicesState()); Future unbindDevice(String deviceId, String deviceName) async { @@ -282,4 +285,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)), + ); + } + + }