feat(ai): Copilot 基因化 Phase 0 Task 1-4 — 迁移 + Entity + 规则引擎
- 4 表迁移: copilot_rules, copilot_insights, copilot_risk_snapshots, copilot_chat_logs - 4 个 SeaORM Entity 对应新表 - JSONLogic 规则引擎 (evaluate + evaluate_rules) + 5 个单元测试
This commit is contained in:
31
crates/erp-ai/src/entity/copilot_chat_logs.rs
Normal file
31
crates/erp-ai/src/entity/copilot_chat_logs.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "copilot_chat_logs")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub session_id: Uuid,
|
||||
pub user_message: String,
|
||||
pub intent_classification: Option<String>,
|
||||
pub ai_raw_response: Option<String>,
|
||||
pub layer1_result: Option<serde_json::Value>,
|
||||
pub layer2_result: Option<serde_json::Value>,
|
||||
pub violations_found: Option<serde_json::Value>,
|
||||
pub fix_strategy: Option<String>,
|
||||
pub final_response: String,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version_lock: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
32
crates/erp-ai/src/entity/copilot_insights.rs
Normal file
32
crates/erp-ai/src/entity/copilot_insights.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "copilot_insights")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub insight_type: String,
|
||||
pub source: String,
|
||||
pub severity: Option<String>,
|
||||
pub title: String,
|
||||
pub content: serde_json::Value,
|
||||
pub rule_matches: Option<serde_json::Value>,
|
||||
pub llm_supplement: Option<String>,
|
||||
pub expires_at: DateTimeUtc,
|
||||
pub is_read: bool,
|
||||
pub is_dismissed: bool,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version_lock: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
28
crates/erp-ai/src/entity/copilot_risk_snapshots.rs
Normal file
28
crates/erp-ai/src/entity/copilot_risk_snapshots.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "copilot_risk_snapshots")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub risk_score: i16,
|
||||
pub risk_level: String,
|
||||
pub rule_details: serde_json::Value,
|
||||
pub llm_summary: Option<String>,
|
||||
pub computed_at: DateTimeUtc,
|
||||
pub data_freshness: Option<serde_json::Value>,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version_lock: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
29
crates/erp-ai/src/entity/copilot_rules.rs
Normal file
29
crates/erp-ai/src/entity/copilot_rules.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "copilot_rules")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub name: String,
|
||||
pub category: String,
|
||||
pub condition_expr: serde_json::Value,
|
||||
pub score: i16,
|
||||
pub severity: String,
|
||||
pub suggestion: Option<String>,
|
||||
pub enabled: bool,
|
||||
pub sort_order: i32,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version_lock: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -8,3 +8,7 @@ pub mod ai_risk_threshold;
|
||||
pub mod ai_suggestion;
|
||||
pub mod ai_tenant_config;
|
||||
pub mod ai_usage;
|
||||
pub mod copilot_chat_logs;
|
||||
pub mod copilot_insights;
|
||||
pub mod copilot_risk_snapshots;
|
||||
pub mod copilot_rules;
|
||||
|
||||
Reference in New Issue
Block a user