41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""
|
|
分析模块数据模型
|
|
"""
|
|
|
|
from sqlalchemy import Column, String, Integer, DateTime, Text, ForeignKey, Index
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
from sqlalchemy.orm import relationship
|
|
import uuid
|
|
|
|
from ..core.database import Base
|
|
|
|
|
|
class AnalysisModule(Base):
|
|
"""分析模块表模型"""
|
|
|
|
__tablename__ = "analysis_modules"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
report_id = Column(UUID(as_uuid=True), ForeignKey("reports.id", ondelete="CASCADE"), nullable=False)
|
|
module_type = Column(String(50), nullable=False, comment="模块类型")
|
|
module_order = Column(Integer, nullable=False, comment="模块顺序")
|
|
title = Column(String(200), nullable=False, comment="模块标题")
|
|
content = Column(JSONB, comment="模块内容")
|
|
status = Column(String(20), nullable=False, default="pending", comment="模块状态")
|
|
started_at = Column(DateTime(timezone=True), comment="开始时间")
|
|
completed_at = Column(DateTime(timezone=True), comment="完成时间")
|
|
error_message = Column(Text, comment="错误信息")
|
|
|
|
# 关系
|
|
report = relationship("Report", back_populates="analysis_modules")
|
|
|
|
# 索引
|
|
__table_args__ = (
|
|
Index('idx_analysis_module_report_id', 'report_id'),
|
|
Index('idx_analysis_module_type', 'module_type'),
|
|
Index('idx_analysis_module_status', 'status'),
|
|
Index('idx_analysis_module_order', 'module_order'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<AnalysisModule(id={self.id}, type={self.module_type}, status={self.status})>" |