From 087e23e57b60faa4e4d2cf9841365b58eb02a434 Mon Sep 17 00:00:00 2001 From: iven Date: Tue, 5 May 2026 23:43:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai):=20AI=20=E5=88=86=E6=9E=90=E9=98=9F?= =?UTF-8?q?=E5=88=97=20claim=5Fnext=20=E6=B7=BB=E5=8A=A0=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/erp-ai/src/service/analysis_queue.rs | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/erp-ai/src/service/analysis_queue.rs b/crates/erp-ai/src/service/analysis_queue.rs index 219696d..d5d0017 100644 --- a/crates/erp-ai/src/service/analysis_queue.rs +++ b/crates/erp-ai/src/service/analysis_queue.rs @@ -88,15 +88,21 @@ impl AnalysisQueue { Ok(id) } - pub async fn claim_next(&self) -> AiResult> { - let sql = r#" - SELECT * FROM ai_analysis_queue - WHERE status = 'pending' - AND deleted_at IS NULL - AND scheduled_at <= NOW() - ORDER BY priority DESC, scheduled_at ASC - LIMIT 1 - "#; + pub async fn claim_next(&self, tenant_id: Option) -> AiResult> { + let sql = match tenant_id { + Some(tid) => format!( + "SELECT * FROM ai_analysis_queue WHERE tenant_id = '{}' AND status = 'pending' AND deleted_at IS NULL AND scheduled_at <= NOW() ORDER BY priority DESC, scheduled_at ASC LIMIT 1", + tid + ), + None => r#" + SELECT * FROM ai_analysis_queue + WHERE status = 'pending' + AND deleted_at IS NULL + AND scheduled_at <= NOW() + ORDER BY priority DESC, scheduled_at ASC + LIMIT 1 + "#.to_string(), + }; let row: Option = QueueRow::find_by_statement( Statement::from_string(sea_orm::DatabaseBackend::Postgres, sql.to_string()),