数据查询,账号字段增加
This commit is contained in:
@@ -20,6 +20,7 @@ from ..services.checkpoint import CheckpointService
|
|||||||
from ..services.settlement_data import SettlementDataService
|
from ..services.settlement_data import SettlementDataService
|
||||||
from ..services.level_data import LevelDataService
|
from ..services.level_data import LevelDataService
|
||||||
from ..services.original_data import OriginalDataService
|
from ..services.original_data import OriginalDataService
|
||||||
|
from ..services.comprehensive import ComprehensiveDataService
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
router = APIRouter(prefix="/comprehensive_data", tags=["综合数据管理"])
|
router = APIRouter(prefix="/comprehensive_data", tags=["综合数据管理"])
|
||||||
@@ -31,6 +32,7 @@ checkpoint_service = CheckpointService()
|
|||||||
settlement_service = SettlementDataService()
|
settlement_service = SettlementDataService()
|
||||||
level_service = LevelDataService()
|
level_service = LevelDataService()
|
||||||
original_service = OriginalDataService()
|
original_service = OriginalDataService()
|
||||||
|
comprehensive_service = ComprehensiveDataService()
|
||||||
|
|
||||||
@router.post("/batch_import_sections", response_model=DataImportResponse)
|
@router.post("/batch_import_sections", response_model=DataImportResponse)
|
||||||
def batch_import_sections(request: BatchSectionDataImportRequest, db: Session = Depends(get_db)):
|
def batch_import_sections(request: BatchSectionDataImportRequest, db: Session = Depends(get_db)):
|
||||||
@@ -138,45 +140,101 @@ def batch_import_original_data(request: BatchOriginalDataImportRequest, db: Sess
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 查询断面数据对应观察点数据
|
# 查询断面数据对应观察点数据
|
||||||
@router.post("/get_section", response_model = DataResponse)
|
@router.post("/get_section", response_model=DataResponse)
|
||||||
def get_section(request: SectionDataQueryRequest, db: Session = Depends(get_db)):
|
def get_section(request: SectionDataQueryRequest, db: Session = Depends(get_db)):
|
||||||
"""获取断面数据 + 观测点"""
|
"""获取断面数据 + 观测点"""
|
||||||
data = section_service.search_section_data(db,
|
try:
|
||||||
id=request.id,
|
logger.info(f"Querying section data with params: {request.dict()}")
|
||||||
section_id=request.section_id,
|
|
||||||
mileage=request.mileage,
|
# 调用服务层的业务方法
|
||||||
work_site=request.work_site
|
result_data = section_service.search_sections_with_checkpoints(
|
||||||
)
|
db,
|
||||||
|
id=request.id,
|
||||||
|
section_id=request.section_id,
|
||||||
|
mileage=request.mileage,
|
||||||
|
work_site=request.work_site,
|
||||||
|
number=request.number,
|
||||||
|
status=request.status
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(f"Found {len(result_data)} sections with checkpoints")
|
||||||
|
return DataResponse(
|
||||||
|
success=True,
|
||||||
|
message="查询成功",
|
||||||
|
count=len(result_data),
|
||||||
|
data=result_data
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Query section data failed: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail=f"查询断面数据失败: {str(e)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# 根据观测点id查询沉降数据
|
# 根据观测点id查询沉降数据
|
||||||
@router.post("/get_section", response_model = DataResponse)
|
@router.post("/get_settlement", response_model=DataResponse)
|
||||||
def get_settlenment(request: SettlementDataQueryRequest, db: Session = Depends(get_db)):
|
def get_settlement(request: SettlementDataQueryRequest, db: Session = Depends(get_db)):
|
||||||
"""获取沉降数据"""
|
"""获取沉降数据"""
|
||||||
data = settlement_service.search_settlement_data(db,
|
try:
|
||||||
id=request.id,
|
logger.info(f"Querying settlement data with params: {request.dict()}")
|
||||||
point_id=request.point_id,
|
|
||||||
nyid=request.NYID,
|
# 调用服务层的业务方法
|
||||||
sjName=request.sjName,
|
result_data = settlement_service.search_settlement_data_formatted(
|
||||||
workinfoname=request.workinfoname
|
db,
|
||||||
)
|
id=request.id,
|
||||||
|
point_id=request.point_id,
|
||||||
|
nyid=request.NYID,
|
||||||
|
sjName=request.sjName,
|
||||||
|
workinfoname=request.workinfoname
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(f"Found {len(result_data)} settlement records")
|
||||||
|
return DataResponse(
|
||||||
|
success=True,
|
||||||
|
message="查询成功",
|
||||||
|
count=len(result_data),
|
||||||
|
data=result_data
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Query settlement data failed: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail=f"查询沉降数据失败: {str(e)}"
|
||||||
|
)
|
||||||
|
|
||||||
# 查询水准数据
|
|
||||||
# @router.post("/get_level", response_model = DataResponse)
|
|
||||||
# def get_level(request: LevelDataQueryRequest, db: Session = Depends(get_db)):
|
|
||||||
# """查询水准数据"""
|
|
||||||
# data = level_service.search_level_data(db,
|
|
||||||
# id=request.id,
|
|
||||||
# linecode=request.linecode,
|
|
||||||
# nyid=request.NYID
|
|
||||||
# )
|
|
||||||
|
|
||||||
# 根据期数id获取原始数据
|
# 根据期数id获取原始数据
|
||||||
|
@router.post("/get_original", response_model=DataResponse)
|
||||||
def get_original(request: OriginalDataQueryRequest, db: Session = Depends(get_db)):
|
def get_original(request: OriginalDataQueryRequest, db: Session = Depends(get_db)):
|
||||||
"""获取水准数据+原始数据"""
|
"""获取水准数据+原始数据"""
|
||||||
data = level_service.search_level_data(db,
|
try:
|
||||||
id=request.id,
|
logger.info(f"Querying original data with params: {request.dict()}")
|
||||||
nyid=request.NYID,
|
|
||||||
linecode=request.linecode
|
# 调用综合服务的业务方法
|
||||||
)
|
result = comprehensive_service.get_level_and_original_data(
|
||||||
|
db,
|
||||||
|
id=request.id,
|
||||||
|
bfpcode=request.bfpcode,
|
||||||
|
bffb=request.bffb,
|
||||||
|
nyid=request.NYID,
|
||||||
|
linecode=request.linecode,
|
||||||
|
bfpl=request.bfpl
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(f"Found level and original data: {result['summary']}")
|
||||||
|
return DataResponse(
|
||||||
|
success=result["success"],
|
||||||
|
message=result["message"],
|
||||||
|
count=result["count"],
|
||||||
|
data=[result["data"]]
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Query original data failed: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail=f"查询原始数据失败: {str(e)}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ class Account(Base):
|
|||||||
__tablename__ = "accounts"
|
__tablename__ = "accounts"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||||
username = Column(String(50), unique=True, index=True, nullable=False, comment="用户名")
|
username = Column(String(500), unique=True, index=True, nullable=False, comment="用户名")
|
||||||
password = Column(String(100), nullable=False, comment="密码")
|
password = Column(String(1000), nullable=False, comment="密码")
|
||||||
status = Column(Integer, default=1, comment="状态: 1-正常, 0-禁用")
|
status = Column(Integer, default=1, comment="状态: 1-正常, 0-禁用")
|
||||||
today_updated = Column(Integer, default=0, comment="是否更新")
|
today_updated = Column(Integer, default=0, comment="是否更新")
|
||||||
project_name = Column(String(100), comment="项目名称")
|
project_name = Column(String(1000), comment="项目名称")
|
||||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
||||||
|
update_time = Column(String(1000), comment="更新时间跨度")
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from sqlalchemy import Column, Integer, String, List
|
from sqlalchemy import Column, Integer, String
|
||||||
|
from typing import List
|
||||||
from ..core.database import Base
|
from ..core.database import Base
|
||||||
from .original_data import OriginalData
|
from .original_data import OriginalData
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from sqlalchemy import Column, Integer, String, List
|
from sqlalchemy import Column, Integer, String
|
||||||
|
from typing import List
|
||||||
from ..core.database import Base
|
from ..core.database import Base
|
||||||
from .checkpoint import Checkpoint
|
from .checkpoint import Checkpoint
|
||||||
|
|
||||||
|
|||||||
@@ -167,8 +167,64 @@ class ComprehensiveDataService:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_level_and_original_data(self, db: Session,
|
||||||
|
id: Optional[int] = None,
|
||||||
|
bfpcode: Optional[str] = None,
|
||||||
|
bffb: Optional[str] = None,
|
||||||
|
nyid: Optional[str] = None,
|
||||||
|
linecode: Optional[str] = None,
|
||||||
|
bfpl: Optional[str] = None) -> Dict[str, Any]:
|
||||||
|
"""根据条件获取水准数据+原始数据的组合查询"""
|
||||||
|
# 查询水准数据
|
||||||
|
level_data = self.level_service.search_level_data(
|
||||||
|
db,
|
||||||
|
nyid=nyid,
|
||||||
|
linecode=linecode
|
||||||
|
)
|
||||||
|
|
||||||
|
# 查询原始数据
|
||||||
|
original_data = self.original_service.search_original_data(
|
||||||
|
db,
|
||||||
|
bfpcode=bfpcode,
|
||||||
|
bffb=bffb,
|
||||||
|
nyid=nyid,
|
||||||
|
bfpl=bfpl
|
||||||
|
)
|
||||||
|
result = []
|
||||||
|
original_count = 0
|
||||||
|
for level in level_data:
|
||||||
|
data = {
|
||||||
|
"id": level.id,
|
||||||
|
"linecode": level.linecode,
|
||||||
|
"benchmarkids": level.benchmarkids,
|
||||||
|
"wsphigh": level.wsphigh,
|
||||||
|
"NYID": level.NYID,
|
||||||
|
"createDate": level.createDate,
|
||||||
|
"originalDatas": [
|
||||||
|
{
|
||||||
|
"id": orig.id,
|
||||||
|
"bfpcode": orig.bfpcode,
|
||||||
|
"mtime": orig.mtime,
|
||||||
|
"bffb": orig.bffb,
|
||||||
|
"bfpl": orig.bfpl,
|
||||||
|
"bfpvalue": orig.bfpvalue,
|
||||||
|
"times": orig.times,
|
||||||
|
"NYID": orig.NYID,
|
||||||
|
"sort": orig.sort
|
||||||
|
} for orig in original_data if orig.NYID == level.NYID
|
||||||
|
]
|
||||||
|
}
|
||||||
|
original_count += len(data["originalDatas"])
|
||||||
|
result.append(data)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"message": "查询成功",
|
||||||
|
"count": original_count,
|
||||||
|
"data": result
|
||||||
|
}
|
||||||
|
|
||||||
def get_statistics_summary(self, db: Session) -> Dict[str, Any]:
|
def get_statistics_summary(self, db: Session) -> Dict[str, Any]:
|
||||||
"""获取全局统计摘要"""
|
|
||||||
all_sections = self.section_service.get_all(db, limit=10000)
|
all_sections = self.section_service.get_all(db, limit=10000)
|
||||||
all_checkpoints = self.checkpoint_service.get_all(db, limit=10000)
|
all_checkpoints = self.checkpoint_service.get_all(db, limit=10000)
|
||||||
all_settlement = self.settlement_service.get_all(db, limit=10000)
|
all_settlement = self.settlement_service.get_all(db, limit=10000)
|
||||||
|
|||||||
@@ -49,10 +49,46 @@ class SectionDataService(BaseService[SectionData]):
|
|||||||
conditions['id'] = id
|
conditions['id'] = id
|
||||||
if mileage is not None:
|
if mileage is not None:
|
||||||
conditions['mileage'] = mileage
|
conditions['mileage'] = mileage
|
||||||
|
|
||||||
section_data = self.search_by_conditions(db, conditions)
|
return self.search_by_conditions(db, conditions)
|
||||||
# 查询对应观察点数据
|
|
||||||
if len(section_data) > 0:
|
def search_sections_with_checkpoints(self, db: Session,
|
||||||
|
id: Optional[int] = None,
|
||||||
|
section_id: Optional[str] = None,
|
||||||
|
mileage: Optional[str] = None,
|
||||||
|
work_site: Optional[str] = None,
|
||||||
|
number: Optional[str] = None,
|
||||||
|
status: Optional[str] = None) -> List[Dict[str, Any]]:
|
||||||
|
"""查询断面数据并返回带观测点的结果"""
|
||||||
|
sections = self.search_section_data(db, id, section_id, mileage, work_site, number, status)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for section in sections:
|
||||||
|
checkpoints = self.checkpoint_service.get_by_section_id(db, section.section_id)
|
||||||
|
|
||||||
|
section_dict = {
|
||||||
|
"id": section.id,
|
||||||
|
"section_id": section.section_id,
|
||||||
|
"mileage": section.mileage,
|
||||||
|
"work_site": section.work_site,
|
||||||
|
"basic_types": section.basic_types,
|
||||||
|
"height": section.height,
|
||||||
|
"status": section.status,
|
||||||
|
"number": section.number,
|
||||||
|
"transition_paragraph": section.transition_paragraph,
|
||||||
|
"checkpoints": [
|
||||||
|
{
|
||||||
|
"id": cp.id,
|
||||||
|
"point_id": cp.point_id,
|
||||||
|
"aname": cp.aname,
|
||||||
|
"burial_date": cp.burial_date,
|
||||||
|
"section_id": cp.section_id
|
||||||
|
} for cp in checkpoints
|
||||||
|
]
|
||||||
|
}
|
||||||
|
result.append(section_dict)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def get_section_with_checkpoints(self, db: Session, section_id: str) -> Dict[str, Any]:
|
def get_section_with_checkpoints(self, db: Session, section_id: str) -> Dict[str, Any]:
|
||||||
"""获取断面数据及其关联的观测点"""
|
"""获取断面数据及其关联的观测点"""
|
||||||
|
|||||||
@@ -24,13 +24,15 @@ class SettlementDataService(BaseService[SettlementData]):
|
|||||||
).first()
|
).first()
|
||||||
|
|
||||||
def search_settlement_data(self, db: Session,
|
def search_settlement_data(self, db: Session,
|
||||||
id: Optional[str] = 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[SettlementData]:
|
workinfoname: Optional[str] = None) -> List[SettlementData]:
|
||||||
"""根据多个条件搜索沉降数据"""
|
"""根据多个条件搜索沉降数据"""
|
||||||
conditions = {}
|
conditions = {}
|
||||||
|
if id is not None:
|
||||||
|
conditions["id"] = id
|
||||||
if point_id is not None:
|
if point_id is not None:
|
||||||
conditions["point_id"] = point_id
|
conditions["point_id"] = point_id
|
||||||
if nyid is not None:
|
if nyid is not None:
|
||||||
@@ -42,6 +44,43 @@ class SettlementDataService(BaseService[SettlementData]):
|
|||||||
|
|
||||||
return self.search_by_conditions(db, conditions)
|
return self.search_by_conditions(db, conditions)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for settlement in settlement_data:
|
||||||
|
settlement_dict = {
|
||||||
|
"id": settlement.id,
|
||||||
|
"point_id": settlement.point_id,
|
||||||
|
"CVALUE": settlement.CVALUE,
|
||||||
|
"MAVALUE": settlement.MAVALUE,
|
||||||
|
"MTIME_W": settlement.MTIME_W,
|
||||||
|
"NYID": settlement.NYID,
|
||||||
|
"PRELOADH": settlement.PRELOADH,
|
||||||
|
"PSTATE": settlement.PSTATE,
|
||||||
|
"REMARK": settlement.REMARK,
|
||||||
|
"WORKINFO": settlement.WORKINFO,
|
||||||
|
"createdate": settlement.createdate,
|
||||||
|
"day": settlement.day,
|
||||||
|
"day_jg": settlement.day_jg,
|
||||||
|
"isgzjdxz": settlement.isgzjdxz,
|
||||||
|
"mavalue_bc": settlement.mavalue_bc,
|
||||||
|
"mavalue_lj": settlement.mavalue_lj,
|
||||||
|
"sjName": settlement.sjName,
|
||||||
|
"useflag": settlement.useflag,
|
||||||
|
"workinfoname": settlement.workinfoname,
|
||||||
|
"upd_remark": settlement.upd_remark
|
||||||
|
}
|
||||||
|
result.append(settlement_dict)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def _check_checkpoint_exists(self, db: Session, point_id: str) -> bool:
|
def _check_checkpoint_exists(self, db: Session, point_id: str) -> bool:
|
||||||
"""检查观测点数据是否存在"""
|
"""检查观测点数据是否存在"""
|
||||||
checkpoint = db.query(Checkpoint).filter(Checkpoint.point_id == point_id).first()
|
checkpoint = db.query(Checkpoint).filter(Checkpoint.point_id == point_id).first()
|
||||||
|
|||||||
Reference in New Issue
Block a user