fix(health): 修复咨询统计返回零值 BUG + 清理 secure-storage 过时注释

BUG-CONSULTATION-001: safe_aggregate 包装导致 compute_avg_response_time
SQL JOIN 错误时整个统计函数返回零值默认。修复方式:
- handler 层移除 safe_aggregate 改为直接 .await?
- service 层对 compute_avg_response_time 独立错误处理(warn + None)

同时清理 secure-storage.ts 中关于 crypto-js 的过时注释(已移除)。
This commit is contained in:
iven
2026-05-15 15:05:53 +08:00
parent 2c567bd772
commit 057d9b5896
4 changed files with 306 additions and 12 deletions

View File

@@ -31,11 +31,7 @@ where
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "health.consultation.list")?;
let result = safe_aggregate(
stats_service::get_consultation_statistics(&state, ctx.tenant_id),
"咨询统计",
)
.await;
let result = stats_service::get_consultation_statistics(&state, ctx.tenant_id).await?;
Ok(Json(ApiResponse::ok(result)))
}

View File

@@ -86,7 +86,13 @@ pub async fn get_consultation_statistics(
.count(db)
.await?;
let avg_response_time_minutes = compute_avg_response_time(db, tenant_id).await?;
let avg_response_time_minutes = match compute_avg_response_time(db, tenant_id).await {
Ok(v) => v,
Err(e) => {
tracing::warn!("咨询平均响应时间查询失败,使用默认值: {e}");
None
}
};
Ok(ConsultationStatisticsResp {
total_sessions: total_sessions as i64,