wms-py/README.md
2025-06-04 10:55:05 +08:00

148 lines
4.0 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.

# WMS-PY 项目
这是一个基于 FastAPI 的仓库管理系统(WMS),采用标准的项目结构,支持多环境配置。
## 项目结构
```
wms-py/
├── app/ # 应用核心代码
│ ├── __init__.py
│ ├── main.py # 主应用文件
│ ├── config/ # 配置模块
│ │ ├── __init__.py
│ │ └── settings.py # 配置管理
│ ├── controllers/ # 控制器(路由)
│ │ ├── __init__.py
│ │ ├── base_controller.py # 基础接口
│ │ ├── database_controller.py # 数据库测试接口
│ │ └── location_controller.py # 库位管理接口
│ ├── services/ # 业务服务层
│ │ ├── __init__.py
│ │ └── location_service.py # 库位业务逻辑
│ ├── models/ # 数据模型
│ │ ├── __init__.py
│ │ └── location.py # 库位数据模型
│ ├── schemas/ # Pydantic模式
│ │ ├── __init__.py
│ │ ├── common.py # 通用响应模式
│ │ └── location.py # 库位请求/响应模式
│ └── utils/ # 工具类
│ ├── __init__.py
│ ├── database.py # 数据库工具类
│ └── string_utils.py # 字符串工具
├── config/ # 环境配置文件
│ ├── development.yaml # 开发环境配置
│ └── production.yaml # 生产环境配置
├── requirements.txt # 依赖包列表
├── run.py # 启动脚本
├── create_tables.py # 数据库表创建脚本
└── README.md # 项目说明
```
## 快速开始
### 1. 安装依赖
```bash
pip install -r requirements.txt
```
### 2. 配置数据库
根据需要修改配置文件:
**开发环境** (`config/development.yaml`):
```yaml
database:
host: "localhost"
port: 3306
username: "root"
password: "root"
database: "wms_ntyc"
```
### 3. 运行应用
```bash
# 开发环境
python run.py
# 生产环境
set ENVIRONMENT=production && python run.py
```
## API接口
### 基础接口
- `GET /` - 系统信息
- `GET /config` - 配置信息
### 数据库测试接口
- `GET /database/test` - 测试数据库连接
- `GET /database/tables` - 获取所有表名
- `GET /database/query?sql=SELECT * FROM table_name` - 执行SQL查询
- `GET /database/table/{table_name}` - 查看指定表数据
### 库位管理接口
**库位查询**:
- `GET /wms/location/getUsedLocations?equipment_id=1&location_type=1` - 获取已使用库位数量
### API 文档
- `GET /docs` - Swagger UI 文档
- `GET /redoc` - ReDoc 文档
## 项目架构说明
### 分层架构
1. **Controller层** (`app/controllers/`)
- 处理HTTP请求
- 参数验证
- 路由定义
2. **Service层** (`app/services/`)
- 业务逻辑处理
- 事务管理
- 数据操作
3. **Model层** (`app/models/`)
- 数据库表映射
- ORM模型定义
4. **Schema层** (`app/schemas/`)
- 请求/响应数据验证
- API文档生成
### 依赖注入
项目使用FastAPI的依赖注入系统
- 数据库会话注入
- 服务类注入
- 配置注入
### 对应关系
| Java概念 | Python/FastAPI概念 | 文件位置 |
|---------|-------------------|----------|
| @RestController | APIRouter | `app/controllers/` |
| @Service | Service类 | `app/services/` |
| @Entity | SQLAlchemy Model | `app/models/` |
| DTO | Pydantic Schema | `app/schemas/` |
| @Autowired | Depends() | 依赖注入 |
## IDE 配置
### PyCharm 配置
创建运行配置:
- **Name**: `WMS Development`
- **Script path**: `run.py`
- **Environment variables**: `ENVIRONMENT=development`
## 注意事项
1. 确保数据库服务已启动
2. 修改配置文件后需要重启应用
3. 库位生成前请确认参数,避免重复数据