Initial commit: UPS management system
This commit is contained in:
270
.trae/documents/ups_management_plan.md
Normal file
270
.trae/documents/ups_management_plan.md
Normal file
@@ -0,0 +1,270 @@
|
||||
# UPS 主机和电池管理系统 - 实现计划
|
||||
|
||||
## 一、项目概述
|
||||
|
||||
本项目是一个基于 Django 的本地部署管理系统,用于管理 UPS 主机和电池的相关信息。
|
||||
|
||||
## 二、需求分析
|
||||
|
||||
### 2.1 数据模型需求
|
||||
|
||||
| 数据类型 | 字段需求 |
|
||||
|---------|---------|
|
||||
| UPS 主机 | IP 地址、型号、数量、存放位置、上次维保时间 |
|
||||
| 电池 | 品牌、存放位置、型号、重量、数量、安装日期(用于计算已使用时长)、上次维保时间 |
|
||||
| 联系人 | 姓名、联系电话、邮箱 |
|
||||
| 维保供应商 | 公司名称、联系人、联系电话、邮箱、地址、备注 |
|
||||
| 维修记录 | 关联设备、维修日期、维修内容、维修人员、关联维保供应商 |
|
||||
|
||||
### 2.2 功能需求
|
||||
|
||||
| 功能 | 描述 |
|
||||
|-----|------|
|
||||
| 电池已使用时长计算 | 根据安装日期自动计算,按年为单位显示(如 2.3 年) |
|
||||
| 上次维保时间 | UPS 主机和电池均需记录上次维保时间 |
|
||||
| 列表页搜索 | 支持按型号、位置、联系人等字段进行搜索过滤 |
|
||||
|
||||
### 2.3 页面需求
|
||||
|
||||
| 页面 | 功能描述 |
|
||||
|-----|---------|
|
||||
| 主页 (Dashboard) | 显示重要统计信息概览 |
|
||||
| UPS 主机管理 | UPS 主机列表(支持搜索)、新增、编辑、删除 |
|
||||
| 电池管理 | 电池列表(支持搜索、显示已使用时长)、新增、编辑、删除 |
|
||||
| 联系人管理 | 联系人列表(支持搜索)、新增、编辑、删除 |
|
||||
| 维保供应商管理 | 维保供应商列表(支持搜索)、新增、编辑、删除 |
|
||||
| 维修记录管理 | 维修记录列表(支持搜索)、新增、编辑、删除 |
|
||||
|
||||
## 三、技术方案
|
||||
|
||||
### 3.1 技术栈
|
||||
|
||||
- **框架**: Django 5.x
|
||||
- **数据库**: SQLite(本地部署)
|
||||
- **前端**: Bootstrap 5
|
||||
- **语言**: Python 3.x
|
||||
|
||||
### 3.2 项目结构
|
||||
|
||||
```
|
||||
ups_management/
|
||||
├── manage.py
|
||||
├── ups_management/
|
||||
│ ├── __init__.py
|
||||
│ ├── settings.py
|
||||
│ ├── urls.py
|
||||
│ └── wsgi.py
|
||||
└── ups_manager/
|
||||
├── __init__.py
|
||||
├── admin.py
|
||||
├── apps.py
|
||||
├── models.py
|
||||
├── views.py
|
||||
├── urls.py
|
||||
└── templates/
|
||||
└── ups_manager/
|
||||
├── index.html
|
||||
├── ups_list.html
|
||||
├── ups_form.html
|
||||
├── battery_list.html
|
||||
├── battery_form.html
|
||||
├── contact_list.html
|
||||
├── contact_form.html
|
||||
├── supplier_list.html
|
||||
├── supplier_form.html
|
||||
├── maintenance_list.html
|
||||
└── maintenance_form.html
|
||||
```
|
||||
|
||||
### 3.3 数据模型设计
|
||||
|
||||
#### 3.3.1 UPS 主机模型 (UPSHost)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|-------|------|------|
|
||||
| ip_address | CharField | IP 地址 |
|
||||
| model | CharField | 型号 |
|
||||
| quantity | IntegerField | 数量 |
|
||||
| location | CharField | 存放位置 |
|
||||
| last_maintenance_date | DateField | 上次维保时间 |
|
||||
| contact | ForeignKey | 关联联系人 |
|
||||
| created_at | DateTimeField | 创建时间 |
|
||||
| updated_at | DateTimeField | 更新时间 |
|
||||
|
||||
#### 3.3.2 电池模型 (Battery)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|-------|------|------|
|
||||
| brand | CharField | 品牌 |
|
||||
| model | CharField | 型号 |
|
||||
| weight | FloatField | 重量 (kg) |
|
||||
| quantity | IntegerField | 数量 |
|
||||
| location | CharField | 存放位置 |
|
||||
| install_date | DateField | 安装日期(用于计算已使用时长) |
|
||||
| last_maintenance_date | DateField | 上次维保时间 |
|
||||
| ups_host | ForeignKey | 关联 UPS 主机(可选) |
|
||||
| created_at | DateTimeField | 创建时间 |
|
||||
| updated_at | DateTimeField | 更新时间 |
|
||||
|
||||
**计算字段**:`used_years` - 根据 `install_date` 自动计算已使用年数
|
||||
|
||||
#### 3.3.3 联系人模型 (Contact)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|-------|------|------|
|
||||
| name | CharField | 姓名 |
|
||||
| phone | CharField | 联系电话 |
|
||||
| email | EmailField | 邮箱(可选) |
|
||||
| created_at | DateTimeField | 创建时间 |
|
||||
|
||||
#### 3.3.4 维保供应商模型 (Supplier)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|-------|------|------|
|
||||
| company_name | CharField | 公司名称 |
|
||||
| contact_person | CharField | 联系人 |
|
||||
| phone | CharField | 联系电话 |
|
||||
| email | EmailField | 邮箱 |
|
||||
| address | CharField | 地址 |
|
||||
| remark | TextField | 备注(可选) |
|
||||
| created_at | DateTimeField | 创建时间 |
|
||||
|
||||
#### 3.3.5 维修记录模型 (MaintenanceRecord)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|-------|------|------|
|
||||
| ups_host | ForeignKey | 关联 UPS 主机 |
|
||||
| battery | ForeignKey | 关联电池(可选) |
|
||||
| supplier | ForeignKey | 关联维保供应商(可选) |
|
||||
| maintenance_date | DateTimeField | 维修日期 |
|
||||
| content | TextField | 维修内容 |
|
||||
| technician | CharField | 维修人员 |
|
||||
| created_at | DateTimeField | 创建时间 |
|
||||
|
||||
### 3.4 搜索功能设计
|
||||
|
||||
各列表页支持以下搜索字段:
|
||||
|
||||
| 页面 | 搜索字段 |
|
||||
|-----|---------|
|
||||
| UPS 主机列表 | 型号、位置、联系人 |
|
||||
| 电池列表 | 型号、品牌、位置 |
|
||||
| 联系人列表 | 姓名、电话 |
|
||||
| 维保供应商列表 | 公司名称、联系人 |
|
||||
| 维修记录列表 | 设备型号、维修人员、维保供应商 |
|
||||
|
||||
## 四、实现步骤
|
||||
|
||||
### 4.1 步骤一:创建 Django 项目
|
||||
|
||||
```bash
|
||||
django-admin startproject ups_management
|
||||
cd ups_management
|
||||
python manage.py startapp ups_manager
|
||||
```
|
||||
|
||||
### 4.2 步骤二:配置项目
|
||||
|
||||
1. 在 `settings.py` 中注册 `ups_manager` 应用
|
||||
2. 配置模板路径
|
||||
3. 配置静态文件路径
|
||||
4. 安装 django-bootstrap5
|
||||
|
||||
### 4.3 步骤三:创建数据模型
|
||||
|
||||
在 `ups_manager/models.py` 中定义五个模型:
|
||||
- UPSHost: 包含 last_maintenance_date 字段
|
||||
- Battery: 包含 install_date 和 last_maintenance_date 字段,添加 used_years 计算属性
|
||||
- Contact
|
||||
- Supplier: 维保供应商模型
|
||||
- MaintenanceRecord: 关联维保供应商字段
|
||||
|
||||
### 4.4 步骤四:创建视图
|
||||
|
||||
在 `ups_manager/views.py` 中创建:
|
||||
- DashboardView: 主页统计概览
|
||||
- UPSHostListView: 支持搜索过滤
|
||||
- UPSHostCreateView/UpdateView/DeleteView
|
||||
- BatteryListView: 支持搜索过滤,显示已使用时长
|
||||
- BatteryCreateView/UpdateView/DeleteView
|
||||
- ContactListView: 支持搜索过滤
|
||||
- ContactCreateView/UpdateView/DeleteView
|
||||
- SupplierListView: 支持搜索过滤
|
||||
- SupplierCreateView/UpdateView/DeleteView
|
||||
- MaintenanceRecordListView: 支持搜索过滤
|
||||
- MaintenanceRecordCreateView/UpdateView/DeleteView
|
||||
|
||||
### 4.5 步骤五:配置 URL 路由
|
||||
|
||||
在 `ups_manager/urls.py` 中配置各页面路由
|
||||
|
||||
### 4.6 步骤六:创建模板
|
||||
|
||||
使用 Bootstrap 5 创建响应式模板:
|
||||
- `index.html`: 主页仪表盘
|
||||
- `ups_list.html`: UPS 主机列表(带搜索框)
|
||||
- `ups_form.html`: UPS 主机表单
|
||||
- `battery_list.html`: 电池列表(带搜索框,显示已使用时长)
|
||||
- `battery_form.html`: 电池表单
|
||||
- `contact_list.html`: 联系人列表(带搜索框)
|
||||
- `contact_form.html`: 联系人表单
|
||||
- `supplier_list.html`: 维保供应商列表(带搜索框)
|
||||
- `supplier_form.html`: 维保供应商表单
|
||||
- `maintenance_list.html`: 维修记录列表(带搜索框)
|
||||
- `maintenance_form.html`: 维修记录表单
|
||||
|
||||
### 4.7 步骤七:数据库迁移
|
||||
|
||||
```bash
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
```
|
||||
|
||||
### 4.8 步骤八:创建管理员用户
|
||||
|
||||
```bash
|
||||
python manage.py createsuperuser
|
||||
```
|
||||
|
||||
## 五、依赖与环境
|
||||
|
||||
### 5.1 依赖列表
|
||||
|
||||
| 依赖 | 版本 | 用途 |
|
||||
|-----|------|------|
|
||||
| Django | >=5.0 | Web 框架 |
|
||||
| django-bootstrap5 | >=23.3 | Bootstrap 集成 |
|
||||
|
||||
### 5.2 安装命令
|
||||
|
||||
```bash
|
||||
pip install django django-bootstrap5
|
||||
```
|
||||
|
||||
## 六、运行方式
|
||||
|
||||
```bash
|
||||
cd ups_management
|
||||
python manage.py runserver
|
||||
```
|
||||
|
||||
访问地址:http://localhost:8000
|
||||
|
||||
## 七、风险评估
|
||||
|
||||
| 风险 | 描述 | 应对措施 |
|
||||
|-----|------|---------|
|
||||
| 数据库迁移失败 | 模型定义错误可能导致迁移失败 | 仔细检查模型定义,先测试迁移 |
|
||||
| 模板渲染错误 | 模板语法错误导致页面无法显示 | 使用 Django 调试模式定位问题 |
|
||||
| 数据关联问题 | 外键关联可能导致删除异常 | 设置合理的 on_delete 行为 |
|
||||
| 日期计算错误 | 已使用时长计算可能出现精度问题 | 使用 datetime 模块精确计算 |
|
||||
|
||||
## 八、交付物
|
||||
|
||||
1. 完整的 Django 项目代码
|
||||
2. SQLite 数据库文件(初始为空)
|
||||
3. 可直接运行的本地服务
|
||||
|
||||
---
|
||||
|
||||
**计划完成后等待用户批准,然后执行实现。**
|
||||
Reference in New Issue
Block a user