Commit e7d4538d authored by 何家明's avatar 何家明

新增除尘器停止状态的查询接口

parent c3760ffa
...@@ -20,11 +20,9 @@ python api.py ...@@ -20,11 +20,9 @@ python api.py
启动成功后,可以调用接口 启动成功后,可以调用接口
``` ```
post http://localhost:8000/mcp/query get localhost:8000/mcp/chat?message=xxx
{
"message": "治理过程全记录", 注意要给header中加一个参数id,代表客户id
"customer_token": "ef616aad53d3eddfb53ca71980421440"
}
``` ```
## config.yaml ## config.yaml
......
...@@ -23,7 +23,7 @@ async def lifespan(app): ...@@ -23,7 +23,7 @@ async def lifespan(app):
api = FastAPI(title="BME MCP服务", lifespan=lifespan) api = FastAPI(title="BME MCP服务", lifespan=lifespan)
router = APIRouter(prefix="/mcp/") router = APIRouter(prefix="/mcp")
@router.get("/chat/logo") @router.get("/chat/logo")
async def get_ai_logo(): async def get_ai_logo():
......
...@@ -42,6 +42,7 @@ remote: ...@@ -42,6 +42,7 @@ remote:
base_url: base_url:
bme-screen-service: https://vis.bmetech.com/vis bme-screen-service: https://vis.bmetech.com/vis
# bme-screen-service: http://localhost:9070/screen # bme-screen-service: http://localhost:9070/screen
bme-pc-service: https://vis.bmetech.com/vispc
# 跨域配置 # 跨域配置
cors: cors:
......
import yaml import yaml
import os
with open("./config/config.yaml", "r", encoding="utf-8") as yml_file: current_dir = os.path.dirname(os.path.abspath(__file__))
yaml_path = os.path.join(current_dir, "../config/config.yaml")
yaml_path = os.path.normpath(yaml_path)
with open(yaml_path, "r", encoding="utf-8") as yml_file:
config = yaml.safe_load(yml_file) config = yaml.safe_load(yml_file)
import os import os
import sys import sys
from typing import List, Any
import requests import requests
from mcp.server.fastmcp import FastMCP from mcp.server.fastmcp import FastMCP
...@@ -45,7 +46,7 @@ def get_size_limit(size: int, max_size=20, min_size=0) -> int: ...@@ -45,7 +46,7 @@ def get_size_limit(size: int, max_size=20, min_size=0) -> int:
@mcp.tool() @mcp.tool()
def get_air_pm_10_month_focus(customer_id: int) -> []: def get_air_pm_10_month_focus(customer_id: int) -> Any:
""" """
根据客户id获取本月重点关注的空气质量微站(PM10标准) 根据客户id获取本月重点关注的空气质量微站(PM10标准)
:param customer_id: 客户id :param customer_id: 客户id
...@@ -68,7 +69,7 @@ def get_air_pm_10_month_focus(customer_id: int) -> []: ...@@ -68,7 +69,7 @@ def get_air_pm_10_month_focus(customer_id: int) -> []:
@mcp.tool() @mcp.tool()
def get_air_pm_rank(customer_id: int, order: int, statistic_type: int) -> []: def get_air_pm_rank(customer_id: int, order: int, statistic_type: int) -> Any:
""" """
根据客户id获取空气质量微站排行(包含PM2.5和PM10标准),其中 根据客户id获取空气质量微站排行(包含PM2.5和PM10标准),其中
order如果没有指定,默认值是1; order如果没有指定,默认值是1;
...@@ -106,7 +107,7 @@ def get_air_pm_rank(customer_id: int, order: int, statistic_type: int) -> []: ...@@ -106,7 +107,7 @@ def get_air_pm_rank(customer_id: int, order: int, statistic_type: int) -> []:
@mcp.tool() @mcp.tool()
def get_tsp_rank(customer_id: int, order: int, statistic_type: int, size: int) -> []: def get_tsp_rank(customer_id: int, order: int, statistic_type: int, size: int) -> Any:
""" """
根据客户id获取TSP监测排行,其中 根据客户id获取TSP监测排行,其中
order如果没有指定,默认值是1; order如果没有指定,默认值是1;
...@@ -150,7 +151,7 @@ def get_tsp_rank(customer_id: int, order: int, statistic_type: int, size: int) - ...@@ -150,7 +151,7 @@ def get_tsp_rank(customer_id: int, order: int, statistic_type: int, size: int) -
@mcp.tool() @mcp.tool()
def get_governance_process_statistics(customer_id: int) -> {}: def get_governance_process_statistics(customer_id: int) -> Any:
""" """
根据客户id获取今天治理过程记录统计数据 根据客户id获取今天治理过程记录统计数据
:param customer_id: 客户id :param customer_id: 客户id
...@@ -171,7 +172,7 @@ def get_governance_process_statistics(customer_id: int) -> {}: ...@@ -171,7 +172,7 @@ def get_governance_process_statistics(customer_id: int) -> {}:
@mcp.tool() @mcp.tool()
def get_governance_process_records(customer_id: int, instruct_type: str, device_name: str, def get_governance_process_records(customer_id: int, instruct_type: str, device_name: str,
start_time: str, end_time: str, size: int) -> []: start_time: str, end_time: str, size: int) -> Any:
""" """
根据客户id查询治理过程全记录,其中: 根据客户id查询治理过程全记录,其中:
instruct_type如果没有指定,默认值是空字符串; instruct_type如果没有指定,默认值是空字符串;
...@@ -218,8 +219,35 @@ def get_governance_process_records(customer_id: int, instruct_type: str, device_ ...@@ -218,8 +219,35 @@ def get_governance_process_records(customer_id: int, instruct_type: str, device_
return result return result
@mcp.tool()
def get_stopped_dust_collector(customer_id: int) -> Any:
"""
根据客户id获取当前已停止的除尘器
:param customer_id: 客户id
:return: 返回结构中的字段名解释:
name: 所在区域
deviceName: 除尘器名称
deviceNo: 除尘器编码
type: 除尘器类型
"""
response = requests.get(bme_screen_service + "/treatment/cc_list", {
"customerId": customer_id,
"pageNo": 1,
"pageSize": 50,
"status": 0
}, headers=headers)
response_data = deal_request_exception(response).get("data", {}).get("records", [])
result = [{
"name": record.get("name"),
"deviceName": record.get("deviceName"),
"deviceNo": record.get("deviceNo"),
"type": record.get("type")
} for record in response_data]
return result
@mcp.resource("api://customers") @mcp.resource("api://customers")
def get_all_available_customer() -> []: def get_all_available_customer() -> Any:
""" """
获取所有的客户信息 获取所有的客户信息
:return: 客户信息数据 :return: 客户信息数据
......
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