VWED_server/.cursor/rules/data-models.mdc
2025-04-30 16:57:46 +08:00

116 lines
2.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description:
globs:
alwaysApply: false
---
# VWED任务模块 - 数据模型
## 数据模型概述
VWED任务模块的数据模型层定义了系统中的各种实体和它们之间的关系。主要数据模型包括任务定义、任务记录、任务块记录、数据缓存和任务模板等。
## 核心数据模型
### 任务定义模型 (TaskDef)
任务定义模型存储任务的基本信息和配置,是系统中最基础的数据实体。
**核心字段**
- `id`: 任务定义ID
- `name`: 任务名称
- `description`: 任务描述
- `task_type`: 任务类型
- `config`: 任务配置JSON
- `status`: 任务状态
- `version`: 任务版本号
**相关文件**: [data/models/taskdef.py](mdc:data/models/taskdef.py)
### 任务记录模型 (TaskRecord)
任务记录模型记录任务的执行历史和状态,每次任务执行都会生成一条任务记录。
**核心字段**:
- `id`: 记录ID
- `task_def_id`: 关联的任务定义ID
- `status`: 执行状态
- `result`: 执行结果
- `start_time`: 开始时间
- `end_time`: 结束时间
- `error_message`: 错误信息
**相关文件**: [data/models/taskrecord.py](mdc:data/models/taskrecord.py)
### 任务块记录模型 (BlockRecord)
任务块记录模型记录任务中各个执行块的执行情况,提供更细粒度的执行信息。
**核心字段**:
- `id`: 记录ID
- `task_record_id`: 关联的任务记录ID
- `block_id`: 块ID
- `block_type`: 块类型
- `status`: 执行状态
- `input_data`: 输入数据
- `output_data`: 输出数据
- `start_time`: 开始时间
- `end_time`: 结束时间
**相关文件**: [data/models/blockrecord.py](mdc:data/models/blockrecord.py)
### 数据缓存模型 (DataCache)
数据缓存模型用于存储任务执行过程中的临时数据和中间结果。
**核心字段**:
- `id`: 缓存ID
- `task_record_id`: 关联的任务记录ID
- `key`: 缓存键
- `value`: 缓存值
- `type`: 数据类型
- `expire_time`: 过期时间
**相关文件**: [data/models/datacache.py](mdc:data/models/datacache.py)
### 任务模板模型 (TaskTemplate)
任务模板模型存储预定义的任务模板,用户可以基于模板快速创建任务。
**核心字段**:
- `id`: 模板ID
- `name`: 模板名称
- `description`: 模板描述
- `config`: 模板配置JSON
- `version`: 模板版本号
- `task_type`: 任务类型
**相关文件**: [data/models/tasktemplate.py](mdc:data/models/tasktemplate.py)
## 数据关系图
```
TaskDef (任务定义)
↓ 1:n
TaskRecord (任务记录)
↓ 1:n
BlockRecord (任务块记录)
TaskDef ← 基于 ← TaskTemplate (任务模板)
TaskRecord
↓ 1:n
DataCache (数据缓存)
```
## 数据库会话管理
系统使用SQLAlchemy作为ORM框架支持同步和异步两种数据库访问方式。
**相关文件**: [data/session.py](mdc:data/session.py)
## 缓存系统
系统使用Redis作为分布式缓存提供高性能的数据缓存和共享。
**相关文件**: [data/cache.py](mdc:data/cache.py)