diff --git a/crates/erp-ai/src/handler/rule_handler.rs b/crates/erp-ai/src/handler/rule_handler.rs index e6024be..a697e45 100644 --- a/crates/erp-ai/src/handler/rule_handler.rs +++ b/crates/erp-ai/src/handler/rule_handler.rs @@ -143,7 +143,7 @@ where } active.updated_at = Set(chrono::Utc::now()); active.updated_by = Set(Some(ctx.user_id)); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); let result = active.update(&state.db).await?; Ok(Json(ApiResponse::ok(result))) @@ -179,7 +179,7 @@ where active.deleted_at = Set(Some(chrono::Utc::now())); active.updated_at = Set(chrono::Utc::now()); active.updated_by = Set(Some(ctx.user_id)); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(&state.db).await?; Ok(Json(ApiResponse::ok(serde_json::json!({"deleted": true})))) diff --git a/crates/erp-ai/src/service/analysis.rs b/crates/erp-ai/src/service/analysis.rs index 94cc0da..21f15cc 100644 --- a/crates/erp-ai/src/service/analysis.rs +++ b/crates/erp-ai/src/service/analysis.rs @@ -170,7 +170,7 @@ impl AnalysisService { active.result_content = Set(Some(content)); active.result_metadata = Set(Some(metadata)); active.updated_at = Set(chrono::Utc::now()); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(&self.db).await?; Ok(()) } @@ -186,7 +186,7 @@ impl AnalysisService { active.status = Set("failed".into()); active.error_message = Set(Some(error)); active.updated_at = Set(chrono::Utc::now()); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(&self.db).await?; Ok(()) } diff --git a/crates/erp-ai/src/service/analysis_queue.rs b/crates/erp-ai/src/service/analysis_queue.rs index 40e65e7..6340713 100644 --- a/crates/erp-ai/src/service/analysis_queue.rs +++ b/crates/erp-ai/src/service/analysis_queue.rs @@ -124,7 +124,7 @@ impl AnalysisQueue { active.status = Set("running".to_string()); active.started_at = Set(Some(now)); active.updated_at = Set(now); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); let model = active.update(&self.db).await?; Ok(Some(model)) } @@ -140,7 +140,7 @@ impl AnalysisQueue { active.completed_at = Set(Some(now)); active.result_analysis_id = Set(Some(result_analysis_id)); active.updated_at = Set(now); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(&self.db).await?; Ok(()) } @@ -163,7 +163,7 @@ impl AnalysisQueue { active.retry_count = Set(retry_count + 1); active.started_at = Set(None); active.updated_at = Set(now); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(&self.db).await?; Ok(()) } diff --git a/crates/erp-ai/src/service/insight_service.rs b/crates/erp-ai/src/service/insight_service.rs index bb625e2..c3e81e9 100644 --- a/crates/erp-ai/src/service/insight_service.rs +++ b/crates/erp-ai/src/service/insight_service.rs @@ -104,7 +104,7 @@ impl InsightService { active.is_dismissed = Set(true); active.updated_at = Set(chrono::Utc::now()); active.updated_by = Set(updated_by); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(db).await?; Ok(()) } @@ -123,7 +123,7 @@ impl InsightService { let mut active: copilot_insights::ActiveModel = model.into(); active.deleted_at = Set(Some(now)); active.updated_at = Set(now); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(db).await?; } Ok(count) diff --git a/crates/erp-ai/src/service/prompt.rs b/crates/erp-ai/src/service/prompt.rs index f264957..5e2687f 100644 --- a/crates/erp-ai/src/service/prompt.rs +++ b/crates/erp-ai/src/service/prompt.rs @@ -169,7 +169,7 @@ impl PromptService { let mut active: ai_prompt::ActiveModel = sibling.into(); active.is_active = Set(false); active.updated_at = Set(chrono::Utc::now()); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(&self.db).await?; } @@ -177,7 +177,7 @@ impl PromptService { let mut active: ai_prompt::ActiveModel = entity.into(); active.is_active = Set(true); active.updated_at = Set(chrono::Utc::now()); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); Ok(active.update(&self.db).await?) } diff --git a/crates/erp-ai/src/service/risk_service.rs b/crates/erp-ai/src/service/risk_service.rs index 3558ed0..ded3281 100644 --- a/crates/erp-ai/src/service/risk_service.rs +++ b/crates/erp-ai/src/service/risk_service.rs @@ -89,7 +89,7 @@ impl RiskService { active.llm_summary = Set(llm_summary); active.computed_at = Set(now); active.updated_at = Set(now); - active.version_lock = Set(active.version_lock.unwrap() + 1); + active.version_lock = Set(active.version_lock.take().unwrap_or(0) + 1); active.update(db).await?; } else { let id = Uuid::now_v7(); diff --git a/crates/erp-auth/src/service/auth_service.rs b/crates/erp-auth/src/service/auth_service.rs index 7dfbb09..972ab5a 100644 --- a/crates/erp-auth/src/service/auth_service.rs +++ b/crates/erp-auth/src/service/auth_service.rs @@ -137,7 +137,7 @@ impl AuthService { let mut user_active: user::ActiveModel = user_model.clone().into(); user_active.last_login_at = Set(Some(Utc::now())); user_active.updated_at = Set(Utc::now()); - user_active.version = Set(user_active.version.unwrap() + 1); + user_active.version = Set(user_active.version.take().unwrap_or(0) + 1); user_active .update(db) .await diff --git a/crates/erp-auth/src/service/role_service.rs b/crates/erp-auth/src/service/role_service.rs index 254b4ac..ec7378e 100644 --- a/crates/erp-auth/src/service/role_service.rs +++ b/crates/erp-auth/src/service/role_service.rs @@ -299,7 +299,7 @@ impl RoleService { active.deleted_at = Set(Some(now)); active.updated_at = Set(now); active.updated_by = Set(operator_id); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active .update(db) .await diff --git a/crates/erp-auth/src/service/token_service.rs b/crates/erp-auth/src/service/token_service.rs index 4199786..f2e433d 100644 --- a/crates/erp-auth/src/service/token_service.rs +++ b/crates/erp-auth/src/service/token_service.rs @@ -168,7 +168,7 @@ impl TokenService { let mut active: user_token::ActiveModel = token_row.into(); active.revoked_at = Set(Some(Utc::now())); active.updated_at = Set(Utc::now()); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active .update(db) .await @@ -238,7 +238,7 @@ impl TokenService { let mut active: user_token::ActiveModel = token.into(); active.revoked_at = Set(Some(now)); active.updated_at = Set(now); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active .update(db) .await diff --git a/crates/erp-config/src/service/menu_service.rs b/crates/erp-config/src/service/menu_service.rs index 7717852..18933c1 100644 --- a/crates/erp-config/src/service/menu_service.rs +++ b/crates/erp-config/src/service/menu_service.rs @@ -383,7 +383,7 @@ impl MenuService { active.deleted_at = Set(Some(now)); active.updated_at = Set(now); active.updated_by = Set(operator_id); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active .update(db) .await diff --git a/crates/erp-config/src/service/numbering_service.rs b/crates/erp-config/src/service/numbering_service.rs index 1d56622..24498a5 100644 --- a/crates/erp-config/src/service/numbering_service.rs +++ b/crates/erp-config/src/service/numbering_service.rs @@ -392,7 +392,7 @@ impl NumberingService { active.seq_current = Set(next_seq); active.last_reset_date = Set(Some(today)); active.updated_at = Set(Utc::now()); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active .update(txn) .await diff --git a/crates/erp-health/src/oauth/service.rs b/crates/erp-health/src/oauth/service.rs index dafdd1d..90f4ba7 100644 --- a/crates/erp-health/src/oauth/service.rs +++ b/crates/erp-health/src/oauth/service.rs @@ -302,7 +302,7 @@ impl OAuthService { let mut active: api_client::ActiveModel = client.into(); active.deleted_at = Set(Some(Utc::now().into())); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.update(db).await?; Ok(()) @@ -328,7 +328,7 @@ impl OAuthService { let mut active: api_client::ActiveModel = client.into(); active.client_secret_hash = Set(hash); active.updated_at = Set(Utc::now().into()); - active.version = Set(active.version.clone().unwrap() + 1); + active.version = Set(active.version.clone().take().unwrap_or(0) + 1); let id = active.id.clone().unwrap().to_string(); active.update(db).await?; diff --git a/crates/erp-health/src/service/article_service.rs b/crates/erp-health/src/service/article_service.rs index b8cc801..363f1d4 100644 --- a/crates/erp-health/src/service/article_service.rs +++ b/crates/erp-health/src/service/article_service.rs @@ -338,7 +338,7 @@ pub async fn increment_view_count( let mut active: article::ActiveModel = model.into(); active.view_count = Set(active.view_count.take().unwrap_or(0) + 1); active.updated_at = Set(Utc::now()); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.update(&state.db).await?; Ok(()) } diff --git a/crates/erp-health/src/service/ble_gateway_service.rs b/crates/erp-health/src/service/ble_gateway_service.rs index 2e2161d..d7456c9 100644 --- a/crates/erp-health/src/service/ble_gateway_service.rs +++ b/crates/erp-health/src/service/ble_gateway_service.rs @@ -264,7 +264,7 @@ pub async fn heartbeat( active.ip_address = Set(Some(v)); } active.updated_at = Set(now); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.update(&state.db).await?; Ok(()) diff --git a/crates/erp-health/src/service/critical_value_threshold_service.rs b/crates/erp-health/src/service/critical_value_threshold_service.rs index 438f57c..6a44596 100644 --- a/crates/erp-health/src/service/critical_value_threshold_service.rs +++ b/crates/erp-health/src/service/critical_value_threshold_service.rs @@ -173,7 +173,7 @@ pub async fn delete_threshold( let mut active: critical_value_threshold::ActiveModel = existing.into(); active.deleted_at = Set(Some(chrono::Utc::now())); active.updated_by = Set(operator_id); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.update(db).await?; Ok(()) } diff --git a/crates/erp-health/src/service/follow_up_template_service.rs b/crates/erp-health/src/service/follow_up_template_service.rs index b7e6c86..e8138bb 100644 --- a/crates/erp-health/src/service/follow_up_template_service.rs +++ b/crates/erp-health/src/service/follow_up_template_service.rs @@ -207,7 +207,7 @@ pub async fn update_template( for old in old_fields { let mut af: follow_up_template_field::ActiveModel = old.into(); af.deleted_at = Set(Some(Utc::now())); - af.version = Set(af.version.unwrap() + 1); + af.version = Set(af.version.take().unwrap_or(0) + 1); af.update(&state.db).await?; } // 插入新字段 @@ -270,7 +270,7 @@ pub async fn delete_template( for f in fields { let mut af: follow_up_template_field::ActiveModel = f.into(); af.deleted_at = Set(Some(Utc::now())); - af.version = Set(af.version.unwrap() + 1); + af.version = Set(af.version.take().unwrap_or(0) + 1); af.update(&state.db).await?; } diff --git a/crates/erp-health/src/service/patient_service/relation.rs b/crates/erp-health/src/service/patient_service/relation.rs index a8996e6..49003f9 100644 --- a/crates/erp-health/src/service/patient_service/relation.rs +++ b/crates/erp-health/src/service/patient_service/relation.rs @@ -530,7 +530,7 @@ pub async fn remove_doctor( active.deleted_at = Set(Some(Utc::now())); active.updated_at = Set(Utc::now()); active.updated_by = Set(operator_id); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.update(&state.db).await?; audit_service::record( diff --git a/crates/erp-health/src/service/points_service/product.rs b/crates/erp-health/src/service/points_service/product.rs index 7e4dc9b..13d95c2 100644 --- a/crates/erp-health/src/service/points_service/product.rs +++ b/crates/erp-health/src/service/points_service/product.rs @@ -542,7 +542,7 @@ pub async fn exchange_product( // 关联消费流水的 order_id let mut spend_active: points_transaction::ActiveModel = spend.into(); spend_active.order_id = Set(Some(inserted_order.id)); - spend_active.version = Set(spend_active.version.unwrap() + 1); + spend_active.version = Set(spend_active.version.take().unwrap_or(0) + 1); spend_active.updated_at = Set(Utc::now()); spend_active.update(&txn).await?; diff --git a/crates/erp-server/src/dialysis_workflow.rs b/crates/erp-server/src/dialysis_workflow.rs index 4eaad98..5c4f515 100644 --- a/crates/erp-server/src/dialysis_workflow.rs +++ b/crates/erp-server/src/dialysis_workflow.rs @@ -108,7 +108,7 @@ async fn handle_dialysis_record_created( .ok_or("透析记录不存在")?; let mut active: erp_dialysis::entity::dialysis_record::ActiveModel = record.into(); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.workflow_instance_id = Set(Some(result.id)); active.updated_at = Set(chrono::Utc::now()); active.update(db).await?; diff --git a/crates/erp-workflow/src/engine/executor.rs b/crates/erp-workflow/src/engine/executor.rs index 5a61824..e63ce09 100644 --- a/crates/erp-workflow/src/engine/executor.rs +++ b/crates/erp-workflow/src/engine/executor.rs @@ -89,7 +89,7 @@ impl FlowExecutor { // 消费当前 token let mut active: token::ActiveModel = current_token.into(); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.status = Set("consumed".to_string()); active.consumed_at = Set(Some(Utc::now())); active @@ -600,7 +600,7 @@ impl FlowExecutor { .ok_or_else(|| WorkflowError::NotFound(format!("流程实例不存在: {instance_id}")))?; let mut active: process_instance::ActiveModel = instance.into(); - active.version = Set(active.version.unwrap() + 1); + active.version = Set(active.version.take().unwrap_or(0) + 1); active.status = Set("completed".to_string()); active.completed_at = Set(Some(Utc::now())); active.updated_at = Set(Utc::now());