Files
assist/.agents/summary/data_models.md

137 lines
3.3 KiB
Markdown
Raw Normal View History

# Data Models / 数据模型
## ORM 模型 (`src/core/models.py`)
所有模型继承 SQLAlchemy `Base`,核心表均包含 `tenant_id` 字段用于多租户隔离。
```mermaid
erDiagram
Tenant ||--o{ WorkOrder : "tenant_id"
Tenant ||--o{ ChatSession : "tenant_id"
Tenant ||--o{ KnowledgeEntry : "tenant_id"
Tenant ||--o{ Alert : "tenant_id"
Tenant ||--o{ Analytics : "tenant_id"
WorkOrder ||--o{ Conversation : "work_order_id"
WorkOrder ||--o{ WorkOrderProcessHistory : "work_order_id"
WorkOrder ||--o{ WorkOrderSuggestion : "work_order_id"
ChatSession ||--o{ Conversation : "session_id"
Tenant {
int id PK
string tenant_id UK
string name
text description
bool is_active
text config "JSON: feishu, system_prompt"
}
WorkOrder {
int id PK
string tenant_id FK
string order_id UK
string title
text description
string category
string priority
string status
string feishu_record_id "飞书记录ID"
string assignee
text ai_suggestion
string assigned_module
string module_owner
string vin_sim "车架号"
}
ChatSession {
int id PK
string tenant_id FK
string session_id UK
string source "websocket/api/feishu_bot"
}
Conversation {
int id PK
string tenant_id FK
int work_order_id FK
string session_id FK
string role "user/assistant/system"
text content
}
KnowledgeEntry {
int id PK
string tenant_id FK
string question
text answer
string category
bool is_verified
float confidence_score
}
Alert {
int id PK
string tenant_id FK
string level
string type
text message
bool is_resolved
}
VehicleData {
int id PK
string vehicle_id
string vin
text data "JSON"
}
Analytics {
int id PK
string tenant_id FK
string metric_type
float value
text details "JSON"
}
User {
int id PK
string username UK
string password_hash
string role "admin/user"
}
WorkOrderProcessHistory {
int id PK
int work_order_id FK
string action
text details
}
WorkOrderSuggestion {
int id PK
int work_order_id FK
text suggestion
float confidence
}
```
## 配置 Dataclasses (`src/config/unified_config.py`)
| Dataclass | 关键字段 |
|-----------|---------|
| `DatabaseConfig` | `url` |
| `LLMConfig` | `api_key`, `base_url`, `model`, `temperature`, `max_tokens`, `timeout` |
| `ServerConfig` | `host`, `port`, `websocket_port`, `debug`, `log_level` |
| `FeishuConfig` | `app_id`, `app_secret`, `app_token`, `table_id` |
| `AIAccuracyConfig` | `auto_approve_threshold`, `manual_review_threshold` |
| `EmbeddingConfig` | `enabled`, `model`, `dimension`, `similarity_threshold` |
| `RedisConfig` | `host`, `port`, `db`, `password`, `pool_size`, `default_ttl`, `enabled` |
## 业务枚举
- `WorkOrderStatus`: 工单状态流转
- `WorkOrderPriority`: 工单优先级
- `AlertLevel`: 预警级别
- `AlertType`: 预警类型