# SmartDBSystem-boot **Repository Path**: eleven-lxs/smart-dbsystem ## Basic Information - **Project Name**: SmartDBSystem-boot - **Description**: SmartDBSystem 是一个集成了AI能力的现代化数据库管理系统,在人人开源 https://gitee.com/renrenio/renren-security 项目基础上增加,基于Spring Boot 3 + Vue 3构建。系统不仅提供了传统的数据库连接管理、代码生成等功能,还创新性地融合了通义千问AI大模型和RAG向量检索技术,为开发者提供智能化的数据库管理。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: https://eleven-lxs.blog.csdn.net/ - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-01 - **Last Updated**: 2026-01-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: SpringBoot, langchain4j, Java, MySQL, MongoDB ## README # SmartDBSystem - AI数据库管理系统
**一个基于AI驱动的智能数据库管理系统** [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.5.4-brightgreen.svg)](https://spring.io/projects/spring-boot) [![Vue](https://img.shields.io/badge/Vue-3.x-green.svg)](https://vuejs.org/) [![LangChain4j](https://img.shields.io/badge/LangChain4j-1.0.0--beta3-orange.svg)](https://github.com/langchain4j/langchain4j) [![Gitee](https://img.shields.io/badge/Gitee-SmartDBSystem-red.svg)](https://gitee.com/eleven-lxs/smart-dbsystem)
--- ## 项目简介 **SmartDBSystem** 是一个集成了AI能力的现代化数据库管理系统,在人人开源 https://gitee.com/renrenio/renren-security 项目基础上增加,基于Spring Boot 3 + Vue 3构建。系统不仅提供了传统的数据库连接管理、代码生成等功能,还创新性地融合了**通义千问AI大模型**和**RAG向量检索技术**,为开发者提供智能化的数据库管理和代码生成体验。 前端地址: https://gitee.com/eleven-lxs/smart-dbsystem-vue3 ### 核心特性 - **AI智能助手**: 集成通义千问3-Coder-Plus模型,支持流式对话、代码生成、智能问答 - **多数据库支持**: 完美支持MySQL、Redis、MongoDB、Oracle、PostgreSQL、SQL Server、达梦等主流数据库 - **低代码开发**: 可视化代码生成器,自动生成70%+代码,大幅提升开发效率 - **向量检索**: 集成Pinecone向量数据库,实现RAG(检索增强生成) - **策略模式架构**: 采用策略模式+工厂模式,轻松扩展新数据库类型 - **权限控制**: 基于Shiro的细粒度权限控制,可精确到按钮级别 - **前后端分离**: Token-based认证,Vue3 + Spring Boot完全分离 - **云存储支持**: 内置七牛云、阿里云OSS、腾讯云COS集成 --- ## 功能展示 ### 1. AI智能助手 集成通义千问AI大模型,提供智能对话、代码生成、数据库查询建议等功能: - 流式对话体验(Server-Sent Events) - 上下文感知的智能回复 - 代码审查和优化建议 - 对话历史记录(MongoDB存储) - RAG向量检索增强 ### 2. 数据库连接管理 支持多种主流数据库的可视化管理: - **MySQL**: 表结构查看、数据查询、字段增删改 - **Redis**: Key扫描、类型检测、Hash/List/Set/ZSet操作 - **MongoDB**: 集合浏览、文档查询 - 连接测试、连接池管理 - 动态数据源切换 ### 3. 智能代码生成器 基于Velocity模板引擎,一键生成完整的增删改查代码: - Entity(实体类) - Dao/Mapper(数据访问层) - Service/ServiceImpl(业务逻辑层) - Controller(控制器) - DTO/VO(数据传输对象) - Vue页面(index.vue + add-or-update.vue) - MyBatis XML映射文件 ### 4. 系统管理 完善的后台管理功能: - 用户管理(支持部门隔离) - 角色管理(灵活的权限绑定) - 菜单管理(动态菜单配置) - 部门管理(树形结构) - 字典管理(系统参数配置) - 操作日志、登录日志、错误日志 ### 5. 定时任务 基于Quartz的动态定时任务管理: - 在线添加/修改任务 - 动态启动/停止/暂停 - 任务执行日志查看 - Cron表达式配置 --- ## 技术架构 ### 后端技术栈 | 技术 | 版本 | 说明 | |------|------|------| | Spring Boot | 3.5.4 | 核心框架 | | Apache Shiro | 1.12.0 | 安全认证框架 | | MyBatis-Plus | 3.5.8 | ORM框架 | | LangChain4j | 1.0.0-beta3 | AI应用框架 | | Quartz | 2.3.2 | 定时任务 | | Druid | 1.2.23 | 数据库连接池 | | HikariCP | 6.3.2 | 高性能连接池 | | Redis | Lettuce/Jedis 5.1.2 | 缓存 | | MongoDB | 5.5.1 | NoSQL数据库 | | Hutool | 5.8.29 | Java工具类库 | | Knife4j | 4.5.0 | API文档 | | EasyExcel | 3.2.1 | Excel处理 | ### 前端技术栈 | 技术 | 说明 | |------|------| | Vue 3.x | 渐进式JavaScript框架 | | TypeScript | JavaScript超集 | | Element Plus | UI组件库 | | Vue Router | 路由管理 | | Pinia | 状态管理 | | Axios | HTTP客户端 | | Vite | 构建工具 | ### AI技术栈 | 技术 | 说明 | |------|------| | 通义千问3-Coder-Plus | 阿里云代码生成模型 | | Text-embedding-v3 | 文本向量化模型 | | Pinecone | 向量数据库 | | LangChain4j | Java版LangChain框架 | --- ## 项目结构 ``` SmartDBSystem-boot/ ├── smartdb-common/ # 公共通用模块 │ ├── aspect/ # AOP切面 │ ├── config/ # 通用配置 │ ├── exception/ # 异常处理 │ ├── page/ # 分页封装 │ ├── utils/ # 工具类 │ └── validator/ # 校验器 │ ├── smartdb-dynamic-datasource/ # 动态数据源模块 │ ├── aspect/ # 数据权限切面 │ ├── config/ # 数据源配置 │ └── interceptor/ # 拦截器 │ ├── smartdb-admin/ # 管理后台(主应用) │ ├── src/main/java/io/smartdb/ │ │ ├── AdminApplication.java # 启动类 │ │ ├── common/ # 通用模块 │ │ │ ├── config/ # 配置类 │ │ │ ├── interceptor/ # 拦截器 │ │ │ └── utils/ # 工具类 │ │ └── modules/ # 业务模块 │ │ ├── ai/ # AI智能助手 │ │ │ ├── assistant/ # AI助手实现 │ │ │ ├── config/ # AI配置 │ │ │ ├── controller/ # AI控制器 │ │ │ └── repository/ # MongoDB仓库 │ │ ├── db/ # 数据库管理 │ │ │ ├── controller/ # 数据库控制器 │ │ │ ├── entity/ # 实体类 │ │ │ ├── service/ # 服务接口 │ │ │ ├── strategy/ # 策略实现 │ │ │ │ ├── DbConnectStrategy.java # 策略接口 │ │ │ │ ├── DbConnectStrategyFactory.java # 工厂类 │ │ │ │ ├── MysqlConnectStrategy.java # MySQL策略 │ │ │ │ └── RedisConnectStrategy.java # Redis策略 │ │ │ └── vo/ # 视图对象 │ │ ├── generator/ # 代码生成器 │ │ ├── job/ # 定时任务 │ │ ├── log/ # 日志管理 │ │ ├── oss/ # 文件存储 │ │ ├── security/ # 安全模块 │ │ └── sys/ # 系统管理 │ ├── src/main/resources/ │ │ ├── application.yml # 主配置文件 │ │ ├── application-dev.yml # 开发环境配置 │ │ ├── application-prod.yml # 生产环境配置 │ │ ├── mapper/ # MyBatis映射文件 │ │ ├── template/ # Velocity模板 │ │ ├── prompts/ # AI提示词配置 │ │ └── db/mysql/ # 数据库脚本 │ └── db/mysql/smartdbsystem.sql # MySQL初始化脚本 │ ├── smartdb-api/ # API服务模块 ├── smartdb-generator/ # 代码生成器模块 ├── docker-compose.yml # Docker编排 └── pom.xml # 根POM配置 ``` --- ## 快速开始 ### 环境要求 - **JDK**: 17+ - **Maven**: 3.6+ - **MySQL**: 8.0+ (推荐) - **Redis**: 5.0+ (可选,用于缓存) - **MongoDB**: 4.0+ (可选,用于AI对话记录) - **Node.js**: 16+ (前端开发) ### 后端部署 #### 1. 克隆项目 ```bash git clone https://gitee.com/eleven-lxs/smart-dbsystem.git cd SmartDBSystem-boot ``` #### 2. 创建数据库 ```sql CREATE DATABASE smartdbsystem DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ``` #### 3. 导入SQL脚本 ```bash mysql -u root -p smartdbsystem < smartdb-admin/db/mysql/smartdbsystem.sql ``` #### 4. 修改配置文件 编辑 `smartdb-admin/src/main/resources/application-dev.yml`: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/smartdbsystem?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: your_password ``` #### 5. 配置AI功能(可选) 如需使用AI助手功能,需要配置通义千问API密钥: ```yaml langchain4j: qwen: chat-model: api-key: sk-your-api-key-here model-name: qwen3-coder-plus ``` 还需要去申请一个pinecone的apikey进行替换: ```yaml # Pinecone向量数据库配置 pinecone: api-key: ${PINECONE_API_KEY} index-name: vend namespace: machine region: us-east-1 ``` #### 6. 编译运行 ```bash # 编译项目 mvn clean install # 运行主应用 cd smartdb-admin mvn spring-boot:run ``` #### 7. 访问系统 - 后台地址: [http://localhost:8080/smartdb-admin](http://localhost:8080/smartdb-admin) - API文档: [http://localhost:8080/smartdb-admin/doc.html](http://localhost:8080/smartdb-admin/doc.html) - Druid监控: [http://localhost:8080/smartdb-admin/druid/](http://localhost:8080/smartdb-admin/druid/) - 默认账号: `admin / admin` ### 前端部署 ```bash cd smartdb-ui npm install npm run dev ``` 访问: [http://localhost:5173](http://localhost:5173) ### Docker部署 ```bash docker-compose up -d ``` --- ## 核心功能详解 ### 策略模式 + 工厂模式架构 系统采用策略模式和工厂模式设计数据库连接管理,使得扩展新数据库类型变得非常简单: ```java // 策略接口 public interface DbConnectStrategy { Result testConnection(DbConnectEntity dbConnect); List> getTables(DbConnectEntity dbConnect); List> queryData(DbConnectEntity dbConnect, String sql); } // 工厂类 public class DbConnectStrategyFactory { public static DbConnectStrategy getStrategy(String dbType) { // 根据数据库类型返回对应策略 } } // 使用示例 DbConnectStrategy strategy = DbConnectStrategyFactory.getStrategy("mysql"); Result result = strategy.testConnection(dbConnect); ``` ### AI智能助手实现 基于LangChain4j框架实现的AI助手: ```java @Service public interface AIAgent { Flux chat(String userId, String message); } // 配置通义千问模型 ChatLanguageModel chatModel = QwenChatModel.builder() .apiKey(apiKey) .modelName("qwen3-coder-plus") .temperature(0.7) .maxTokens(4096) .build(); ``` ### 数据权限控制 通过AOP实现部门级别的数据权限控制: ```java @DataFilter(tableAlias = "t1", deptId = "dept_id") public PageData page(Map params) { // 自动过滤非本部门数据 } ``` --- ## 数据库设计 ### 核心表结构 | 表名 | 说明 | |------|------| | db_connect | 数据库连接配置表 | | ai_code_snippets | AI代码片段表 | | sys_user | 系统用户表 | | sys_role | 角色表 | | sys_menu | 菜单表 | | sys_dept | 部门表 | | sys_dict_type | 字典类型表 | | sys_dict_data | 字典数据表 | | sys_log_login | 登录日志表 | | sys_log_operation | 操作日志表 | | sys_log_error | 错误日志表 | | schedule_job | 定时任务表 | | qrtz_* | Quartz相关表(16张) | --- ## 数据库支持 | 数据库类型 | 支持程度 | 连接池 | 特殊功能 | |-----------|---------|--------|---------| | MySQL | 完整支持 | HikariCP | 字段增删改、表结构查看 | | Redis | 完整支持 | Lettuce | SCAN遍历、类型检测、分页 | | MongoDB | 基础支持 | 原生连接 | 集合查询、文档操作 | | PostgreSQL | 支持 | HikariCP | 兼容JDBC标准 | | Oracle | 支持 | HikariCP | 兼容JDBC标准 | | SQL Server | 支持 | HikariCP | 兼容JDBC标准 | | 达梦(DM) | 支持 | HikariCP | 国产数据库适配 | --- ## API接口 ### 数据库管理接口 | 接口 | 方法 | 路径 | 说明 | |------|------|------|------| | 连接测试 | POST | /db/connect/test | 测试数据库连接 | | 保存连接 | POST | /db/connect/save | 保存连接配置 | | 查询表列表 | GET | /db/connect/tables | 获取数据库表列表 | | 查询数据 | POST | /db/connect/query | 执行SQL查询 | | 字段管理 | POST | /db/field/add | 添加字段 | ### AI智能助手接口 | 接口 | 方法 | 路径 | 说明 | |------|------|------|------| | 流式对话 | POST | /ai/chat | SSE流式对话 | | 历史记录 | GET | /ai/history | 获取对话历史 | ### 系统管理接口 | 接口 | 方法 | 路径 | 说明 | |------|------|------|------| | 用户列表 | GET | /sys/user/page | 分页查询用户 | | 角色列表 | GET | /sys/role/page | 分页查询角色 | | 菜单列表 | GET | /sys/menu/list | 获取菜单树 | 完整API文档请访问: [Knife4j文档](http://localhost:8080/smartdb-admin/doc.html) --- ## 配置说明 ### 主配置文件 (application.yml) ```yaml server: port: 8080 servlet: context-path: /smartdb-admin spring: profiles: active: dev # MongoDB配置(AI对话存储) data: mongodb: uri: mongodb://mongo:mongo@localhost:27017/smartdbsystem # Redis配置(缓存) data: redis: host: localhost port: 6379 password: database: 0 # AI配置 langchain4j: qwen: chat-model: api-key: ${QWEN_API_KEY} model-name: qwen3-coder-plus temperature: 0.7 max-tokens: 4096 # Pinecone向量数据库配置 pinecone: api-key: ${PINECONE_API_KEY} index-name: vend namespace: machine region: us-east-1 ``` ### 开发环境配置 (application-dev.yml) ```yaml spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/smartdbsystem?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: your_password # 连接池配置 initial-size: 10 max-active: 100 min-idle: 10 max-wait: 60000 ``` --- ## 开发指南 ### 如何扩展新的数据库类型 1. 实现 `DbConnectStrategy` 接口: ```java @Component public class PostgresqlConnectStrategy implements DbConnectStrategy { @Override public Result testConnection(DbConnectEntity dbConnect) { // 实现连接测试逻辑 } @Override public List> getTables(DbConnectEntity dbConnect) { // 实现获取表列表逻辑 } @Override public List> queryData(DbConnectEntity dbConnect, String sql) { // 实现数据查询逻辑 } } ``` 2. 在工厂类中注册新策略: ```java public class DbConnectStrategyFactory { public static DbConnectStrategy getStrategy(String dbType) { return switch (dbType.toLowerCase()) { case "mysql" -> new MysqlConnectStrategy(); case "redis" -> new RedisConnectStrategy(); case "postgresql" -> new PostgresqlConnectStrategy(); // 新增 default -> throw new IllegalArgumentException("不支持的数据库类型: " + dbType); }; } } ``` ### 如何自定义代码生成模板 1. 进入模板目录: `smartdb-admin/src/main/resources/template/` 2. 修改或新增 `.vm` 文件 3. 在 `generator.properties` 中配置模板参数 4. 使用代码生成器生成代码 --- ## 性能优化 ### 数据库连接池优化 - 使用HikariCP作为主连接池(高性能) - Druid作为监控连接池 - 合理配置连接池参数 ### Redis缓存优化 - 使用Lettuce连接池 - 支持集群模式 - 合理设置过期时间 ### MyBatis-Plus优化 - 启用二级缓存 - 使用分页插件 - 开启SQL性能分析 --- ## 安全特性 - **XSS防护**: Jsoup脚本过滤 - **CSRF防护**: Token验证 - **SQL注入防护**: MyBatis预编译 - **权限控制**: Shiro细粒度权限 - **密码加密**: BCrypt加密存储 - **接口限流**: Redis + AOP实现 - **操作日志**: 记录所有敏感操作 --- ## 更新日志 ### v5.5.0 (Latest) - [新增] AI智能助手模块 - [新增] MySQL字段增删改功能 - [完善] Redis数据类型查询(Hash、List) - [优化] 整体架构(策略模式+工厂模式) - [升级] Spring Boot 3.5.4 - [升级] MyBatis-Plus 3.5.8 ### v5.0.0 - [新增] 数据库连接管理 - [新增] 代码生成器 - [新增] 系统管理模块 - [新增] 定时任务模块 --- ## 常见问题 ### 1. 如何配置AI功能? 需要申请通义千问API密钥,并在配置文件中设置: ```yaml langchain4j: qwen: chat-model: api-key: sk-your-api-key ``` ### 2. 如何添加新的数据库类型? 参考"开发指南"章节,实现 `DbConnectStrategy` 接口即可。 ### 3. 代码生成器生成的代码在哪里? 默认生成到 `target/generated-sources` 目录,可在生成器配置中修改。 ### 4. 如何启用Redis缓存? 在 `application.yml` 中设置: ```yaml smartdb: redis: open: true ``` --- ## 贡献指南 欢迎贡献代码!请遵循以下步骤: 1. Fork本仓库 2. 创建特性分支: `git checkout -b feature/AmazingFeature` 3. 提交更改: `git commit -m 'Add some AmazingFeature'` 4. 推送到分支: `git push origin feature/AmazingFeature` 5. 提交Pull Request ### 代码规范 - 遵循阿里巴巴Java开发手册 - 使用统一的代码格式化配置 - 编写单元测试 - 添加必要的注释 --- ### 代码仓库 - Gitee: [https://gitee.com/eleven-lxs/smart-dbsystem](https://gitee.com/eleven-lxs/smart-dbsystem) ### 问题反馈 - 提交Issue: [Gitee Issues](https://gitee.com/eleven-lxs/smart-dbsystem/issues) --- ## 致谢 感谢以下开源项目: - [Spring Boot](https://spring.io/projects/spring-boot) - [MyBatis-Plus](https://baomidou.com/) - [Vue.js](https://vuejs.org/) - [Element Plus](https://element-plus.org/) - [LangChain4j](https://github.com/langchain4j/langchain4j) - [Apache Shiro](https://shiro.apache.org/) - [Hutool](https://hutool.cn/) --- ## 项目截图 ![数据库展示](smartdb-common/src/main/resources/assets/数据库展示.png) ![数据库展示1](smartdb-common/src/main/resources/assets/数据库展示1.png) ![数据库展示2](smartdb-common/src/main/resources/assets/数据库展示2.png) ![数据库展示3](smartdb-common/src/main/resources/assets/数据库展示3.png) ![数据库展示4](smartdb-common/src/main/resources/assets/数据库展示4.png) ![数据库展示5](smartdb-common/src/main/resources/assets/数据库展示5.png) ![数据库展示6](smartdb-common/src/main/resources/assets/数据库展示6.png) ![数据库展示7](smartdb-common/src/main/resources/assets/数据库展示7.png) --- **如果这个项目对你有帮助,请给个Star支持一下!**