demand_video_expansion.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from sqlalchemy import BigInteger, Index, Integer, String, Text, UniqueConstraint, func
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from supply_infra.db.base import Base
  6. class DemandVideoExpansion(Base):
  7. """S/A 需求关联视频点位拓展结果。"""
  8. __tablename__ = "demand_video_expansion"
  9. __table_args__ = (
  10. UniqueConstraint(
  11. "biz_dt",
  12. "source_demand_grade_id",
  13. "expanded_text",
  14. "video_id",
  15. name="uk_demand_video_expansion",
  16. ),
  17. Index("idx_dve_biz_dt", "biz_dt"),
  18. Index("idx_dve_source_grade", "source_demand_grade_id"),
  19. )
  20. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  21. biz_dt: Mapped[str] = mapped_column(String(32), nullable=False, comment="业务日 YYYYMMDD")
  22. run_id: Mapped[str] = mapped_column(String(64), nullable=False, comment="任务批次 run_id")
  23. source_demand_grade_id: Mapped[int] = mapped_column(
  24. BigInteger, nullable=False, comment="来源 demand_grade.id"
  25. )
  26. source_demand_name: Mapped[str] = mapped_column(
  27. String(256), nullable=False, comment="来源需求名"
  28. )
  29. source_grade: Mapped[str] = mapped_column(String(4), nullable=False, comment="来源等级 S/A")
  30. expanded_text: Mapped[str] = mapped_column(
  31. String(512), nullable=False, comment="拓展需求文本(来自 point_data)"
  32. )
  33. point_type: Mapped[str] = mapped_column(
  34. String(32), nullable=False, comment="点类型:inspiration / purpose / key"
  35. )
  36. point_desc: Mapped[str | None] = mapped_column(Text, nullable=True, comment="点位描述快照")
  37. video_id: Mapped[str] = mapped_column(String(64), nullable=False, comment="来源视频 id")
  38. reason: Mapped[str] = mapped_column(Text, nullable=False, comment="相近判断依据")
  39. is_delete: Mapped[int] = mapped_column(
  40. Integer, default=0, nullable=False, comment="是否删除 0-正常 1-删除"
  41. )
  42. create_time: Mapped[datetime] = mapped_column(
  43. nullable=False,
  44. server_default=func.now(),
  45. comment="创建时间",
  46. )
  47. update_time: Mapped[datetime] = mapped_column(
  48. nullable=False,
  49. server_default=func.now(),
  50. onupdate=func.now(),
  51. comment="更新时间",
  52. )
  53. class DemandVideoExpansionRun(Base):
  54. """记录每个需求是否已完成拓展判断(含零结果),用于幂等跳过。"""
  55. __tablename__ = "demand_video_expansion_run"
  56. __table_args__ = (
  57. UniqueConstraint(
  58. "biz_dt",
  59. "source_demand_grade_id",
  60. name="uk_demand_video_expansion_run",
  61. ),
  62. Index("idx_dver_biz_dt", "biz_dt"),
  63. )
  64. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  65. biz_dt: Mapped[str] = mapped_column(String(32), nullable=False, comment="业务日 YYYYMMDD")
  66. run_id: Mapped[str] = mapped_column(String(64), nullable=False, comment="任务批次 run_id")
  67. source_demand_grade_id: Mapped[int] = mapped_column(
  68. BigInteger, nullable=False, comment="来源 demand_grade.id"
  69. )
  70. saved_count: Mapped[int] = mapped_column(
  71. Integer, nullable=False, default=0, comment="落库拓展条数"
  72. )
  73. status: Mapped[str] = mapped_column(
  74. String(16), nullable=False, default="finished", comment="finished / failed"
  75. )
  76. error_message: Mapped[str | None] = mapped_column(
  77. Text, nullable=True, comment="失败原因"
  78. )
  79. create_time: Mapped[datetime] = mapped_column(
  80. nullable=False,
  81. server_default=func.now(),
  82. comment="创建时间",
  83. )
  84. update_time: Mapped[datetime] = mapped_column(
  85. nullable=False,
  86. server_default=func.now(),
  87. onupdate=func.now(),
  88. comment="更新时间",
  89. )