Commit 15cd9c08 by tinywell

监测点返回结果 bug fix

parent df832ca9
...@@ -11,7 +11,7 @@ class MonitorPointResponse(): ...@@ -11,7 +11,7 @@ class MonitorPointResponse():
class MonitorPointArgs(BaseModel): class MonitorPointArgs(BaseModel):
"""监测点查询参数""" """监测点查询参数"""
key: str = Field(..., description="行政区划名称(省/市/区县级别均可)") key: str = Field(..., description="行政区划名称(省/市/区县级别均可,只需要最后一级,如岳麓区,不需要长沙市)")
class MonitorPointTool(BaseTool): class MonitorPointTool(BaseTool):
"""查询监测点信息的工具""" """查询监测点信息的工具"""
...@@ -48,40 +48,37 @@ class MonitorPointTool(BaseTool): ...@@ -48,40 +48,37 @@ class MonitorPointTool(BaseTool):
try: try:
print(f"进入 monitor_points_query 工具, 查询监测点信息: {key}") print(f"进入 monitor_points_query 工具, 查询监测点信息: {key}")
response = self.client.query_points_sync(key) response = self.client.query_points_sync(key)
print(f"查询结果: {response}")
# 格式化返回结果 if response.type != 1 or len(response.resultdata) == 0:
if not response.resultdata: return {
return MonitorPointResponse( 'code': 400,
status="success", 'message': f"查询失败: {response.message},请检查是否有相关数据权限"
message=f"未在{key}找到监测点信息", }
points=[]
)
# 提取关键信息并格式化 # 提取关键信息并格式化
points_info = [] points_info = []
for point in response.resultdata: for point in response.resultdata:
points_info.append({ points_info.append({
"名称": point.MONITORPOINTNAME, "名称": point["MONITORPOINTNAME"] if point["MONITORPOINTNAME"] else "",
"位置": point.LOCATION, "位置": point["LOCATION"] if point["LOCATION"] else "",
"经度": point.LONGITUDE, "经度": point["LONGITUDE"] if point["LONGITUDE"] else "",
"纬度": point.LATITUDE, "纬度": point["LATITUDE"] if point["LATITUDE"] else "",
"海拔": point.ELEVATION, "海拔": point["ELEVATION"] if point["ELEVATION"] else "",
"建设单位": point.BUILDUNIT, "建设单位": point["BUILDUNIT"] if point["BUILDUNIT"] else "",
"监测单位": point.MONITORUNIT "监测单位": point["MONITORUNIT"] if point["MONITORUNIT"] else ""
}) })
return MonitorPointResponse( return {
status="success", 'code': 200,
message=f"在{key}找到{len(points_info)}个监测点", 'message': f"在{key}找到{len(points_info)}个监测点",
points=points_info 'points': points_info
) }
except Exception as e: except Exception as e:
return MonitorPointResponse( return {
status="error", 'code': 400,
message=f"查询失败: {str(e)}", 'message': f"查询失败: {str(e)}"
points=[] }
)
def _arun(self, key: str) -> Dict[str, Any]: def _arun(self, key: str) -> Dict[str, Any]:
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment