优化掉核心功能中print打印影响性能的代码用日志对象代替打印
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// lib/features/devices/domain/services/path_planning_service.dart
|
||||
import 'dart:collection';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../../core/logging/i_logger_service.dart';
|
||||
import '../data/models/device_add_path_point_model.dart';
|
||||
|
||||
class PathPlanningService {
|
||||
@@ -8,6 +10,8 @@ class PathPlanningService {
|
||||
factory PathPlanningService() => _instance;
|
||||
PathPlanningService._internal();
|
||||
|
||||
final ILoggerService _logger = GetIt.I<ILoggerService>();
|
||||
|
||||
// 🔥 核心:全局唯一的可变队列
|
||||
final Queue<DeviceAddPathPointModel> locationQueue = Queue();
|
||||
|
||||
@@ -18,8 +22,10 @@ class PathPlanningService {
|
||||
/// 🔥 存:生成路径后立即存储
|
||||
void updateQueue(List<DeviceAddPathPointModel> locations) {
|
||||
debugPrint('进入[PathPlanningService]updateQueue方法尝试更新空队列');
|
||||
_logger.logWithLevel('进入[PathPlanningService]updateQueue方法尝试更新空队列');
|
||||
if (locations.isEmpty) {
|
||||
debugPrint('⚠️ [PathPlanningService] 尝试更新空队列');
|
||||
_logger.logWithLevel('⚠️ [PathPlanningService] 尝试更新空队列');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,20 +34,26 @@ class PathPlanningService {
|
||||
currentIndex = 0;
|
||||
totalCount = locations.length;
|
||||
|
||||
debugPrint('✅ [PathPlanningService] 队列已更新,共 $totalCount 个点');
|
||||
//debugPrint('✅ [PathPlanningService] 队列已更新,共 $totalCount 个点');
|
||||
_logger.logWithLevel('✅ [PathPlanningService] 队列已更新,共 $totalCount 个点');
|
||||
}
|
||||
|
||||
/// 🔥 取:发送时取出第一个点
|
||||
DeviceAddPathPointModel? removeFirst() {
|
||||
if (locationQueue.isEmpty) {
|
||||
debugPrint('⚠️ [PathPlanningService] 队列为空');
|
||||
//debugPrint('⚠️ [PathPlanningService] 队列为空');
|
||||
_logger.logWithLevel('⚠️ [PathPlanningService] 队列为空');
|
||||
return null;
|
||||
}
|
||||
|
||||
final point = locationQueue.removeFirst();
|
||||
currentIndex++;
|
||||
|
||||
debugPrint(
|
||||
// debugPrint(
|
||||
// '📍 [PathPlanningService] 取出第 $currentIndex/$totalCount 个点:'
|
||||
// '${point.latitude}, ${point.longitude}',
|
||||
// );
|
||||
_logger.logWithLevel(
|
||||
'📍 [PathPlanningService] 取出第 $currentIndex/$totalCount 个点:'
|
||||
'${point.latitude}, ${point.longitude}',
|
||||
);
|
||||
@@ -63,7 +75,8 @@ class PathPlanningService {
|
||||
isRunning = false;
|
||||
currentIndex = 0;
|
||||
totalCount = 0;
|
||||
debugPrint('🧹 [PathPlanningService] 队列已清空');
|
||||
//debugPrint('🧹 [PathPlanningService] 队列已清空');
|
||||
_logger.logWithLevel('🧹 [PathPlanningService] 队列已清空');
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user