feat: Iteration 3 — 咨询轮询、统计概览、埋点后端
- consultation_service 支持 after_id 增量消息查询 - 小程序咨询详情页 8 秒轮询新消息 - 新增 DashboardStatsResp 综合统计端点 (/statistics/dashboard) - 新增 /analytics/batch 埋点接收端点(日志记录模式)
This commit is contained in:
34
crates/erp-server/src/handlers/analytics.rs
Normal file
34
crates/erp-server/src/handlers/analytics.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use axum::Json;
|
||||
use serde::Deserialize;
|
||||
use tracing;
|
||||
|
||||
use erp_core::types::ApiResponse;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct AnalyticsEvent {
|
||||
pub event: String,
|
||||
pub properties: Option<serde_json::Value>,
|
||||
pub timestamp: Option<String>,
|
||||
pub page: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct BatchRequest {
|
||||
pub events: Vec<AnalyticsEvent>,
|
||||
}
|
||||
|
||||
/// 接收小程序批量埋点事件。
|
||||
/// 当前为日志记录模式 — 后续可接入 ClickHouse/PostgreSQL 分析表。
|
||||
pub async fn batch(
|
||||
Json(req): Json<BatchRequest>,
|
||||
) -> Json<ApiResponse<()>> {
|
||||
for evt in &req.events {
|
||||
tracing::info!(
|
||||
event = %evt.event,
|
||||
page = ?evt.page,
|
||||
properties = ?evt.properties,
|
||||
"Analytics event received"
|
||||
);
|
||||
}
|
||||
Json(ApiResponse::ok(()))
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod analytics;
|
||||
pub mod audit_log;
|
||||
pub mod crypto_admin;
|
||||
pub mod health;
|
||||
|
||||
@@ -494,6 +494,10 @@ async fn main() -> anyhow::Result<()> {
|
||||
"/docs/openapi.json",
|
||||
axum::routing::get(handlers::openapi::openapi_spec),
|
||||
)
|
||||
.route(
|
||||
"/analytics/batch",
|
||||
axum::routing::post(handlers::analytics::batch),
|
||||
)
|
||||
.layer(axum::middleware::from_fn_with_state(
|
||||
state.clone(),
|
||||
middleware::rate_limit::rate_limit_by_ip,
|
||||
|
||||
Reference in New Issue
Block a user