25 lines
1.2 KiB
Python
25 lines
1.2 KiB
Python
|
|
"""通知模型 — 用于定时任务结果推送及系统通知"""
|
||
|
|
import uuid
|
||
|
|
from datetime import datetime
|
||
|
|
from sqlalchemy import Column, String, Text, DateTime, ForeignKey, Boolean
|
||
|
|
from sqlalchemy.dialects.mysql import CHAR
|
||
|
|
from app.core.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class Notification(Base):
|
||
|
|
"""系统通知 — 定时任务结果、告警、系统消息等"""
|
||
|
|
__tablename__ = "notifications"
|
||
|
|
|
||
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||
|
|
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, index=True, comment="接收用户 ID")
|
||
|
|
title = Column(String(200), nullable=False, comment="通知标题")
|
||
|
|
content = Column(Text, nullable=True, comment="通知正文")
|
||
|
|
category = Column(String(32), default="system", comment="分类: schedule/alert/system")
|
||
|
|
ref_type = Column(String(32), nullable=True, comment="关联对象类型: schedule/execution")
|
||
|
|
ref_id = Column(String(36), nullable=True, comment="关联对象 ID")
|
||
|
|
is_read = Column(Boolean, default=False, comment="是否已读")
|
||
|
|
created_at = Column(DateTime, default=datetime.utcnow, comment="创建时间")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<Notification(id={self.id}, user_id={self.user_id}, title={self.title})>"
|