# 无人机-后端 **Repository Path**: xusun000/drone-backend ## Basic Information - **Project Name**: 无人机-后端 - **Description**: 1234567890 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-04 - **Last Updated**: 2026-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Drone Inspection Backend 无人机/电机智能质检系统后端 API ## 技术栈 - **框架**: FastAPI - **数据库**: SQLite (本地文件存储) - **文件存储**: 本地文件系统 ## 项目结构 ``` drone-inspection-backend/ ├── app/ │ ├── __init__.py │ ├── database.py # 数据库连接 │ ├── models.py # SQLAlchemy 数据模型 │ ├── schemas.py # Pydantic 数据验证模型 │ └── routers/ │ ├── __init__.py │ ├── tasks.py # 任务相关 API │ ├── defects.py # 缺陷相关 API │ ├── images.py # 图片相关 API │ └── dashboard.py # 仪表盘统计 API ├── db/ # SQLite 数据库文件 ├── uploads/ # 上传的图片存储目录 ├── main.py # 应用入口 └── requirements.txt # 依赖列表 ``` ## 安装与运行 ### 1. 安装依赖 ```bash cd /Users/xusun/Desktop/Python/drone-inspection-backend pip install -r requirements.txt ``` ### 2. 启动服务 ```bash python main.py ``` 或 ```bash uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` ### 3. 访问 API 文档 - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## API 接口概览 ### 任务管理 (Tasks) | 方法 | 路径 | 说明 | |------|------|------| | POST | `/api/tasks` | 创建新任务 | | GET | `/api/tasks` | 获取任务列表 | | GET | `/api/tasks/{id}` | 获取任务详情 | | POST | `/api/tasks/{id}/images` | 上传图片 | | GET | `/api/tasks/{id}/images` | 获取任务图片列表 | | POST | `/api/tasks/{id}/detect` | 执行 AI 检测 | | GET | `/api/tasks/{id}/defects` | 获取任务缺陷列表 | | GET | `/api/tasks/{id}/timeline` | 获取任务时间线 | ### 缺陷管理 (Defects) | 方法 | 路径 | 说明 | |------|------|------| | GET | `/api/defects` | 获取缺陷列表 | | GET | `/api/defects/{id}` | 获取缺陷详情 | | PUT | `/api/defects/{id}/review` | 复核缺陷 | | POST | `/api/defects/{id}/analyze` | AI 大模型分析 | | GET | `/api/defects/{id}/report` | 获取分析报告 | | POST | `/api/defects/{id}/feedback` | 提交整改反馈 | | PUT | `/api/defects/{id}/close` | 闭环缺陷 | ### 图片 (Images) | 方法 | 路径 | 说明 | |------|------|------| | GET | `/api/images/{id}` | 获取图片文件 | ### 仪表盘 (Dashboard) | 方法 | 路径 | 说明 | |------|------|------| | GET | `/api/dashboard/stats` | 获取统计数据 | | GET | `/api/dashboard/defect-distribution` | 缺陷类型分布 | | GET | `/api/dashboard/trend` | 趋势数据 | | GET | `/api/dashboard/recent-tasks` | 最近任务 | | GET | `/api/dashboard/trace/{task_id}` | 任务溯源 | ## 数据模型 ### 任务 (Task) - `id`: 任务ID (如: TSK-20260312-ABCD) - `model`: 机型 - `batch`: 批次 - `station`: 工位 - `operator`: 操作员 - `status`: 状态 (pending/detected/reviewed/analyzing/analyzed/closed) - `defects_count`: 缺陷数量 - `created_at`: 创建时间 - `updated_at`: 更新时间 ### 缺陷 (Defect) - `id`: 缺陷ID (如: DEF-0312-ABCD) - `task_id`: 关联任务ID - `type`: 缺陷类型 (螺丝缺失/线束异常/划痕/异物) - `location`: 位置 - `confidence`: 置信度 - `bbox_x/y/w/h`: 边界框坐标 - `status`: 状态 - `created_at`: 创建时间 ### 分析报告 (AnalysisReport) - `id`: 报告ID - `defect_id`: 关联缺陷ID - `conclusion`: 问题结论 - `root_cause`: 根因分析 - `action_plan`: 处理建议 - `generated_at`: 生成时间 ### 时间线事件 (TimelineEvent) - `id`: 事件ID - `task_id`: 关联任务ID - `action`: 动作名称 - `status`: 状态 (success/warning/pending) - `detail`: 详情 - `operator`: 操作人 - `created_at`: 时间 ## 前端集成示例 ### 创建任务 ```javascript const response = await fetch('http://localhost:8000/api/tasks', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'EV-Motor-X1', batch: 'B-20260312', station: 'Station-A', operator: 'OP-01' }) }); const task = await response.json(); ``` ### 上传图片 ```javascript const formData = new FormData(); formData.append('file', imageFile); const response = await fetch(`http://localhost:8000/api/tasks/${taskId}/images`, { method: 'POST', body: formData }); ``` ### 运行 AI 检测 ```javascript const response = await fetch(`http://localhost:8000/api/tasks/${taskId}/detect`, { method: 'POST' }); const result = await response.json(); ```