mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
feat(mcp): 重构 MCP 服务器及智能助手模块
- 新增代码生成模块路由支持 - 重构 MCP 服务器API,支持增删改查接口和分页查询 - 实现 MCP 智能对话的流式响应和 WebSocket 通信 - 优化 MCP 数据模型,支持环境变量等配置项 - 改进 MCP CRUD 层,集成权限控制和统一操作方法 - 优化异常处理,提升接口错误信息准确性 - 修正依赖导入和数据校验,增强代码健壮性
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
import importlib
|
||||
import os
|
||||
from types import ModuleType
|
||||
import uuid
|
||||
import re
|
||||
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from typing import Any, Generator, List, Dict, Sequence, Optional
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
from app.config import setting
|
||||
from app.core.logger import logger
|
||||
@@ -228,79 +224,3 @@ def get_filepath_from_url(url: str) -> Path:
|
||||
filepath = setting.settings.STATIC_ROOT.joinpath(task_path, task_id, file_name)
|
||||
|
||||
return filepath
|
||||
|
||||
|
||||
def export_list2excel(list_data: List) -> Any:
|
||||
"""
|
||||
工具方法:将需要导出的list数据转化为对应excel的二进制数据
|
||||
|
||||
:param list_data: 数据列表
|
||||
:return: 字典信息对应excel的二进制数据
|
||||
"""
|
||||
df = pd.DataFrame(list_data)
|
||||
binary_data = io.BytesIO()
|
||||
df.to_excel(binary_data, index=False, engine='openpyxl')
|
||||
binary_data = binary_data.getvalue()
|
||||
|
||||
return binary_data
|
||||
|
||||
|
||||
def get_excel_template(header_list: List, selector_header_list: List, option_list: List[dict]) -> Any:
|
||||
"""
|
||||
工具方法:将需要导出的list数据转化为对应excel的二进制数据
|
||||
|
||||
:param header_list: 表头数据列表
|
||||
:param selector_header_list: 需要设置为选择器格式的表头数据列表
|
||||
:param option_list: 选择器格式的表头预设的选项列表
|
||||
:return: 模板excel的二进制数据
|
||||
"""
|
||||
# 创建Excel工作簿
|
||||
wb = Workbook()
|
||||
# 选择默认的活动工作表
|
||||
ws = wb.active
|
||||
|
||||
# 设置表头文字
|
||||
headers = header_list
|
||||
|
||||
# 设置表头背景样式为灰色,前景色为白色
|
||||
header_fill = PatternFill(start_color='ababab', end_color='ababab', fill_type='solid')
|
||||
|
||||
# 将表头写入第一行
|
||||
for col_num, header in enumerate(headers, 1):
|
||||
cell = ws.cell(row=1, column=col_num)
|
||||
cell.value = header
|
||||
cell.fill = header_fill
|
||||
# 设置列宽度为16
|
||||
ws.column_dimensions[chr(64 + col_num)].width = 12
|
||||
# 设置水平居中对齐
|
||||
cell.alignment = Alignment(horizontal='center')
|
||||
|
||||
# 设置选择器的预设选项
|
||||
options = option_list
|
||||
|
||||
# 获取selector_header的字母索引
|
||||
for selector_header in selector_header_list:
|
||||
column_selector_header_index = headers.index(selector_header) + 1
|
||||
|
||||
# 创建数据有效性规则
|
||||
header_option = []
|
||||
for option in options:
|
||||
if option.get(selector_header):
|
||||
header_option = option.get(selector_header)
|
||||
dv = DataValidation(type='list', formula1=f'"{",".join(header_option)}"')
|
||||
# 设置数据有效性规则的起始单元格和结束单元格
|
||||
dv.add(
|
||||
f'{get_column_letter(column_selector_header_index)}2:{get_column_letter(column_selector_header_index)}1048576'
|
||||
)
|
||||
# 添加数据有效性规则到工作表
|
||||
ws.add_data_validation(dv)
|
||||
|
||||
# 保存Excel文件为字节类型的数据
|
||||
file = io.BytesIO()
|
||||
wb.save(file)
|
||||
file.seek(0)
|
||||
|
||||
# 读取字节数据
|
||||
excel_data = file.getvalue()
|
||||
|
||||
return excel_data
|
||||
|
||||
Reference in New Issue
Block a user