feat: 添加公司AI管理平台基础架构 添加了完整的FastAPI后端项目结构,包括: - 环境配置文件(.env.example)和项目说明文档(README.md、AGENTS.md) - Dockerfile用于容器化部署 - 核心基础设施:配置管理、数据库连接、调度器、安全认证 - 模块化设计:AI代理、审批流程、审计日志、业务台账等功能模块 - 支持多数据库连接(主库和遗留系统只读库) - AI适配器支持OpenClaw、Hermes、OpenAI兼容接口 - 飞书集成、报表生成、风险监控等企业级功能 - 完整的依赖管理和测试指南 ```
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import require_api_key
|
|
from app.modules.legacy_mysql.schemas import (
|
|
LegacyProjectSyncRequest,
|
|
LegacyProjectSyncResult,
|
|
QueryResult,
|
|
ReadonlyQueryRequest,
|
|
)
|
|
from app.modules.legacy_mysql.service import LegacyMySQLService
|
|
|
|
router = APIRouter(dependencies=[Depends(require_api_key)])
|
|
|
|
|
|
@router.get("/health")
|
|
def mysql_health(db: Session = Depends(get_db)) -> dict[str, str]:
|
|
return LegacyMySQLService(db).health()
|
|
|
|
|
|
@router.get("/tables")
|
|
def list_tables(db: Session = Depends(get_db)) -> dict[str, list[str]]:
|
|
return {"tables": LegacyMySQLService(db).list_tables()}
|
|
|
|
|
|
@router.get("/tables/{table_name}")
|
|
def describe_table(table_name: str, db: Session = Depends(get_db)) -> dict:
|
|
return {"table": table_name, "columns": LegacyMySQLService(db).describe_table(table_name)}
|
|
|
|
|
|
@router.post("/query", response_model=QueryResult)
|
|
def readonly_query(payload: ReadonlyQueryRequest, db: Session = Depends(get_db)) -> dict:
|
|
return LegacyMySQLService(db).execute_readonly(payload.sql, payload.params, payload.limit)
|
|
|
|
|
|
@router.get("/projects", response_model=QueryResult)
|
|
def default_project_query(limit: int = 100, db: Session = Depends(get_db)) -> dict:
|
|
return LegacyMySQLService(db).fetch_default_projects(limit=limit)
|
|
|
|
|
|
@router.post("/projects/sync", response_model=LegacyProjectSyncResult)
|
|
def sync_projects(payload: LegacyProjectSyncRequest, db: Session = Depends(get_db)) -> dict:
|
|
return LegacyMySQLService(db).sync_projects(
|
|
source_query=payload.source_query,
|
|
field_map=payload.field_map,
|
|
limit=payload.limit,
|
|
dry_run=payload.dry_run,
|
|
actor=payload.actor,
|
|
)
|