diff --git a/apps/desktop/src-tauri/src/business/services/material_matching_service.rs b/apps/desktop/src-tauri/src/business/services/material_matching_service.rs index 99d6356..9d69f1a 100644 --- a/apps/desktop/src-tauri/src/business/services/material_matching_service.rs +++ b/apps/desktop/src-tauri/src/business/services/material_matching_service.rs @@ -755,7 +755,7 @@ impl MaterialMatchingService { let mut total_rounds = 0u32; let mut successful_rounds = 0u32; let mut global_used_segment_ids = HashSet::new(); - let mut termination_reason = String::new(); + let mut termination_reason: Option = None; let mut materials_exhausted = false; // 为每个模板维护独立的序号计数器 @@ -805,7 +805,7 @@ impl MaterialMatchingService { // 如果没有任何模板可以匹配,提前终止 if !any_template_can_match { - termination_reason = format!("第{}轮预检查发现无任何模板可完整匹配,提前终止", total_rounds); + termination_reason = Some(format!("第{}轮预检查发现无任何模板可完整匹配,提前终止", total_rounds)); materials_exhausted = true; break; } @@ -916,7 +916,7 @@ impl MaterialMatchingService { // 检查是否应该继续下一轮 if round_successful_matches == 0 { // 本轮没有任何成功匹配,终止循环 - termination_reason = format!("第{}轮无任何成功匹配,素材已耗尽", total_rounds); + termination_reason = Some(format!("第{}轮无任何成功匹配,素材已耗尽", total_rounds)); materials_exhausted = true; break; } else { @@ -925,15 +925,13 @@ impl MaterialMatchingService { // 可选:添加最大轮数限制,防止无限循环 if total_rounds >= 100 { - termination_reason = "达到最大轮数限制(100轮)".to_string(); + termination_reason = Some("达到最大轮数限制(100轮)".to_string()); break; } } // 设置默认终止原因(如果没有设置) - if termination_reason.is_empty() { - termination_reason = "正常完成".to_string(); - } + let final_termination_reason = termination_reason.unwrap_or_else(|| "正常完成".to_string()); // 计算汇总信息 let summary = self.calculate_batch_summary(&matching_results); @@ -949,7 +947,7 @@ impl MaterialMatchingService { summary, total_rounds, successful_rounds, - termination_reason, + termination_reason: final_termination_reason, materials_exhausted, }) }