增加水准编码查询账号接口
This commit is contained in:
@@ -18,6 +18,7 @@ from ..schemas.comprehensive_data import (
|
||||
SettlementDataCheckpointQueryRequest,
|
||||
LevelDataQueryRequest,
|
||||
LinecodeRequest,
|
||||
LinecodeAccountRequest,
|
||||
NYIDRequest,
|
||||
SectionByAccountRequest,
|
||||
PointByAccountRequest,
|
||||
@@ -30,6 +31,7 @@ from ..services.settlement_data import SettlementDataService
|
||||
from ..services.level_data import LevelDataService
|
||||
from ..services.original_data import OriginalDataService
|
||||
from ..services.comprehensive import ComprehensiveDataService
|
||||
from ..services.account import AccountService
|
||||
from ..utils.get_operating_mode import OperatingModePredictor
|
||||
import logging
|
||||
router = APIRouter(prefix="/comprehensive_data", tags=["综合数据管理"])
|
||||
@@ -727,4 +729,66 @@ def get_checkpoint_by_point(request: LevelDataQueryRequest, db: Session = Depend
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
|
||||
@router.post("/get_accounts_by_linecode", response_model=DataResponse)
|
||||
def get_accounts_by_linecode(request: LinecodeAccountRequest, db: Session = Depends(get_db)):
|
||||
"""
|
||||
通过水准线路编码查询账号信息
|
||||
业务逻辑:
|
||||
1. 根据linecode在水准数据表查询最新的NYID
|
||||
2. 根据NYID在沉降数据表查询所有point_id(去重)
|
||||
3. 根据point_id在观测点表查询所有section_id(去重)
|
||||
4. 根据section_id在断面表查询所有account_id(去重)
|
||||
5. 根据account_id在账号表查询账号信息并返回
|
||||
|
||||
优化:使用批量IN查询,避免循环查询数据库
|
||||
"""
|
||||
try:
|
||||
linecode = request.linecode
|
||||
logger.info(f"接口请求:根据linecode={linecode}查询账号信息")
|
||||
|
||||
# 调用服务层方法
|
||||
accounts = AccountService.get_accounts_by_linecode(db, linecode)
|
||||
|
||||
if not accounts:
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message=f"未找到linecode={linecode}对应的账号信息",
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
|
||||
# 转换为字典列表
|
||||
account_data = []
|
||||
for account in accounts:
|
||||
account_dict = {
|
||||
"id": account.id,
|
||||
"username": account.username,
|
||||
"status": account.status,
|
||||
"today_updated": account.today_updated,
|
||||
"project_name": account.project_name,
|
||||
"created_at": account.created_at.strftime("%Y-%m-%d %H:%M:%S") if account.created_at else None,
|
||||
"updated_at": account.updated_at.strftime("%Y-%m-%d %H:%M:%S") if account.updated_at else None,
|
||||
"update_time": account.update_time,
|
||||
"max_variation": account.max_variation,
|
||||
"yh_id": account.yh_id,
|
||||
"cl_name": account.cl_name
|
||||
}
|
||||
account_data.append(account_dict)
|
||||
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message=f"查询成功,共获取{len(account_data)}个账号",
|
||||
total=len(account_data),
|
||||
data=account_data
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"查询账号信息失败:{str(e)}", exc_info=True)
|
||||
return DataResponse(
|
||||
code=ResponseCode.QUERY_FAILED,
|
||||
message=f"查询失败:{str(e)}",
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user