mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
refactor: 抽离 AI pipeline 与调度共享能力逻辑
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
use crate::{AppState, GatewayError};
|
||||
|
||||
impl AppState {
|
||||
pub(crate) async fn read_auth_api_key_force_capabilities(
|
||||
&self,
|
||||
user_id: &str,
|
||||
api_key_id: &str,
|
||||
) -> Result<Option<serde_json::Value>, GatewayError> {
|
||||
Ok(self
|
||||
.list_auth_api_key_export_records_by_ids(&[api_key_id.to_string()])
|
||||
.await?
|
||||
.into_iter()
|
||||
.find(|record| record.api_key_id == api_key_id && record.user_id == user_id)
|
||||
.and_then(|record| record.force_capabilities))
|
||||
}
|
||||
|
||||
pub(crate) async fn list_auth_api_key_export_records_by_user_ids(
|
||||
&self,
|
||||
user_ids: &[String],
|
||||
|
||||
@@ -60,7 +60,7 @@ impl AppState {
|
||||
variables: input.variables.clone(),
|
||||
dimension_mappings: input.dimension_mappings.clone(),
|
||||
is_enabled: input.is_enabled,
|
||||
created_at_unix_secs: now_unix_secs,
|
||||
created_at_unix_ms: now_unix_secs,
|
||||
updated_at_unix_secs: now_unix_secs,
|
||||
};
|
||||
store
|
||||
@@ -187,7 +187,7 @@ impl AppState {
|
||||
default_value: input.default_value.clone(),
|
||||
priority: input.priority,
|
||||
is_enabled: input.is_enabled,
|
||||
created_at_unix_secs: now_unix_secs,
|
||||
created_at_unix_ms: now_unix_secs,
|
||||
updated_at_unix_secs: now_unix_secs,
|
||||
};
|
||||
store
|
||||
@@ -369,7 +369,7 @@ impl AppState {
|
||||
default_value: collector.default_value.clone(),
|
||||
priority: collector.priority,
|
||||
is_enabled: collector.is_enabled,
|
||||
created_at_unix_secs: now_unix_secs,
|
||||
created_at_unix_ms: now_unix_secs,
|
||||
updated_at_unix_secs: now_unix_secs,
|
||||
};
|
||||
guard.insert(record.id.clone(), record);
|
||||
|
||||
@@ -86,8 +86,8 @@ impl AppState {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
let total = items.len() as u64;
|
||||
@@ -137,8 +137,8 @@ impl AppState {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
let total = items.len() as u64;
|
||||
@@ -182,8 +182,8 @@ impl AppState {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
let total = items.len() as u64;
|
||||
@@ -209,7 +209,7 @@ impl AppState {
|
||||
operator_name: None,
|
||||
operator_email: None,
|
||||
description: record.description,
|
||||
created_at_unix_secs: Some(record.created_at_unix_secs),
|
||||
created_at_unix_ms: Some(record.created_at_unix_ms),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
return Ok((items, total));
|
||||
@@ -240,8 +240,8 @@ impl AppState {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
let total = items.len() as u64;
|
||||
@@ -296,8 +296,8 @@ impl AppState {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
let total = items.len() as u64;
|
||||
@@ -332,7 +332,7 @@ impl AppState {
|
||||
wallet_api_key_id: wallet.api_key_id.clone(),
|
||||
api_key_name: None,
|
||||
wallet_status: wallet.status.clone(),
|
||||
created_at_unix_secs: Some(refund.created_at_unix_secs),
|
||||
created_at_unix_ms: Some(refund.created_at_unix_ms),
|
||||
updated_at_unix_secs: Some(refund.updated_at_unix_secs),
|
||||
processed_at_unix_secs: refund.processed_at_unix_secs,
|
||||
completed_at_unix_secs: refund.completed_at_unix_secs,
|
||||
@@ -406,7 +406,7 @@ fn stored_admin_payment_order_to_gateway(
|
||||
gateway_order_id: record.gateway_order_id,
|
||||
status: record.status,
|
||||
gateway_response: record.gateway_response,
|
||||
created_at_unix_secs: record.created_at_unix_secs,
|
||||
created_at_unix_ms: record.created_at_unix_ms,
|
||||
paid_at_unix_secs: record.paid_at_unix_secs,
|
||||
credited_at_unix_secs: record.credited_at_unix_secs,
|
||||
expires_at_unix_secs: record.expires_at_unix_secs,
|
||||
@@ -428,7 +428,7 @@ fn stored_admin_payment_callback_to_gateway(
|
||||
status: record.status,
|
||||
payload: record.payload,
|
||||
error_message: record.error_message,
|
||||
created_at_unix_secs: record.created_at_unix_secs,
|
||||
created_at_unix_ms: record.created_at_unix_ms,
|
||||
processed_at_unix_secs: record.processed_at_unix_secs,
|
||||
}
|
||||
}
|
||||
@@ -456,7 +456,7 @@ fn stored_admin_wallet_refund_to_gateway(
|
||||
requested_by: record.requested_by,
|
||||
approved_by: record.approved_by,
|
||||
processed_by: record.processed_by,
|
||||
created_at_unix_secs: record.created_at_unix_secs,
|
||||
created_at_unix_ms: record.created_at_unix_ms,
|
||||
updated_at_unix_secs: record.updated_at_unix_secs,
|
||||
processed_at_unix_secs: record.processed_at_unix_secs,
|
||||
completed_at_unix_secs: record.completed_at_unix_secs,
|
||||
|
||||
@@ -249,7 +249,7 @@ fn stored_admin_payment_order_to_gateway(
|
||||
gateway_order_id: order.gateway_order_id,
|
||||
status: order.status,
|
||||
gateway_response: order.gateway_response,
|
||||
created_at_unix_secs: order.created_at_unix_secs,
|
||||
created_at_unix_ms: order.created_at_unix_ms,
|
||||
paid_at_unix_secs: order.paid_at_unix_secs,
|
||||
credited_at_unix_secs: order.credited_at_unix_secs,
|
||||
expires_at_unix_secs: order.expires_at_unix_secs,
|
||||
|
||||
@@ -85,7 +85,7 @@ impl AppState {
|
||||
.unwrap_or("管理员调账")
|
||||
.to_string(),
|
||||
),
|
||||
created_at_unix_secs: chrono::Utc::now().timestamp().max(0) as u64,
|
||||
created_at_unix_ms: chrono::Utc::now().timestamp().max(0) as u64,
|
||||
};
|
||||
return Ok(Some((wallet.clone(), transaction)));
|
||||
}
|
||||
@@ -148,7 +148,7 @@ impl AppState {
|
||||
"operator_id": operator_id,
|
||||
"description": description,
|
||||
})),
|
||||
created_at_unix_secs: created_at,
|
||||
created_at_unix_ms: created_at,
|
||||
paid_at_unix_secs: Some(created_at),
|
||||
credited_at_unix_secs: Some(created_at),
|
||||
expires_at_unix_secs: None,
|
||||
@@ -193,7 +193,7 @@ fn stored_wallet_transaction_to_gateway(
|
||||
link_id: transaction.link_id,
|
||||
operator_id: transaction.operator_id,
|
||||
description: transaction.description,
|
||||
created_at_unix_secs: transaction.created_at_unix_secs.unwrap_or_default(),
|
||||
created_at_unix_ms: transaction.created_at_unix_ms.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ fn stored_admin_payment_order_to_gateway(
|
||||
gateway_order_id: order.gateway_order_id,
|
||||
status: order.status,
|
||||
gateway_response: order.gateway_response,
|
||||
created_at_unix_secs: order.created_at_unix_secs,
|
||||
created_at_unix_ms: order.created_at_unix_ms,
|
||||
paid_at_unix_secs: order.paid_at_unix_secs,
|
||||
credited_at_unix_secs: order.credited_at_unix_secs,
|
||||
expires_at_unix_secs: order.expires_at_unix_secs,
|
||||
|
||||
@@ -102,8 +102,8 @@ pub(super) fn admin_wallet_payment_order_from_row(
|
||||
gateway_response: row
|
||||
.try_get("gateway_response")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?,
|
||||
created_at_unix_secs: row
|
||||
.try_get::<i64, _>("created_at_unix_secs")
|
||||
created_at_unix_ms: row
|
||||
.try_get::<i64, _>("created_at_unix_ms")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?
|
||||
.max(0) as u64,
|
||||
paid_at_unix_secs: row
|
||||
@@ -182,8 +182,8 @@ pub(super) fn admin_wallet_refund_from_row(
|
||||
processed_by: row
|
||||
.try_get("processed_by")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?,
|
||||
created_at_unix_secs: row
|
||||
.try_get::<i64, _>("created_at_unix_secs")
|
||||
created_at_unix_ms: row
|
||||
.try_get::<i64, _>("created_at_unix_ms")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?
|
||||
.max(0) as u64,
|
||||
updated_at_unix_secs: row
|
||||
@@ -234,8 +234,8 @@ pub(super) fn admin_billing_rule_from_row(
|
||||
is_enabled: row
|
||||
.try_get("is_enabled")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?,
|
||||
created_at_unix_secs: row
|
||||
.try_get::<i64, _>("created_at_unix_secs")
|
||||
created_at_unix_ms: row
|
||||
.try_get::<i64, _>("created_at_unix_ms")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?
|
||||
.max(0) as u64,
|
||||
updated_at_unix_secs: row
|
||||
@@ -282,8 +282,8 @@ pub(super) fn admin_billing_collector_from_row(
|
||||
is_enabled: row
|
||||
.try_get("is_enabled")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?,
|
||||
created_at_unix_secs: row
|
||||
.try_get::<i64, _>("created_at_unix_secs")
|
||||
created_at_unix_ms: row
|
||||
.try_get::<i64, _>("created_at_unix_ms")
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))?
|
||||
.max(0) as u64,
|
||||
updated_at_unix_secs: row
|
||||
|
||||
@@ -104,7 +104,7 @@ impl AppState {
|
||||
link_id: Some(refund.id.clone()),
|
||||
operator_id: operator_id.map(ToOwned::to_owned),
|
||||
description: Some("退款占款".to_string()),
|
||||
created_at_unix_secs: now_unix_secs,
|
||||
created_at_unix_ms: now_unix_secs,
|
||||
};
|
||||
|
||||
let mut updated_refund = refund.clone();
|
||||
@@ -318,7 +318,7 @@ impl AppState {
|
||||
link_id: Some(refund.id.clone()),
|
||||
operator_id: operator_id.map(ToOwned::to_owned),
|
||||
description: Some("退款失败回补".to_string()),
|
||||
created_at_unix_secs: now_unix_secs,
|
||||
created_at_unix_ms: now_unix_secs,
|
||||
};
|
||||
|
||||
if let Some(payment_order_id) = refund.payment_order_id.clone() {
|
||||
@@ -415,7 +415,7 @@ fn stored_admin_wallet_refund_to_gateway(
|
||||
requested_by: refund.requested_by,
|
||||
approved_by: refund.approved_by,
|
||||
processed_by: refund.processed_by,
|
||||
created_at_unix_secs: refund.created_at_unix_secs,
|
||||
created_at_unix_ms: refund.created_at_unix_ms,
|
||||
updated_at_unix_secs: refund.updated_at_unix_secs,
|
||||
processed_at_unix_secs: refund.processed_at_unix_secs,
|
||||
completed_at_unix_secs: refund.completed_at_unix_secs,
|
||||
@@ -441,6 +441,6 @@ fn stored_admin_wallet_transaction_to_gateway(
|
||||
link_id: transaction.link_id,
|
||||
operator_id: transaction.operator_id,
|
||||
description: transaction.description,
|
||||
created_at_unix_secs: transaction.created_at_unix_secs.unwrap_or_default(),
|
||||
created_at_unix_ms: transaction.created_at_unix_ms.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user