# 浪兎兎-Cloud **Repository Path**: huyiming52/ltt-cloud ## Basic Information - **Project Name**: 浪兎兎-Cloud - **Description**: 浪兎兎脚手架 - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-23 - **Last Updated**: 2025-06-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LTT-Cloud 微服务云平台 一个基于Spring Cloud Alibaba的微服务云平台,包含认证授权、代码生成、性能监测等功能。 ## 项目结构 ``` LTT-Cloud/ ├── docs/ # 文档和SQL脚本 │ ├── ltt-cloud-schema.sql # 业务数据库脚本 │ └── nacos-schema.sql # Nacos配置中心数据库脚本 ├── ltt-cloud-api/ # API模块(实体类和DTO) ├── ltt-cloud-auth/ # 认证授权模块 ├── ltt-cloud-codegen/ # 代码生成模块 ├── ltt-cloud-common/ # 公共模块(工具类和通用组件) ├── ltt-cloud-framework/ # 框架模块(性能监测等) ├── ltt-cloud-gateway/ # 网关模块 ├── ltt-cloud-service/ # 业务服务模块 │ └── ltt-cloud-service-system/ # 系统管理服务 ├── ltt-cloud-ui/ # 前端UI模块(Nuxt.js) └── pom.xml # 父POM文件 ``` ## 技术栈 ### 后端技术栈 - **Spring Boot 2.7.x** - 基础框架 - **Spring Cloud Alibaba** - 微服务框架 - **Spring Security** - 安全框架 - **MyBatis-Plus** - 数据持久层 - **MySQL** - 关系型数据库 - **Redis** - 缓存和会话存储 - **JWT** - 无状态认证 - **Nacos** - 服务注册发现和配置中心 - **Freemarker** - 模板引擎(代码生成) - **Maven** - 项目管理工具 ### 前端技术栈 - **Nuxt.js 3** - Vue.js全栈框架 - **TypeScript** - 类型安全的JavaScript - **Tailwind CSS** - 实用优先的CSS框架 ## 功能特性 ### 1. 认证授权模块 (ltt-cloud-auth) - ✅ JWT + Redis 无状态认证 - ✅ 用户注册/登录/登出 - ✅ Token刷新机制 - ✅ 密码加密存储 - ✅ 用户状态管理 **API接口:** - `POST /auth/login` - 用户登录 - `POST /auth/register` - 用户注册 - `POST /auth/logout` - 用户登出 - `POST /auth/refresh` - 刷新Token - `GET /auth/validate` - 验证Token ### 2. 代码生成模块 (ltt-cloud-codegen) - ✅ 数据库表结构扫描 - ✅ 自动生成Entity、Repository、Service、Controller - ✅ 支持自定义模板 - ✅ 代码预览和下载 - ✅ 批量代码生成 **API接口:** - `GET /codegen/tables` - 获取数据库表列表 - `GET /codegen/columns/{tableName}` - 获取表字段信息 - `POST /codegen/preview` - 预览生成的代码 - `POST /codegen/generate` - 生成代码 - `POST /codegen/download` - 下载生成的代码 ### 3. 性能监测模块 (ltt-cloud-framework) - ✅ AOP切面性能监控 - ✅ 方法执行时间统计 - ✅ 慢查询检测 - ✅ 超时监控 - ✅ Redis存储监控数据 **API接口:** - `GET /performance/stats` - 获取性能统计 - `GET /performance/history/{methodName}` - 获取方法调用历史 - `GET /performance/slow` - 获取慢查询列表 - `DELETE /performance/history` - 清理历史数据 ### 4. 公共模块 (ltt-cloud-common) - ✅ Redis工具类 - ✅ JWT工具类 - ✅ 统一响应格式 - ✅ 错误码定义 ## 快速开始 ### 环境要求 - JDK 8+ - Maven 3.6+ - MySQL 8.0+ - Redis 6.0+ - Nacos 2.0+ - Node.js 18+ (前端) ### 1. 数据库初始化 ```sql -- 创建业务数据库 CREATE DATABASE ltt_cloud DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- 创建Nacos配置中心数据库 CREATE DATABASE nacos_config DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- 执行SQL脚本 -- docs/ltt-cloud-schema.sql -- docs/nacos-schema.sql ``` ### 2. 启动Nacos服务 ```bash # 下载并启动Nacos cd nacos/bin ./startup.sh -m standalone ``` ### 3. 配置Nacos 在Nacos控制台创建配置文件: - `ltt-cloud-common.yml` - 公共配置 - `ltt-cloud-auth.yml` - 认证模块配置 - `ltt-cloud-gateway.yml` - 网关配置 - `ltt-cloud-system.yml` - 系统服务配置 ### 4. 启动后端服务 ```bash # 编译项目 mvn clean install # 启动各个模块(按顺序) # 1. 启动认证模块 cd ltt-cloud-auth mvn spring-boot:run # 2. 启动代码生成模块 cd ltt-cloud-codegen mvn spring-boot:run # 3. 启动系统服务 cd ltt-cloud-service/ltt-cloud-service-system mvn spring-boot:run # 4. 启动网关 cd ltt-cloud-gateway mvn spring-boot:run ``` ### 5. 启动前端服务 ```bash cd ltt-cloud-ui npm install npm run dev ``` ## 配置说明 ### 数据库配置 ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/ltt_cloud username: root password: 123456 ``` ### Redis配置 ```yaml spring: redis: host: localhost port: 6379 password: database: 0 ``` ### Nacos配置 ```yaml spring: cloud: nacos: discovery: server-addr: localhost:8848 config: server-addr: localhost:8848 file-extension: yml ``` ## 使用示例 ### 1. 用户认证 ```bash # 用户注册 curl -X POST http://localhost:8081/auth/register \ -H "Content-Type: application/json" \ -d '{ "username": "admin", "password": "123456", "email": "admin@example.com" }' # 用户登录 curl -X POST http://localhost:8081/auth/login \ -H "Content-Type: application/json" \ -d '{ "username": "admin", "password": "123456" }' ``` ### 2. 代码生成 ```bash # 获取数据库表列表 curl -X GET http://localhost:8083/codegen/tables # 生成代码 curl -X POST http://localhost:8083/codegen/generate \ -H "Content-Type: application/json" \ -d '{ "tableName": "sys_user", "className": "User", "packageName": "com.sssre.lttcloud.system" }' ``` ### 3. 性能监控 ```bash # 获取性能统计 curl -X GET http://localhost:8084/performance/stats # 获取慢查询 curl -X GET http://localhost:8084/performance/slow?threshold=1000 ``` ## 开发指南 ### 添加性能监控 在需要监控的方法上添加注解: ```java @PerformanceMonitor(description = "用户登录", timeout = 5000) public Result login(String username, String password) { // 业务逻辑 } ``` ### 自定义代码生成模板 在 `ltt-cloud-codegen/src/main/resources/templates/` 目录下添加或修改模板文件。 ### 扩展业务模块 1. 在 `ltt-cloud-service` 下创建新的服务模块 2. 在 `ltt-cloud-api` 中添加相关实体和DTO 3. 配置Nacos服务注册 4. 在网关中添加路由配置 ## 部署说明 ### Docker部署 ```bash # 构建镜像 mvn clean package docker:build # 启动容器 docker-compose up -d ``` ### 生产环境配置 1. 修改数据库连接配置 2. 配置Redis集群 3. 配置Nacos集群 4. 设置JWT密钥 5. 配置日志级别 ## 常见问题 ### 1. Redis连接失败 检查Redis服务是否启动,以及连接配置是否正确。 ### 2. Nacos连接失败 确保Nacos服务正常运行,检查网络连接和配置。 ### 3. 代码生成失败 检查数据库连接和表结构,确保有足够的权限。 ### 4. 性能监控数据不显示 检查Redis连接和AOP配置是否正确。 ## 贡献指南 1. Fork 项目 2. 创建功能分支 3. 提交代码 4. 创建 Pull Request ## 许可证 MIT License ## 联系方式 - 项目地址:https://github.com/your-username/LTT-Cloud - 问题反馈:https://github.com/your-username/LTT-Cloud/issues