generated_demand.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from decimal import Decimal
  4. from sqlalchemy import BigInteger, Index, Integer, Numeric, String, Text, func
  5. from sqlalchemy.orm import Mapped, mapped_column
  6. from supply_infra.db.base import Base
  7. class GeneratedDemand(Base):
  8. """单维度需求产生结果。"""
  9. __tablename__ = "generated_demand"
  10. __table_args__ = (
  11. Index("idx_generated_demand_dim_biz", "source_dim", "biz_dt"),
  12. Index("idx_generated_demand_name", "demand_name"),
  13. Index("idx_generated_demand_run", "run_id"),
  14. )
  15. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  16. source_dim: Mapped[str] = mapped_column(String(32), nullable=False, comment="来源热度维度")
  17. overall_direction: Mapped[str] = mapped_column(
  18. String(256), nullable=False, comment="整体方向"
  19. )
  20. summary_event: Mapped[str] = mapped_column(String(512), nullable=False, comment="汇总事件")
  21. demand_name: Mapped[str] = mapped_column(
  22. String(256), nullable=False, comment="需求名称(来自 demand_belong_category.name)"
  23. )
  24. demand_belong_id: Mapped[int | None] = mapped_column(
  25. BigInteger, nullable=True, comment="demand_belong_category.id"
  26. )
  27. category_id: Mapped[int | None] = mapped_column(
  28. BigInteger, nullable=True, comment="选用时的类目 id"
  29. )
  30. category_path: Mapped[str | None] = mapped_column(
  31. String(1024), nullable=True, comment="类目路径文本"
  32. )
  33. dim_avg: Mapped[Decimal | None] = mapped_column(
  34. Numeric(16, 8), nullable=True, comment="落库时该维 avg 快照"
  35. )
  36. dim_count: Mapped[int | None] = mapped_column(
  37. Integer, nullable=True, comment="落库时该维 count 快照"
  38. )
  39. reason: Mapped[str | None] = mapped_column(Text, nullable=True, comment="选用理由")
  40. biz_dt: Mapped[str | None] = mapped_column(
  41. String(32), nullable=True, comment="对齐热度统计日 YYYYMMDD"
  42. )
  43. run_id: Mapped[str] = mapped_column(String(64), nullable=False, comment="同一次生成批次")
  44. is_delete: Mapped[int] = mapped_column(
  45. Integer, default=0, nullable=False, comment="是否删除 0-正常 1-删除"
  46. )
  47. create_time: Mapped[datetime] = mapped_column(
  48. nullable=False,
  49. server_default=func.now(),
  50. comment="创建时间",
  51. )
  52. update_time: Mapped[datetime] = mapped_column(
  53. nullable=False,
  54. server_default=func.now(),
  55. onupdate=func.now(),
  56. comment="更新时间",
  57. )