Files
zcglxt/app/models/notification.py
Claude e71181f0a3 fix: 修复多个关键问题
- 修复前端路由守卫:未登录时不显示提示,直接跳转登录页
- 修复API拦截器:401错误不显示提示,直接跳转
- 增强验证码显示:图片尺寸从120x40增加到200x80
- 增大验证码字体:从28号增加到48号
- 优化验证码字符:排除易混淆的0和1
- 减少干扰线:从5条减少到3条,添加背景色优化
- 增强登录API日志:添加详细的调试日志
- 增强验证码生成和验证日志
- 优化异常处理和错误追踪

影响文件:
- src/router/index.ts
- src/api/request.ts
- app/services/auth_service.py
- app/api/v1/auth.py
- app/schemas/user.py

测试状态:
- 前端构建通过
- 后端语法检查通过
- 验证码显示效果优化完成

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 00:26:21 +08:00

72 lines
3.8 KiB
Python

"""
消息通知数据模型
"""
from datetime import datetime
from sqlalchemy import Column, BigInteger, String, Text, Integer, DateTime, Boolean, Index, ForeignKey
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import relationship
from app.db.base import Base
class Notification(Base):
"""消息通知表"""
__tablename__ = "notifications"
id = Column(BigInteger, primary_key=True, index=True)
recipient_id = Column(BigInteger, ForeignKey("users.id"), nullable=False, index=True, comment="接收人ID")
recipient_name = Column(String(100), nullable=False, comment="接收人姓名(冗余)")
title = Column(String(200), nullable=False, comment="通知标题")
content = Column(Text, nullable=False, comment="通知内容")
notification_type = Column(String(20), nullable=False, index=True, comment="通知类型: system/approval/maintenance/allocation等")
priority = Column(String(20), default="normal", nullable=False, comment="优先级: low/normal/high/urgent")
is_read = Column(Boolean, default=False, nullable=False, index=True, comment="是否已读")
read_at = Column(DateTime, nullable=True, comment="已读时间")
related_entity_type = Column(String(50), nullable=True, comment="关联实体类型")
related_entity_id = Column(BigInteger, nullable=True, comment="关联实体ID")
action_url = Column(String(500), nullable=True, comment="操作链接")
extra_data = Column(JSONB, nullable=True, comment="额外数据")
sent_via_email = Column(Boolean, default=False, nullable=False, comment="是否已发送邮件")
sent_via_sms = Column(Boolean, default=False, nullable=False, comment="是否已发送短信")
created_at = Column(DateTime, default=datetime.utcnow, nullable=False, index=True, comment="创建时间")
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False, comment="更新时间")
expire_at = Column(DateTime, nullable=True, comment="过期时间")
# 关系
recipient = relationship("User", foreign_keys=[recipient_id])
# 索引
__table_args__ = (
Index("idx_notification_recipient", "recipient_id"),
Index("idx_notification_read", "is_read"),
Index("idx_notification_type", "notification_type"),
Index("idx_notification_time", "created_at"),
)
def __repr__(self):
return f"<Notification(id={self.id}, recipient={self.recipient_name}, title={self.title})>"
class NotificationTemplate(Base):
"""消息通知模板表"""
__tablename__ = "notification_templates"
id = Column(BigInteger, primary_key=True, index=True)
template_code = Column(String(50), unique=True, nullable=False, comment="模板编码")
template_name = Column(String(200), nullable=False, comment="模板名称")
notification_type = Column(String(20), nullable=False, comment="通知类型")
title_template = Column(String(200), nullable=False, comment="标题模板")
content_template = Column(Text, nullable=False, comment="内容模板")
variables = Column(JSONB, nullable=True, comment="变量说明")
priority = Column(String(20), default="normal", nullable=False, comment="默认优先级")
send_email = Column(Boolean, default=False, nullable=False, comment="是否发送邮件")
send_sms = Column(Boolean, default=False, nullable=False, comment="是否发送短信")
is_active = Column(Boolean, default=True, nullable=False, comment="是否启用")
description = Column(Text, nullable=True, comment="模板描述")
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
def __repr__(self):
return f"<NotificationTemplate(id={self.id}, code={self.template_code}, name={self.template_name})>"