1d11bf9fc3
- 后端:创建system_messages表模型和Schema - 后端:实现消息创建、查询、标记已读的服务层 - 后端:新增REST API接口(需admin.system_message权限) - 前端:完善系统消息抽屉弹窗,显示消息列表 - 前端:自动加载未读数量,支持标记已读 - 数据库:新增迁移脚本建表 Co-authored-by: multica-agent <github@multica.ai>
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
from uuid import uuid4
|
|
|
|
from sqlalchemy import Boolean, DateTime, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from ..core.database import Base
|
|
from .base import utcnow
|
|
|
|
if TYPE_CHECKING:
|
|
from .user import User
|
|
|
|
|
|
class SystemMessage(Base):
|
|
__tablename__ = "system_messages"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
"message_id",
|
|
String(36),
|
|
primary_key=True,
|
|
default=lambda: uuid4().hex,
|
|
)
|
|
title: Mapped[str] = mapped_column(String(255))
|
|
content: Mapped[str] = mapped_column(Text)
|
|
message_type: Mapped[str] = mapped_column(
|
|
String(32),
|
|
default="info",
|
|
index=True,
|
|
)
|
|
target_user_id: Mapped[str | None] = mapped_column(
|
|
String(36),
|
|
index=True,
|
|
nullable=True,
|
|
)
|
|
is_read: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
"created_at",
|
|
DateTime(timezone=False),
|
|
default=utcnow,
|
|
index=True,
|
|
)
|
|
read_at: Mapped[datetime | None] = mapped_column(
|
|
"read_at",
|
|
DateTime(timezone=False),
|
|
nullable=True,
|
|
)
|