feat(ai): Copilot 评分引擎 + Handler + 路由 + 权限码
- scoring.rs: 混合评分 (calculate_risk) + RiskScore/MatchedRule 结构 - engine.rs: CopilotEngine 协调规则评估和评分 - risk_service.rs: 风险计算 + UPSERT 快照 + 规则加载 - insight_service.rs: 洞察 CRUD + 过期清理 - 3 个 Handler: insight/risk/rule,7 个 API 端点 - 5 个权限码: copilot.insights.list/manage, copilot.risk.view, copilot.rules.list/manage - AiState 扩展 risk_service + insight_service
This commit is contained in:
52
crates/erp-ai/src/dto/copilot.rs
Normal file
52
crates/erp-ai/src/dto/copilot.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ListInsightsQuery {
|
||||
pub patient_id: Option<uuid::Uuid>,
|
||||
pub insight_type: Option<String>,
|
||||
pub severity: Option<String>,
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InsightType {
|
||||
RiskScore,
|
||||
Anomaly,
|
||||
FollowUpHint,
|
||||
ConsultHint,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RiskLevel {
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
Critical,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateRuleBody {
|
||||
pub name: String,
|
||||
pub category: String,
|
||||
pub condition_expr: serde_json::Value,
|
||||
pub score: i16,
|
||||
pub severity: String,
|
||||
pub suggestion: Option<String>,
|
||||
pub enabled: Option<bool>,
|
||||
pub sort_order: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct UpdateRuleBody {
|
||||
pub name: Option<String>,
|
||||
pub category: Option<String>,
|
||||
pub condition_expr: Option<serde_json::Value>,
|
||||
pub score: Option<i16>,
|
||||
pub severity: Option<String>,
|
||||
pub suggestion: Option<String>,
|
||||
pub enabled: Option<bool>,
|
||||
pub sort_order: Option<i32>,
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod copilot;
|
||||
pub mod suggestion;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
Reference in New Issue
Block a user