原始数据分表处理
This commit is contained in:
@@ -2,13 +2,63 @@ from sqlalchemy import Column, Integer, String, DateTime
|
||||
from ..core.database import Base
|
||||
|
||||
class OriginalData(Base):
|
||||
"""原始数据模型基类 - 仅用作模板,实际使用动态生成的分表模型"""
|
||||
__tablename__ = "original_data"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||
account_id = Column(Integer, nullable=False, comment="账号ID", index=True)
|
||||
bfpcode = Column(String(1000), nullable=False, comment="前(后)视点名称")
|
||||
mtime = Column(DateTime, nullable=False, comment="测点观测时间")
|
||||
bffb = Column(String(1000), nullable=False, comment="前(后)视标记符")
|
||||
bfpl = Column(String(1000), nullable=False, comment="前(后)视距离(m)")
|
||||
bfpvalue = Column(String(1000), nullable=False, comment="前(后)视尺读数(m)")
|
||||
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
||||
sort = Column(Integer, comment="序号")
|
||||
sort = Column(Integer, comment="序号")
|
||||
|
||||
|
||||
def get_original_data_model(account_id: int):
|
||||
"""
|
||||
根据账号ID动态生成原始数据表模型
|
||||
|
||||
Args:
|
||||
account_id: 账号ID
|
||||
|
||||
Returns:
|
||||
动态生成的原始数据表模型类
|
||||
"""
|
||||
class_name = f"OriginalData_{account_id}"
|
||||
table_name = f"original_data_{account_id}"
|
||||
|
||||
# 动态创建模型类
|
||||
DynamicModel = type(
|
||||
class_name,
|
||||
(Base,),
|
||||
{
|
||||
'__tablename__': table_name,
|
||||
'__table_args__': {'extend_existing': True},
|
||||
'id': Column(Integer, primary_key=True, index=True, autoincrement=True),
|
||||
'account_id': Column(Integer, nullable=False, comment="账号ID", index=True),
|
||||
'bfpcode': Column(String(1000), nullable=False, comment="前(后)视点名称"),
|
||||
'mtime': Column(DateTime, nullable=False, comment="测点观测时间"),
|
||||
'bffb': Column(String(1000), nullable=False, comment="前(后)视标记符"),
|
||||
'bfpl': Column(String(1000), nullable=False, comment="前(后)视距离(m)"),
|
||||
'bfpvalue': Column(String(1000), nullable=False, comment="前(后)视尺读数(m)"),
|
||||
'NYID': Column(String(100), nullable=False, comment="期数id", index=True),
|
||||
'sort': Column(Integer, comment="序号")
|
||||
}
|
||||
)
|
||||
|
||||
return DynamicModel
|
||||
|
||||
|
||||
def get_table_name(account_id: int) -> str:
|
||||
"""
|
||||
根据账号ID获取原始数据表名
|
||||
|
||||
Args:
|
||||
account_id: 账号ID
|
||||
|
||||
Returns:
|
||||
表名
|
||||
"""
|
||||
return f"original_data_{account_id}"
|
||||
Reference in New Issue
Block a user