删除 _fix_startwork.py
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
import sys
|
||||
|
||||
path = r'C:\Users\jsmbz\Documents\flutter-app-02\lib\features\home\presentation\widgets\map\testmap_pages.dart'
|
||||
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# Find the block to replace
|
||||
old_block_start = content.find('result.fold(')
|
||||
if old_block_start < 0:
|
||||
print('ERROR: result.fold( not found')
|
||||
sys.exit(1)
|
||||
|
||||
# Find the end of the fold block: ');' after the fold call
|
||||
# The fold ends with ');' on a line
|
||||
old_block_end = content.find(' );', old_block_start)
|
||||
if old_block_end < 0:
|
||||
print('ERROR: fold end not found')
|
||||
sys.exit(1)
|
||||
old_block_end += len(' );')
|
||||
|
||||
old_block = content[old_block_start:old_block_end]
|
||||
print('Old block found:')
|
||||
print(repr(old_block[:100]))
|
||||
print('...')
|
||||
|
||||
new_block = ''' final taskIdOrFlag = result.fold<int?>(
|
||||
(failure) {
|
||||
debugPrint('❌ [开始作业] 创建设备任务失败: $failure');
|
||||
final failMsg = failure.toString();
|
||||
if (failMsg.contains('存在任务') || failMsg.contains('already exists')) {
|
||||
return null;
|
||||
}
|
||||
_showPageToast(message: "作业启动失败", type: ToastType.error);
|
||||
return -1;
|
||||
},
|
||||
(taskId) => taskId,
|
||||
);
|
||||
|
||||
if (taskIdOrFlag == null) {
|
||||
debugPrint('⚠️ [开始作业] 设备已有任务,重新查询任务池...');
|
||||
await taskCubit.fetchAndFilterTask(deviceId);
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
final existingTasks = taskCubit.state.activeTasks;
|
||||
debugPrint('🔍 [开始作业] 重新查询到 ${existingTasks.length} 个活跃任务');
|
||||
if (existingTasks.isNotEmpty) {
|
||||
final existingTask = existingTasks.first;
|
||||
taskCubit.selectTask(existingTask);
|
||||
debugPrint('✅ [开始作业] 复用已有任务 #${existingTask.id},taskId已保存');
|
||||
_showPageToast(message: "设备正在作业中", type: ToastType.success);
|
||||
_saveDataToLocal();
|
||||
return;
|
||||
}
|
||||
debugPrint('⚠️ [开始作业] 重新查询后仍未找到活跃任务');
|
||||
_showPageToast(message: "设备正在作业中", type: ToastType.warn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (taskIdOrFlag == -1) {
|
||||
taskCubit.clearCurrentTask();
|
||||
setState(() {
|
||||
isStartWork = false;
|
||||
_workStatus = WorkStatus.idle;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
final taskId = taskIdOrFlag as int;
|
||||
debugPrint('✅ [开始作业] 创建设备任务成功,taskId: $taskId');
|
||||
taskCubit.updateCurrentTaskId(taskId);'''
|
||||
|
||||
new_content = content[:old_block_start] + new_block + content[old_block_end:]
|
||||
|
||||
with open(path, 'w', encoding='utf-8', newline='') as f:
|
||||
f.write(new_content)
|
||||
|
||||
print('SUCCESS: File updated')
|
||||
Reference in New Issue
Block a user