From ef0d92f86f58dd3d5869a5a3a26abc3819b9d194 Mon Sep 17 00:00:00 2001 From: lhx Date: Tue, 14 Oct 2025 09:14:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=B2=89=E9=99=8D=E6=95=B0=E6=8D=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/comprehensive_data.py | 5 ++-- app/models/level_data.py | 5 ++-- app/models/original_data.py | 3 +-- app/models/settlement_data.py | 6 ++--- app/schemas/comprehensive_data.py | 1 + app/services/settlement_data.py | 44 +++++++++++++++++++------------ 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/api/comprehensive_data.py b/app/api/comprehensive_data.py index a37d596..fdb56e4 100644 --- a/app/api/comprehensive_data.py +++ b/app/api/comprehensive_data.py @@ -176,7 +176,7 @@ def get_section(request: SectionDataQueryRequest, db: Session = Depends(get_db)) # 根据观测点id查询沉降数据 @router.post("/get_settlement", response_model=DataResponse) def get_settlement(request: SettlementDataQueryRequest, db: Session = Depends(get_db)): - """获取沉降数据""" + """获取沉降数据,按上传时间倒序排序,支持limit参数限制返回数量""" try: 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, nyid=request.NYID, sjName=request.sjName, - workinfoname=request.workinfoname + workinfoname=request.workinfoname, + limit=request.limit ) logger.info(f"Found {len(result_data)} settlement records") diff --git a/app/models/level_data.py b/app/models/level_data.py index 64c0c01..fe7b567 100644 --- a/app/models/level_data.py +++ b/app/models/level_data.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, String +from sqlalchemy import Column, Integer, String, DateTime from ..core.database import Base class LevelData(Base): @@ -9,4 +9,5 @@ class LevelData(Base): benchmarkids = Column(String(100), comment="工作基点名称序列") wsphigh = Column(String(100), comment="工作基点高程序列(m)") NYID = Column(String(100), nullable=False, comment="期数id", index=True) - createDate = Column(String(100), comment="上传时间") \ No newline at end of file + createDate = Column(DateTime, comment="上传时间") + mtype = Column(String(100), comment="水准观测类型") \ No newline at end of file diff --git a/app/models/original_data.py b/app/models/original_data.py index 5ef7647..809c70c 100644 --- a/app/models/original_data.py +++ b/app/models/original_data.py @@ -6,10 +6,9 @@ class OriginalData(Base): id = Column(Integer, primary_key=True, index=True, autoincrement=True) 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="前(后)视标记符") bfpl = 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) sort = Column(Integer, comment="序号") \ No newline at end of file diff --git a/app/models/settlement_data.py b/app/models/settlement_data.py index 02c0d86..0be83d3 100644 --- a/app/models/settlement_data.py +++ b/app/models/settlement_data.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, String +from sqlalchemy import Column, Integer, String, DateTime from ..core.database import Base class SettlementData(Base): @@ -8,13 +8,13 @@ class SettlementData(Base): point_id = Column(String(100), nullable=False, comment="观测点id", index=True) CVALUE = 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) PRELOADH = Column(String(100), nullable=False) PSTATE = Column(String(100), nullable=False) REMARK = Column(String(100), comment="备注") 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_jg = Column(String(100), nullable=False, comment="两次观测时") isgzjdxz = Column(String(100)) diff --git a/app/schemas/comprehensive_data.py b/app/schemas/comprehensive_data.py index 27080fb..cf5c2f1 100644 --- a/app/schemas/comprehensive_data.py +++ b/app/schemas/comprehensive_data.py @@ -97,6 +97,7 @@ class SettlementDataQueryRequest(BaseModel): workinfoname: Optional[str] = None isgzjdxz: Optional[str] = None upd_remark: Optional[str] = None + limit: Optional[int] = None # 限制返回数量,None表示返回全部 # 断面数据导入请求 class SectionDataQueryRequest(BaseModel): diff --git a/app/services/settlement_data.py b/app/services/settlement_data.py index 262708f..5e63794 100644 --- a/app/services/settlement_data.py +++ b/app/services/settlement_data.py @@ -28,30 +28,40 @@ class SettlementDataService(BaseService[SettlementData]): point_id: Optional[str] = None, nyid: Optional[str] = None, sjName: Optional[str] = None, - workinfoname: Optional[str] = None) -> List[SettlementData]: - """根据多个条件搜索沉降数据""" - conditions = {} - if id is not None: - 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 + workinfoname: Optional[str] = None, + limit: Optional[int] = None) -> List[SettlementData]: + """根据多个条件搜索沉降数据,按上传时间倒序排序""" + query = db.query(SettlementData) - 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, id: Optional[int] = None, point_id: Optional[str] = None, nyid: Optional[str] = None, sjName: Optional[str] = None, - workinfoname: Optional[str] = None) -> List[Dict[str, Any]]: - """查询沉降数据并返回格式化结果""" - settlement_data = self.search_settlement_data(db, id, point_id, nyid, sjName, workinfoname) + 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, limit) result = [] for settlement in settlement_data: