时间格式,获取沉降数据接口limit
This commit is contained in:
@@ -176,7 +176,7 @@ def get_section(request: SectionDataQueryRequest, db: Session = Depends(get_db))
|
|||||||
# 根据观测点id查询沉降数据
|
# 根据观测点id查询沉降数据
|
||||||
@router.post("/get_settlement", response_model=DataResponse)
|
@router.post("/get_settlement", response_model=DataResponse)
|
||||||
def get_settlement(request: SettlementDataQueryRequest, db: Session = Depends(get_db)):
|
def get_settlement(request: SettlementDataQueryRequest, db: Session = Depends(get_db)):
|
||||||
"""获取沉降数据"""
|
"""获取沉降数据,按上传时间倒序排序,支持limit参数限制返回数量"""
|
||||||
try:
|
try:
|
||||||
logger.info(f"Querying settlement data with params: {request.dict()}")
|
logger.info(f"Querying settlement data with params: {request.dict()}")
|
||||||
|
|
||||||
@@ -187,7 +187,8 @@ def get_settlement(request: SettlementDataQueryRequest, db: Session = Depends(ge
|
|||||||
point_id=request.point_id,
|
point_id=request.point_id,
|
||||||
nyid=request.NYID,
|
nyid=request.NYID,
|
||||||
sjName=request.sjName,
|
sjName=request.sjName,
|
||||||
workinfoname=request.workinfoname
|
workinfoname=request.workinfoname,
|
||||||
|
limit=request.limit
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Found {len(result_data)} settlement records")
|
logger.info(f"Found {len(result_data)} settlement records")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from sqlalchemy import Column, Integer, String
|
from sqlalchemy import Column, Integer, String, DateTime
|
||||||
from ..core.database import Base
|
from ..core.database import Base
|
||||||
|
|
||||||
class LevelData(Base):
|
class LevelData(Base):
|
||||||
@@ -9,4 +9,5 @@ class LevelData(Base):
|
|||||||
benchmarkids = Column(String(100), comment="工作基点名称序列")
|
benchmarkids = Column(String(100), comment="工作基点名称序列")
|
||||||
wsphigh = Column(String(100), comment="工作基点高程序列(m)")
|
wsphigh = Column(String(100), comment="工作基点高程序列(m)")
|
||||||
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
||||||
createDate = Column(String(100), comment="上传时间")
|
createDate = Column(DateTime, comment="上传时间")
|
||||||
|
mtype = Column(String(100), comment="水准观测类型")
|
||||||
@@ -6,10 +6,9 @@ class OriginalData(Base):
|
|||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||||
bfpcode = Column(String(1000), nullable=False, comment="前(后)视点名称")
|
bfpcode = Column(String(1000), nullable=False, comment="前(后)视点名称")
|
||||||
mtime = Column(String(1000), nullable=False, comment="测点观测时间")
|
mtime = Column(DateTime, nullable=False, comment="测点观测时间")
|
||||||
bffb = Column(String(1000), nullable=False, comment="前(后)视标记符")
|
bffb = Column(String(1000), nullable=False, comment="前(后)视标记符")
|
||||||
bfpl = Column(String(1000), nullable=False, comment="前(后)视距离(m)")
|
bfpl = Column(String(1000), nullable=False, comment="前(后)视距离(m)")
|
||||||
bfpvalue = Column(String(1000), nullable=False, comment="前(后)视尺读数(m)")
|
bfpvalue = Column(String(1000), nullable=False, comment="前(后)视尺读数(m)")
|
||||||
times = Column(String(1000), nullable=False, comment="上传时间")
|
|
||||||
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
||||||
sort = Column(Integer, comment="序号")
|
sort = Column(Integer, comment="序号")
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from sqlalchemy import Column, Integer, String
|
from sqlalchemy import Column, Integer, String, DateTime
|
||||||
from ..core.database import Base
|
from ..core.database import Base
|
||||||
|
|
||||||
class SettlementData(Base):
|
class SettlementData(Base):
|
||||||
@@ -8,13 +8,13 @@ class SettlementData(Base):
|
|||||||
point_id = Column(String(100), nullable=False, comment="观测点id", index=True)
|
point_id = Column(String(100), nullable=False, comment="观测点id", index=True)
|
||||||
CVALUE = Column(String(100), nullable=False, comment="修正量(m)")
|
CVALUE = Column(String(100), nullable=False, comment="修正量(m)")
|
||||||
MAVALUE = Column(String(100), nullable=False, comment="成果值(m)")
|
MAVALUE = Column(String(100), nullable=False, comment="成果值(m)")
|
||||||
MTIME_W = Column(String(100), nullable=False, comment="观测时间")
|
MTIME_W = Column(DateTime, nullable=False, comment="观测时间")
|
||||||
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
NYID = Column(String(100), nullable=False, comment="期数id", index=True)
|
||||||
PRELOADH = Column(String(100), nullable=False)
|
PRELOADH = Column(String(100), nullable=False)
|
||||||
PSTATE = Column(String(100), nullable=False)
|
PSTATE = Column(String(100), nullable=False)
|
||||||
REMARK = Column(String(100), comment="备注")
|
REMARK = Column(String(100), comment="备注")
|
||||||
WORKINFO = Column(String(100))
|
WORKINFO = Column(String(100))
|
||||||
createdate = Column(String(100), nullable=False, comment="上传时间")
|
createdate = Column(DateTime, nullable=False, comment="上传时间", index=True)
|
||||||
day = Column(String(100), nullable=False, comment="累计天数")
|
day = Column(String(100), nullable=False, comment="累计天数")
|
||||||
day_jg = Column(String(100), nullable=False, comment="两次观测时")
|
day_jg = Column(String(100), nullable=False, comment="两次观测时")
|
||||||
isgzjdxz = Column(String(100))
|
isgzjdxz = Column(String(100))
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class SettlementDataQueryRequest(BaseModel):
|
|||||||
workinfoname: Optional[str] = None
|
workinfoname: Optional[str] = None
|
||||||
isgzjdxz: Optional[str] = None
|
isgzjdxz: Optional[str] = None
|
||||||
upd_remark: Optional[str] = None
|
upd_remark: Optional[str] = None
|
||||||
|
limit: Optional[int] = None # 限制返回数量,None表示返回全部
|
||||||
|
|
||||||
# 断面数据导入请求
|
# 断面数据导入请求
|
||||||
class SectionDataQueryRequest(BaseModel):
|
class SectionDataQueryRequest(BaseModel):
|
||||||
|
|||||||
@@ -28,30 +28,40 @@ class SettlementDataService(BaseService[SettlementData]):
|
|||||||
point_id: Optional[str] = None,
|
point_id: Optional[str] = None,
|
||||||
nyid: Optional[str] = None,
|
nyid: Optional[str] = None,
|
||||||
sjName: Optional[str] = None,
|
sjName: Optional[str] = None,
|
||||||
workinfoname: Optional[str] = None) -> List[SettlementData]:
|
workinfoname: Optional[str] = None,
|
||||||
"""根据多个条件搜索沉降数据"""
|
limit: Optional[int] = None) -> List[SettlementData]:
|
||||||
conditions = {}
|
"""根据多个条件搜索沉降数据,按上传时间倒序排序"""
|
||||||
if id is not None:
|
query = db.query(SettlementData)
|
||||||
conditions["id"] = id
|
|
||||||
if point_id is not None:
|
|
||||||
conditions["point_id"] = point_id
|
|
||||||
if nyid is not None:
|
|
||||||
conditions["NYID"] = nyid
|
|
||||||
if sjName is not None:
|
|
||||||
conditions["sjName"] = sjName
|
|
||||||
if workinfoname is not None:
|
|
||||||
conditions["workinfoname"] = workinfoname
|
|
||||||
|
|
||||||
return self.search_by_conditions(db, conditions)
|
if id is not None:
|
||||||
|
query = query.filter(SettlementData.id == id)
|
||||||
|
if point_id is not None:
|
||||||
|
query = query.filter(SettlementData.point_id == point_id)
|
||||||
|
if nyid is not None:
|
||||||
|
query = query.filter(SettlementData.NYID == nyid)
|
||||||
|
if sjName is not None:
|
||||||
|
query = query.filter(SettlementData.sjName == sjName)
|
||||||
|
if workinfoname is not None:
|
||||||
|
query = query.filter(SettlementData.workinfoname == workinfoname)
|
||||||
|
|
||||||
|
# 按上传时间倒序排序
|
||||||
|
query = query.order_by(SettlementData.createdate.desc())
|
||||||
|
|
||||||
|
# 如果指定了limit,则限制返回数量
|
||||||
|
if limit is not None and limit > 0:
|
||||||
|
query = query.limit(limit)
|
||||||
|
|
||||||
|
return query.all()
|
||||||
|
|
||||||
def search_settlement_data_formatted(self, db: Session,
|
def search_settlement_data_formatted(self, db: Session,
|
||||||
id: Optional[int] = None,
|
id: Optional[int] = None,
|
||||||
point_id: Optional[str] = None,
|
point_id: Optional[str] = None,
|
||||||
nyid: Optional[str] = None,
|
nyid: Optional[str] = None,
|
||||||
sjName: Optional[str] = None,
|
sjName: Optional[str] = None,
|
||||||
workinfoname: Optional[str] = None) -> List[Dict[str, Any]]:
|
workinfoname: Optional[str] = None,
|
||||||
"""查询沉降数据并返回格式化结果"""
|
limit: Optional[int] = None) -> List[Dict[str, Any]]:
|
||||||
settlement_data = self.search_settlement_data(db, id, point_id, nyid, sjName, workinfoname)
|
"""查询沉降数据并返回格式化结果,按上传时间倒序排序"""
|
||||||
|
settlement_data = self.search_settlement_data(db, id, point_id, nyid, sjName, workinfoname, limit)
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for settlement in settlement_data:
|
for settlement in settlement_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user