2025-08-05 11:57:14 +08:00

110 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 边检CV算法接口服务
## 项目简介
这是一个简化的边检计算机视觉算法管理系统API服务采用FastAPI框架开发。
## 项目结构
```
server/
├── app.py # 主应用文件
├── requirements.txt # 依赖包列表
├── init_data.py # 初始化数据脚本
├── env.example # 环境变量示例
├── core/ # 核心配置
│ └── database.py # 数据库配置
├── models/ # 数据模型
│ ├── __init__.py
│ ├── base.py # 基础模型
│ ├── algorithm.py # 算法模型
│ ├── device.py # 设备模型
│ └── event.py # 事件模型
└── routers/ # 路由接口
├── __init__.py
├── algorithms.py # 算法管理接口
├── devices.py # 设备管理接口
└── events.py # 事件管理接口
```
## 简化设计
本项目采用简化的架构设计:
1. **去掉schemas层**:直接使用字典进行数据传递,减少代码复杂度
2. **简化响应格式**:所有接口直接返回字典格式,便于维护
3. **保持核心功能**保留所有必要的CRUD操作和业务逻辑
## API接口
### 算法管理 (/api/algorithms)
- `POST /` - 创建算法
- `GET /` - 获取算法列表
- `GET /{id}` - 获取算法详情
- `PUT /{id}` - 更新算法
- `DELETE /{id}` - 删除算法
- `PATCH /{id}/status` - 更新算法状态
- `PATCH /{id}/enable` - 启用/禁用算法
### 设备管理 (/api/devices)
- `POST /` - 创建设备
- `GET /` - 获取设备列表
- `GET /{id}` - 获取设备详情
- `PUT /{id}` - 更新设备
- `DELETE /{id}` - 删除设备
- `PATCH /{id}/status` - 更新设备状态
- `PATCH /{id}/enable` - 启用/禁用设备
- `GET /types/list` - 获取设备类型列表
- `GET /status/stats` - 获取设备状态统计
### 事件管理 (/api/events)
- `POST /` - 创建事件
- `GET /` - 获取事件列表
- `GET /{id}` - 获取事件详情
- `PUT /{id}` - 更新事件
- `DELETE /{id}` - 删除事件
- `PATCH /{id}/status` - 更新事件状态
- `GET /types/list` - 获取事件类型列表
- `GET /stats/summary` - 获取事件统计摘要
- `GET /stats/by-type` - 按类型统计事件
## 安装和运行
1. 安装依赖:
```bash
pip install -r requirements.txt
```
2. 配置环境变量:
```bash
cp env.example .env
# 编辑.env文件配置数据库连接等
```
3. 初始化数据:
```bash
python init_data.py
```
4. 启动服务:
```bash
python app.py
```
服务将在 http://localhost:8000 启动API文档访问 http://localhost:8000/docs
## 技术栈
- **框架**: FastAPI
- **数据库**: SQLAlchemy + SQLite
- **ORM**: SQLAlchemy
- **文档**: 自动生成OpenAPI文档
## 特点
- 简化的架构,易于维护
- 完整的CRUD操作
- 支持分页和筛选
- 自动生成API文档
- 支持CORS跨域
- 健康检查接口