'commit'
This commit is contained in:
@@ -31,4 +31,37 @@ async def get_education_data_by_year(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/populationByYear")
|
||||
async def get_population_data_by_year(
|
||||
year: int = Query(default=2023, ge=2015, le=2028,
|
||||
description="年份: 2015-2028范围内的年份")
|
||||
):
|
||||
"""获取指定年份的云南省人口数据"""
|
||||
try:
|
||||
# 调用EducationDataModel的方法获取人口数据
|
||||
data = EducationDataModel.get_population_data_by_year(year)
|
||||
|
||||
if data:
|
||||
# 返回包含状态和数据的响应
|
||||
return {
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": data
|
||||
}
|
||||
else:
|
||||
# 未找到数据的情况
|
||||
return {
|
||||
"code": 404,
|
||||
"message": f"未找到{year}年的云南省人口数据",
|
||||
"data": None
|
||||
}
|
||||
except Exception as e:
|
||||
# 异常处理
|
||||
return {
|
||||
"code": 500,
|
||||
"message": f"获取数据失败: {str(e)}",
|
||||
"data": None
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user