Files
FastapiAdmin/backend/app/api/v1/module_system/notice/model.py
T
zhangtao 73f2823692 refactor: 大规模代码整理与功能优化
1. 重构后端API路由、CRUD与模块结构,整合日志管理,移除废弃demo代码
2. 优化前端组件类型定义、样式与路由配置,修复权限判断逻辑
3. 调整默认排序规则、滚动条样式与工具类函数,更新依赖与配置文件
4. 修复多处类型不匹配与默认值问题,完善表单与菜单验证逻辑
2026-06-17 01:56:31 +08:00

55 lines
2.1 KiB
Python

from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.base_model import MappedBase, ModelMixin, TenantMixin, UserMixin
class NoticeModel(ModelMixin, TenantMixin, UserMixin):
"""
通知公告表
"""
__tablename__: str = "sys_notice"
__table_args__: dict[str, str] = {"comment": "通知公告表"}
__loader_options__: list[str] = ["created_by", "updated_by", "deleted_by"]
notice_title: Mapped[str] = mapped_column(String(64), nullable=False, comment="公告标题")
notice_type: Mapped[str] = mapped_column(
String(1), nullable=False, comment="公告类型(1通知 2公告)"
)
notice_content: Mapped[str | None] = mapped_column(Text, nullable=True, comment="公告内容")
class NoticeReadModel(MappedBase):
"""
通知已读记录表 — 记录用户对公告的已读状态。
设计说明:
- 不继承 TenantMixin:该表按 user_id 隔离,租户上下文由所属 notice 间接确定
- (user_id, notice_id) 唯一约束 — 未建立记录即代表未读
- 仅用于标记已读时间,不做其他业务用途
- 不继承 ModelMixin:使用 (user_id, notice_id) 复合主键,无需自增 id 列
(避免 SQLite 不支持复合主键列 autoincrement 的问题)
"""
__tablename__: str = "sys_notice_read"
__table_args__: tuple = (
UniqueConstraint("user_id", "notice_id", name="uq_user_notice_read"),
{"comment": "通知已读记录表"},
)
user_id: Mapped[int] = mapped_column(
Integer, ForeignKey("sys_user.id", ondelete="CASCADE"), primary_key=True, comment="用户ID"
)
notice_id: Mapped[int] = mapped_column(
Integer, ForeignKey("sys_notice.id", ondelete="CASCADE"), primary_key=True, comment="通知ID"
)
read_time: Mapped[datetime] = mapped_column(
DateTime, nullable=False, default=datetime.now, comment="已读时间"
)
# 关联
notice: Mapped[NoticeModel] = relationship("NoticeModel", lazy="selectin")