# Cloud purchase **Repository Path**: deng-xianxing/cloud-purchase ## Basic Information - **Project Name**: Cloud purchase - **Description**: 【云购优选】 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-23 - **Last Updated**: 2025-10-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🛒 云购优选 (Cloud Purchase)
**一个基于Spring Cloud微服务架构的现代化电商平台** ![Spring Boot](https://img.shields.io/badge/Spring%20Boot-2.7.12-brightgreen.svg?style=for-the-badge&logo=springboot) ![Spring Cloud](https://img.shields.io/badge/Spring%20Cloud-2021.0.3-blue.svg?style=for-the-badge&logo=spring) ![Spring Cloud Alibaba](https://img.shields.io/badge/Spring%20Cloud%20Alibaba-2021.0.4.0-orange.svg?style=for-the-badge&logo=alibabacloud) ![Java](https://img.shields.io/badge/Java-11-red.svg?style=for-the-badge&logo=openjdk) ![MySQL](https://img.shields.io/badge/MySQL-8.0.23-blue.svg?style=for-the-badge&logo=mysql) ![Docker](https://img.shields.io/badge/Docker-Container-blue.svg?style=for-the-badge&logo=docker)

[![GitHub stars](https://img.shields.io/github/stars/your-username/cloud-purchase.svg?style=social&label=Star)](https://github.com/your-username/cloud-purchase) [![GitHub forks](https://img.shields.io/github/forks/your-username/cloud-purchase.svg?style=social&label=Fork)](https://github.com/your-username/cloud-purchase) [![GitHub watchers](https://img.shields.io/github/watchers/your-username/cloud-purchase.svg?style=social&label=Watch)](https://github.com/your-username/cloud-purchase)
--- ## 📋 目录
| 📖 导航 | 🎯 内容 | |---------|---------| | [🎯 项目简介](#-项目简介) | 项目概述和亮点 | | [✨ 核心特性](#-核心特性) | 功能和技术特性 | | [🏗️ 技术架构](#-技术架构) | 微服务架构设计 | | [📊 系统架构图](#-系统架构图) | 可视化架构图 | | [📁 项目结构](#-项目结构) | 代码组织结构 | | [🛠️ 技术栈](#-技术栈) | 技术选型详情 | | [🚀 快速开始](#-快速开始) | 安装运行指南 | | [📚 API文档](#-api文档) | 接口文档说明 | | [🐳 部署指南](#-部署指南) | 部署运维指南 | | [👨‍💻 开发指南](#-开发指南) | 开发规范指南 | | [🤝 贡献指南](#-贡献指南) | 开源协作指南 |
--- ## 🎯 项目简介 **云购优选**是一个基于Spring Cloud微服务架构的现代化电商平台,采用前后端分离的设计理念,为用户提供完整的在线购物体验。项目集成了用户管理、商品管理、购物车、订单处理、支付等核心电商功能,支持高并发、高可用的业务场景。 ### 🌟 项目亮点
| 🏗️ | 🔐 | 📊 | 🚀 | 📝 | 🐳 | |-----|-----|-----|-----|-----|-----| | **微服务架构** | **安全认证** | **服务治理** | **API网关** | **接口文档** | **容器化** | | 采用Spring Cloud生态,服务间松耦合,易于扩展 | 基于JWT的身份认证和授权机制 | 集成Nacos实现服务注册发现和配置管理 | 统一入口,路由转发,负载均衡 | 集成Knife4j,提供完整的API文档 | 支持Docker部署,便于运维管理 |
--- ## ✨ 核心特性 ### 🛍️ 电商功能 - **用户管理**:用户注册、登录、个人信息管理 - **商品管理**:商品展示、搜索、分类浏览 - **购物车**:商品添加、数量修改、批量操作 - **订单系统**:订单创建、状态跟踪、物流信息 - **支付系统**:多种支付方式,支付状态管理 - **地址管理**:收货地址的增删改查 ### 🔧 技术特性 - **微服务架构**:服务拆分,独立部署 - **服务注册发现**:基于Nacos的服务治理 - **配置中心**:统一配置管理,动态刷新 - **API网关**:路由转发,统一鉴权 - **数据库**:MySQL + MyBatis Plus - **缓存**:Redis缓存支持 - **日志管理**:结构化日志,便于监控 --- ## 🏗️ 技术架构 ### 微服务架构图 ```mermaid graph TB subgraph "客户端层" A[Web前端] --> B[移动端] end subgraph "网关层" C[API Gateway
Spring Cloud Gateway] end subgraph "微服务层" D[用户服务
User Service] E[商品服务
Item Service] F[购物车服务
Cart Service] G[订单服务
Trade Service] H[支付服务
Pay Service] end subgraph "基础设施层" I[Nacos
注册中心/配置中心] J[MySQL
数据库] K[Redis
缓存] end A --> C B --> C C --> D C --> E C --> F C --> G C --> H D --> I E --> I F --> I G --> I H --> I D --> J E --> J F --> J G --> J H --> J D --> K E --> K F --> K G --> K H --> K ``` --- ## 📁 项目结构 ``` cloud-purchase/ ├── 📁 hm-api/ # API接口定义 │ ├── src/main/java/com/hmall/ │ │ ├── client/ # Feign客户端 │ │ └── dto/ # 数据传输对象 │ └── pom.xml ├── 📁 hm-common/ # 公共组件 │ ├── src/main/java/com/hmall/ │ │ ├── config/ # 公共配置 │ │ ├── exception/ # 异常处理 │ │ ├── interceptor/ # 拦截器 │ │ └── utils/ # 工具类 │ └── pom.xml ├── 📁 hm-gateway/ # API网关 │ ├── src/main/java/com/heima/ │ │ └── gateway/ # 网关配置 │ └── pom.xml ├── 📁 hm-service/ # 主服务(单体应用) │ ├── src/main/java/com/hmall/ │ │ ├── controller/ # 控制器 │ │ ├── service/ # 业务服务 │ │ ├── mapper/ # 数据访问层 │ │ └── domain/ # 领域对象 │ ├── Dockerfile # Docker配置 │ └── pom.xml ├── 📁 user-service/ # 用户服务 ├── 📁 item-service/ # 商品服务 ├── 📁 cart-service/ # 购物车服务 ├── 📁 trade-service/ # 订单服务 ├── 📁 pay-service/ # 支付服务 ├── 📁 logs/ # 日志文件 └── 📄 pom.xml # 父级POM配置 ``` --- ## 🛠️ 技术栈 ### 后端技术 | 技术 | 版本 | 说明 | |------|------|------| | **Java** | 11 | 开发语言 | | **Spring Boot** | 2.7.12 | 基础框架 | | **Spring Cloud** | 2021.0.3 | 微服务框架 | | **Spring Cloud Alibaba** | 2021.0.4.0 | 阿里云微服务组件 | | **Nacos** | - | 服务注册发现、配置中心 | | **Spring Cloud Gateway** | - | API网关 | | **OpenFeign** | - | 服务间调用 | | **MyBatis Plus** | 3.4.2 | ORM框架 | | **MySQL** | 8.0.23 | 关系型数据库 | | **Hutool** | 5.8.11 | Java工具包 | | **Lombok** | 1.18.32 | 代码简化 | | **Knife4j** | - | API文档生成 | ### 开发工具 | 工具 | 说明 | |------|------| | **Maven** | 项目构建工具 | | **Docker** | 容器化部署 | | **Git** | 版本控制 | --- ## 🚀 快速开始 ### 环境要求
| 🛠️ 环境 | 📋 要求 | 📊 状态 | |---------|---------|---------| | **JDK** | 11+ | ✅ | | **Maven** | 3.6+ | ✅ | | **MySQL** | 8.0+ | ✅ | | **Nacos** | 2.0+ | ✅ |
### 1. 克隆项目 ```bash git clone https://github.com/your-username/cloud-purchase.git cd cloud-purchase ``` ### 2. 数据库配置 创建数据库并导入SQL脚本: ```sql -- 创建数据库 CREATE DATABASE hmall; CREATE DATABASE hm_user; CREATE DATABASE hm_item; CREATE DATABASE hm_cart; CREATE DATABASE hm_trade; CREATE DATABASE hm_pay; -- 导入对应的SQL脚本 ``` ### 3. 配置文件修改 修改各服务的数据库连接配置: ```yaml # application.yaml spring: datasource: url: jdbc:mysql://localhost:3306/hmall?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai username: root password: your_password ``` ### 4. 启动Nacos ```bash # 下载并启动Nacos sh startup.sh -m standalone ``` 访问:http://localhost:8848/nacos ### 5. 启动服务 ```bash # 启动网关 cd hm-gateway mvn spring-boot:run # 启动用户服务 cd user-service mvn spring-boot:run # 启动其他服务... ``` ### 6. 访问应用
| 🌐 服务 | 🔗 地址 | 📝 说明 | |---------|---------|---------| | **API网关** | http://localhost:8080 | 统一入口 | | **API文档** | http://localhost:8080/doc.html | 接口文档 | | **Nacos控制台** | http://localhost:8848/nacos | 服务治理 |
--- ## 📚 API文档 ### 接口概览
| 🎯 服务 | 🔌 端口 | 📡 主要接口 | |---------|---------|-------------| | **用户服务** | 8084 | `/users/**`, `/addresses/**` | | **商品服务** | 8081 | `/items/**`, `/search/**` | | **购物车服务** | 8082 | `/carts/**` | | **订单服务** | 8083 | `/orders/**` | | **支付服务** | 8085 | `/pay-orders/**` |
### 认证方式 项目使用JWT进行身份认证: ```bash # 登录获取token POST /users/login { "username": "your_username", "password": "your_password" } # 请求头携带token Authorization: Bearer your_jwt_token ``` ### 接口示例 #### 用户登录 ```http POST /users/login Content-Type: application/json { "username": "admin", "password": "123456" } ``` #### 获取商品列表 ```http GET /items?page=1&size=10&categoryId=1 Authorization: Bearer your_jwt_token ``` --- ## 🐳 部署指南 ### Docker部署 #### 1. 构建镜像 ```bash # 构建主服务镜像 cd hm-service docker build -t hm-service:latest . ``` #### 2. Docker Compose部署 创建 `docker-compose.yml`: ```yaml version: '3.8' services: mysql: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: 123456 MYSQL_DATABASE: hmall ports: - "3306:3306" volumes: - mysql_data:/var/lib/mysql nacos: image: nacos/nacos-server:v2.0.3 environment: MODE: standalone ports: - "8848:8848" hm-service: image: hm-service:latest ports: - "8080:8080" depends_on: - mysql - nacos volumes: mysql_data: ``` #### 3. 启动服务 ```bash docker-compose up -d ``` ### 生产环境部署 1. **服务器配置**:建议4核8G以上配置 2. **负载均衡**:使用Nginx进行负载均衡 3. **监控告警**:集成Prometheus + Grafana 4. **日志收集**:使用ELK Stack --- ## 👨‍💻 开发指南 ### 开发环境搭建 1. **IDE配置**:推荐使用IntelliJ IDEA 2. **代码规范**:遵循阿里巴巴Java开发手册 3. **Git规范**:使用Git Flow工作流 ### 代码结构说明 ``` src/main/java/com/hmall/ ├── controller/ # 控制器层 ├── service/ # 业务服务层 ├── mapper/ # 数据访问层 ├── domain/ # 领域对象 │ ├── dto/ # 数据传输对象 │ ├── po/ # 持久化对象 │ ├── vo/ # 视图对象 │ └── query/ # 查询对象 ├── config/ # 配置类 ├── interceptor/ # 拦截器 └── utils/ # 工具类 ``` ### 开发规范 - **命名规范**:使用驼峰命名法 - **注释规范**:类和方法必须添加注释 - **异常处理**:统一异常处理机制 - **日志规范**:使用SLF4J + Logback --- ## 🤝 贡献指南 我们欢迎所有形式的贡献! ### 如何贡献 1. **Fork** 本仓库 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`) 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`) 4. 推送到分支 (`git push origin feature/AmazingFeature`) 5. 创建 **Pull Request** ### 贡献类型
| 🐛 | ✨ | 📚 | 🎨 | 🧪 | |-----|-----|-----|-----|-----| | **Bug修复** | **新功能开发** | **文档完善** | **代码优化** | **测试用例** |
---
**⭐ 如果这个项目对你有帮助,请给它一个星标!** Made with ❤️ by Your Name