demand_feedback.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from sqlalchemy import BigInteger, DateTime, Index, Integer, String, Text, UniqueConstraint, func
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from supply_infra.db.base import Base
  6. class DemandFeedback(Base):
  7. """需求汇总页面的人工反馈记录。"""
  8. __tablename__ = "demand_feedback"
  9. __table_args__ = (
  10. UniqueConstraint(
  11. "client_request_id",
  12. name="uk_demand_feedback_request",
  13. ),
  14. Index(
  15. "idx_demand_feedback_demand",
  16. "demand_grade_id",
  17. "created_at",
  18. ),
  19. Index(
  20. "idx_demand_feedback_video",
  21. "demand_grade_id",
  22. "video_id",
  23. "created_at",
  24. ),
  25. Index(
  26. "idx_demand_feedback_expansion",
  27. "demand_video_expansion_id",
  28. "created_at",
  29. ),
  30. Index(
  31. "idx_demand_feedback_user",
  32. "feedback_user_id",
  33. "created_at",
  34. ),
  35. )
  36. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  37. client_request_id: Mapped[str] = mapped_column(String(64), nullable=False)
  38. target_type: Mapped[str] = mapped_column(
  39. String(32),
  40. nullable=False,
  41. comment="反馈对象:demand / video / hit_content",
  42. )
  43. biz_dt: Mapped[str] = mapped_column(
  44. String(32),
  45. nullable=False,
  46. comment="目标所属业务日",
  47. )
  48. demand_grade_id: Mapped[int] = mapped_column(
  49. BigInteger,
  50. nullable=False,
  51. comment="目标 demand_grade.id",
  52. )
  53. video_id: Mapped[str | None] = mapped_column(
  54. String(64),
  55. nullable=True,
  56. comment="视频反馈或命中内容反馈的视频 id",
  57. )
  58. demand_video_expansion_id: Mapped[int | None] = mapped_column(
  59. BigInteger,
  60. nullable=True,
  61. comment="命中内容 demand_video_expansion.id",
  62. )
  63. feedback_action: Mapped[str] = mapped_column(
  64. String(32),
  65. nullable=False,
  66. comment="support / oppose / correct / supplement",
  67. )
  68. reason_code: Mapped[str | None] = mapped_column(String(64), nullable=True)
  69. content: Mapped[str | None] = mapped_column(Text, nullable=True)
  70. target_snapshot_json: Mapped[str] = mapped_column(
  71. Text,
  72. nullable=False,
  73. comment="提交时由服务端生成的目标快照",
  74. )
  75. feedback_user_id: Mapped[int] = mapped_column(
  76. Integer,
  77. nullable=False,
  78. comment="反馈人 auth_user.id",
  79. )
  80. feedback_user_name_snapshot: Mapped[str] = mapped_column(
  81. String(128),
  82. nullable=False,
  83. comment="反馈人名称快照",
  84. )
  85. feedback_username_snapshot: Mapped[str] = mapped_column(
  86. String(64),
  87. nullable=False,
  88. comment="反馈人登录账号快照",
  89. )
  90. created_at: Mapped[datetime] = mapped_column(
  91. DateTime,
  92. nullable=False,
  93. server_default=func.now(),
  94. )
  95. updated_at: Mapped[datetime] = mapped_column(
  96. DateTime,
  97. nullable=False,
  98. server_default=func.now(),
  99. onupdate=func.now(),
  100. )