db_models.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. """地磅(db)模块数据模型 — 对齐 docs/sql/db_tables.sql"""
  2. from datetime import datetime
  3. from sqlalchemy import Column, Date, DateTime, Float, Integer, SmallInteger, String, Text
  4. from app.core.database import Base
  5. class DbPurchasePlan(Base):
  6. __tablename__ = "db_purchase_plan"
  7. id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
  8. plan_no = Column(String(255), nullable=True, comment="计划号")
  9. plan_date = Column(Date, nullable=False, comment="计划日期")
  10. start_date = Column(Date, nullable=True, comment="开始时间")
  11. end_date = Column(Date, nullable=True, comment="结束时间")
  12. business_type = Column(String(255), nullable=False, comment="业务类型")
  13. product_id = Column(String(64), nullable=True, comment="CRM产品ID")
  14. product = Column(String(255), nullable=False, comment="产品名称")
  15. specification = Column(String(255), nullable=True, comment="规格")
  16. planned_quantity = Column(Float, nullable=False, comment="计划数量(t)")
  17. vehicle_no = Column(String(255), nullable=True, default="", comment="车牌号")
  18. customer_name = Column(String(255), nullable=True, comment="往来单位")
  19. execution_status = Column(String(50), nullable=True, comment="执行状态")
  20. executed_at = Column(DateTime, nullable=True, comment="执行时间")
  21. last_weighing_slip_id = Column(String(64), nullable=True, comment="最后关联地磅单ID")
  22. executed_quantity = Column(Float, nullable=True, default=0, comment="已执行量(kg)")
  23. auto_generate_enabled = Column(SmallInteger, nullable=False, default=0, comment="是否自动按月生成")
  24. auto_generate_end_month = Column(String(7), nullable=True, comment="自动生成结束月份")
  25. auto_generate_last_month = Column(String(7), nullable=True, comment="最后一次自动生成月份")
  26. tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
  27. order_num = Column(Integer, nullable=True, comment="排序号")
  28. remark = Column(String(512), nullable=True, comment="备注")
  29. create_by = Column(String(64), nullable=True, comment="创建人")
  30. create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
  31. create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
  32. update_by = Column(String(64), nullable=True, comment="更新人")
  33. update_time = Column(
  34. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  35. )
  36. del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
  37. class DbInboundOutbound(Base):
  38. __tablename__ = "db_inbound_outbound"
  39. id = Column(String(64), primary_key=True, comment="主键ID(租户内纯数字字符串)")
  40. date = Column(Date, nullable=False, comment="日期")
  41. partner_company = Column(String(255), nullable=False, comment="往来单位")
  42. business_type = Column(String(255), nullable=False, comment="业务类型")
  43. product_id = Column(String(64), nullable=True, comment="CRM产品ID")
  44. product = Column(String(255), nullable=False, comment="产品")
  45. specification = Column(String(255), nullable=True, comment="规格")
  46. quantity = Column(Float, nullable=False, comment="本次量(t)")
  47. plan_no = Column(String(255), nullable=True, comment="计划号")
  48. batch_no = Column(String(255), nullable=True, comment="批次号")
  49. vehicle_no = Column(String(255), nullable=False, comment="车牌号")
  50. status = Column(String(50), nullable=True, comment="状态")
  51. purchase_plan_id = Column(String(64), nullable=True, comment="关联计划ID")
  52. tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
  53. order_num = Column(Integer, nullable=True, comment="排序号")
  54. remark = Column(String(512), nullable=True, comment="备注")
  55. site_access_token = Column(String(64), nullable=True, comment="现场人员免登录访问令牌")
  56. site_feedback_remark = Column(String(500), nullable=True, comment="现场回执备注")
  57. site_feedback_images = Column(Text, nullable=True, comment="现场回执附件URLs(JSON数组)")
  58. site_feedback_time = Column(DateTime, nullable=True, comment="现场回执保存时间")
  59. create_by = Column(String(64), nullable=True, comment="创建人")
  60. create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
  61. create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
  62. update_by = Column(String(64), nullable=True, comment="更新人")
  63. update_time = Column(
  64. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  65. )
  66. del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
  67. class DbWeighingSlip(Base):
  68. __tablename__ = "db_weighing_slip"
  69. id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
  70. vehicle_no = Column(String(255), nullable=False, comment="车号")
  71. plan_no = Column(String(255), nullable=True, comment="计划单号")
  72. product_id = Column(String(64), nullable=True, comment="CRM产品ID")
  73. cargo_name = Column(String(255), nullable=False, comment="货物名称")
  74. specification = Column(String(255), nullable=True, comment="规格")
  75. business_type = Column(String(255), nullable=False, comment="业务类型")
  76. batch_no = Column(String(255), nullable=True, comment="批次号")
  77. supplier = Column(String(255), nullable=False, comment="供货单位")
  78. consignee = Column(String(255), nullable=False, comment="收货单位")
  79. gross_weight = Column(Float, nullable=False, comment="毛重(kg)")
  80. gross_weight_time = Column(DateTime, nullable=False, comment="毛重时间")
  81. tare_weight = Column(Float, nullable=False, comment="皮重(kg)")
  82. tare_weight_time = Column(DateTime, nullable=True, comment="皮重时间")
  83. deduction = Column(Float, nullable=True, default=0, comment="扣杂(kg)")
  84. net_weight = Column(Float, nullable=False, comment="净重(kg)")
  85. planned_quantity = Column(Float, nullable=True, comment="计划数量(kg)")
  86. executed_quantity = Column(Float, nullable=True, comment="执行数量(kg)")
  87. purchase_plan_id = Column(String(64), nullable=True, comment="关联计划ID")
  88. inbound_outbound_id = Column(String(64), nullable=True, comment="关联出入库单ID")
  89. weighing_point = Column(String(255), nullable=True, default="山峡地磅", comment="称重点")
  90. current_quantity = Column(Float, nullable=True, comment="本次量(kg)")
  91. is_voided = Column(SmallInteger, nullable=False, default=0, comment="是否作废")
  92. void_reason = Column(String(500), nullable=True, comment="作废原因")
  93. void_time = Column(DateTime, nullable=True, comment="作废时间")
  94. void_by = Column(String(64), nullable=True, comment="作废人ID")
  95. tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
  96. order_num = Column(Integer, nullable=True, comment="排序号")
  97. remark = Column(String(512), nullable=True, comment="备注")
  98. create_by = Column(String(64), nullable=True, comment="创建人")
  99. create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
  100. create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
  101. update_by = Column(String(64), nullable=True, comment="更新人")
  102. update_time = Column(
  103. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  104. )
  105. del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
  106. class DbSequence(Base):
  107. """租户内业务序号(并发安全自增)。"""
  108. __tablename__ = "db_sequence"
  109. id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
  110. tenant_no = Column(String(64), nullable=False, comment="租户编号")
  111. seq_name = Column(String(64), nullable=False, comment="序号名称")
  112. next_val = Column(Integer, nullable=False, comment="下一个待分配序号")
  113. update_time = Column(
  114. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  115. )