添加Redis缓存支持和Docker部署配置

- 新增Redis缓存功能,用于优化仪表板统计数据查询性能
- 添加Redis连接池管理和自动降级机制,无连接时自动跳过缓存
- 配置Dockerfile支持前后端容器化部署
- 添加docker-compose编排文件实现一键部署
- 更新README文档包含新的部署方式和架构说明
- 在入库出库操作后清除相关缓存以保证数据一致性
This commit is contained in:
2026-07-07 10:08:33 +08:00
parent 48007f536d
commit b764f6fa59
12 changed files with 245 additions and 6 deletions

View File

@@ -18,8 +18,9 @@
| ORM | MyBatis-Plus | 3.5.11 |
| 安全认证 | Spring Security + JWT (jjwt 0.13.0) | — |
| 数据库 | MySQL 8.0 (JDBC + HikariCP) | — |
| 缓存 | Redis 7 + Jedis可选无连接自动跳过 | — |
| 工具库 | Hutool 5.8 / Lombok | — |
| 构建 | Maven 3.9+ | — |
| 构建 / 部署 | Maven 3.9+ / Docker + Docker Compose | — |
---
@@ -37,8 +38,10 @@ graph TB
end
DB["🐬 MySQL 8.0<br/>InnoDB · utf8mb4"]
Cache["⚡ Redis 7<br/>可选 · 自动降级"]
Client -->|"HTTPS + JWT Token"| Security
Service --> Cache
Security --> Controller
Controller --> Service
Service --> Mapper
@@ -278,11 +281,28 @@ sequenceDiagram
## 快速开始
### 环境要求
### 方式一Docker Compose推荐
```bash
# 1. 配置环境变量
cp .env.example .env
# 编辑 .env 设置 DB_PASSWORD 和 JWT_SECRET
# 2. 一键启动MySQL + Redis + 后端 + 前端)
docker-compose up -d
# 3. 访问
open http://localhost
```
> 首次启动 MySQL 会自动执行 `init.sql` 建表和数据。Redis 不可用时后端自动降级跳过缓存。
### 方式二:手动启动
**环境要求**
- JDK 21+ · Node.js 18+ · MySQL 8.0+ · Maven 3.9+
### 1. 初始化数据库
#### 1. 初始化数据库
```bash
mysql -u root -p < backend/src/main/resources/database/init.sql
@@ -340,9 +360,12 @@ npm run dev
MedicineManagerSystem/
├── README.md
├── .env.example
├── docker-compose.yml # Docker 编排
├── projectDesigning.md # 详细架构设计文档
├── frontend/ # Vue 3 SPA
│ ├── Dockerfile
│ ├── nginx.conf
│ └── src/
│ ├── api/ (11) # API 模块
│ ├── directives/ (1) # v-permission
@@ -350,10 +373,11 @@ MedicineManagerSystem/
│ ├── router/ (1) # 路由 + 动态菜单
│ ├── stores/ (2) # Pinia
│ ├── styles/ (1) # SCSS
│ ├── utils/ (1) # Axios 封装
│ ├── utils/ (2) # Axios · Redis 缓存
│ └── views/ (16) # 页面组件
└── backend/ # Spring Boot
├── Dockerfile
└── src/main/
├── java/com/kronecker/backend/
│ ├── common/ (4) # Result · 异常
@@ -363,7 +387,8 @@ MedicineManagerSystem/
│ ├── entity/ (15) # 数据库实体
│ ├── mapper/ (15) # MP Mapper
│ ├── security/ (3) # JWT
── service/ (23) # 业务逻辑
── service/ (23) # 业务逻辑
│ └── utils/ (1) # Redis 缓存
└── resources/
├── application.yml
└── database/init.sql # 建表 + 种子数据