1.今日任务接口
2.根据NYID获取所有相关的测点信息
This commit is contained in:
@@ -16,8 +16,10 @@ from ..schemas.comprehensive_data import (
|
||||
OriginalDataQueryRequest,
|
||||
SettlementDataCheckpointQueryRequest,
|
||||
LevelDataQueryRequest,
|
||||
LinecodeRequest
|
||||
LinecodeRequest,
|
||||
NYIDRequest
|
||||
)
|
||||
from ..services.daily import DailyDataService
|
||||
from ..services.section_data import SectionDataService
|
||||
from ..services.checkpoint import CheckpointService
|
||||
from ..services.settlement_data import SettlementDataService
|
||||
@@ -344,4 +346,60 @@ def get_settlement_by_linecode(
|
||||
message=f"查询失败:{str(e)}",
|
||||
total=0,
|
||||
data=[]
|
||||
)
|
||||
@router.post("/get_settlement_by_nyid", response_model=DataResponse)
|
||||
def get_settlement_by_nyid(
|
||||
request: NYIDRequest, # 假设定义了接收nyid的请求模型
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
try:
|
||||
nyid = request.NYID # 从请求体中获取nyid
|
||||
logger.info(f"接口请求:根据nyid={nyid}查询沉降数据")
|
||||
|
||||
settlement = SettlementDataService()
|
||||
# 获取模型实例列表
|
||||
checkpoint_instances = settlement.get_by_nyid(db, nyid="4993546")
|
||||
# 转为字典列表(核心修正)
|
||||
checkpoint_data = [instance.__dict__ for instance in checkpoint_instances]
|
||||
# 清理 SQLAlchemy 内部属性(可选,避免多余字段)
|
||||
checkpoint_data = [{k: v for k, v in item.items() if not k.startswith('_sa_')} for item in checkpoint_data]
|
||||
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message=f"查询成功,共获取{len(checkpoint_data)}条沉降数据",
|
||||
total=len(checkpoint_data),
|
||||
data=checkpoint_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=[]
|
||||
)
|
||||
@router.get("/get_today_data", response_model=DataResponse)
|
||||
def get_today_data(db: Session = Depends(get_db)):
|
||||
"""接口:直接触发调度器中的 scheduled_get_max_nyid_by_point_id 定时任务"""
|
||||
try:
|
||||
|
||||
|
||||
# scheduled_get_max_nyid_by_point_id()
|
||||
daily_service = DailyDataService()
|
||||
daily_data = daily_service.get_daily_data_by_account(db,account_id=1)
|
||||
|
||||
return DataResponse(
|
||||
code=ResponseCode.SUCCESS,
|
||||
message="定时任务触发执行成功!任务已开始处理(具体结果查看系统日志)",
|
||||
total=1,
|
||||
data=daily_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={}
|
||||
)
|
||||
@@ -20,7 +20,9 @@ class LevelDataImportRequest(BaseModel):
|
||||
wsphigh: Optional[str] = None
|
||||
mtype: Optional[str] = None
|
||||
createDate: Optional[str] = None
|
||||
|
||||
# 水准数据导入请求
|
||||
class NYIDRequest(BaseModel):
|
||||
NYID: str
|
||||
# 沉降数据导入请求
|
||||
class SettlementDataImportRequest(BaseModel):
|
||||
point_id: str
|
||||
|
||||
@@ -118,4 +118,7 @@ class CheckpointService(BaseService[Checkpoint]):
|
||||
'success_count': success_count,
|
||||
'failed_count': failed_count,
|
||||
'failed_items': failed_items
|
||||
}
|
||||
}
|
||||
def get_by_nyid(self, db: Session, nyid: str) -> List[Checkpoint]:
|
||||
"""根据NYID获取所有相关的测点信息"""
|
||||
return self.get_by_field(db, "NYID", nyid)
|
||||
@@ -191,4 +191,46 @@ class DailyDataService(BaseService[DailyData]):
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"获取日常数据失败:{str(e)}", exc_info=True)
|
||||
raise e
|
||||
def get_daily_data_by_account(
|
||||
self,
|
||||
db: Session,
|
||||
account_id: str, # 账号ID(必填,因为是核心筛选条件)
|
||||
user_id: Optional[int] = None # 可选参数:额外按user_id筛选
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
根据account_id获取对应日常数据,支持额外按user_id筛选
|
||||
:param db: 数据库会话
|
||||
:param account_id: 账号ID(必填),用于精准筛选数据
|
||||
:param user_id: 可选用户ID,若提供则则进一步筛选该用户的数据
|
||||
:return: 符合条件的日常数据字典列表,包含所有字段
|
||||
"""
|
||||
try:
|
||||
# 基础查询:先按account_id筛选(必填条件)
|
||||
query = db.query(DailyData).filter(DailyData.account_id == account_id)
|
||||
|
||||
# 若提供了user_id,则添加额外筛选条件
|
||||
if user_id is not None:
|
||||
query = query.filter(DailyData.user_id == user_id)
|
||||
logger.info(f"查询account_id={account_id}且user_id={user_id}的日常数据")
|
||||
else:
|
||||
logger.info(f"查询account_id={account_id}的所有日常数据")
|
||||
|
||||
# 执行查询并获取记录
|
||||
daily_records = query.all()
|
||||
|
||||
# 转换为字典列表(保留所有字段)
|
||||
result = []
|
||||
for record in daily_records:
|
||||
record_dict = {
|
||||
column.name: getattr(record, column.name)
|
||||
for column in DailyData.__table__.columns
|
||||
}
|
||||
result.append(record_dict)
|
||||
|
||||
logger.info(f"查询完成,account_id={account_id}对应{len(result)}条日常数据")
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"获取account_id={account_id}的日常数据失败:{str(e)}", exc_info=True)
|
||||
raise e
|
||||
@@ -280,7 +280,7 @@ def scheduled_get_max_nyid_by_point_id():
|
||||
'point_id': d['point_id'],
|
||||
'linecode': d['level_data']['linecode'],
|
||||
'account_id': d['account_data']['account_id'],
|
||||
'section_id': d['section_data']['id'],
|
||||
'section_id': d['section_data']['section_id'],
|
||||
'remaining': d['remaining'],
|
||||
}
|
||||
daily_create_data.append(tem)
|
||||
|
||||
Reference in New Issue
Block a user