chore: apply cargo fmt across workspace and update docs
- Run cargo fmt on all Rust crates for consistent formatting - Update CLAUDE.md with WASM plugin commands and dev.ps1 instructions - Update wiki: add WASM plugin architecture, rewrite dev environment docs - Minor frontend cleanup (unused imports)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use chrono::Utc;
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, Set,
|
||||
};
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, Set};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::dto::SettingResp;
|
||||
@@ -46,9 +44,7 @@ impl SettingService {
|
||||
db: &sea_orm::DatabaseConnection,
|
||||
) -> ConfigResult<SettingResp> {
|
||||
// 1. Try exact match
|
||||
if let Some(resp) =
|
||||
Self::find_exact(key, scope, scope_id, tenant_id, db).await?
|
||||
{
|
||||
if let Some(resp) = Self::find_exact(key, scope, scope_id, tenant_id, db).await? {
|
||||
return Ok(resp);
|
||||
}
|
||||
|
||||
@@ -81,12 +77,18 @@ impl SettingService {
|
||||
event_bus: &EventBus,
|
||||
) -> ConfigResult<SettingResp> {
|
||||
// Look for an existing non-deleted record
|
||||
let existing = setting::Entity::find()
|
||||
let mut query = setting::Entity::find()
|
||||
.filter(setting::Column::TenantId.eq(tenant_id))
|
||||
.filter(setting::Column::Scope.eq(¶ms.scope))
|
||||
.filter(setting::Column::ScopeId.eq(params.scope_id))
|
||||
.filter(setting::Column::SettingKey.eq(¶ms.key))
|
||||
.filter(setting::Column::DeletedAt.is_null())
|
||||
.filter(setting::Column::DeletedAt.is_null());
|
||||
|
||||
query = match params.scope_id {
|
||||
Some(id) => query.filter(setting::Column::ScopeId.eq(id)),
|
||||
None => query.filter(setting::Column::ScopeId.is_null()),
|
||||
};
|
||||
|
||||
let existing = query
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
@@ -94,7 +96,9 @@ impl SettingService {
|
||||
if let Some(model) = existing {
|
||||
// Update existing record — 乐观锁校验
|
||||
let next_version = match params.version {
|
||||
Some(v) => check_version(v, model.version).map_err(|_| ConfigError::VersionMismatch)?,
|
||||
Some(v) => {
|
||||
check_version(v, model.version).map_err(|_| ConfigError::VersionMismatch)?
|
||||
}
|
||||
None => model.version + 1,
|
||||
};
|
||||
|
||||
@@ -109,15 +113,20 @@ impl SettingService {
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
|
||||
event_bus.publish(erp_core::events::DomainEvent::new(
|
||||
"setting.updated",
|
||||
tenant_id,
|
||||
serde_json::json!({
|
||||
"setting_id": updated.id,
|
||||
"key": params.key,
|
||||
"scope": params.scope,
|
||||
}),
|
||||
), db).await;
|
||||
event_bus
|
||||
.publish(
|
||||
erp_core::events::DomainEvent::new(
|
||||
"setting.updated",
|
||||
tenant_id,
|
||||
serde_json::json!({
|
||||
"setting_id": updated.id,
|
||||
"key": params.key,
|
||||
"scope": params.scope,
|
||||
}),
|
||||
),
|
||||
db,
|
||||
)
|
||||
.await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "setting.upsert", "setting")
|
||||
@@ -150,15 +159,20 @@ impl SettingService {
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
|
||||
event_bus.publish(erp_core::events::DomainEvent::new(
|
||||
"setting.created",
|
||||
tenant_id,
|
||||
serde_json::json!({
|
||||
"setting_id": id,
|
||||
"key": params.key,
|
||||
"scope": params.scope,
|
||||
}),
|
||||
), db).await;
|
||||
event_bus
|
||||
.publish(
|
||||
erp_core::events::DomainEvent::new(
|
||||
"setting.created",
|
||||
tenant_id,
|
||||
serde_json::json!({
|
||||
"setting_id": id,
|
||||
"key": params.key,
|
||||
"scope": params.scope,
|
||||
}),
|
||||
),
|
||||
db,
|
||||
)
|
||||
.await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "setting.upsert", "setting")
|
||||
@@ -179,12 +193,17 @@ impl SettingService {
|
||||
pagination: &Pagination,
|
||||
db: &sea_orm::DatabaseConnection,
|
||||
) -> ConfigResult<(Vec<SettingResp>, u64)> {
|
||||
let paginator = setting::Entity::find()
|
||||
let mut query = setting::Entity::find()
|
||||
.filter(setting::Column::TenantId.eq(tenant_id))
|
||||
.filter(setting::Column::Scope.eq(scope))
|
||||
.filter(setting::Column::ScopeId.eq(*scope_id))
|
||||
.filter(setting::Column::DeletedAt.is_null())
|
||||
.paginate(db, pagination.limit());
|
||||
.filter(setting::Column::DeletedAt.is_null());
|
||||
|
||||
query = match scope_id {
|
||||
Some(id) => query.filter(setting::Column::ScopeId.eq(*id)),
|
||||
None => query.filter(setting::Column::ScopeId.is_null()),
|
||||
};
|
||||
|
||||
let paginator = query.paginate(db, pagination.limit());
|
||||
|
||||
let total = paginator
|
||||
.num_items()
|
||||
@@ -197,8 +216,7 @@ impl SettingService {
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
|
||||
let resps: Vec<SettingResp> =
|
||||
models.iter().map(Self::model_to_resp).collect();
|
||||
let resps: Vec<SettingResp> = models.iter().map(Self::model_to_resp).collect();
|
||||
|
||||
Ok((resps, total))
|
||||
}
|
||||
@@ -214,20 +232,23 @@ impl SettingService {
|
||||
version: i32,
|
||||
db: &sea_orm::DatabaseConnection,
|
||||
) -> ConfigResult<()> {
|
||||
let model = setting::Entity::find()
|
||||
let mut query = setting::Entity::find()
|
||||
.filter(setting::Column::TenantId.eq(tenant_id))
|
||||
.filter(setting::Column::Scope.eq(scope))
|
||||
.filter(setting::Column::ScopeId.eq(*scope_id))
|
||||
.filter(setting::Column::SettingKey.eq(key))
|
||||
.filter(setting::Column::DeletedAt.is_null())
|
||||
.filter(setting::Column::DeletedAt.is_null());
|
||||
|
||||
query = match scope_id {
|
||||
Some(id) => query.filter(setting::Column::ScopeId.eq(*id)),
|
||||
None => query.filter(setting::Column::ScopeId.is_null()),
|
||||
};
|
||||
|
||||
let model = query
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?
|
||||
.ok_or_else(|| {
|
||||
ConfigError::NotFound(format!(
|
||||
"设置 '{}' 在 '{}' 作用域下不存在",
|
||||
key, scope
|
||||
))
|
||||
ConfigError::NotFound(format!("设置 '{}' 在 '{}' 作用域下不存在", key, scope))
|
||||
})?;
|
||||
|
||||
let next_version =
|
||||
@@ -264,12 +285,19 @@ impl SettingService {
|
||||
tenant_id: Uuid,
|
||||
db: &sea_orm::DatabaseConnection,
|
||||
) -> ConfigResult<Option<SettingResp>> {
|
||||
let model = setting::Entity::find()
|
||||
let mut query = setting::Entity::find()
|
||||
.filter(setting::Column::TenantId.eq(tenant_id))
|
||||
.filter(setting::Column::Scope.eq(scope))
|
||||
.filter(setting::Column::ScopeId.eq(*scope_id))
|
||||
.filter(setting::Column::SettingKey.eq(key))
|
||||
.filter(setting::Column::DeletedAt.is_null())
|
||||
.filter(setting::Column::DeletedAt.is_null());
|
||||
|
||||
// SQL 中 `= NULL` 永远返回 false,必须用 IS NULL 匹配 NULL 值
|
||||
query = match scope_id {
|
||||
Some(id) => query.filter(setting::Column::ScopeId.eq(*id)),
|
||||
None => query.filter(setting::Column::ScopeId.is_null()),
|
||||
};
|
||||
|
||||
let model = query
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
@@ -301,9 +329,7 @@ impl SettingService {
|
||||
(SCOPE_TENANT.to_string(), Some(tenant_id)),
|
||||
(SCOPE_PLATFORM.to_string(), None),
|
||||
]),
|
||||
SCOPE_TENANT => {
|
||||
Ok(vec![(SCOPE_PLATFORM.to_string(), None)])
|
||||
}
|
||||
SCOPE_TENANT => Ok(vec![(SCOPE_PLATFORM.to_string(), None)]),
|
||||
SCOPE_PLATFORM => Ok(vec![]),
|
||||
_ => Err(ConfigError::Validation(format!(
|
||||
"不支持的作用域类型: '{}'",
|
||||
|
||||
Reference in New Issue
Block a user