feat(ai): 添加 SeaORM Entity (ai_prompt/ai_analysis/ai_usage)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
33
crates/erp-ai/src/entity/ai_analysis.rs
Normal file
33
crates/erp-ai/src/entity/ai_analysis.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "ai_analysis_results")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub analysis_type: String,
|
||||
pub source_ref: String,
|
||||
pub prompt_id: Uuid,
|
||||
pub prompt_version: i32,
|
||||
pub model_used: String,
|
||||
pub input_data_hash: String,
|
||||
pub sanitized_input: Option<serde_json::Value>,
|
||||
pub result_content: Option<String>,
|
||||
pub result_metadata: Option<serde_json::Value>,
|
||||
pub status: String,
|
||||
pub error_message: Option<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 {}
|
||||
31
crates/erp-ai/src/entity/ai_prompt.rs
Normal file
31
crates/erp-ai/src/entity/ai_prompt.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 = "ai_prompts")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub system_prompt: String,
|
||||
pub user_prompt_template: String,
|
||||
pub variables_schema: Option<serde_json::Value>,
|
||||
pub model_config: serde_json::Value,
|
||||
pub version: i32,
|
||||
pub is_active: bool,
|
||||
pub category: String,
|
||||
pub tags: 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 {}
|
||||
24
crates/erp-ai/src/entity/ai_usage.rs
Normal file
24
crates/erp-ai/src/entity/ai_usage.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "ai_usage_logs")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub provider: String,
|
||||
pub model: String,
|
||||
pub analysis_type: String,
|
||||
pub input_tokens: i32,
|
||||
pub output_tokens: i32,
|
||||
pub duration_ms: i32,
|
||||
pub cost_cents: i32,
|
||||
pub is_cache_hit: bool,
|
||||
pub created_at: DateTimeUtc,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
3
crates/erp-ai/src/entity/mod.rs
Normal file
3
crates/erp-ai/src/entity/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod ai_analysis;
|
||||
pub mod ai_prompt;
|
||||
pub mod ai_usage;
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod entity;
|
||||
pub mod error;
|
||||
|
||||
pub use error::{AiError, AiResult};
|
||||
|
||||
Reference in New Issue
Block a user