Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ backend/.vscode
backend/.idea
backend/.DS_Store
backend/venv
backend/.venv
backend/logs
backend/*.db
backend/env/*

frontend/__pycache__
frontend/.vscode
frontend/.idea
frontend/.DS_Store
frontend/node_modules
frontend/dist
frontend/dist
frontend/.husky
frontend/.env.development
frontend/.env.production
frontend/src/types/auto-imports.d.ts
frontend/src/types/components.d.ts

devops/nginx/fastapp/dist
devops/nginx/fastdocs/dist
devops/nginx/frontend/dist
devops/nginx/ssl
fastapp/components.d.ts
frontend/src/types/auto-imports.d.ts
frontend/src/types/components.d.ts
fastdocs/.vitepress/cache/*
devops/nginx/ssl
268 changes: 2 additions & 266 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,7 @@ module_*/
- **数据库**: MySQL 8.0+ / PostgreSQL 13+ / SQLite 3.x
- **Redis**: 6.0+ (可选)

### 安装与运行

#### 1. 项目初始化

```bash
# 克隆项目
git clone <repository-url>
cd FastapiAdmin/backend

# 创建虚拟环境(推荐)
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate

# 安装依赖
pip3 install -r requirements.txt
```

#### 2. 环境配置

复制并编辑环境配置文件:

```bash
cp env/dev.env.example env/dev.env
# 编辑 env/dev.env 文件,配置数据库连接和其他参数
```

主要配置项:

- `DATABASE_URL`: 数据库连接地址
- `SECRET_KEY`: JWT 加密密钥
- `REDIS_URL`: Redis 连接地址(可选)

#### 3. 数据库初始化
#### 1. 数据库初始化

```bash
# 生成迁移文件(仅首次或模型变更时)
Expand All @@ -132,194 +100,16 @@ python main.py revision "数据迁移" --env=dev(不加默认为dev)
python main.py upgrade --env=dev(不加默认为dev)
```

#### 4. 启动服务
#### 2. 启动服务

```bash
# 开发环境启动
python main.py run --env=dev (不加默认为dev)

# 生产环境启动
python main.py run --env=prod (不加默认为dev)

# 或使用 uvicorn 直接启动
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```

服务成功启动后,您可以访问:

- **API 文档**: [http://localhost:8000/docs](http://localhost:8000/docs) (Swagger UI)
- **替代文档**: [http://localhost:8000/redoc](http://localhost:8000/redoc) (ReDoc)
- **健康检查**: [http://localhost:8000/health](http://localhost:8000/health)

## 📚 API 文档

### 主要接口模块

| 模块 | 路径 | 说明 |
|------|------|------|
| 用户管理 | `/api/v1/system/user` | 用户增删改查、角色分配 |
| 角色管理 | `/api/v1/system/role` | 角色管理、权限分配 |
| 菜单管理 | `/api/v1/system/menu` | 系统菜单、权限节点 |
| 部门管理 | `/api/v1/system/dept` | 组织架构管理 |
| 岗位管理 | `/api/v1/system/position` | 岗位信息管理 |
| 系统监控 | `/api/v1/monitor/*` | 系统性能、日志监控 |
| 任务调度 | `/api/v1/monitor/job` | 定时任务管理 |
| 文件管理 | `/api/v1/common/file` | 文件上传下载 |
| 代码生成 | `/api/v1/generator/*` | 代码生成工具 |

### 认证授权

系统使用 JWT Bearer Token 进行身份验证:

```bash
# 登录获取 Token
curl -X POST "http://localhost:8000/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "123456"}'

# 使用 Token 访问受保护的资源
curl -X GET "http://localhost:8000/api/v1/system/user/list" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"
```

## 🛠️ 开发指南

### 项目配置

主要配置文件位于 `app/config/setting.py`,支持通过环境变量进行覆盖。

### 数据库迁移

```bash
# 查看当前迁移状态
python3 main.py current --env=dev

# 查看迁移历史
python3 main.py history --env=dev

# 回滚到上一个版本
python3 main.py downgrade -1 --env=dev
```

### 添加新模块

1. 在 `app/api/v1/` 下创建新的模块目录
2. 按照现有模块结构创建文件:
- `model.py` - SQLAlchemy ORM 模型
- `schema.py` - Pydantic 数据模型
- `crud.py` - 数据库操作层
- `service.py` - 业务逻辑层
- `controller.py` - API 控制器
- `param.py` - 请求参数模型
3. 在主路由中注册新模块

### 测试

```bash
# 运行单元测试
pytest tests/

# 运行指定测试文件
pytest tests/test_user.py -v

# 生成测试覆盖率报告
pytest --cov=app tests/
```

## 📊 监控与日志

### 日志级别

- **DEBUG**: 详细的调试信息
- **INFO**: 一般信息(默认级别)
- **WARNING**: 警告信息
- **ERROR**: 错误信息
- **CRITICAL**: 严重错误

### 性能监控

系统内置了完整的性能监控功能:

- API 响应时间监控
- 数据库连接池监控
- 内存与 CPU 使用率监控
- 自定义业务指标监控

## 🚀 部署指南

### Docker 部署

```bash
# 构建镜像
docker build -t fastapi-admin .

# 运行容器
docker run -d \
--name fastapi-admin \
-p 8000:8000 \
-e DATABASE_URL="postgresql://user:pass@host:5432/db" \
fastapi-admin
```

### 传统部署

```bash
# 使用 Gunicorn 作为 WSGI 服务器
gunicorn main:app \
--workers 4 \
--worker-class uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8000 \
--access-logfile - \
--error-logfile -
```

### Nginx 配置

```nginx
server {
listen 80;
server_name your-domain.com;

location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```

## 🤝 贡献指南

欢迎提交 Issue 和 Pull Request!

### 开发流程

1. Fork 项目
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
3. 提交更改 (`git commit -m 'Add some amazing feature'`)
4. 推送到分支 (`git push origin feature/amazing-feature`)
5. 发起 Pull Request

### 代码规范

- 遵循 PEP 8 Python 编码规范
- 使用类型注解 (Type Hints)
- 编写单元测试
- 添加必要的注释和文档

## 📝 更新日志

### v1.0.0 (2024-09-06)

- ✨ 初始版本发布
- ✨ 完整的用户权限管理系统
- ✨ 支持多数据库类型
- ✨ 定时任务调度功能
- ✨ 代码生成工具
- ✨ AI 集成功能

## 📜 相关链接

- **FastAPI 官方文档**: [https://fastapi.tiangolo.com/](https://fastapi.tiangolo.com/)
Expand All @@ -337,57 +127,3 @@ server {
---

❤️ **感谢您的关注和支持!** 如果这个项目对您有帮助,请给我们一个 ⭐️ Star!


# MCP 模块

## 概述

MCP (Model Context Protocol) 模块为系统提供与AI模型交互的能力,基于FastAPI-MCP实现。

## 功能特性

- 智能对话接口
- 流式和非流式响应支持
- WebSocket聊天支持
- MCP服务器状态监控

## API接口

### 智能对话

```
POST /api/v1/mcp/chat
```

请求参数:
- `message` (string, required): 聊天消息
- `stream` (boolean, optional): 是否流式返回,默认为false

### 获取服务器状态

```
GET /api/v1/mcp/status
```

### WebSocket聊天

```
GET /api/v1/mcp/ws/chat
```

## MCP集成

系统已集成FastAPI-MCP,可通过以下URL访问MCP服务器:

```
http://localhost:8000/mcp
```

## 配置

在系统配置中设置以下参数:

- `OPENAI_API_KEY`: OpenAI API密钥
- `OPENAI_BASE_URL`: OpenAI API基础URL
- `OPENAI_MODEL`: OpenAI模型名称
2 changes: 1 addition & 1 deletion backend/app/api/v1/module_application/job/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async def get_job_log_controller():
"coalesce": i.coalesce,
"max_instances": i.max_instances,
"next_run_time": i.next_run_time,
"state": SchedulerUtil.get_job_status()
"state": SchedulerUtil.get_single_job_status(job_id=i.id)
}
for i in SchedulerUtil.get_all_jobs()
]
Expand Down
13 changes: 10 additions & 3 deletions backend/app/api/v1/module_application/job/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,16 @@ async def option_job_service(cls, auth: AuthSchema, id: int, option: int) -> Non
elif option == 2:
SchedulerUtil().resume_job(job_id=id)
await JobCRUD(auth).set_obj_field_crud(ids=[id], status=True)
# elif option == 3:
# SchedulerUtil().reschedule_job(job_id=id)
# await JobCRUD(auth).set_obj_field_crud(ids=[id], status=False)
elif option == 3:
# 重启任务:先移除再添加,确保使用最新的任务配置
SchedulerUtil.remove_job(job_id=id)
# 获取最新的任务配置
updated_job = await JobCRUD(auth).get_obj_by_id_crud(id=id)
if updated_job:
# 重新添加任务
SchedulerUtil.add_job(job_info=updated_job)
# 设置状态为运行中
await JobCRUD(auth).set_obj_field_crud(ids=[id], status=True)

@classmethod
async def export_job_service(cls, data_list: List[Dict[str, Any]]) -> bytes:
Expand Down
Loading