80 lines
3.4 KiB
Python
80 lines
3.4 KiB
Python
"""统一反馈中心模型。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, Optional
|
||
|
||
from sqlalchemy import BigInteger, Boolean, Float, ForeignKey, Integer, Text, TIMESTAMP, UniqueConstraint, VARCHAR
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from .base import Base
|
||
from .types import JSONB
|
||
|
||
|
||
class FeedbackCenterRecord(Base):
|
||
"""统一反馈记录:承载任务、QA、信号三类学习样本。"""
|
||
|
||
__tablename__ = "feedback_center_records"
|
||
|
||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||
project_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
||
source_type: Mapped[str] = mapped_column(VARCHAR(32), nullable=False, index=True)
|
||
source_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True)
|
||
object_type: Mapped[str] = mapped_column(VARCHAR(32), nullable=False, index=True)
|
||
object_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True)
|
||
field_name: Mapped[str] = mapped_column(VARCHAR(128), nullable=False, index=True)
|
||
source_title: Mapped[Optional[str]] = mapped_column(VARCHAR(500), nullable=True)
|
||
object_title: Mapped[Optional[str]] = mapped_column(VARCHAR(500), nullable=True)
|
||
before_value: Mapped[Any] = mapped_column(JSONB, nullable=True)
|
||
after_value: Mapped[Any] = mapped_column(JSONB, nullable=True)
|
||
ai_snapshot: Mapped[Any] = mapped_column(JSONB, nullable=True)
|
||
ai_confidence: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
||
reason_candidates: Mapped[Any] = mapped_column(JSONB, nullable=True)
|
||
reason_code: Mapped[Optional[str]] = mapped_column(VARCHAR(64), nullable=True, index=True)
|
||
reason_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||
review_status: Mapped[str] = mapped_column(VARCHAR(16), nullable=False, default="pending", index=True)
|
||
reviewed_by: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
||
reviewed_at: Mapped[Optional[TIMESTAMP]] = mapped_column(TIMESTAMP, nullable=True)
|
||
auto_assigned: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||
|
||
__table_args__ = (
|
||
UniqueConstraint(
|
||
"tenant_id",
|
||
"source_type",
|
||
"source_id",
|
||
"object_type",
|
||
"object_id",
|
||
"field_name",
|
||
name="uq_feedback_center_records_source_object_field",
|
||
),
|
||
)
|
||
|
||
revisions = relationship(
|
||
"FeedbackCenterRecordRevision",
|
||
back_populates="record",
|
||
cascade="all, delete-orphan",
|
||
)
|
||
|
||
|
||
class FeedbackCenterRecordRevision(Base):
|
||
"""统一反馈记录的修订历史。"""
|
||
|
||
__tablename__ = "feedback_center_record_revisions"
|
||
|
||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||
record_id: Mapped[int] = mapped_column(
|
||
Integer,
|
||
ForeignKey("feedback_center_records.id", ondelete="CASCADE"),
|
||
nullable=False,
|
||
index=True,
|
||
)
|
||
before_snapshot: Mapped[Any] = mapped_column(JSONB, nullable=False)
|
||
after_snapshot: Mapped[Any] = mapped_column(JSONB, nullable=False)
|
||
reviewed_by: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
||
reviewed_at: Mapped[Optional[TIMESTAMP]] = mapped_column(TIMESTAMP, nullable=True)
|
||
|
||
record = relationship("FeedbackCenterRecord", back_populates="revisions")
|
||
|
||
|
||
__all__ = ["FeedbackCenterRecord", "FeedbackCenterRecordRevision"]
|