优化掉核心功能中print打印影响性能的代码用日志对象代替打印
This commit is contained in:
@@ -13,6 +13,7 @@ import 'package:maibu_satabot_v2/features/devices/domain/usecases/unbind_device_
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/update_devicename_usecase.dart';
|
||||
|
||||
import '../../../../core/consts/tcp_consts.dart';
|
||||
import '../../../../core/logging/i_logger_service.dart';
|
||||
import '../../../../core/network/tcp/tcp_client.dart';
|
||||
import '../../data/models/device_add_path_point_model.dart';
|
||||
import '../../data/models/device_work_area_param_model.dart';
|
||||
@@ -44,6 +45,9 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// 🔥 关键:注入全局服务
|
||||
final PathPlanningService _pathPlanningService;
|
||||
|
||||
final ILoggerService _logger = GetIt.I<ILoggerService>();
|
||||
|
||||
|
||||
DevicesCubit(
|
||||
this.repository,
|
||||
this._getUserDeviceUseCase,
|
||||
@@ -115,7 +119,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
successCode,
|
||||
) {
|
||||
// 核心修复:int 转 bool 条件判断
|
||||
print('更新设备名称结果代码: $successCode'); // 调试输出结果代码
|
||||
//print('更新设备名称结果代码: $successCode'); // 调试输出结果代码
|
||||
_logger.logWithLevel('更新设备名称结果代码: $successCode');
|
||||
final isSuccess = successCode == 1; // 显式转为 bool
|
||||
if (isSuccess) {
|
||||
//final updatedDevices = state.devices?.map((device) {
|
||||
@@ -218,7 +223,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// 🔥 关键修复 1:先强制断开旧连接!
|
||||
// 这一步会销毁旧 Socket,清除旧 Listener,防止旧数据继续推送
|
||||
if (_tcpClient.isConnected) {
|
||||
debugPrint('🛑 检测到已连接,先断开旧 TCP 连接...');
|
||||
//debugPrint('🛑 检测到已连接,先断开旧 TCP 连接...');
|
||||
_logger.logWithLevel('🔥 检测到已连接,先断开旧 TCP 连接...');
|
||||
_tcpClient.disconnects(forSwitch: true);
|
||||
// 稍微等待一下,确保底层 Socket 资源释放 (可选,但推荐)
|
||||
// await Future.delayed(const Duration(milliseconds: 100));
|
||||
@@ -226,7 +232,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
// 🔥 关键修复 2:发起新连接
|
||||
// connect 方法内部会自动调用 _sendAuthPacket -> 获取设备列表 -> 自动订阅当前选中的设备
|
||||
debugPrint('🔌 开始重新新连接 TCP,将自动订阅新设备:${device.deviceName}');
|
||||
// debugPrint('🔌 开始重新新连接 TCP,将自动订阅新设备:${device.deviceName}');
|
||||
_logger.logWithLevel('🔌 启动重新新连接 TCP,将自动订阅新设备:${device.deviceName}');
|
||||
await _tcpClient.connectBySwitch(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT, deviceName: device.deviceName);
|
||||
// 🔥 关键修复 3:重置设备状态 Bloc,清除旧设备图表数据
|
||||
_deviceStatusBloc.add(DeviceStatusReset());
|
||||
@@ -347,20 +354,24 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
// 开始路径规划
|
||||
Future<void> startRoutePlanning(Queue<DeviceAddPathPointModel> locationQueue) async {
|
||||
print("cubit层开始路径规划");
|
||||
/// print("cubit层开始路径规划");
|
||||
_logger.logWithLevel('开始路径规划');
|
||||
// 清空全局 Service 中的队列
|
||||
// _routePlanningUseCase.clearLocationQueue();
|
||||
final List<DeviceAddPathPointModel> pathList = locationQueue.toList();
|
||||
print('✅ 队列转换为 List,长度:${pathList.length}');
|
||||
// print('✅ 队列转换为 List,长度:${pathList.length}');
|
||||
_logger.logWithLevel('队列转换为 List,长度:${pathList.length}');
|
||||
|
||||
_pathPlanningService.updateQueue(pathList);
|
||||
print('✅ 队列更新成功');
|
||||
//print('✅ 队列更新成功');
|
||||
_logger.logWithLevel('队列更新成功');
|
||||
|
||||
// 开始路径规划
|
||||
emit(state.copyWith(isLoading: true));
|
||||
//传入全局的Service 中路径规划队列
|
||||
Queue<DeviceAddPathPointModel> queue = _pathPlanningService.getQueue();
|
||||
print('📦 从 Service 获取的队列长度:${queue.length}');
|
||||
//print('📦 从 Service 获取的队列长度:${queue.length}');
|
||||
_logger.logWithLevel('从 Service 获取的队列长度:${queue.length}');
|
||||
final result = await _routePlanningUseCase.startRoutePlanning(queue);
|
||||
result.fold(
|
||||
(failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message ?? '路径规划启动失败')),
|
||||
@@ -407,7 +418,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
void setArrivedLocation(double latitude, double longitude) {
|
||||
emit(state.copyWith(arriLatitude: latitude, arriLongitude: longitude));
|
||||
print('✅ [DevicesCubit] 监听更新已完成到达位置:Lat=$latitude, Lng=$longitude');
|
||||
// print('✅ [DevicesCubit] 监听更新已完成到达位置:Lat=$latitude, Lng=$longitude');
|
||||
_logger.logWithLevel('✅ [DevicesCubit] 监听更新已完成到达位置:Lat=$latitude, Lng=$longitude');
|
||||
}
|
||||
|
||||
//获取已到达的点的经纬度
|
||||
@@ -418,6 +430,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// 重置已到达记录
|
||||
void resetArrivedLocation() {
|
||||
emit(state.copyWith(arriLatitude: null, arriLongitude: null));
|
||||
print('🔄 [DevicesCubit] 已重置到达位置');
|
||||
//print('🔄 [DevicesCubit] 已重置到达位置');
|
||||
_logger.logWithLevel('🔄 [DevicesCubit] 已重置到达位置');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user