实体: - journal_entry: 日记核心表 (心情/天气/标签/版本) - journal_element: 日记元素 (文字/图片/贴纸/手写/胶带) - handwriting_stroke: 手写笔画 (独立大字段表) - school_class: 班级 (6位码/过期控制) - class_member: 班级成员 (复合PK) - topic_assignment: 主题布置 - comment: 老师点评 - sticker_pack + sticker: 贴纸包和贴纸 - template: 日记模板 - achievement + user_achievement: 成就系统 - parent_child_binding: 家长-孩子绑定 (PIPL) - teacher_profile: 老师档案 - user_settings: 用户设置 迁移 (000170-000184): - 15 个建表迁移 + 索引 + RLS 策略 + 种子数据 - 所有表含 tenant_id 多租户隔离 - 软删除 + 乐观锁版本号 - 外键级联删除 - 暖记权限注册到基座 permissions 表 验证: cargo check 通过, 425 个测试全通过
66 lines
1.9 KiB
Rust
66 lines
1.9 KiB
Rust
// 班级 — 老师创建,学生通过班级码加入
|
||
|
||
use sea_orm::entity::prelude::*;
|
||
use serde::{Deserialize, Serialize};
|
||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||
#[sea_orm(table_name = "school_classes")]
|
||
pub struct Model {
|
||
#[sea_orm(primary_key, auto_increment = false)]
|
||
pub id: Uuid,
|
||
pub tenant_id: Uuid,
|
||
/// 班级名称
|
||
pub name: String,
|
||
/// 学校名称
|
||
#[serde(skip_serializing_if = "Option::is_none")]
|
||
pub school_name: Option<String>,
|
||
/// 创建者(老师)ID
|
||
pub teacher_id: Uuid,
|
||
/// 6 位班级码(字母数字混合,62^6 ≈ 568 亿种组合)
|
||
pub class_code: String,
|
||
/// 成员数量(缓存字段)
|
||
pub member_count: i32,
|
||
/// 是否激活
|
||
pub is_active: bool,
|
||
/// 班级码过期时间(学期结束自动失效)
|
||
#[serde(skip_serializing_if = "Option::is_none")]
|
||
pub expires_at: Option<DateTimeUtc>,
|
||
pub created_at: DateTimeUtc,
|
||
pub updated_at: DateTimeUtc,
|
||
pub created_by: Uuid,
|
||
pub updated_by: Uuid,
|
||
#[serde(skip_serializing_if = "Option::is_none")]
|
||
pub deleted_at: Option<DateTimeUtc>,
|
||
pub version: i32,
|
||
}
|
||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||
pub enum Relation {
|
||
#[sea_orm(has_many = "super::class_member::Entity")]
|
||
ClassMember,
|
||
#[sea_orm(has_many = "super::topic_assignment::Entity")]
|
||
TopicAssignment,
|
||
#[sea_orm(has_many = "super::journal_entry::Entity")]
|
||
JournalEntry,
|
||
}
|
||
|
||
impl Related<super::class_member::Entity> for Entity {
|
||
fn to() -> RelationDef {
|
||
Relation::ClassMember.def()
|
||
}
|
||
}
|
||
|
||
impl Related<super::topic_assignment::Entity> for Entity {
|
||
fn to() -> RelationDef {
|
||
Relation::TopicAssignment.def()
|
||
}
|
||
}
|
||
|
||
impl Related<super::journal_entry::Entity> for Entity {
|
||
fn to() -> RelationDef {
|
||
Relation::JournalEntry.def()
|
||
}
|
||
}
|
||
|
||
impl ActiveModelBehavior for ActiveModel {}
|