Commit 2e58e8585eafad6425d6e2513cc3e31b603ccd66
Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into sms_temp_zzf_0127
Conflicts: pom.xml src/main/java/cn/iocoder/dashboard/framework/redis/core/RedisKeyDefine.java src/main/java/cn/iocoder/dashboard/framework/redis/core/RedisKeyRegistry.java src/main/java/cn/iocoder/dashboard/framework/security/config/SecurityConfiguration.java src/main/java/cn/iocoder/dashboard/modules/infra/controller/redis/RedisController.java src/main/java/cn/iocoder/dashboard/modules/system/dal/redis/RedisKeyConstants.java src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java
Showing
546 changed files
with
21836 additions
and
14475 deletions
Too many changes.
To preserve performance only 100 of 546 files are displayed.
README.md
| 1 | 1 | ## 平台简介 |
| 2 | 2 | |
| 3 | -**芋道** 是基于 [RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue) **重构**,一套**全部开源**的**企业级**的快速开发平台,毫无保留给个人及企业免费使用。 | |
| 3 | +**芋道**,一套**全部开源**的**企业级**的快速开发平台,毫无保留给个人及企业免费使用。 | |
| 4 | 4 | |
| 5 | 5 | > 有任何问题,或者想要的功能,可以在 _Issues_ 中提给艿艿。 |
| 6 | 6 | |
| 7 | 7 | * 前端采用 [vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)。 |
| 8 | 8 | * 后端采用 Spring Boot、MySQL、Redis。 |
| 9 | -* 权限认证使用 Spring Security & JWT,支持多终端认证系统。 | |
| 9 | +* 权限认证使用 Spring Security & Token,支持多终端认证系统。 | |
| 10 | 10 | * 支持加载动态权限菜单,多方式轻松权限控制。 |
| 11 | 11 | * 高效率开发,使用代码生成器可以一键生成前后端代码。 |
| 12 | 12 | |
| 13 | 13 | ## 内置功能 |
| 14 | 14 | |
| 15 | -分成 **业务** 和 **技术** 两类内置功能。 | |
| 16 | - | |
| 17 | -### 业务功能 | |
| 18 | - | |
| 19 | -1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。 | |
| 20 | -2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。 | |
| 21 | -3. 岗位管理:配置系统用户所属担任职务。 | |
| 22 | -4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。 | |
| 23 | -5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。 | |
| 24 | -6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。 | |
| 25 | -7. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。 | |
| 26 | -8. 登录日志:系统登录日志记录查询包含登录异常。 | |
| 27 | -9. 在线用户:当前系统中活跃用户状态监控。 | |
| 28 | -10. 通知公告:系统通知公告信息发布维护。 | |
| 29 | - | |
| 30 | -## 技术功能 | |
| 31 | - | |
| 32 | -1. 配置管理:对系统动态配置常用参数。 | |
| 33 | -2. 定时任务:在线(添加、修改、删除)任务调度包含执行结果日志。 | |
| 34 | -3. 代码生成:前后端代码的生成(java、html、xml、sql)支持CRUD下载 。 | |
| 35 | -4. 系统接口:根据业务代码自动生成相关的api接口文档。 | |
| 36 | -5. 服务监控:监视当前系统CPU、内存、磁盘、堆栈等相关信息。 | |
| 37 | -6. 在线构建器:拖动表单元素生成相应的HTML代码。 | |
| 38 | -7. 连接池监视:监视当前系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈。 | |
| 39 | - | |
| 40 | - | |
| 15 | +分成三种内置功能: | |
| 16 | +* 系统功能 | |
| 17 | +* 基础设施 | |
| 18 | +* 研发工具 | |
| 19 | + | |
| 20 | +> 友情提示:本项目基于 RuoYi-Vue 修改,**重构优化**后端的代码,**美化**前端的界面。 | |
| 21 | +> | |
| 22 | +> 额外新增的功能,我们使用 🚀 标记。 | |
| 23 | + | |
| 24 | +🙂 所有功能,都通过 **单元测试** 保证高质量。 | |
| 25 | + | |
| 26 | +### 系统功能 | |
| 27 | + | |
| 28 | + | |
| 29 | +| | 功能 | 描述 | | |
| 30 | +| --- | --- | --- | | |
| 31 | +| | 用户管理 | 用户是系统操作者,该功能主要完成系统用户配置 | | |
| 32 | +| | 在线用户 | 当前系统中活跃用户状态监控,支持手动踢下线 | | |
| 33 | +| | 角色管理 | 角色菜单权限分配、设置角色按机构进行数据范围权限划分 | | |
| 34 | +| | 菜单管理 | 配置系统菜单,操作权限,按钮权限标识等 | | |
| 35 | +| | 部门管理 | 配置系统组织机构(公司、部门、小组),树结构展现支持数据权限 | | |
| 36 | +| | 岗位管理 | 配置系统用户所属担任职务 | | |
| 37 | +| | 字典管理 | 对系统中经常使用的一些较为固定的数据进行维护 | | |
| 38 | +| | 通知公告 | 系统通知公告信息发布维护 | | |
| 39 | +| 🚀 | 操作日志 | 系统正常操作日志记录和查询,集成 Swagger 生成日志内容 | | |
| 40 | +| | 登录日志 | 系统登录日志记录查询包含登录异常 | | |
| 41 | + | |
| 42 | +计划新增功能: | |
| 43 | +* 短信 | |
| 44 | +* 邮件 | |
| 45 | +* 钉钉、飞书等通知 | |
| 46 | + | |
| 47 | +### 基础设施 | |
| 48 | + | |
| 49 | +| | 功能 | 描述 | | |
| 50 | +| --- | --- | --- | | |
| 51 | +| 🚀 | 配置管理 | 对系统动态配置常用参数,支持 SpringBoot 加载 | | |
| 52 | +| | 定时任务 | 在线(添加、修改、删除)任务调度包含执行结果日志 | | |
| 53 | +| 🚀 | 文件服务 | 支持本地文件存储,同时支持兼容 Amazon S3 协议的云服务、开源组件 | | |
| 54 | +| 🚀 | API 日志 | 包括 RESTful API 访问日志、异常日志两部分,方便排查 API 相关的问题 | | |
| 55 | +| | MySQL 监控 | 监视当前系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈 | | |
| 56 | +| | Redis 监控 |监控 Redis 数据库的使用情况,使用的 Redis Key 管理 | | |
| 57 | +| 🚀 |Java 监控 | 基于 Spring Boot Admin 实现 Java 应用的监控 | | |
| 58 | +| 🚀 | 链路追踪 | 基于 SkyWalking 实现性能监控,特别是链路的追踪 | | |
| 59 | +| 🚀 | 分布式锁 | 基于 Redis 实现分布式锁,满足并发场景 | | |
| 60 | +| 🚀 | 幂等组件 | 基于 Redis 实现幂等组件,解决重复请求问题 | | |
| 61 | +| 🚀 | 服务保障 | 基于 Resilience4j 实现服务的稳定性,包括限流、熔断等功能 | | |
| 62 | +| 🚀 | 日志服务 | 轻量级日志中心,查看远程服务器的日志 | | |
| 63 | +| 🚀 | 单元测试 |基于 JUnit + Mockito 实现单元测试,保证功能的正确性、代码的质量等 | | |
| 64 | + | |
| 65 | +计划新增: | |
| 66 | +* 工作流 | |
| 67 | +* 错误码 | |
| 68 | + | |
| 69 | +### 研发工具 | |
| 70 | + | |
| 71 | +| | 功能 | 描述 | | |
| 72 | +| --- | --- | --- | | |
| 73 | +| 🚀 | 代码生成 |前后端代码的生成(Java、Vue、SQL、单元测试),支持 CRUD 下载 | | |
| 74 | +| 🚀 | 系统接口 | 基于 Swagger 自动生成相关的 RESTful API 接口文档 | | |
| 75 | +| 🚀 | 数据库文档 | 基于 Screw 自动生成数据库文档,支持导出 Word、HTML、MD 格式 | | |
| 76 | +| | 表单构建 | 拖动表单元素生成相应的 HTML 代码 | | |
| 41 | 77 | |
| 42 | 78 | ## 在线体验 |
| 43 | 79 | |
| 44 | -- admin/admin123 | |
| 45 | - | |
| 46 | -演示地址:http://vue.ruoyi.vip | |
| 47 | -文档地址:http://doc.ruoyi.vip | |
| 80 | +演示地址:<http://dashboard.yudao.iocoder.cn> | |
| 81 | +* 账号密码:admin/admin123 | |
| 82 | + | |
| 83 | +文档地址:<http://www.iocoder.cn/categories/Yudao/> | |
| 84 | +* [《如何搭建环境》](http://www.iocoder.cn/categories/Yudao/?yudao) | |
| 85 | + | |
| 86 | +> 未来会补充文档和视频,方便胖友冲冲冲! | |
| 87 | + | |
| 88 | +## 技术栈 | |
| 89 | + | |
| 90 | +**后端** | |
| 91 | + | |
| 92 | +| 框架 | 说明 | 版本 | 学习指南 | | |
| 93 | +| --- | --- | --- | --- | | |
| 94 | +| [Spring Boot](https://spring.io/projects/spring-boot) | 应用开发框架 | 2.4.2 | [文档](https://github.com/YunaiV/SpringBoot-Labs) | | |
| 95 | +| [MySQL](https://www.mysql.com/cn/) | 数据库服务器 | 5.7 | | | |
| 96 | +| [Druid](https://github.com/alibaba/druid) | JDBC 连接池、监控组件 | 1.2.4 | [文档](http://www.iocoder.cn/Spring-Boot/datasource-pool/?yudao) | | |
| 97 | +| [MyBatis-Plus](https://mp.baomidou.com/) | MyBatis 增强工具包 | 3.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MyBatis/?yudao) | | |
| 98 | +| [Redis](https://redis.io/) | key-value 数据库 | 5.0 | | | |
| 99 | +| [Redisson](https://github.com/redisson/redisson) | Redis 客户端 | 3.1.46 | [文档](http://www.iocoder.cn/Spring-Boot/Redis/?yudao) | | |
| 100 | +| [Spring MVC](https://github.com/spring-projects/spring-framework/tree/master/spring-webmvc) | MVC 框架 | 5.4.2 | [文档](http://www.iocoder.cn/SpringMVC/MVC/?yudao) | | |
| 101 | +| [Spring Security](https://github.com/spring-projects/spring-security) | Spring 安全框架 | 5.4.2 | [文档](http://www.iocoder.cn/Spring-Boot/Spring-Security/?yudao) | | |
| 102 | +| [Hibernate Validator](https://github.com/hibernate/hibernate-validator) | 参数校验组件 | 6.1.7 | [文档](http://www.iocoder.cn/Spring-Boot/Validation/?yudao) | | |
| 103 | +| [Quartz](https://github.com/quartz-scheduler) | 任务调度组件 | 2.3.2 | [文档](http://www.iocoder.cn/Spring-Boot/Job/?yudao) | | |
| 104 | +| [Knife4j](https://gitee.com/xiaoym/knife4j) | Swagger 增强 UI 实现 | 3.0.2 | [文档](http://www.iocoder.cn/Spring-Boot/Swagger/?yudao) | | |
| 105 | +| [Resilience4j](https://github.com/quartz-scheduler) | 服务保障组件 | 1.7.0 | [文档](http://www.iocoder.cn/Spring-Boot/Resilience4j/?yudao) | | |
| 106 | +| [SkyWalking](https://skywalking.apache.org/) | 分布式应用追踪系统 | 8.6.0 | [文档](http://www.iocoder.cn/Spring-Boot/SkyWalking/?yudao) | | |
| 107 | +| [Spring Boot Admin](https://github.com/skywalking) | Spring Boot 监控平台 | 8.6.0 | [文档](http://www.iocoder.cn/Spring-Boot/Admin/?yudao) | | |
| 108 | +| [Jackson](https://github.com/FasterXML/jackson) | JSON 工具库 | 2.11.4 | | | |
| 109 | +| [MapStruct](https://mapstruct.org/) | Java Bean 转换 | 1.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao) | | |
| 110 | +| [Lombok](https://projectlombok.org/) | 消除冗长的 Java 代码 | 1.16.14 | [文档](http://www.iocoder.cn/Spring-Boot/Lombok/?yudao) | | |
| 111 | +| [JUnit](https://junit.org/junit5/) | Java 单元测试框架 | 5.7.0 | - | | |
| 112 | +| [Mockito](https://github.com/mockito/mockito) | Java Mock 框架 | 3.6.28 | - | | |
| 113 | + | |
| 114 | +**前端** | |
| 115 | + | |
| 116 | +| 框架 | 说明 | 版本 | | |
| 117 | +| --- | --- | --- | | |
| 118 | +| [Vue](https://cn.vuejs.org/index.html) | JavaScript 框架 | 2.6.12 | | |
| 119 | +| [Vue Element Admin](https://ant.design/docs/react/introduce-cn) | 后台前端解决方案 | - | | |
| 48 | 120 | |
| 49 | 121 | ## 演示图 |
| 50 | 122 | |
| ... | ... | @@ -79,7 +151,7 @@ |
| 79 | 151 | </tr> |
| 80 | 152 | <tr> |
| 81 | 153 | <td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td> |
| 82 | - <td><img src="https://oscimg.oschina.net/oscnet/up-6d73c2140ce694e3de4c05035fdc1868d4c.png"/></td> | |
| 154 | + <td> - </td> | |
| 83 | 155 | </tr> |
| 84 | 156 | </table> |
| 85 | 157 | ... | ... |
bin/clean.bat deleted
bin/deploy.sh
0 → 100644
| 1 | +#!/bin/bash | |
| 2 | +set -e | |
| 3 | + | |
| 4 | +# 基础 | |
| 5 | +# export JAVA_HOME=/work/programs/jdk/jdk1.8.0_181 | |
| 6 | +# export PATH=PATH=$PATH:$JAVA_HOME/bin | |
| 7 | +# export CLASSPATH=$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar | |
| 8 | + | |
| 9 | +DATE=$(date +%Y%m%d%H%M) | |
| 10 | +# 基础路径 | |
| 11 | +BASE_PATH=/work/projects/dashboard | |
| 12 | +# 编译后 jar 的地址。部署时,Jenkins 会上传 jar 包到该目录下 | |
| 13 | +SOURCE_PATH=$BASE_PATH/build | |
| 14 | +# 服务名称。同时约定部署服务的 jar 包名字也为它。 | |
| 15 | +SERVER_NAME=dashboard | |
| 16 | +# 环境 | |
| 17 | +PROFILES_ACTIVE=dev | |
| 18 | +# 健康检查 URL | |
| 19 | +HEALTH_CHECK_URL=http://127.0.0.1:48080/actuator/health/ | |
| 20 | + | |
| 21 | +# heapError 存放路径 | |
| 22 | +HEAP_ERROR_PATH=$BASE_PATH/heapError | |
| 23 | +# JVM 参数 | |
| 24 | +JAVA_OPS="-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$HEAP_ERROR_PATH" | |
| 25 | + | |
| 26 | +# SkyWalking Agent 配置 | |
| 27 | +export SW_AGENT_NAME=$SERVER_NAME | |
| 28 | +export SW_AGENT_COLLECTOR_BACKEND_SERVICES=192.168.0.84:11800 | |
| 29 | +export JAVA_AGENT=-javaagent:/work/skywalking/apache-skywalking-apm-bin/agent/skywalking-agent.jar | |
| 30 | + | |
| 31 | +# 备份 | |
| 32 | +function backup() { | |
| 33 | + # 如果不存在,则无需备份 | |
| 34 | + if [ ! -f "$BASE_PATH/$SERVER_NAME.jar" ]; then | |
| 35 | + echo "[backup] $BASE_PATH/$SERVER_NAME.jar 不存在,跳过备份" | |
| 36 | + # 如果存在,则备份到 backup 目录下,使用时间作为后缀 | |
| 37 | + else | |
| 38 | + echo "[backup] 开始备份 $SERVER_NAME ..." | |
| 39 | + cp $BASE_PATH/$SERVER_NAME.jar $BASE_PATH/backup/$SERVER_NAME-$DATE.jar | |
| 40 | + echo "[backup] 备份 $SERVER_NAME 完成" | |
| 41 | + fi | |
| 42 | +} | |
| 43 | + | |
| 44 | +# 最新构建代码 移动到项目环境 | |
| 45 | +function transfer() { | |
| 46 | + echo "[transfer] 开始转移 $SERVER_NAME.jar" | |
| 47 | + | |
| 48 | + # 删除原 jar 包 | |
| 49 | + if [ ! -f "$BASE_PATH/$SERVER_NAME.jar" ]; then | |
| 50 | + echo "[transfer] $BASE_PATH/$SERVER_NAME.jar 不存在,跳过删除" | |
| 51 | + else | |
| 52 | + echo "[transfer] 移除 $BASE_PATH/$SERVER_NAME.jar 完成" | |
| 53 | + rm $BASE_PATH/$SERVER_NAME.jar | |
| 54 | + fi | |
| 55 | + | |
| 56 | + # 复制新 jar 包 | |
| 57 | + echo "[transfer] 从 $SOURCE_PATH 中获取 $SERVER_NAME.jar 并迁移至 $BASE_PATH ...." | |
| 58 | + cp $SOURCE_PATH/$SERVER_NAME.jar $BASE_PATH | |
| 59 | + | |
| 60 | + echo "[transfer] 转移 $SERVER_NAME.jar 完成" | |
| 61 | +} | |
| 62 | + | |
| 63 | +# 停止 | |
| 64 | +function stop() { | |
| 65 | + echo "[stop] 开始停止 $BASE_PATH/$SERVER_NAME" | |
| 66 | + PID=$(ps -ef | grep $BASE_PATH/$SERVER_NAME | grep -v "grep" | awk '{print $2}') | |
| 67 | + # 如果 Java 服务启动中,则进行关闭 | |
| 68 | + if [ -n "$PID" ]; then | |
| 69 | + # 正常关闭 | |
| 70 | + echo "[stop] $BASE_PATH/$SERVER_NAME 运行中,开始 kill [$PID]" | |
| 71 | + kill -15 $PID | |
| 72 | + # 等待最大 60 秒,直到关闭完成。 | |
| 73 | + for ((i = 0; i < 60; i++)) | |
| 74 | + do | |
| 75 | + sleep 1 | |
| 76 | + PID=$(ps -ef | grep $BASE_PATH/$SERVER_NAME | grep -v "grep" | awk '{print $2}') | |
| 77 | + if [ -n "$PID" ]; then | |
| 78 | + echo -e ".\c" | |
| 79 | + else | |
| 80 | + echo '[stop] 停止 $BASE_PATH/$SERVER_NAME 成功' | |
| 81 | + break | |
| 82 | + fi | |
| 83 | + done | |
| 84 | + | |
| 85 | + # 如果正常关闭失败,那么进行强制 kill -9 进行关闭 | |
| 86 | + if [ -n "$PID" ]; then | |
| 87 | + echo "[stop] $BASE_PATH/$SERVER_NAME 失败,强制 kill -9 $PID" | |
| 88 | + kill -9 $PID | |
| 89 | + fi | |
| 90 | + # 如果 Java 服务未启动,则无需关闭 | |
| 91 | + else | |
| 92 | + echo "[stop] $BASE_PATH/$SERVER_NAME 未启动,无需停止" | |
| 93 | + fi | |
| 94 | +} | |
| 95 | + | |
| 96 | +# 启动 | |
| 97 | +function start() { | |
| 98 | + # 开启启动前,打印启动参数 | |
| 99 | + echo "[start] 开始启动 $BASE_PATH/$SERVER_NAME" | |
| 100 | + echo "[start] JAVA_OPS: $JAVA_OPS" | |
| 101 | + echo "[start] JAVA_AGENT: $JAVA_AGENT" | |
| 102 | + echo "[start] PROFILES: $PROFILES_ACTIVE" | |
| 103 | + | |
| 104 | + # 开始启动 | |
| 105 | + BUILD_ID=dontKillMe nohup java -server $JAVA_OPS $JAVA_AGENT -jar $BASE_PATH/$SERVER_NAME.jar --spring.profiles.active=$PROFILES_ACTIVE & | |
| 106 | + echo "[start] 启动 $BASE_PATH/$SERVER_NAME 完成" | |
| 107 | +} | |
| 108 | + | |
| 109 | +# 健康检查 | |
| 110 | +function healthCheck() { | |
| 111 | + # 如果配置健康检查,则进行健康检查 | |
| 112 | + if [ -n "$HEALTH_CHECK_URL" ]; then | |
| 113 | + # 健康检查最大 60 秒,直到健康检查通过 | |
| 114 | + echo "[healthCheck] 开始通过 $HEALTH_CHECK_URL 地址,进行健康检查"; | |
| 115 | + for ((i = 0; i < 60; i++)) | |
| 116 | + do | |
| 117 | + # 请求健康检查地址,只获取状态码。 | |
| 118 | + result=`curl -I -m 10 -o /dev/null -s -w %{http_code} $HEALTH_CHECK_URL || echo "000"` | |
| 119 | + # 如果状态码为 200,则说明健康检查通过 | |
| 120 | + if [ "$result" == "200" ]; then | |
| 121 | + echo "[healthCheck] 健康检查通过"; | |
| 122 | + break | |
| 123 | + # 如果状态码非 200,则说明未通过。sleep 1 秒后,继续重试 | |
| 124 | + else | |
| 125 | + echo -e ".\c" | |
| 126 | + sleep 1 | |
| 127 | + fi | |
| 128 | + done | |
| 129 | + | |
| 130 | + # 健康检查未通过,则异常退出 shell 脚本,不继续部署。 | |
| 131 | + if [ ! "$result" == "200" ]; then | |
| 132 | + echo "[healthCheck] 健康检查不通过,可能部署失败。查看日志,自行判断是否启动成功"; | |
| 133 | + tail -n 10 nohup.out | |
| 134 | + exit 1; | |
| 135 | + # 健康检查通过,打印最后 10 行日志,可能部署的人想看下日志。 | |
| 136 | + else | |
| 137 | + tail -n 10 nohup.out | |
| 138 | + fi | |
| 139 | + # 如果未配置健康检查,则 slepp 60 秒,人工看日志是否部署成功。 | |
| 140 | + else | |
| 141 | + echo "[healthCheck] HEALTH_CHECK_URL 未配置,开始 sleep 60 秒"; | |
| 142 | + sleep 60 | |
| 143 | + echo "[healthCheck] sleep 60 秒完成,查看日志,自行判断是否启动成功"; | |
| 144 | + tail -n 50 nohup.out | |
| 145 | + fi | |
| 146 | +} | |
| 147 | + | |
| 148 | +# 部署 | |
| 149 | +function deploy() { | |
| 150 | + cd $BASE_PATH | |
| 151 | + # 备份原 jar | |
| 152 | + backup | |
| 153 | + # 停止 Java 服务 | |
| 154 | + stop | |
| 155 | + # 部署新 jar | |
| 156 | + transfer | |
| 157 | + # 启动 Java 服务 | |
| 158 | + start | |
| 159 | + # 健康检查 | |
| 160 | + healthCheck | |
| 161 | +} | |
| 162 | + | |
| 163 | +deploy | ... | ... |
bin/package.bat deleted
bin/run.bat deleted
doc/若依环境使用手册.docx deleted
No preview for this file type
http-client.env.json
lombok.config
0 → 100644
pom.xml
| ... | ... | @@ -2,15 +2,15 @@ |
| 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| 3 | 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 4 | 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 5 | - <modelVersion>4.0.0</modelVersion> | |
| 5 | + <modelVersion>4.0.0</modelVersion> | |
| 6 | 6 | |
| 7 | 7 | <groupId>cn.iocoder</groupId> |
| 8 | 8 | <artifactId>dashboard</artifactId> |
| 9 | 9 | <version>1.0.0</version> |
| 10 | 10 | |
| 11 | - <name>ruoyi</name> | |
| 12 | - <url>http://www.ruoyi.vip</url> | |
| 13 | - <description>若依管理系统</description> | |
| 11 | + <name>dashboard</name> | |
| 12 | + <url>http://www.iocoder.cn</url> | |
| 13 | + <description>芋道管理系统</description> | |
| 14 | 14 | <packaging>jar</packaging> |
| 15 | 15 | |
| 16 | 16 | <properties> |
| ... | ... | @@ -23,52 +23,34 @@ |
| 23 | 23 | <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> |
| 24 | 24 | <!-- 统一依赖管理 --> |
| 25 | 25 | <spring.boot.version>2.4.2</spring.boot.version> |
| 26 | - | |
| 27 | -<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>--> | |
| 28 | -<!-- <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>--> | |
| 29 | -<!-- <druid.version>1.2.2</druid.version>--> | |
| 30 | -<!-- <bitwalker.version>1.21</bitwalker.version>--> | |
| 31 | -<!-- <swagger.version>2.9.2</swagger.version>--> | |
| 32 | -<!-- <kaptcha.version>2.3.2</kaptcha.version>--> | |
| 33 | -<!-- <pagehelper.boot.version>1.3.0</pagehelper.boot.version>--> | |
| 34 | -<!-- <oshi.version>5.3.6</oshi.version>--> | |
| 35 | -<!-- <jna.version>5.6.0</jna.version>--> | |
| 36 | -<!-- <commons.io.version>2.5</commons.io.version>--> | |
| 37 | -<!-- <commons.fileupload.version>1.3.3</commons.fileupload.version>--> | |
| 38 | -<!-- <poi.version>4.1.2</poi.version>--> | |
| 39 | -<!-- <velocity.version>1.7</velocity.version>--> | |
| 40 | -<!-- <jwt.version>0.9.1</jwt.version>--> | |
| 41 | - | |
| 42 | 26 | <!-- Web 相关 --> |
| 43 | 27 | <knife4j.version>3.0.2</knife4j.version> |
| 44 | - | |
| 28 | + <swagger-annotations.version>1.5.22</swagger-annotations.version> | |
| 45 | 29 | <!-- DB 相关 --> |
| 46 | 30 | <mysql-connector-java.version>5.1.46</mysql-connector-java.version> |
| 47 | 31 | <druid.version>1.2.4</druid.version> |
| 48 | 32 | <mybatis-plus.version>3.4.1</mybatis-plus.version> |
| 49 | 33 | <redisson.version>3.14.1</redisson.version> |
| 34 | + <!-- Config 配置中心相关 --> | |
| 35 | + <apollo.version>1.7.0</apollo.version> | |
| 36 | + <!-- 服务保障相关 --> | |
| 37 | + <lock4j.version>2.2.0</lock4j.version> | |
| 38 | + <resilience4j.version>1.7.0</resilience4j.version> | |
| 50 | 39 | <!-- 监控相关 --> |
| 51 | 40 | <skywalking.version>8.3.0</skywalking.version> |
| 52 | 41 | <spring-boot-admin.version>2.3.1</spring-boot-admin.version> |
| 53 | 42 | <!-- 工具类相关 --> |
| 54 | 43 | <lombok.version>1.16.14</lombok.version> |
| 55 | 44 | <mapstruct.version>1.4.1.Final</mapstruct.version> |
| 56 | - <jjwt.version>0.9.1</jjwt.version> | |
| 57 | 45 | <hutool.version>5.5.6</hutool.version> |
| 58 | 46 | <easyexcel.verion>2.2.7</easyexcel.verion> |
| 47 | + <velocity.version>2.2</velocity.version> | |
| 48 | + <screw.version>1.0.5</screw.version> | |
| 59 | 49 | </properties> |
| 60 | 50 | |
| 61 | 51 | <!-- 依赖声明 --> |
| 62 | 52 | <dependencyManagement> |
| 63 | 53 | <dependencies> |
| 64 | - | |
| 65 | -<!-- <!–velocity代码生成使用模板 –>--> | |
| 66 | -<!-- <dependency>--> | |
| 67 | -<!-- <groupId>org.apache.velocity</groupId>--> | |
| 68 | -<!-- <artifactId>velocity</artifactId>--> | |
| 69 | -<!-- <version>${velocity.version}</version>--> | |
| 70 | -<!-- </dependency>--> | |
| 71 | - | |
| 72 | 54 | <!-- 统一依赖管理 --> |
| 73 | 55 | <dependency> |
| 74 | 56 | <groupId>org.springframework.boot</groupId> |
| ... | ... | @@ -119,8 +101,21 @@ |
| 119 | 101 | <artifactId>mapstruct</artifactId> |
| 120 | 102 | <groupId>org.mapstruct</groupId> <!-- 避免冲突 --> |
| 121 | 103 | </exclusion> |
| 104 | + <exclusion> | |
| 105 | + <artifactId>guava</artifactId> | |
| 106 | + <groupId>com.google.guava</groupId> | |
| 107 | + </exclusion> | |
| 108 | + <exclusion> | |
| 109 | + <artifactId>swagger-annotations</artifactId> | |
| 110 | + <groupId>io.swagger</groupId> | |
| 111 | + </exclusion> | |
| 122 | 112 | </exclusions> |
| 123 | 113 | </dependency> |
| 114 | + <dependency> | |
| 115 | + <groupId>io.swagger</groupId> | |
| 116 | + <artifactId>swagger-annotations</artifactId> | |
| 117 | + <version>${swagger-annotations.version}</version> | |
| 118 | + </dependency> | |
| 124 | 119 | |
| 125 | 120 | <!-- DB 相关 --> |
| 126 | 121 | <dependency> |
| ... | ... | @@ -149,7 +144,32 @@ |
| 149 | 144 | <dependency> |
| 150 | 145 | <groupId>com.ctrip.framework.apollo</groupId> |
| 151 | 146 | <artifactId>apollo-client</artifactId> <!-- 引入 Apollo Client 库,实现内嵌的配置中心 --> |
| 152 | - <version>1.7.0</version> | |
| 147 | + <version>${apollo.version}</version> | |
| 148 | + </dependency> | |
| 149 | + | |
| 150 | + <!-- Job 定时任务相关 --> | |
| 151 | + <dependency> | |
| 152 | + <groupId>org.springframework.boot</groupId> | |
| 153 | + <artifactId>spring-boot-starter-quartz</artifactId> | |
| 154 | + </dependency> | |
| 155 | + | |
| 156 | + <!-- 服务保障相关 --> | |
| 157 | + <dependency> | |
| 158 | + <groupId>com.baomidou</groupId> | |
| 159 | + <artifactId>lock4j-redisson-spring-boot-starter</artifactId> | |
| 160 | + <version>${lock4j.version}</version> | |
| 161 | + <exclusions> | |
| 162 | + <exclusion> | |
| 163 | + <artifactId>redisson-spring-boot-starter</artifactId> | |
| 164 | + <groupId>org.redisson</groupId> | |
| 165 | + </exclusion> | |
| 166 | + </exclusions> | |
| 167 | + </dependency> | |
| 168 | + | |
| 169 | + <dependency> | |
| 170 | + <groupId>io.github.resilience4j</groupId> | |
| 171 | + <artifactId>resilience4j-spring-boot2</artifactId> | |
| 172 | + <version>${resilience4j.version}</version> | |
| 153 | 173 | </dependency> |
| 154 | 174 | |
| 155 | 175 | <!-- 监控相关 --> |
| ... | ... | @@ -170,6 +190,39 @@ |
| 170 | 190 | <version>${spring-boot-admin.version}</version> |
| 171 | 191 | </dependency> |
| 172 | 192 | |
| 193 | + <!-- Test 测试相关 --> | |
| 194 | + <dependency> | |
| 195 | + <groupId>org.springframework.boot</groupId> | |
| 196 | + <artifactId>spring-boot-starter-test</artifactId> | |
| 197 | + <scope>test</scope> | |
| 198 | + <exclusions> | |
| 199 | + <exclusion> | |
| 200 | + <artifactId>asm</artifactId> | |
| 201 | + <groupId>org.ow2.asm</groupId> | |
| 202 | + </exclusion> | |
| 203 | + </exclusions> | |
| 204 | + </dependency> | |
| 205 | + | |
| 206 | + <dependency> | |
| 207 | + <groupId>com.h2database</groupId> <!-- 单元测试,我们采用 H2 作为数据库 --> | |
| 208 | + <artifactId>h2</artifactId> | |
| 209 | + <scope>test</scope> | |
| 210 | + </dependency> | |
| 211 | + | |
| 212 | + <dependency> | |
| 213 | + <groupId>com.github.fppt</groupId> <!-- 单元测试,我们采用内嵌的 Redis 数据库 --> | |
| 214 | + <artifactId>jedis-mock</artifactId> | |
| 215 | + <version>0.1.16</version> | |
| 216 | + <scope>test</scope> | |
| 217 | + </dependency> | |
| 218 | + | |
| 219 | + <dependency> | |
| 220 | + <groupId>uk.co.jemos.podam</groupId> <!-- 单元测试,随机生成 POJO 类 --> | |
| 221 | + <artifactId>podam</artifactId> | |
| 222 | + <version>7.2.6.RELEASE</version> | |
| 223 | + <scope>test</scope> | |
| 224 | + </dependency> | |
| 225 | + | |
| 173 | 226 | <!-- 工具类相关 --> |
| 174 | 227 | <dependency> |
| 175 | 228 | <groupId>org.projectlombok</groupId> |
| ... | ... | @@ -178,15 +231,15 @@ |
| 178 | 231 | </dependency> |
| 179 | 232 | |
| 180 | 233 | <dependency> |
| 181 | - <groupId>io.jsonwebtoken</groupId> | |
| 182 | - <artifactId>jjwt</artifactId> | |
| 183 | - <version>${jjwt.version}</version> | |
| 234 | + <groupId>org.mapstruct</groupId> | |
| 235 | + <artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher --> | |
| 236 | + <version>${mapstruct.version}</version> | |
| 184 | 237 | </dependency> |
| 185 | - | |
| 186 | 238 | <dependency> |
| 187 | 239 | <groupId>org.mapstruct</groupId> |
| 188 | - <artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher --> | |
| 240 | + <artifactId>mapstruct-processor</artifactId> | |
| 189 | 241 | <version>${mapstruct.version}</version> |
| 242 | + <optional>true</optional> | |
| 190 | 243 | </dependency> |
| 191 | 244 | <dependency> |
| 192 | 245 | <groupId>org.mapstruct</groupId> |
| ... | ... | @@ -209,6 +262,16 @@ |
| 209 | 262 | <artifactId>hutool-captcha</artifactId> |
| 210 | 263 | <version>${hutool.version}</version> |
| 211 | 264 | </dependency> |
| 265 | + <dependency> | |
| 266 | + <groupId>cn.hutool</groupId> | |
| 267 | + <artifactId>hutool-http</artifactId> | |
| 268 | + <version>${hutool.version}</version> | |
| 269 | + </dependency> | |
| 270 | + <dependency> | |
| 271 | + <groupId>cn.hutool</groupId> | |
| 272 | + <artifactId>hutool-crypto</artifactId> | |
| 273 | + <version>${hutool.version}</version> | |
| 274 | + </dependency> | |
| 212 | 275 | |
| 213 | 276 | <dependency> |
| 214 | 277 | <groupId>com.alibaba</groupId> |
| ... | ... | @@ -216,6 +279,17 @@ |
| 216 | 279 | <version>${easyexcel.verion}</version> |
| 217 | 280 | </dependency> |
| 218 | 281 | |
| 282 | + <dependency> | |
| 283 | + <groupId>org.apache.velocity</groupId> | |
| 284 | + <artifactId>velocity-engine-core</artifactId> | |
| 285 | + <version>${velocity.version}</version> | |
| 286 | + </dependency> | |
| 287 | + | |
| 288 | + <dependency> | |
| 289 | + <groupId>cn.smallbun.screw</groupId> | |
| 290 | + <artifactId>screw-core</artifactId> <!-- 实现数据库文档 --> | |
| 291 | + <version>${screw.version}</version> | |
| 292 | + </dependency> | |
| 219 | 293 | |
| 220 | 294 | <!-- SMS SDK begin --> |
| 221 | 295 | <dependency> |
| ... | ... | @@ -240,41 +314,49 @@ |
| 240 | 314 | |
| 241 | 315 | |
| 242 | 316 | <build> |
| 243 | - <pluginManagement> | |
| 244 | - <plugins> | |
| 245 | - <!-- 提供给 mapstruct 使用 --> | |
| 246 | - <plugin> | |
| 247 | - <groupId>org.apache.maven.plugins</groupId> | |
| 248 | - <artifactId>maven-compiler-plugin</artifactId> | |
| 249 | - <version>${maven-compiler-plugin.version}</version> | |
| 250 | - <configuration> | |
| 251 | - <source>${java.version}</source> <!-- or higher, depending on your project --> | |
| 252 | - <target>${java.version}</target> <!-- or higher, depending on your project --> | |
| 253 | - <annotationProcessorPaths> | |
| 254 | - <path> | |
| 255 | - <groupId>org.mapstruct</groupId> | |
| 256 | - <artifactId>mapstruct-processor</artifactId> | |
| 257 | - <version>${mapstruct.version}</version> | |
| 258 | - </path> | |
| 259 | - <path> | |
| 260 | - <groupId>org.projectlombok</groupId> | |
| 261 | - <artifactId>lombok</artifactId> | |
| 262 | - <version>${lombok.version}</version> | |
| 263 | - </path> | |
| 264 | - </annotationProcessorPaths> | |
| 265 | - </configuration> | |
| 266 | - </plugin> | |
| 267 | - | |
| 268 | - <!-- 打包 --> | |
| 269 | - <plugin> | |
| 270 | - <groupId>org.springframework.boot</groupId> | |
| 271 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 272 | - <configuration> | |
| 273 | - <fork>true</fork> | |
| 274 | - </configuration> | |
| 275 | - </plugin> | |
| 276 | - </plugins> | |
| 277 | - </pluginManagement> | |
| 317 | + <!-- 设置构建的 jar 包名 --> | |
| 318 | + <finalName>${project.artifactId}</finalName> | |
| 319 | + <plugins> | |
| 320 | + <!-- 打包 --> | |
| 321 | + <plugin> | |
| 322 | + <groupId>org.springframework.boot</groupId> | |
| 323 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
| 324 | + <version>${spring.boot.version}</version> | |
| 325 | + <configuration> | |
| 326 | + <fork>true</fork> | |
| 327 | + </configuration> | |
| 328 | + <executions> | |
| 329 | + <execution> | |
| 330 | + <goals> | |
| 331 | + <goal>repackage</goal> <!-- 将原来的 jar 打入其中 --> | |
| 332 | + </goals> | |
| 333 | + </execution> | |
| 334 | + </executions> | |
| 335 | + </plugin> | |
| 336 | + | |
| 337 | + <!-- 提供给 mapstruct 使用 --> | |
| 338 | + <plugin> | |
| 339 | + <groupId>org.apache.maven.plugins</groupId> | |
| 340 | + <artifactId>maven-compiler-plugin</artifactId> | |
| 341 | + <version>${maven-compiler-plugin.version}</version> | |
| 342 | + <configuration> | |
| 343 | + <source>${java.version}</source> <!-- or higher, depending on your project --> | |
| 344 | + <target>${java.version}</target> <!-- or higher, depending on your project --> | |
| 345 | + <annotationProcessorPaths> | |
| 346 | + <path> | |
| 347 | + <groupId>org.mapstruct</groupId> | |
| 348 | + <artifactId>mapstruct-processor</artifactId> | |
| 349 | + <version>${mapstruct.version}</version> | |
| 350 | + </path> | |
| 351 | + <path> | |
| 352 | + <groupId>org.projectlombok</groupId> | |
| 353 | + <artifactId>lombok</artifactId> | |
| 354 | + <version>${lombok.version}</version> | |
| 355 | + </path> | |
| 356 | + </annotationProcessorPaths> | |
| 357 | + </configuration> | |
| 358 | + </plugin> | |
| 359 | + </plugins> | |
| 278 | 360 | </build> |
| 279 | 361 | |
| 280 | 362 | </project> | ... | ... |
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java deleted
| 1 | -package com.ruoyi; | |
| 2 | - | |
| 3 | -import org.springframework.boot.SpringApplication; | |
| 4 | -import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 5 | -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 启动程序 | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - */ | |
| 12 | -@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) | |
| 13 | -public class RuoYiApplication | |
| 14 | -{ | |
| 15 | - public static void main(String[] args) | |
| 16 | - { | |
| 17 | - // System.setProperty("spring.devtools.restart.enabled", "false"); | |
| 18 | - SpringApplication.run(RuoYiApplication.class, args); | |
| 19 | - System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" + | |
| 20 | - " .-------. ____ __ \n" + | |
| 21 | - " | _ _ \\ \\ \\ / / \n" + | |
| 22 | - " | ( ' ) | \\ _. / ' \n" + | |
| 23 | - " |(_ o _) / _( )_ .' \n" + | |
| 24 | - " | (_,_).' __ ___(_ o _)' \n" + | |
| 25 | - " | |\\ \\ | || |(_,_)' \n" + | |
| 26 | - " | | \\ `' /| `-' / \n" + | |
| 27 | - " | | \\ / \\ / \n" + | |
| 28 | - " ''-' `'-' `-..-' "); | |
| 29 | - } | |
| 30 | -} |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ISysUserOnlineService.java deleted
| 1 | -package com.ruoyi.system.service; | |
| 2 | - | |
| 3 | -import com.ruoyi.common.core.domain.model.LoginUser; | |
| 4 | -import com.ruoyi.system.domain.SysUserOnline; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 在线用户 服务层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface ISysUserOnlineService | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 通过登录地址查询信息 | |
| 15 | - * | |
| 16 | - * @param ipaddr 登录地址 | |
| 17 | - * @param user 用户信息 | |
| 18 | - * @return 在线用户信息 | |
| 19 | - */ | |
| 20 | - public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user); | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * 通过用户名称查询信息 | |
| 24 | - * | |
| 25 | - * @param userName 用户名称 | |
| 26 | - * @param user 用户信息 | |
| 27 | - * @return 在线用户信息 | |
| 28 | - */ | |
| 29 | - public SysUserOnline selectOnlineByUserName(String userName, LoginUser user); | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 通过登录地址/用户名称查询信息 | |
| 33 | - * | |
| 34 | - * @param ipaddr 登录地址 | |
| 35 | - * @param userName 用户名称 | |
| 36 | - * @param user 用户信息 | |
| 37 | - * @return 在线用户信息 | |
| 38 | - */ | |
| 39 | - public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user); | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 设置在线用户信息 | |
| 43 | - * | |
| 44 | - * @param user 用户信息 | |
| 45 | - * @return 在线用户 | |
| 46 | - */ | |
| 47 | - public SysUserOnline loginUserToUserOnline(LoginUser user); | |
| 48 | -} |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SwaggerController.java deleted
| 1 | -package com.ruoyi.web.controller.tool; | |
| 2 | - | |
| 3 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 4 | -import org.springframework.stereotype.Controller; | |
| 5 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 6 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | -import com.ruoyi.common.core.controller.BaseController; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * swagger 接口 | |
| 11 | - * | |
| 12 | - * @author ruoyi | |
| 13 | - */ | |
| 14 | -@Controller | |
| 15 | -@RequestMapping("/tool/swagger") | |
| 16 | -public class SwaggerController extends BaseController | |
| 17 | -{ | |
| 18 | - @PreAuthorize("@ss.hasPermi('tool:swagger:view')") | |
| 19 | - @GetMapping() | |
| 20 | - public String index() | |
| 21 | - { | |
| 22 | - return redirect("/swagger-ui.html"); | |
| 23 | - } | |
| 24 | -} |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnline.java deleted
| 1 | -package com.ruoyi.system.domain; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * 当前在线会话 | |
| 5 | - * | |
| 6 | - * @author ruoyi | |
| 7 | - */ | |
| 8 | -public class SysUserOnline { | |
| 9 | - /** | |
| 10 | - * 会话编号 | |
| 11 | - */ | |
| 12 | - private String tokenId; | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * 部门名称 | |
| 16 | - */ | |
| 17 | - private String deptName; | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * 用户名称 | |
| 21 | - */ | |
| 22 | - private String userName; | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * 登录IP地址 | |
| 26 | - */ | |
| 27 | - private String ipaddr; | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 登录地址 | |
| 31 | - */ | |
| 32 | - private String loginLocation; | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * 浏览器类型 | |
| 36 | - */ | |
| 37 | - private String browser; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * 操作系统 | |
| 41 | - */ | |
| 42 | - private String os; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 登录时间 | |
| 46 | - */ | |
| 47 | - private Long loginTime; | |
| 48 | - | |
| 49 | -} |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java deleted
| 1 | -package com.ruoyi.web.controller.monitor; | |
| 2 | - | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.Collection; | |
| 5 | -import java.util.Collections; | |
| 6 | -import java.util.List; | |
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 9 | -import org.springframework.web.bind.annotation.DeleteMapping; | |
| 10 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 11 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 12 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 13 | -import org.springframework.web.bind.annotation.RestController; | |
| 14 | -import com.ruoyi.common.annotation.Log; | |
| 15 | -import com.ruoyi.common.constant.Constants; | |
| 16 | -import com.ruoyi.common.core.controller.BaseController; | |
| 17 | -import com.ruoyi.common.core.domain.AjaxResult; | |
| 18 | -import com.ruoyi.common.core.domain.model.LoginUser; | |
| 19 | -import com.ruoyi.common.core.page.TableDataInfo; | |
| 20 | -import com.ruoyi.common.core.redis.RedisCache; | |
| 21 | -import com.ruoyi.common.enums.BusinessType; | |
| 22 | -import com.ruoyi.common.utils.StringUtils; | |
| 23 | -import com.ruoyi.system.domain.SysUserOnline; | |
| 24 | -import com.ruoyi.system.service.ISysUserOnlineService; | |
| 25 | - | |
| 26 | -/** | |
| 27 | - * 在线用户监控 | |
| 28 | - * | |
| 29 | - * @author ruoyi | |
| 30 | - */ | |
| 31 | -@RestController | |
| 32 | -@RequestMapping("/monitor/online") | |
| 33 | -public class SysUserOnlineController extends BaseController | |
| 34 | -{ | |
| 35 | - @Autowired | |
| 36 | - private ISysUserOnlineService userOnlineService; | |
| 37 | - | |
| 38 | - @Autowired | |
| 39 | - private RedisCache redisCache; | |
| 40 | - | |
| 41 | - @PreAuthorize("@ss.hasPermi('monitor:online:list')") | |
| 42 | - @GetMapping("/list") | |
| 43 | - public TableDataInfo list(String ipaddr, String userName) | |
| 44 | - { | |
| 45 | - Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*"); | |
| 46 | - List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); | |
| 47 | - for (String key : keys) | |
| 48 | - { | |
| 49 | - LoginUser user = redisCache.getCacheObject(key); | |
| 50 | - if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) | |
| 51 | - { | |
| 52 | - if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) | |
| 53 | - { | |
| 54 | - userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); | |
| 55 | - } | |
| 56 | - } | |
| 57 | - else if (StringUtils.isNotEmpty(ipaddr)) | |
| 58 | - { | |
| 59 | - if (StringUtils.equals(ipaddr, user.getIpaddr())) | |
| 60 | - { | |
| 61 | - userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); | |
| 62 | - } | |
| 63 | - } | |
| 64 | - else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) | |
| 65 | - { | |
| 66 | - if (StringUtils.equals(userName, user.getUsername())) | |
| 67 | - { | |
| 68 | - userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - else | |
| 72 | - { | |
| 73 | - userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); | |
| 74 | - } | |
| 75 | - } | |
| 76 | - Collections.reverse(userOnlineList); | |
| 77 | - userOnlineList.removeAll(Collections.singleton(null)); | |
| 78 | - return getDataTable(userOnlineList); | |
| 79 | - } | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * 强退用户 | |
| 83 | - */ | |
| 84 | - @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')") | |
| 85 | - @Log(title = "在线用户", businessType = BusinessType.FORCE) | |
| 86 | - @DeleteMapping("/{tokenId}") | |
| 87 | - public AjaxResult forceLogout(@PathVariable String tokenId) | |
| 88 | - { | |
| 89 | - redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId); | |
| 90 | - return AjaxResult.success(); | |
| 91 | - } | |
| 92 | -} |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineServiceImpl.java deleted
| 1 | -package com.ruoyi.system.service.impl; | |
| 2 | - | |
| 3 | -import org.springframework.stereotype.Service; | |
| 4 | -import com.ruoyi.common.core.domain.model.LoginUser; | |
| 5 | -import com.ruoyi.common.utils.StringUtils; | |
| 6 | -import com.ruoyi.system.domain.SysUserOnline; | |
| 7 | -import com.ruoyi.system.service.ISysUserOnlineService; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 在线用户 服务层处理 | |
| 11 | - * | |
| 12 | - * @author ruoyi | |
| 13 | - */ | |
| 14 | -@Service | |
| 15 | -public class SysUserOnlineServiceImpl implements ISysUserOnlineService { | |
| 16 | - /** | |
| 17 | - * 通过登录地址查询信息 | |
| 18 | - * | |
| 19 | - * @param ipaddr 登录地址 | |
| 20 | - * @param user 用户信息 | |
| 21 | - * @return 在线用户信息 | |
| 22 | - */ | |
| 23 | - @Override | |
| 24 | - public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) { | |
| 25 | - if (StringUtils.equals(ipaddr, user.getIpaddr())) { | |
| 26 | - return loginUserToUserOnline(user); | |
| 27 | - } | |
| 28 | - return null; | |
| 29 | - } | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 通过用户名称查询信息 | |
| 33 | - * | |
| 34 | - * @param userName 用户名称 | |
| 35 | - * @param user 用户信息 | |
| 36 | - * @return 在线用户信息 | |
| 37 | - */ | |
| 38 | - @Override | |
| 39 | - public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) { | |
| 40 | - if (StringUtils.equals(userName, user.getUsername())) { | |
| 41 | - return loginUserToUserOnline(user); | |
| 42 | - } | |
| 43 | - return null; | |
| 44 | - } | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 通过登录地址/用户名称查询信息 | |
| 48 | - * | |
| 49 | - * @param ipaddr 登录地址 | |
| 50 | - * @param userName 用户名称 | |
| 51 | - * @param user 用户信息 | |
| 52 | - * @return 在线用户信息 | |
| 53 | - */ | |
| 54 | - @Override | |
| 55 | - public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) { | |
| 56 | - if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) { | |
| 57 | - return loginUserToUserOnline(user); | |
| 58 | - } | |
| 59 | - return null; | |
| 60 | - } | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * 设置在线用户信息 | |
| 64 | - * | |
| 65 | - * @param user 用户信息 | |
| 66 | - * @return 在线用户 | |
| 67 | - */ | |
| 68 | - @Override | |
| 69 | - public SysUserOnline loginUserToUserOnline(LoginUser user) { | |
| 70 | - if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) { | |
| 71 | - return null; | |
| 72 | - } | |
| 73 | - SysUserOnline sysUserOnline = new SysUserOnline(); | |
| 74 | - sysUserOnline.setTokenId(user.getToken()); | |
| 75 | - sysUserOnline.setUserName(user.getUsername()); | |
| 76 | - sysUserOnline.setIpaddr(user.getIpaddr()); | |
| 77 | - sysUserOnline.setLoginLocation(user.getLoginLocation()); | |
| 78 | - sysUserOnline.setBrowser(user.getBrowser()); | |
| 79 | - sysUserOnline.setOs(user.getOs()); | |
| 80 | - sysUserOnline.setLoginTime(user.getLoginTime()); | |
| 81 | - if (StringUtils.isNotNull(user.getUser().getDept())) { | |
| 82 | - sysUserOnline.setDeptName(user.getUser().getDept().getDeptName()); | |
| 83 | - } | |
| 84 | - return sysUserOnline; | |
| 85 | - } | |
| 86 | -} |
ruoyi-admin/src/main/resources/META-INF/spring-devtools.properties deleted
ruoyi-admin/src/main/resources/application.yml deleted
| 1 | -# 项目相关配置 | |
| 2 | -ruoyi: | |
| 3 | - # 名称 | |
| 4 | - name: RuoYi | |
| 5 | - # 版本 | |
| 6 | - version: 3.3.0 | |
| 7 | - # 版权年份 | |
| 8 | - copyrightYear: 2020 | |
| 9 | - # 实例演示开关 | |
| 10 | - demoEnabled: true | |
| 11 | - # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) | |
| 12 | - profile: D:/ruoyi/uploadPath | |
| 13 | - # 获取ip地址开关 | |
| 14 | - addressEnabled: false | |
| 15 | - | |
| 16 | -# 开发环境配置 | |
| 17 | -server: | |
| 18 | - # 服务器的HTTP端口,默认为8080 | |
| 19 | - port: 8080 | |
| 20 | - servlet: | |
| 21 | - # 应用的访问路径 | |
| 22 | - context-path: / | |
| 23 | - tomcat: | |
| 24 | - # tomcat的URI编码 | |
| 25 | - uri-encoding: UTF-8 | |
| 26 | - # tomcat最大线程数,默认为200 | |
| 27 | - max-threads: 800 | |
| 28 | - # Tomcat启动初始化的线程数,默认值25 | |
| 29 | - min-spare-threads: 30 | |
| 30 | - | |
| 31 | -# 日志配置 | |
| 32 | -logging: | |
| 33 | - level: | |
| 34 | - com.ruoyi: debug | |
| 35 | - org.springframework: warn | |
| 36 | - | |
| 37 | -# Spring配置 | |
| 38 | -spring: | |
| 39 | - # 资源信息 | |
| 40 | - messages: | |
| 41 | - # 国际化资源文件路径 | |
| 42 | - basename: i18n/messages | |
| 43 | - profiles: | |
| 44 | - active: druid | |
| 45 | - # 服务模块 | |
| 46 | - devtools: | |
| 47 | - restart: | |
| 48 | - # 热部署开关 | |
| 49 | - enabled: true | |
| 50 | - # redis 配置 | |
| 51 | - redis: | |
| 52 | - # 地址 | |
| 53 | - host: 127.0.0.1 | |
| 54 | - # 端口,默认为6379 | |
| 55 | - port: 6379 | |
| 56 | - # 数据库索引 | |
| 57 | - database: 0 | |
| 58 | - # 密码 | |
| 59 | - password: | |
| 60 | - # 连接超时时间 | |
| 61 | - timeout: 10s | |
| 62 | - lettuce: | |
| 63 | - pool: | |
| 64 | - # 连接池中的最小空闲连接 | |
| 65 | - min-idle: 0 | |
| 66 | - # 连接池中的最大空闲连接 | |
| 67 | - max-idle: 8 | |
| 68 | - # 连接池的最大数据库连接数 | |
| 69 | - max-active: 8 | |
| 70 | - # #连接池最大阻塞等待时间(使用负值表示没有限制) | |
| 71 | - max-wait: -1ms | |
| 72 | - | |
| 73 | -# 防止XSS攻击 | |
| 74 | -xss: | |
| 75 | - # 过滤开关 | |
| 76 | - enabled: true | |
| 77 | - # 排除链接(多个用逗号分隔) | |
| 78 | - excludes: /system/notice/* | |
| 79 | - # 匹配链接 | |
| 80 | - urlPatterns: /system/*,/monitor/*,/tool/* |
ruoyi-admin/src/main/resources/banner.txt deleted
| 1 | -Application Version: ${ruoyi.version} | |
| 2 | -Spring Boot Version: ${spring-boot.version} | |
| 3 | -//////////////////////////////////////////////////////////////////// | |
| 4 | -// _ooOoo_ // | |
| 5 | -// o8888888o // | |
| 6 | -// 88" . "88 // | |
| 7 | -// (| ^_^ |) // | |
| 8 | -// O\ = /O // | |
| 9 | -// ____/`---'\____ // | |
| 10 | -// .' \\| |// `. // | |
| 11 | -// / \\||| : |||// \ // | |
| 12 | -// / _||||| -:- |||||- \ // | |
| 13 | -// | | \\\ - /// | | // | |
| 14 | -// | \_| ''\---/'' | | // | |
| 15 | -// \ .-\__ `-` ___/-. / // | |
| 16 | -// ___`. .' /--.--\ `. . ___ // | |
| 17 | -// ."" '< `.___\_<|>_/___.' >'"". // | |
| 18 | -// | | : `- \`.;`\ _ /`;.`/ - ` : | | // | |
| 19 | -// \ \ `-. \_ __\ /__ _/ .-` / / // | |
| 20 | -// ========`-.____`-.___\_____/___.-`____.-'======== // | |
| 21 | -// `=---=' // | |
| 22 | -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // | |
| 23 | -// 佛祖保佑 永不宕机 永无BUG // | |
| 24 | -//////////////////////////////////////////////////////////////////// | |
| 25 | 0 | \ No newline at end of file |
ruoyi-admin/src/main/resources/i18n/messages.properties deleted
| 1 | -#错误消息 | |
| 2 | -not.null=* 必须填写 | |
| 3 | -user.jcaptcha.error=验证码错误 | |
| 4 | -user.jcaptcha.expire=验证码已失效 | |
| 5 | -user.not.exists=用户不存在/密码错误 | |
| 6 | -user.password.not.match=用户不存在/密码错误 | |
| 7 | -user.password.retry.limit.count=密码输入错误{0}次 | |
| 8 | -user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定10分钟 | |
| 9 | -user.password.delete=对不起,您的账号已被删除 | |
| 10 | -user.blocked=用户已封禁,请联系管理员 | |
| 11 | -role.blocked=角色已封禁,请联系管理员 | |
| 12 | -user.logout.success=退出成功 | |
| 13 | - | |
| 14 | -length.not.valid=长度必须在{min}到{max}个字符之间 | |
| 15 | - | |
| 16 | -user.username.not.valid=* 2到20个汉字、字母、数字或下划线组成,且必须以非数字开头 | |
| 17 | -user.password.not.valid=* 5-50个字符 | |
| 18 | - | |
| 19 | -user.email.not.valid=邮箱格式错误 | |
| 20 | -user.mobile.phone.number.not.valid=手机号格式错误 | |
| 21 | -user.login.success=登录成功 | |
| 22 | -user.notfound=请重新登录 | |
| 23 | -user.forcelogout=管理员强制退出,请重新登录 | |
| 24 | -user.unknown.error=未知错误,请重新登录 | |
| 25 | - | |
| 26 | -##文件上传消息 | |
| 27 | -upload.exceed.maxSize=上传的文件大小超出限制的文件大小!<br/>允许的文件最大大小是:{0}MB! | |
| 28 | -upload.filename.exceed.length=上传的文件名最长{0}个字符 | |
| 29 | - | |
| 30 | -##权限 | |
| 31 | -no.permission=您没有数据的权限,请联系管理员添加权限 [{0}] | |
| 32 | -no.create.permission=您没有创建数据的权限,请联系管理员添加权限 [{0}] | |
| 33 | -no.update.permission=您没有修改数据的权限,请联系管理员添加权限 [{0}] | |
| 34 | -no.delete.permission=您没有删除数据的权限,请联系管理员添加权限 [{0}] | |
| 35 | -no.export.permission=您没有导出数据的权限,请联系管理员添加权限 [{0}] | |
| 36 | -no.view.permission=您没有查看数据的权限,请联系管理员添加权限 [{0}] |
ruoyi-admin/src/main/resources/logback.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<configuration> | |
| 3 | - <!-- 日志存放路径 --> | |
| 4 | - <property name="log.path" value="/home/ruoyi/logs" /> | |
| 5 | - <!-- 日志输出格式 --> | |
| 6 | - <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" /> | |
| 7 | - | |
| 8 | - <!-- 控制台输出 --> | |
| 9 | - <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | |
| 10 | - <encoder> | |
| 11 | - <pattern>${log.pattern}</pattern> | |
| 12 | - </encoder> | |
| 13 | - </appender> | |
| 14 | - | |
| 15 | - <!-- 系统日志输出 --> | |
| 16 | - <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
| 17 | - <file>${log.path}/sys-info.log</file> | |
| 18 | - <!-- 循环政策:基于时间创建日志文件 --> | |
| 19 | - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |
| 20 | - <!-- 日志文件名格式 --> | |
| 21 | - <fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern> | |
| 22 | - <!-- 日志最大的历史 60天 --> | |
| 23 | - <maxHistory>60</maxHistory> | |
| 24 | - </rollingPolicy> | |
| 25 | - <encoder> | |
| 26 | - <pattern>${log.pattern}</pattern> | |
| 27 | - </encoder> | |
| 28 | - <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |
| 29 | - <!-- 过滤的级别 --> | |
| 30 | - <level>INFO</level> | |
| 31 | - <!-- 匹配时的操作:接收(记录) --> | |
| 32 | - <onMatch>ACCEPT</onMatch> | |
| 33 | - <!-- 不匹配时的操作:拒绝(不记录) --> | |
| 34 | - <onMismatch>DENY</onMismatch> | |
| 35 | - </filter> | |
| 36 | - </appender> | |
| 37 | - | |
| 38 | - <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
| 39 | - <file>${log.path}/sys-error.log</file> | |
| 40 | - <!-- 循环政策:基于时间创建日志文件 --> | |
| 41 | - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |
| 42 | - <!-- 日志文件名格式 --> | |
| 43 | - <fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern> | |
| 44 | - <!-- 日志最大的历史 60天 --> | |
| 45 | - <maxHistory>60</maxHistory> | |
| 46 | - </rollingPolicy> | |
| 47 | - <encoder> | |
| 48 | - <pattern>${log.pattern}</pattern> | |
| 49 | - </encoder> | |
| 50 | - <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |
| 51 | - <!-- 过滤的级别 --> | |
| 52 | - <level>ERROR</level> | |
| 53 | - <!-- 匹配时的操作:接收(记录) --> | |
| 54 | - <onMatch>ACCEPT</onMatch> | |
| 55 | - <!-- 不匹配时的操作:拒绝(不记录) --> | |
| 56 | - <onMismatch>DENY</onMismatch> | |
| 57 | - </filter> | |
| 58 | - </appender> | |
| 59 | - | |
| 60 | - <!-- 用户访问日志输出 --> | |
| 61 | - <appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
| 62 | - <file>${log.path}/sys-user.log</file> | |
| 63 | - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |
| 64 | - <!-- 按天回滚 daily --> | |
| 65 | - <fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern> | |
| 66 | - <!-- 日志最大的历史 60天 --> | |
| 67 | - <maxHistory>60</maxHistory> | |
| 68 | - </rollingPolicy> | |
| 69 | - <encoder> | |
| 70 | - <pattern>${log.pattern}</pattern> | |
| 71 | - </encoder> | |
| 72 | - </appender> | |
| 73 | - | |
| 74 | - <!-- 系统模块日志级别控制 --> | |
| 75 | - <logger name="com.ruoyi" level="info" /> | |
| 76 | - <!-- Spring日志级别控制 --> | |
| 77 | - <logger name="org.springframework" level="warn" /> | |
| 78 | - | |
| 79 | - <root level="info"> | |
| 80 | - <appender-ref ref="console" /> | |
| 81 | - </root> | |
| 82 | - | |
| 83 | - <!--系统操作日志--> | |
| 84 | - <root level="info"> | |
| 85 | - <appender-ref ref="file_info" /> | |
| 86 | - <appender-ref ref="file_error" /> | |
| 87 | - </root> | |
| 88 | - | |
| 89 | - <!--系统用户操作日志--> | |
| 90 | - <logger name="sys-user" level="info"> | |
| 91 | - <appender-ref ref="sys-user"/> | |
| 92 | - </logger> | |
| 93 | -</configuration> | |
| 94 | 0 | \ No newline at end of file |
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java renamed to ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScopeAspect.java
| 1 | -package com.ruoyi.framework.aspectj; | |
| 2 | - | |
| 3 | -import java.lang.reflect.Method; | |
| 4 | - | |
| 5 | -import org.aspectj.lang.JoinPoint; | |
| 6 | -import org.aspectj.lang.Signature; | |
| 7 | -import org.aspectj.lang.annotation.Aspect; | |
| 8 | -import org.aspectj.lang.annotation.Before; | |
| 9 | -import org.aspectj.lang.annotation.Pointcut; | |
| 10 | -import org.aspectj.lang.reflect.MethodSignature; | |
| 11 | -import org.springframework.stereotype.Component; | |
| 12 | -import com.ruoyi.common.annotation.DataScope; | |
| 13 | -import com.ruoyi.common.core.domain.BaseEntity; | |
| 14 | -import com.ruoyi.common.core.domain.entity.SysRole; | |
| 15 | -import com.ruoyi.common.core.domain.entity.SysUser; | |
| 16 | -import com.ruoyi.common.core.domain.model.LoginUser; | |
| 17 | -import com.ruoyi.common.utils.ServletUtils; | |
| 18 | -import com.ruoyi.common.utils.StringUtils; | |
| 19 | -import com.ruoyi.common.utils.spring.SpringUtils; | |
| 20 | -import com.ruoyi.framework.web.service.TokenService; | |
| 21 | - | |
| 22 | -/** | |
| 23 | - * 数据过滤处理 | |
| 24 | - * | |
| 25 | - * @author ruoyi | |
| 26 | - */ | |
| 27 | -@Aspect | |
| 28 | -@Component | |
| 29 | -public class DataScopeAspect { | |
| 30 | - /** | |
| 31 | - * 全部数据权限 | |
| 32 | - */ | |
| 33 | - public static final String DATA_SCOPE_ALL = "1"; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * 自定数据权限 | |
| 37 | - */ | |
| 38 | - public static final String DATA_SCOPE_CUSTOM = "2"; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * 部门数据权限 | |
| 42 | - */ | |
| 43 | - public static final String DATA_SCOPE_DEPT = "3"; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 部门及以下数据权限 | |
| 47 | - */ | |
| 48 | - public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * 仅本人数据权限 | |
| 52 | - */ | |
| 53 | - public static final String DATA_SCOPE_SELF = "5"; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * 数据权限过滤关键字 | |
| 57 | - */ | |
| 58 | - public static final String DATA_SCOPE = "dataScope"; | |
| 59 | - | |
| 60 | - // 配置织入点 | |
| 61 | - @Pointcut("@annotation(com.ruoyi.common.annotation.DataScope)") | |
| 62 | - public void dataScopePointCut() { | |
| 63 | - } | |
| 64 | - | |
| 65 | - @Before("dataScopePointCut()") | |
| 66 | - public void doBefore(JoinPoint point) throws Throwable { | |
| 67 | - handleDataScope(point); | |
| 68 | - } | |
| 69 | - | |
| 70 | - protected void handleDataScope(final JoinPoint joinPoint) { | |
| 71 | - // 获得注解 | |
| 72 | - DataScope controllerDataScope = getAnnotationLog(joinPoint); | |
| 73 | - if (controllerDataScope == null) { | |
| 74 | - return; | |
| 75 | - } | |
| 76 | - // 获取当前的用户 | |
| 77 | - LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); | |
| 78 | - if (StringUtils.isNotNull(loginUser)) { | |
| 79 | - SysUser currentUser = loginUser.getUser(); | |
| 80 | - // 如果是超级管理员,则不过滤数据 | |
| 81 | - if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) { | |
| 82 | - dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), | |
| 83 | - controllerDataScope.userAlias()); | |
| 84 | - } | |
| 85 | - } | |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * 数据范围过滤 | |
| 90 | - * | |
| 91 | - * @param joinPoint 切点 | |
| 92 | - * @param user 用户 | |
| 93 | - * @param userAlias 别名 | |
| 94 | - */ | |
| 95 | - public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) { | |
| 96 | - StringBuilder sqlString = new StringBuilder(); | |
| 97 | - | |
| 98 | - for (SysRole role : user.getRoles()) { | |
| 99 | - String dataScope = role.getDataScope(); | |
| 100 | - if (DATA_SCOPE_ALL.equals(dataScope)) { | |
| 101 | - sqlString = new StringBuilder(); | |
| 102 | - break; | |
| 103 | - } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { | |
| 104 | - sqlString.append(StringUtils.format( | |
| 105 | - " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, | |
| 106 | - role.getRoleId())); | |
| 107 | - } else if (DATA_SCOPE_DEPT.equals(dataScope)) { | |
| 108 | - sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); | |
| 109 | - } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) { | |
| 110 | - sqlString.append(StringUtils.format( | |
| 111 | - " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", | |
| 112 | - deptAlias, user.getDeptId(), user.getDeptId())); | |
| 113 | - } else if (DATA_SCOPE_SELF.equals(dataScope)) { | |
| 114 | - if (StringUtils.isNotBlank(userAlias)) { | |
| 115 | - sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); | |
| 116 | - } else { | |
| 117 | - // 数据权限为仅本人且没有userAlias别名不查询任何数据 | |
| 118 | - sqlString.append(" OR 1=0 "); | |
| 119 | - } | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - if (StringUtils.isNotBlank(sqlString.toString())) { | |
| 124 | - Object params = joinPoint.getArgs()[0]; | |
| 125 | - if (StringUtils.isNotNull(params) && params instanceof BaseEntity) { | |
| 126 | - BaseEntity baseEntity = (BaseEntity) params; | |
| 127 | - baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); | |
| 128 | - } | |
| 129 | - } | |
| 130 | - } | |
| 131 | - | |
| 132 | - /** | |
| 133 | - * 是否存在注解,如果存在就获取 | |
| 134 | - */ | |
| 135 | - private DataScope getAnnotationLog(JoinPoint joinPoint) { | |
| 136 | - Signature signature = joinPoint.getSignature(); | |
| 137 | - MethodSignature methodSignature = (MethodSignature) signature; | |
| 138 | - Method method = methodSignature.getMethod(); | |
| 139 | - | |
| 140 | - if (method != null) { | |
| 141 | - return method.getAnnotation(DataScope.class); | |
| 142 | - } | |
| 143 | - return null; | |
| 144 | - } | |
| 145 | -} | |
| 1 | +package com.ruoyi.framework.aspectj; | |
| 2 | + | |
| 3 | +import java.lang.reflect.Method; | |
| 4 | + | |
| 5 | +import org.aspectj.lang.JoinPoint; | |
| 6 | +import org.aspectj.lang.Signature; | |
| 7 | +import org.aspectj.lang.annotation.Aspect; | |
| 8 | +import org.aspectj.lang.annotation.Before; | |
| 9 | +import org.aspectj.lang.annotation.Pointcut; | |
| 10 | +import org.aspectj.lang.reflect.MethodSignature; | |
| 11 | +import org.springframework.stereotype.Component; | |
| 12 | +import com.ruoyi.common.annotation.DataScope; | |
| 13 | +import com.ruoyi.common.core.domain.BaseEntity; | |
| 14 | +import com.ruoyi.common.core.domain.entity.SysRole; | |
| 15 | +import com.ruoyi.common.core.domain.entity.SysUser; | |
| 16 | +import com.ruoyi.common.core.domain.model.LoginUser; | |
| 17 | +import com.ruoyi.common.utils.ServletUtils; | |
| 18 | +import com.ruoyi.common.utils.StringUtils; | |
| 19 | +import com.ruoyi.common.utils.spring.SpringUtils; | |
| 20 | +import com.ruoyi.framework.web.service.TokenService; | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * 数据过滤处理 | |
| 24 | + * | |
| 25 | + * @author ruoyi | |
| 26 | + */ | |
| 27 | +@Aspect | |
| 28 | +@Component | |
| 29 | +public class DataScopeAspect { | |
| 30 | + /** | |
| 31 | + * 全部数据权限 | |
| 32 | + */ | |
| 33 | + public static final String DATA_SCOPE_ALL = "1"; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 自定数据权限 | |
| 37 | + */ | |
| 38 | + public static final String DATA_SCOPE_CUSTOM = "2"; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 部门数据权限 | |
| 42 | + */ | |
| 43 | + public static final String DATA_SCOPE_DEPT = "3"; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 部门及以下数据权限 | |
| 47 | + */ | |
| 48 | + public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 仅本人数据权限 | |
| 52 | + */ | |
| 53 | + public static final String DATA_SCOPE_SELF = "5"; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * 数据权限过滤关键字 | |
| 57 | + */ | |
| 58 | + public static final String DATA_SCOPE = "dataScope"; | |
| 59 | + | |
| 60 | + // 配置织入点 | |
| 61 | + @Pointcut("@annotation(com.ruoyi.common.annotation.DataScope)") | |
| 62 | + public void dataScopePointCut() { | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Before("dataScopePointCut()") | |
| 66 | + public void doBefore(JoinPoint point) throws Throwable { | |
| 67 | + handleDataScope(point); | |
| 68 | + } | |
| 69 | + | |
| 70 | + protected void handleDataScope(final JoinPoint joinPoint) { | |
| 71 | + // 获得注解 | |
| 72 | + DataScope controllerDataScope = getAnnotationLog(joinPoint); | |
| 73 | + if (controllerDataScope == null) { | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + // 获取当前的用户 | |
| 77 | + LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); | |
| 78 | + if (StringUtils.isNotNull(loginUser)) { | |
| 79 | + SysUser currentUser = loginUser.getUser(); | |
| 80 | + // 如果是超级管理员,则不过滤数据 | |
| 81 | + if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) { | |
| 82 | + dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), | |
| 83 | + controllerDataScope.userAlias()); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * 数据范围过滤 | |
| 90 | + * | |
| 91 | + * @param joinPoint 切点 | |
| 92 | + * @param user 用户 | |
| 93 | + * @param userAlias 别名 | |
| 94 | + */ | |
| 95 | + public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) { | |
| 96 | + StringBuilder sqlString = new StringBuilder(); | |
| 97 | + | |
| 98 | + for (SysRole role : user.getRoles()) { | |
| 99 | + String dataScope = role.getDataScope(); | |
| 100 | + if (DATA_SCOPE_ALL.equals(dataScope)) { | |
| 101 | + sqlString = new StringBuilder(); | |
| 102 | + break; | |
| 103 | + } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { | |
| 104 | + sqlString.append(StringUtils.format( | |
| 105 | + " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, | |
| 106 | + role.getRoleId())); | |
| 107 | + } else if (DATA_SCOPE_DEPT.equals(dataScope)) { | |
| 108 | + sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); | |
| 109 | + } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) { | |
| 110 | + sqlString.append(StringUtils.format( | |
| 111 | + " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", | |
| 112 | + deptAlias, user.getDeptId(), user.getDeptId())); | |
| 113 | + } else if (DATA_SCOPE_SELF.equals(dataScope)) { | |
| 114 | + if (StringUtils.isNotBlank(userAlias)) { | |
| 115 | + sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); | |
| 116 | + } else { | |
| 117 | + // 数据权限为仅本人且没有userAlias别名不查询任何数据 | |
| 118 | + sqlString.append(" OR 1=0 "); | |
| 119 | + } | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | + if (StringUtils.isNotBlank(sqlString.toString())) { | |
| 124 | + Object params = joinPoint.getArgs()[0]; | |
| 125 | + if (StringUtils.isNotNull(params) && params instanceof BaseEntity) { | |
| 126 | + BaseEntity baseEntity = (BaseEntity) params; | |
| 127 | + baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * 是否存在注解,如果存在就获取 | |
| 134 | + */ | |
| 135 | + private DataScope getAnnotationLog(JoinPoint joinPoint) { | |
| 136 | + Signature signature = joinPoint.getSignature(); | |
| 137 | + MethodSignature methodSignature = (MethodSignature) signature; | |
| 138 | + Method method = methodSignature.getMethod(); | |
| 139 | + | |
| 140 | + if (method != null) { | |
| 141 | + return method.getAnnotation(DataScope.class); | |
| 142 | + } | |
| 143 | + return null; | |
| 144 | + } | |
| 145 | +} | ... | ... |
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java renamed to ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataSourceAspect.java
| 1 | -package com.ruoyi.framework.aspectj; | |
| 2 | - | |
| 3 | -import java.util.Objects; | |
| 4 | - | |
| 5 | -import org.aspectj.lang.ProceedingJoinPoint; | |
| 6 | -import org.aspectj.lang.annotation.Around; | |
| 7 | -import org.aspectj.lang.annotation.Aspect; | |
| 8 | -import org.aspectj.lang.annotation.Pointcut; | |
| 9 | -import org.aspectj.lang.reflect.MethodSignature; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.core.annotation.AnnotationUtils; | |
| 13 | -import org.springframework.core.annotation.Order; | |
| 14 | -import org.springframework.stereotype.Component; | |
| 15 | -import com.ruoyi.common.annotation.DataSource; | |
| 16 | -import com.ruoyi.common.utils.StringUtils; | |
| 17 | -import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * 多数据源处理 | |
| 21 | - * | |
| 22 | - * @author ruoyi | |
| 23 | - */ | |
| 24 | -@Aspect | |
| 25 | -@Order(1) | |
| 26 | -@Component | |
| 27 | -public class DataSourceAspect { | |
| 28 | - protected Logger logger = LoggerFactory.getLogger(getClass()); | |
| 29 | - | |
| 30 | - @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)" | |
| 31 | - + "|| @within(com.ruoyi.common.annotation.DataSource)") | |
| 32 | - public void dsPointCut() { | |
| 33 | - | |
| 34 | - } | |
| 35 | - | |
| 36 | - @Around("dsPointCut()") | |
| 37 | - public Object around(ProceedingJoinPoint point) throws Throwable { | |
| 38 | - DataSource dataSource = getDataSource(point); | |
| 39 | - | |
| 40 | - if (StringUtils.isNotNull(dataSource)) { | |
| 41 | - DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); | |
| 42 | - } | |
| 43 | - | |
| 44 | - try { | |
| 45 | - return point.proceed(); | |
| 46 | - } finally { | |
| 47 | - // 销毁数据源 在执行方法之后 | |
| 48 | - DynamicDataSourceContextHolder.clearDataSourceType(); | |
| 49 | - } | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 获取需要切换的数据源 | |
| 54 | - */ | |
| 55 | - public DataSource getDataSource(ProceedingJoinPoint point) { | |
| 56 | - MethodSignature signature = (MethodSignature) point.getSignature(); | |
| 57 | - DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class); | |
| 58 | - if (Objects.nonNull(dataSource)) { | |
| 59 | - return dataSource; | |
| 60 | - } | |
| 61 | - | |
| 62 | - return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); | |
| 63 | - } | |
| 64 | -} | |
| 1 | +package com.ruoyi.framework.aspectj; | |
| 2 | + | |
| 3 | +import java.util.Objects; | |
| 4 | + | |
| 5 | +import org.aspectj.lang.ProceedingJoinPoint; | |
| 6 | +import org.aspectj.lang.annotation.Around; | |
| 7 | +import org.aspectj.lang.annotation.Aspect; | |
| 8 | +import org.aspectj.lang.annotation.Pointcut; | |
| 9 | +import org.aspectj.lang.reflect.MethodSignature; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.core.annotation.AnnotationUtils; | |
| 13 | +import org.springframework.core.annotation.Order; | |
| 14 | +import org.springframework.stereotype.Component; | |
| 15 | +import com.ruoyi.common.annotation.DataSource; | |
| 16 | +import com.ruoyi.common.utils.StringUtils; | |
| 17 | +import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * 多数据源处理 | |
| 21 | + * | |
| 22 | + * @author ruoyi | |
| 23 | + */ | |
| 24 | +@Aspect | |
| 25 | +@Order(1) | |
| 26 | +@Component | |
| 27 | +public class DataSourceAspect { | |
| 28 | + protected Logger logger = LoggerFactory.getLogger(getClass()); | |
| 29 | + | |
| 30 | + @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)" | |
| 31 | + + "|| @within(com.ruoyi.common.annotation.DataSource)") | |
| 32 | + public void dsPointCut() { | |
| 33 | + | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Around("dsPointCut()") | |
| 37 | + public Object around(ProceedingJoinPoint point) throws Throwable { | |
| 38 | + DataSource dataSource = getDataSource(point); | |
| 39 | + | |
| 40 | + if (StringUtils.isNotNull(dataSource)) { | |
| 41 | + DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); | |
| 42 | + } | |
| 43 | + | |
| 44 | + try { | |
| 45 | + return point.proceed(); | |
| 46 | + } finally { | |
| 47 | + // 销毁数据源 在执行方法之后 | |
| 48 | + DynamicDataSourceContextHolder.clearDataSourceType(); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * 获取需要切换的数据源 | |
| 54 | + */ | |
| 55 | + public DataSource getDataSource(ProceedingJoinPoint point) { | |
| 56 | + MethodSignature signature = (MethodSignature) point.getSignature(); | |
| 57 | + DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class); | |
| 58 | + if (Objects.nonNull(dataSource)) { | |
| 59 | + return dataSource; | |
| 60 | + } | |
| 61 | + | |
| 62 | + return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); | |
| 63 | + } | |
| 64 | +} | ... | ... |
ruoyi-common/src/main/java/com/ruoyi/common/enums/DataSourceType.java renamed to ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataSourceType.java
| 1 | -package com.ruoyi.common.enums; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * 数据源 | |
| 5 | - * | |
| 6 | - * @author ruoyi | |
| 7 | - */ | |
| 8 | -public enum DataSourceType | |
| 9 | -{ | |
| 10 | - /** | |
| 11 | - * 主库 | |
| 12 | - */ | |
| 13 | - MASTER, | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * 从库 | |
| 17 | - */ | |
| 18 | - SLAVE | |
| 19 | -} | |
| 1 | +package com.ruoyi.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 数据源 | |
| 5 | + * | |
| 6 | + * @author ruoyi | |
| 7 | + */ | |
| 8 | +public enum DataSourceType | |
| 9 | +{ | |
| 10 | + /** | |
| 11 | + * 主库 | |
| 12 | + */ | |
| 13 | + MASTER, | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 从库 | |
| 17 | + */ | |
| 18 | + SLAVE | |
| 19 | +} | ... | ... |
ruoyi-framework/src/main/java/com/ruoyi/framework/datasource/DynamicDataSource.java renamed to ruoyi-common/src/main/java/com/ruoyi/common/annotation/DynamicDataSource.java
| 1 | -package com.ruoyi.framework.datasource; | |
| 2 | - | |
| 3 | -import java.util.Map; | |
| 4 | -import javax.sql.DataSource; | |
| 5 | - | |
| 6 | -import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 动态数据源 | |
| 10 | - * | |
| 11 | - * @author ruoyi | |
| 12 | - */ | |
| 13 | -public class DynamicDataSource extends AbstractRoutingDataSource { | |
| 14 | - public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) { | |
| 15 | - super.setDefaultTargetDataSource(defaultTargetDataSource); | |
| 16 | - super.setTargetDataSources(targetDataSources); | |
| 17 | - super.afterPropertiesSet(); | |
| 18 | - } | |
| 19 | - | |
| 20 | - @Override | |
| 21 | - protected Object determineCurrentLookupKey() { | |
| 22 | - return DynamicDataSourceContextHolder.getDataSourceType(); | |
| 23 | - } | |
| 24 | -} | |
| 1 | +package com.ruoyi.framework.datasource; | |
| 2 | + | |
| 3 | +import java.util.Map; | |
| 4 | +import javax.sql.DataSource; | |
| 5 | + | |
| 6 | +import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 动态数据源 | |
| 10 | + * | |
| 11 | + * @author ruoyi | |
| 12 | + */ | |
| 13 | +public class DynamicDataSource extends AbstractRoutingDataSource { | |
| 14 | + public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) { | |
| 15 | + super.setDefaultTargetDataSource(defaultTargetDataSource); | |
| 16 | + super.setTargetDataSources(targetDataSources); | |
| 17 | + super.afterPropertiesSet(); | |
| 18 | + } | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + protected Object determineCurrentLookupKey() { | |
| 22 | + return DynamicDataSourceContextHolder.getDataSourceType(); | |
| 23 | + } | |
| 24 | +} | ... | ... |
ruoyi-framework/src/main/java/com/ruoyi/framework/datasource/DynamicDataSourceContextHolder.java renamed to ruoyi-common/src/main/java/com/ruoyi/common/annotation/DynamicDataSourceContextHolder.java
| 1 | -package com.ruoyi.framework.datasource; | |
| 2 | - | |
| 3 | -import org.slf4j.Logger; | |
| 4 | -import org.slf4j.LoggerFactory; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 数据源切换处理 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public class DynamicDataSourceContextHolder { | |
| 12 | - public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class); | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * 使用ThreadLocal维护变量,ThreadLocal为每个使用该变量的线程提供独立的变量副本, | |
| 16 | - * 所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。 | |
| 17 | - */ | |
| 18 | - private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>(); | |
| 19 | - | |
| 20 | - /** | |
| 21 | - * 设置数据源的变量 | |
| 22 | - */ | |
| 23 | - public static void setDataSourceType(String dsType) { | |
| 24 | - log.info("切换到{}数据源", dsType); | |
| 25 | - CONTEXT_HOLDER.set(dsType); | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 获得数据源的变量 | |
| 30 | - */ | |
| 31 | - public static String getDataSourceType() { | |
| 32 | - return CONTEXT_HOLDER.get(); | |
| 33 | - } | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * 清空数据源变量 | |
| 37 | - */ | |
| 38 | - public static void clearDataSourceType() { | |
| 39 | - CONTEXT_HOLDER.remove(); | |
| 40 | - } | |
| 41 | -} | |
| 1 | +package com.ruoyi.framework.datasource; | |
| 2 | + | |
| 3 | +import org.slf4j.Logger; | |
| 4 | +import org.slf4j.LoggerFactory; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 数据源切换处理 | |
| 8 | + * | |
| 9 | + * @author ruoyi | |
| 10 | + */ | |
| 11 | +public class DynamicDataSourceContextHolder { | |
| 12 | + public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class); | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 使用ThreadLocal维护变量,ThreadLocal为每个使用该变量的线程提供独立的变量副本, | |
| 16 | + * 所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。 | |
| 17 | + */ | |
| 18 | + private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>(); | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 设置数据源的变量 | |
| 22 | + */ | |
| 23 | + public static void setDataSourceType(String dsType) { | |
| 24 | + log.info("切换到{}数据源", dsType); | |
| 25 | + CONTEXT_HOLDER.set(dsType); | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 获得数据源的变量 | |
| 30 | + */ | |
| 31 | + public static String getDataSourceType() { | |
| 32 | + return CONTEXT_HOLDER.get(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 清空数据源变量 | |
| 37 | + */ | |
| 38 | + public static void clearDataSourceType() { | |
| 39 | + CONTEXT_HOLDER.remove(); | |
| 40 | + } | |
| 41 | +} | ... | ... |
ruoyi-common/src/main/java/com/ruoyi/common/annotation/RepeatSubmit.java deleted
| 1 | -package com.ruoyi.common.annotation; | |
| 2 | - | |
| 3 | -import java.lang.annotation.Documented; | |
| 4 | -import java.lang.annotation.ElementType; | |
| 5 | -import java.lang.annotation.Inherited; | |
| 6 | -import java.lang.annotation.Retention; | |
| 7 | -import java.lang.annotation.RetentionPolicy; | |
| 8 | -import java.lang.annotation.Target; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * 自定义注解防止表单重复提交 | |
| 12 | - * | |
| 13 | - * @author ruoyi | |
| 14 | - */ | |
| 15 | -@Inherited | |
| 16 | -@Target(ElementType.METHOD) | |
| 17 | -@Retention(RetentionPolicy.RUNTIME) | |
| 18 | -@Documented | |
| 19 | -public @interface RepeatSubmit { | |
| 20 | - | |
| 21 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java renamed to ruoyi-common/src/main/java/com/ruoyi/common/config/DruidConfig.java
| 1 | -package com.ruoyi.framework.config; | |
| 2 | - | |
| 3 | -import java.io.IOException; | |
| 4 | -import java.util.HashMap; | |
| 5 | -import java.util.Map; | |
| 6 | -import javax.servlet.Filter; | |
| 7 | -import javax.servlet.FilterChain; | |
| 8 | -import javax.servlet.ServletException; | |
| 9 | -import javax.servlet.ServletRequest; | |
| 10 | -import javax.servlet.ServletResponse; | |
| 11 | -import javax.sql.DataSource; | |
| 12 | - | |
| 13 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
| 14 | -import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 15 | -import org.springframework.boot.web.servlet.FilterRegistrationBean; | |
| 16 | -import org.springframework.context.annotation.Bean; | |
| 17 | -import org.springframework.context.annotation.Configuration; | |
| 18 | -import org.springframework.context.annotation.Primary; | |
| 19 | -import com.alibaba.druid.pool.DruidDataSource; | |
| 20 | -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; | |
| 21 | -import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; | |
| 22 | -import com.alibaba.druid.util.Utils; | |
| 23 | -import com.ruoyi.common.enums.DataSourceType; | |
| 24 | -import com.ruoyi.common.utils.spring.SpringUtils; | |
| 25 | -import com.ruoyi.framework.config.properties.DruidProperties; | |
| 26 | -import com.ruoyi.framework.datasource.DynamicDataSource; | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * druid 配置多数据源 | |
| 30 | - * | |
| 31 | - * @author ruoyi | |
| 32 | - */ | |
| 33 | -@Configuration | |
| 34 | -public class DruidConfig { | |
| 35 | - @Bean | |
| 36 | - @ConfigurationProperties("spring.datasource.druid.master") | |
| 37 | - public DataSource masterDataSource(DruidProperties druidProperties) { | |
| 38 | - DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); | |
| 39 | - return druidProperties.dataSource(dataSource); | |
| 40 | - } | |
| 41 | - | |
| 42 | - @Bean | |
| 43 | - @ConfigurationProperties("spring.datasource.druid.slave") | |
| 44 | - @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true") | |
| 45 | - public DataSource slaveDataSource(DruidProperties druidProperties) { | |
| 46 | - DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); | |
| 47 | - return druidProperties.dataSource(dataSource); | |
| 48 | - } | |
| 49 | - | |
| 50 | - @Bean(name = "dynamicDataSource") | |
| 51 | - @Primary | |
| 52 | - public DynamicDataSource dataSource(DataSource masterDataSource) { | |
| 53 | - Map<Object, Object> targetDataSources = new HashMap<>(); | |
| 54 | - targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); | |
| 55 | - setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); | |
| 56 | - return new DynamicDataSource(masterDataSource, targetDataSources); | |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * 设置数据源 | |
| 61 | - * | |
| 62 | - * @param targetDataSources 备选数据源集合 | |
| 63 | - * @param sourceName 数据源名称 | |
| 64 | - * @param beanName bean名称 | |
| 65 | - */ | |
| 66 | - public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName) { | |
| 67 | - try { | |
| 68 | - DataSource dataSource = SpringUtils.getBean(beanName); | |
| 69 | - targetDataSources.put(sourceName, dataSource); | |
| 70 | - } catch (Exception e) { | |
| 71 | - } | |
| 72 | - } | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * 去除监控页面底部的广告 | |
| 76 | - */ | |
| 77 | - @SuppressWarnings({"rawtypes", "unchecked"}) | |
| 78 | - @Bean | |
| 79 | - @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true") | |
| 80 | - public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) { | |
| 81 | - // 获取web监控页面的参数 | |
| 82 | - DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); | |
| 83 | - // 提取common.js的配置路径 | |
| 84 | - String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; | |
| 85 | - String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); | |
| 86 | - final String filePath = "support/http/resources/js/common.js"; | |
| 87 | - // 创建filter进行过滤 | |
| 88 | - Filter filter = new Filter() { | |
| 89 | - @Override | |
| 90 | - public void init(javax.servlet.FilterConfig filterConfig) throws ServletException { | |
| 91 | - } | |
| 92 | - | |
| 93 | - @Override | |
| 94 | - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
| 95 | - throws IOException, ServletException { | |
| 96 | - chain.doFilter(request, response); | |
| 97 | - // 重置缓冲区,响应头不会被重置 | |
| 98 | - response.resetBuffer(); | |
| 99 | - // 获取common.js | |
| 100 | - String text = Utils.readFromResource(filePath); | |
| 101 | - // 正则替换banner, 除去底部的广告信息 | |
| 102 | - text = text.replaceAll("<a.*?banner\"></a><br/>", ""); | |
| 103 | - text = text.replaceAll("powered.*?shrek.wang</a>", ""); | |
| 104 | - response.getWriter().write(text); | |
| 105 | - } | |
| 106 | - | |
| 107 | - @Override | |
| 108 | - public void destroy() { | |
| 109 | - } | |
| 110 | - }; | |
| 111 | - FilterRegistrationBean registrationBean = new FilterRegistrationBean(); | |
| 112 | - registrationBean.setFilter(filter); | |
| 113 | - registrationBean.addUrlPatterns(commonJsPattern); | |
| 114 | - return registrationBean; | |
| 115 | - } | |
| 116 | -} | |
| 1 | +package com.ruoyi.framework.config; | |
| 2 | + | |
| 3 | +import java.io.IOException; | |
| 4 | +import java.util.HashMap; | |
| 5 | +import java.util.Map; | |
| 6 | +import javax.servlet.Filter; | |
| 7 | +import javax.servlet.FilterChain; | |
| 8 | +import javax.servlet.ServletException; | |
| 9 | +import javax.servlet.ServletRequest; | |
| 10 | +import javax.servlet.ServletResponse; | |
| 11 | +import javax.sql.DataSource; | |
| 12 | + | |
| 13 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
| 14 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 15 | +import org.springframework.boot.web.servlet.FilterRegistrationBean; | |
| 16 | +import org.springframework.context.annotation.Bean; | |
| 17 | +import org.springframework.context.annotation.Configuration; | |
| 18 | +import org.springframework.context.annotation.Primary; | |
| 19 | +import com.alibaba.druid.pool.DruidDataSource; | |
| 20 | +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; | |
| 21 | +import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; | |
| 22 | +import com.alibaba.druid.util.Utils; | |
| 23 | +import com.ruoyi.common.enums.DataSourceType; | |
| 24 | +import com.ruoyi.common.utils.spring.SpringUtils; | |
| 25 | +import com.ruoyi.framework.config.properties.DruidProperties; | |
| 26 | +import com.ruoyi.framework.datasource.DynamicDataSource; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * druid 配置多数据源 | |
| 30 | + * | |
| 31 | + * @author ruoyi | |
| 32 | + */ | |
| 33 | +@Configuration | |
| 34 | +public class DruidConfig { | |
| 35 | + @Bean | |
| 36 | + @ConfigurationProperties("spring.datasource.druid.master") | |
| 37 | + public DataSource masterDataSource(DruidProperties druidProperties) { | |
| 38 | + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); | |
| 39 | + return druidProperties.dataSource(dataSource); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Bean | |
| 43 | + @ConfigurationProperties("spring.datasource.druid.slave") | |
| 44 | + @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true") | |
| 45 | + public DataSource slaveDataSource(DruidProperties druidProperties) { | |
| 46 | + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); | |
| 47 | + return druidProperties.dataSource(dataSource); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Bean(name = "dynamicDataSource") | |
| 51 | + @Primary | |
| 52 | + public DynamicDataSource dataSource(DataSource masterDataSource) { | |
| 53 | + Map<Object, Object> targetDataSources = new HashMap<>(); | |
| 54 | + targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); | |
| 55 | + setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); | |
| 56 | + return new DynamicDataSource(masterDataSource, targetDataSources); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 设置数据源 | |
| 61 | + * | |
| 62 | + * @param targetDataSources 备选数据源集合 | |
| 63 | + * @param sourceName 数据源名称 | |
| 64 | + * @param beanName bean名称 | |
| 65 | + */ | |
| 66 | + public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName) { | |
| 67 | + try { | |
| 68 | + DataSource dataSource = SpringUtils.getBean(beanName); | |
| 69 | + targetDataSources.put(sourceName, dataSource); | |
| 70 | + } catch (Exception e) { | |
| 71 | + } | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * 去除监控页面底部的广告 | |
| 76 | + */ | |
| 77 | + @SuppressWarnings({"rawtypes", "unchecked"}) | |
| 78 | + @Bean | |
| 79 | + @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true") | |
| 80 | + public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) { | |
| 81 | + // 获取web监控页面的参数 | |
| 82 | + DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); | |
| 83 | + // 提取common.js的配置路径 | |
| 84 | + String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; | |
| 85 | + String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); | |
| 86 | + final String filePath = "support/http/resources/js/common.js"; | |
| 87 | + // 创建filter进行过滤 | |
| 88 | + Filter filter = new Filter() { | |
| 89 | + @Override | |
| 90 | + public void init(javax.servlet.FilterConfig filterConfig) throws ServletException { | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
| 95 | + throws IOException, ServletException { | |
| 96 | + chain.doFilter(request, response); | |
| 97 | + // 重置缓冲区,响应头不会被重置 | |
| 98 | + response.resetBuffer(); | |
| 99 | + // 获取common.js | |
| 100 | + String text = Utils.readFromResource(filePath); | |
| 101 | + // 正则替换banner, 除去底部的广告信息 | |
| 102 | + text = text.replaceAll("<a.*?banner\"></a><br/>", ""); | |
| 103 | + text = text.replaceAll("powered.*?shrek.wang</a>", ""); | |
| 104 | + response.getWriter().write(text); | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public void destroy() { | |
| 109 | + } | |
| 110 | + }; | |
| 111 | + FilterRegistrationBean registrationBean = new FilterRegistrationBean(); | |
| 112 | + registrationBean.setFilter(filter); | |
| 113 | + registrationBean.addUrlPatterns(commonJsPattern); | |
| 114 | + return registrationBean; | |
| 115 | + } | |
| 116 | +} | ... | ... |
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java deleted
| 1 | -package com.ruoyi.common.constant; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * 代码生成通用常量 | |
| 5 | - * | |
| 6 | - * @author ruoyi | |
| 7 | - */ | |
| 8 | -public class GenConstants | |
| 9 | -{ | |
| 10 | - /** 单表(增删改查) */ | |
| 11 | - public static final String TPL_CRUD = "crud"; | |
| 12 | - | |
| 13 | - /** 树表(增删改查) */ | |
| 14 | - public static final String TPL_TREE = "tree"; | |
| 15 | - | |
| 16 | - | |
| 17 | - /** 树编码字段 */ | |
| 18 | - public static final String TREE_CODE = "treeCode"; | |
| 19 | - | |
| 20 | - /** 树父编码字段 */ | |
| 21 | - public static final String TREE_PARENT_CODE = "treeParentCode"; | |
| 22 | - | |
| 23 | - /** 树名称字段 */ | |
| 24 | - public static final String TREE_NAME = "treeName"; | |
| 25 | - | |
| 26 | - /** 上级菜单ID字段 */ | |
| 27 | - public static final String PARENT_MENU_ID = "parentMenuId"; | |
| 28 | - | |
| 29 | - /** 上级菜单名称字段 */ | |
| 30 | - public static final String PARENT_MENU_NAME = "parentMenuName"; | |
| 31 | - | |
| 32 | - /** 数据库字符串类型 */ | |
| 33 | - public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; | |
| 34 | - | |
| 35 | - /** 数据库文本类型 */ | |
| 36 | - public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" }; | |
| 37 | - | |
| 38 | - /** 数据库时间类型 */ | |
| 39 | - public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" }; | |
| 40 | - | |
| 41 | - /** 数据库数字类型 */ | |
| 42 | - public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer", | |
| 43 | - "bit", "bigint", "float", "double", "decimal" }; | |
| 44 | - | |
| 45 | - /** 页面不需要编辑字段 */ | |
| 46 | - public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" }; | |
| 47 | - | |
| 48 | - /** 页面不需要显示的列表字段 */ | |
| 49 | - public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by", | |
| 50 | - "update_time" }; | |
| 51 | - | |
| 52 | - /** 页面不需要查询字段 */ | |
| 53 | - public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by", | |
| 54 | - "update_time", "remark" }; | |
| 55 | - | |
| 56 | - /** Entity基类字段 */ | |
| 57 | - public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" }; | |
| 58 | - | |
| 59 | - /** Tree基类字段 */ | |
| 60 | - public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" }; | |
| 61 | - | |
| 62 | - /** 文本框 */ | |
| 63 | - public static final String HTML_INPUT = "input"; | |
| 64 | - | |
| 65 | - /** 文本域 */ | |
| 66 | - public static final String HTML_TEXTAREA = "textarea"; | |
| 67 | - | |
| 68 | - /** 下拉框 */ | |
| 69 | - public static final String HTML_SELECT = "select"; | |
| 70 | - | |
| 71 | - /** 单选框 */ | |
| 72 | - public static final String HTML_RADIO = "radio"; | |
| 73 | - | |
| 74 | - /** 复选框 */ | |
| 75 | - public static final String HTML_CHECKBOX = "checkbox"; | |
| 76 | - | |
| 77 | - /** 日期控件 */ | |
| 78 | - public static final String HTML_DATETIME = "datetime"; | |
| 79 | - | |
| 80 | - /** 上传控件 */ | |
| 81 | - public static final String HTML_UPLOAD_IMAGE = "uploadImage"; | |
| 82 | - | |
| 83 | - /** 富文本控件 */ | |
| 84 | - public static final String HTML_EDITOR = "editor"; | |
| 85 | - | |
| 86 | - /** 字符串类型 */ | |
| 87 | - public static final String TYPE_STRING = "String"; | |
| 88 | - | |
| 89 | - /** 整型 */ | |
| 90 | - public static final String TYPE_INTEGER = "Integer"; | |
| 91 | - | |
| 92 | - /** 长整型 */ | |
| 93 | - public static final String TYPE_LONG = "Long"; | |
| 94 | - | |
| 95 | - /** 浮点型 */ | |
| 96 | - public static final String TYPE_DOUBLE = "Double"; | |
| 97 | - | |
| 98 | - /** 高精度计算类型 */ | |
| 99 | - public static final String TYPE_BIGDECIMAL = "BigDecimal"; | |
| 100 | - | |
| 101 | - /** 时间类型 */ | |
| 102 | - public static final String TYPE_DATE = "Date"; | |
| 103 | - | |
| 104 | - /** 模糊查询 */ | |
| 105 | - public static final String QUERY_LIKE = "LIKE"; | |
| 106 | - | |
| 107 | - /** 需要 */ | |
| 108 | - public static final String REQUIRE = "1"; | |
| 109 | -} |
ruoyi-common/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java deleted
| 1 | -package com.ruoyi.common.constant; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * 任务调度通用常量 | |
| 5 | - * | |
| 6 | - * @author ruoyi | |
| 7 | - */ | |
| 8 | -public class ScheduleConstants | |
| 9 | -{ | |
| 10 | - public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; | |
| 11 | - | |
| 12 | - /** 执行目标key */ | |
| 13 | - public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; | |
| 14 | - | |
| 15 | - /** 默认 */ | |
| 16 | - public static final String MISFIRE_DEFAULT = "0"; | |
| 17 | - | |
| 18 | - /** 立即触发执行 */ | |
| 19 | - public static final String MISFIRE_IGNORE_MISFIRES = "1"; | |
| 20 | - | |
| 21 | - /** 触发一次执行 */ | |
| 22 | - public static final String MISFIRE_FIRE_AND_PROCEED = "2"; | |
| 23 | - | |
| 24 | - /** 不触发立即执行 */ | |
| 25 | - public static final String MISFIRE_DO_NOTHING = "3"; | |
| 26 | - | |
| 27 | - public enum Status | |
| 28 | - { | |
| 29 | - /** | |
| 30 | - * 正常 | |
| 31 | - */ | |
| 32 | - NORMAL("0"), | |
| 33 | - /** | |
| 34 | - * 暂停 | |
| 35 | - */ | |
| 36 | - PAUSE("1"); | |
| 37 | - | |
| 38 | - private String value; | |
| 39 | - | |
| 40 | - private Status(String value) | |
| 41 | - { | |
| 42 | - this.value = value; | |
| 43 | - } | |
| 44 | - | |
| 45 | - public String getValue() | |
| 46 | - { | |
| 47 | - return value; | |
| 48 | - } | |
| 49 | - } | |
| 50 | -} |
ruoyi-common/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java deleted
| 1 | -package com.ruoyi.common.filter; | |
| 2 | - | |
| 3 | -import java.io.IOException; | |
| 4 | -import javax.servlet.Filter; | |
| 5 | -import javax.servlet.FilterChain; | |
| 6 | -import javax.servlet.FilterConfig; | |
| 7 | -import javax.servlet.ServletException; | |
| 8 | -import javax.servlet.ServletRequest; | |
| 9 | -import javax.servlet.ServletResponse; | |
| 10 | -import javax.servlet.http.HttpServletRequest; | |
| 11 | - | |
| 12 | -import org.springframework.http.MediaType; | |
| 13 | -import com.ruoyi.common.utils.StringUtils; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * Repeatable 过滤器 | |
| 17 | - * | |
| 18 | - * @author ruoyi | |
| 19 | - */ | |
| 20 | -public class RepeatableFilter implements Filter { | |
| 21 | - @Override | |
| 22 | - public void init(FilterConfig filterConfig) throws ServletException { | |
| 23 | - | |
| 24 | - } | |
| 25 | - | |
| 26 | - @Override | |
| 27 | - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
| 28 | - throws IOException, ServletException { | |
| 29 | - ServletRequest requestWrapper = null; | |
| 30 | - if (request instanceof HttpServletRequest | |
| 31 | - && StringUtils.equalsAnyIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) { | |
| 32 | - requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); | |
| 33 | - } | |
| 34 | - if (null == requestWrapper) { | |
| 35 | - chain.doFilter(request, response); | |
| 36 | - } else { | |
| 37 | - chain.doFilter(requestWrapper, response); | |
| 38 | - } | |
| 39 | - } | |
| 40 | - | |
| 41 | - @Override | |
| 42 | - public void destroy() { | |
| 43 | - | |
| 44 | - } | |
| 45 | -} |
ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java deleted
| 1 | -package com.ruoyi.common.filter; | |
| 2 | - | |
| 3 | -import java.io.IOException; | |
| 4 | -import java.util.ArrayList; | |
| 5 | -import java.util.List; | |
| 6 | -import java.util.regex.Matcher; | |
| 7 | -import java.util.regex.Pattern; | |
| 8 | -import javax.servlet.Filter; | |
| 9 | -import javax.servlet.FilterChain; | |
| 10 | -import javax.servlet.FilterConfig; | |
| 11 | -import javax.servlet.ServletException; | |
| 12 | -import javax.servlet.ServletRequest; | |
| 13 | -import javax.servlet.ServletResponse; | |
| 14 | -import javax.servlet.http.HttpServletRequest; | |
| 15 | -import javax.servlet.http.HttpServletResponse; | |
| 16 | -import com.ruoyi.common.utils.StringUtils; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * 防止XSS攻击的过滤器 | |
| 20 | - * | |
| 21 | - * @author ruoyi | |
| 22 | - */ | |
| 23 | -public class XssFilter implements Filter | |
| 24 | -{ | |
| 25 | - /** | |
| 26 | - * 排除链接 | |
| 27 | - */ | |
| 28 | - public List<String> excludes = new ArrayList<>(); | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * xss过滤开关 | |
| 32 | - */ | |
| 33 | - public boolean enabled = false; | |
| 34 | - | |
| 35 | - @Override | |
| 36 | - public void init(FilterConfig filterConfig) throws ServletException | |
| 37 | - { | |
| 38 | - String tempExcludes = filterConfig.getInitParameter("excludes"); | |
| 39 | - String tempEnabled = filterConfig.getInitParameter("enabled"); | |
| 40 | - if (StringUtils.isNotEmpty(tempExcludes)) | |
| 41 | - { | |
| 42 | - String[] url = tempExcludes.split(","); | |
| 43 | - for (int i = 0; url != null && i < url.length; i++) | |
| 44 | - { | |
| 45 | - excludes.add(url[i]); | |
| 46 | - } | |
| 47 | - } | |
| 48 | - if (StringUtils.isNotEmpty(tempEnabled)) | |
| 49 | - { | |
| 50 | - enabled = Boolean.valueOf(tempEnabled); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | - @Override | |
| 55 | - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |
| 56 | - throws IOException, ServletException | |
| 57 | - { | |
| 58 | - HttpServletRequest req = (HttpServletRequest) request; | |
| 59 | - HttpServletResponse resp = (HttpServletResponse) response; | |
| 60 | - if (handleExcludeURL(req, resp)) | |
| 61 | - { | |
| 62 | - chain.doFilter(request, response); | |
| 63 | - return; | |
| 64 | - } | |
| 65 | - XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request); | |
| 66 | - chain.doFilter(xssRequest, response); | |
| 67 | - } | |
| 68 | - | |
| 69 | - private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) | |
| 70 | - { | |
| 71 | - if (!enabled) | |
| 72 | - { | |
| 73 | - return true; | |
| 74 | - } | |
| 75 | - if (excludes == null || excludes.isEmpty()) | |
| 76 | - { | |
| 77 | - return false; | |
| 78 | - } | |
| 79 | - String url = request.getServletPath(); | |
| 80 | - for (String pattern : excludes) | |
| 81 | - { | |
| 82 | - Pattern p = Pattern.compile("^" + pattern); | |
| 83 | - Matcher m = p.matcher(url); | |
| 84 | - if (m.find()) | |
| 85 | - { | |
| 86 | - return true; | |
| 87 | - } | |
| 88 | - } | |
| 89 | - return false; | |
| 90 | - } | |
| 91 | - | |
| 92 | - @Override | |
| 93 | - public void destroy() | |
| 94 | - { | |
| 95 | - | |
| 96 | - } | |
| 97 | -} | |
| 98 | 0 | \ No newline at end of file |
ruoyi-common/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java deleted
| 1 | -package com.ruoyi.common.filter; | |
| 2 | - | |
| 3 | -import java.io.ByteArrayInputStream; | |
| 4 | -import java.io.IOException; | |
| 5 | -import javax.servlet.ReadListener; | |
| 6 | -import javax.servlet.ServletInputStream; | |
| 7 | -import javax.servlet.http.HttpServletRequest; | |
| 8 | -import javax.servlet.http.HttpServletRequestWrapper; | |
| 9 | -import org.apache.commons.io.IOUtils; | |
| 10 | -import org.springframework.http.HttpHeaders; | |
| 11 | -import org.springframework.http.MediaType; | |
| 12 | -import com.ruoyi.common.utils.StringUtils; | |
| 13 | -import com.ruoyi.common.utils.html.EscapeUtil; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * XSS过滤处理 | |
| 17 | - * | |
| 18 | - * @author ruoyi | |
| 19 | - */ | |
| 20 | -public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper | |
| 21 | -{ | |
| 22 | - /** | |
| 23 | - * @param request | |
| 24 | - */ | |
| 25 | - public XssHttpServletRequestWrapper(HttpServletRequest request) | |
| 26 | - { | |
| 27 | - super(request); | |
| 28 | - } | |
| 29 | - | |
| 30 | - @Override | |
| 31 | - public String[] getParameterValues(String name) | |
| 32 | - { | |
| 33 | - String[] values = super.getParameterValues(name); | |
| 34 | - if (values != null) | |
| 35 | - { | |
| 36 | - int length = values.length; | |
| 37 | - String[] escapseValues = new String[length]; | |
| 38 | - for (int i = 0; i < length; i++) | |
| 39 | - { | |
| 40 | - // 防xss攻击和过滤前后空格 | |
| 41 | - escapseValues[i] = EscapeUtil.clean(values[i]).trim(); | |
| 42 | - } | |
| 43 | - return escapseValues; | |
| 44 | - } | |
| 45 | - return super.getParameterValues(name); | |
| 46 | - } | |
| 47 | - | |
| 48 | - @Override | |
| 49 | - public ServletInputStream getInputStream() throws IOException | |
| 50 | - { | |
| 51 | - // 非json类型,直接返回 | |
| 52 | - if (!isJsonRequest()) | |
| 53 | - { | |
| 54 | - return super.getInputStream(); | |
| 55 | - } | |
| 56 | - | |
| 57 | - // 为空,直接返回 | |
| 58 | - String json = IOUtils.toString(super.getInputStream(), "utf-8"); | |
| 59 | - if (StringUtils.isEmpty(json)) | |
| 60 | - { | |
| 61 | - return super.getInputStream(); | |
| 62 | - } | |
| 63 | - | |
| 64 | - // xss过滤 | |
| 65 | - json = EscapeUtil.clean(json).trim(); | |
| 66 | - final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); | |
| 67 | - return new ServletInputStream() | |
| 68 | - { | |
| 69 | - @Override | |
| 70 | - public boolean isFinished() | |
| 71 | - { | |
| 72 | - return true; | |
| 73 | - } | |
| 74 | - | |
| 75 | - @Override | |
| 76 | - public boolean isReady() | |
| 77 | - { | |
| 78 | - return true; | |
| 79 | - } | |
| 80 | - | |
| 81 | - @Override | |
| 82 | - public void setReadListener(ReadListener readListener) | |
| 83 | - { | |
| 84 | - } | |
| 85 | - | |
| 86 | - @Override | |
| 87 | - public int read() throws IOException | |
| 88 | - { | |
| 89 | - return bis.read(); | |
| 90 | - } | |
| 91 | - }; | |
| 92 | - } | |
| 93 | - | |
| 94 | - /** | |
| 95 | - * 是否是Json请求 | |
| 96 | - * | |
| 97 | - * @param request | |
| 98 | - */ | |
| 99 | - public boolean isJsonRequest() | |
| 100 | - { | |
| 101 | - String header = super.getHeader(HttpHeaders.CONTENT_TYPE); | |
| 102 | - return MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(header); | |
| 103 | - } | |
| 104 | -} | |
| 105 | 0 | \ No newline at end of file |
ruoyi-admin/src/main/resources/application-druid.yml renamed to ruoyi-common/src/main/resources/application-druid.yml
| 1 | -# 数据源配置 | |
| 2 | -spring: | |
| 3 | - datasource: | |
| 4 | - type: com.alibaba.druid.pool.DruidDataSource | |
| 5 | - driverClassName: com.mysql.cj.jdbc.Driver | |
| 6 | - druid: | |
| 7 | - # 主库数据源 | |
| 8 | - master: | |
| 9 | - url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 | |
| 10 | - username: root | |
| 11 | - password: password | |
| 12 | - # 从库数据源 | |
| 13 | - slave: | |
| 14 | - # 从数据源开关/默认关闭 | |
| 15 | - enabled: false | |
| 16 | - url: | |
| 17 | - username: | |
| 18 | - password: | |
| 19 | - # 初始连接数 | |
| 20 | - initialSize: 5 | |
| 21 | - # 最小连接池数量 | |
| 22 | - minIdle: 10 | |
| 23 | - # 最大连接池数量 | |
| 24 | - maxActive: 20 | |
| 25 | - # 配置获取连接等待超时的时间 | |
| 26 | - maxWait: 60000 | |
| 27 | - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | |
| 28 | - timeBetweenEvictionRunsMillis: 60000 | |
| 29 | - # 配置一个连接在池中最小生存的时间,单位是毫秒 | |
| 30 | - minEvictableIdleTimeMillis: 300000 | |
| 31 | - # 配置一个连接在池中最大生存的时间,单位是毫秒 | |
| 32 | - maxEvictableIdleTimeMillis: 900000 | |
| 33 | - # 配置检测连接是否有效 | |
| 34 | - validationQuery: SELECT 1 FROM DUAL | |
| 35 | - testWhileIdle: true | |
| 36 | - testOnBorrow: false | |
| 37 | - testOnReturn: false | |
| 38 | - webStatFilter: | |
| 39 | - enabled: true | |
| 40 | - statViewServlet: | |
| 41 | - enabled: true | |
| 42 | - # 设置白名单,不填则允许所有访问 | |
| 43 | - allow: | |
| 44 | - url-pattern: /druid/* | |
| 45 | - # 控制台管理用户名和密码 | |
| 46 | - login-username: | |
| 47 | - login-password: | |
| 48 | - filter: | |
| 49 | - stat: | |
| 50 | - enabled: true | |
| 51 | - # 慢SQL记录 | |
| 52 | - log-slow-sql: true | |
| 53 | - slow-sql-millis: 1000 | |
| 54 | - merge-sql: true | |
| 55 | - wall: | |
| 56 | - config: | |
| 57 | - multi-statement-allow: true | |
| 58 | 1 | \ No newline at end of file |
| 2 | +# 数据源配置 | |
| 3 | +spring: | |
| 4 | + datasource: | |
| 5 | + type: com.alibaba.druid.pool.DruidDataSource | |
| 6 | + driverClassName: com.mysql.cj.jdbc.Driver | |
| 7 | + druid: | |
| 8 | + # 主库数据源 | |
| 9 | + master: | |
| 10 | + url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 | |
| 11 | + username: root | |
| 12 | + password: password | |
| 13 | + # 从库数据源 | |
| 14 | + slave: | |
| 15 | + # 从数据源开关/默认关闭 | |
| 16 | + enabled: false | |
| 17 | + url: | |
| 18 | + username: | |
| 19 | + password: | |
| 20 | + # 初始连接数 | |
| 21 | + initialSize: 5 | |
| 22 | + # 最小连接池数量 | |
| 23 | + minIdle: 10 | |
| 24 | + # 最大连接池数量 | |
| 25 | + maxActive: 20 | |
| 26 | + # 配置获取连接等待超时的时间 | |
| 27 | + maxWait: 60000 | |
| 28 | + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | |
| 29 | + timeBetweenEvictionRunsMillis: 60000 | |
| 30 | + # 配置一个连接在池中最小生存的时间,单位是毫秒 | |
| 31 | + minEvictableIdleTimeMillis: 300000 | |
| 32 | + # 配置一个连接在池中最大生存的时间,单位是毫秒 | |
| 33 | + maxEvictableIdleTimeMillis: 900000 | |
| 34 | + # 配置检测连接是否有效 | |
| 35 | + validationQuery: SELECT 1 FROM DUAL | |
| 36 | + testWhileIdle: true | |
| 37 | + testOnBorrow: false | |
| 38 | + testOnReturn: false | ... | ... |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java deleted
| 1 | -package com.ruoyi.framework.config; | |
| 2 | - | |
| 3 | -import java.util.HashMap; | |
| 4 | -import java.util.Map; | |
| 5 | -import javax.servlet.DispatcherType; | |
| 6 | - | |
| 7 | -import org.springframework.beans.factory.annotation.Value; | |
| 8 | -import org.springframework.boot.web.servlet.FilterRegistrationBean; | |
| 9 | -import org.springframework.context.annotation.Bean; | |
| 10 | -import org.springframework.context.annotation.Configuration; | |
| 11 | -import com.ruoyi.common.filter.RepeatableFilter; | |
| 12 | -import com.ruoyi.common.filter.XssFilter; | |
| 13 | -import com.ruoyi.common.utils.StringUtils; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * Filter配置 | |
| 17 | - * | |
| 18 | - * @author ruoyi | |
| 19 | - */ | |
| 20 | -@Configuration | |
| 21 | -public class FilterConfig { | |
| 22 | - @Value("${xss.enabled}") | |
| 23 | - private String enabled; | |
| 24 | - | |
| 25 | - @Value("${xss.excludes}") | |
| 26 | - private String excludes; | |
| 27 | - | |
| 28 | - @Value("${xss.urlPatterns}") | |
| 29 | - private String urlPatterns; | |
| 30 | - | |
| 31 | - @SuppressWarnings({"rawtypes", "unchecked"}) | |
| 32 | - @Bean | |
| 33 | - public FilterRegistrationBean xssFilterRegistration() { | |
| 34 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | |
| 35 | - registration.setDispatcherTypes(DispatcherType.REQUEST); | |
| 36 | - registration.setFilter(new XssFilter()); | |
| 37 | - registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); | |
| 38 | - registration.setName("xssFilter"); | |
| 39 | - registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); | |
| 40 | - Map<String, String> initParameters = new HashMap<String, String>(); | |
| 41 | - initParameters.put("excludes", excludes); | |
| 42 | - initParameters.put("enabled", enabled); | |
| 43 | - registration.setInitParameters(initParameters); | |
| 44 | - return registration; | |
| 45 | - } | |
| 46 | - | |
| 47 | - @SuppressWarnings({"rawtypes", "unchecked"}) | |
| 48 | - @Bean | |
| 49 | - public FilterRegistrationBean someFilterRegistration() { | |
| 50 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | |
| 51 | - registration.setFilter(new RepeatableFilter()); | |
| 52 | - registration.addUrlPatterns("/*"); | |
| 53 | - registration.setName("repeatableFilter"); | |
| 54 | - registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE); | |
| 55 | - return registration; | |
| 56 | - } | |
| 57 | - | |
| 58 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java deleted
| 1 | -package com.ruoyi.framework.config; | |
| 2 | - | |
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | -import org.springframework.context.annotation.Bean; | |
| 5 | -import org.springframework.context.annotation.Configuration; | |
| 6 | -import org.springframework.web.cors.CorsConfiguration; | |
| 7 | -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | |
| 8 | -import org.springframework.web.filter.CorsFilter; | |
| 9 | -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |
| 10 | -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |
| 11 | -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
| 12 | -import com.ruoyi.common.config.RuoYiConfig; | |
| 13 | -import com.ruoyi.common.constant.Constants; | |
| 14 | -import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * 通用配置 | |
| 18 | - * | |
| 19 | - * @author ruoyi | |
| 20 | - */ | |
| 21 | -@Configuration | |
| 22 | -public class ResourcesConfig implements WebMvcConfigurer { | |
| 23 | - @Autowired | |
| 24 | - private RepeatSubmitInterceptor repeatSubmitInterceptor; | |
| 25 | - | |
| 26 | - @Override | |
| 27 | - public void addResourceHandlers(ResourceHandlerRegistry registry) { | |
| 28 | - /** 本地文件上传路径 */ | |
| 29 | - registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); | |
| 30 | - | |
| 31 | - /** swagger配置 */ | |
| 32 | - registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); | |
| 33 | - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); | |
| 34 | - } | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 自定义拦截规则 | |
| 38 | - */ | |
| 39 | - @Override | |
| 40 | - public void addInterceptors(InterceptorRegistry registry) { | |
| 41 | - registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); | |
| 42 | - } | |
| 43 | - | |
| 44 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ServerConfig.java deleted
| 1 | -package com.ruoyi.framework.config; | |
| 2 | - | |
| 3 | -import javax.servlet.http.HttpServletRequest; | |
| 4 | - | |
| 5 | -import org.springframework.stereotype.Component; | |
| 6 | -import com.ruoyi.common.utils.ServletUtils; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 服务相关配置 | |
| 10 | - * | |
| 11 | - * @author ruoyi | |
| 12 | - */ | |
| 13 | -@Component | |
| 14 | -public class ServerConfig { | |
| 15 | - /** | |
| 16 | - * 获取完整的请求路径,包括:域名,端口,上下文访问路径 | |
| 17 | - * | |
| 18 | - * @return 服务地址 | |
| 19 | - */ | |
| 20 | - public String getUrl() { | |
| 21 | - HttpServletRequest request = ServletUtils.getRequest(); | |
| 22 | - return getDomain(request); | |
| 23 | - } | |
| 24 | - | |
| 25 | - public static String getDomain(HttpServletRequest request) { | |
| 26 | - StringBuffer url = request.getRequestURL(); | |
| 27 | - String contextPath = request.getServletContext().getContextPath(); | |
| 28 | - return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString(); | |
| 29 | - } | |
| 30 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java deleted
| 1 | -package com.ruoyi.framework.config; | |
| 2 | - | |
| 3 | -import java.util.concurrent.ScheduledExecutorService; | |
| 4 | -import java.util.concurrent.ScheduledThreadPoolExecutor; | |
| 5 | -import java.util.concurrent.ThreadPoolExecutor; | |
| 6 | - | |
| 7 | -import org.apache.commons.lang3.concurrent.BasicThreadFactory; | |
| 8 | -import org.springframework.context.annotation.Bean; | |
| 9 | -import org.springframework.context.annotation.Configuration; | |
| 10 | -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
| 11 | -import com.ruoyi.common.utils.Threads; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * 线程池配置 | |
| 15 | - * | |
| 16 | - * @author ruoyi | |
| 17 | - **/ | |
| 18 | -@Configuration | |
| 19 | -public class ThreadPoolConfig { | |
| 20 | - // 核心线程池大小 | |
| 21 | - private int corePoolSize = 50; | |
| 22 | - | |
| 23 | - // 最大可创建的线程数 | |
| 24 | - private int maxPoolSize = 200; | |
| 25 | - | |
| 26 | - // 队列最大长度 | |
| 27 | - private int queueCapacity = 1000; | |
| 28 | - | |
| 29 | - // 线程池维护线程所允许的空闲时间 | |
| 30 | - private int keepAliveSeconds = 300; | |
| 31 | - | |
| 32 | - @Bean(name = "threadPoolTaskExecutor") | |
| 33 | - public ThreadPoolTaskExecutor threadPoolTaskExecutor() { | |
| 34 | - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | |
| 35 | - executor.setMaxPoolSize(maxPoolSize); | |
| 36 | - executor.setCorePoolSize(corePoolSize); | |
| 37 | - executor.setQueueCapacity(queueCapacity); | |
| 38 | - executor.setKeepAliveSeconds(keepAliveSeconds); | |
| 39 | - // 线程池对拒绝任务(无线程可用)的处理策略 | |
| 40 | - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); | |
| 41 | - return executor; | |
| 42 | - } | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 执行周期性或定时任务 | |
| 46 | - */ | |
| 47 | - @Bean(name = "scheduledExecutorService") | |
| 48 | - protected ScheduledExecutorService scheduledExecutorService() { | |
| 49 | - return new ScheduledThreadPoolExecutor(corePoolSize, | |
| 50 | - new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) { | |
| 51 | - @Override | |
| 52 | - protected void afterExecute(Runnable r, Throwable t) { | |
| 53 | - super.afterExecute(r, t); | |
| 54 | - Threads.printException(r, t); | |
| 55 | - } | |
| 56 | - }; | |
| 57 | - } | |
| 58 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java deleted
| 1 | -package com.ruoyi.framework.config.properties; | |
| 2 | - | |
| 3 | -import org.springframework.beans.factory.annotation.Value; | |
| 4 | -import org.springframework.context.annotation.Configuration; | |
| 5 | -import com.alibaba.druid.pool.DruidDataSource; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * druid 配置属性 | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - */ | |
| 12 | -@Configuration | |
| 13 | -public class DruidProperties { | |
| 14 | - @Value("${spring.datasource.druid.initialSize}") | |
| 15 | - private int initialSize; | |
| 16 | - | |
| 17 | - @Value("${spring.datasource.druid.minIdle}") | |
| 18 | - private int minIdle; | |
| 19 | - | |
| 20 | - @Value("${spring.datasource.druid.maxActive}") | |
| 21 | - private int maxActive; | |
| 22 | - | |
| 23 | - @Value("${spring.datasource.druid.maxWait}") | |
| 24 | - private int maxWait; | |
| 25 | - | |
| 26 | - @Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}") | |
| 27 | - private int timeBetweenEvictionRunsMillis; | |
| 28 | - | |
| 29 | - @Value("${spring.datasource.druid.minEvictableIdleTimeMillis}") | |
| 30 | - private int minEvictableIdleTimeMillis; | |
| 31 | - | |
| 32 | - @Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}") | |
| 33 | - private int maxEvictableIdleTimeMillis; | |
| 34 | - | |
| 35 | - @Value("${spring.datasource.druid.validationQuery}") | |
| 36 | - private String validationQuery; | |
| 37 | - | |
| 38 | - @Value("${spring.datasource.druid.testWhileIdle}") | |
| 39 | - private boolean testWhileIdle; | |
| 40 | - | |
| 41 | - @Value("${spring.datasource.druid.testOnBorrow}") | |
| 42 | - private boolean testOnBorrow; | |
| 43 | - | |
| 44 | - @Value("${spring.datasource.druid.testOnReturn}") | |
| 45 | - private boolean testOnReturn; | |
| 46 | - | |
| 47 | - public DruidDataSource dataSource(DruidDataSource datasource) { | |
| 48 | - /** 配置初始化大小、最小、最大 */ | |
| 49 | - datasource.setInitialSize(initialSize); | |
| 50 | - datasource.setMaxActive(maxActive); | |
| 51 | - datasource.setMinIdle(minIdle); | |
| 52 | - | |
| 53 | - /** 配置获取连接等待超时的时间 */ | |
| 54 | - datasource.setMaxWait(maxWait); | |
| 55 | - | |
| 56 | - /** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */ | |
| 57 | - datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); | |
| 58 | - | |
| 59 | - /** 配置一个连接在池中最小、最大生存的时间,单位是毫秒 */ | |
| 60 | - datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); | |
| 61 | - datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。 | |
| 65 | - */ | |
| 66 | - datasource.setValidationQuery(validationQuery); | |
| 67 | - /** 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 */ | |
| 68 | - datasource.setTestWhileIdle(testWhileIdle); | |
| 69 | - /** 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ | |
| 70 | - datasource.setTestOnBorrow(testOnBorrow); | |
| 71 | - /** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ | |
| 72 | - datasource.setTestOnReturn(testOnReturn); | |
| 73 | - return datasource; | |
| 74 | - } | |
| 75 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java deleted
| 1 | -package com.ruoyi.framework.interceptor; | |
| 2 | - | |
| 3 | -import java.lang.reflect.Method; | |
| 4 | -import javax.servlet.http.HttpServletRequest; | |
| 5 | -import javax.servlet.http.HttpServletResponse; | |
| 6 | - | |
| 7 | -import org.springframework.stereotype.Component; | |
| 8 | -import org.springframework.web.method.HandlerMethod; | |
| 9 | -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |
| 10 | -import com.alibaba.fastjson.JSONObject; | |
| 11 | -import com.ruoyi.common.annotation.RepeatSubmit; | |
| 12 | -import com.ruoyi.common.core.domain.AjaxResult; | |
| 13 | -import com.ruoyi.common.utils.ServletUtils; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 防止重复提交拦截器 | |
| 17 | - * | |
| 18 | - * @author ruoyi | |
| 19 | - */ | |
| 20 | -@Component | |
| 21 | -public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter { | |
| 22 | - @Override | |
| 23 | - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |
| 24 | - if (handler instanceof HandlerMethod) { | |
| 25 | - HandlerMethod handlerMethod = (HandlerMethod) handler; | |
| 26 | - Method method = handlerMethod.getMethod(); | |
| 27 | - RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); | |
| 28 | - if (annotation != null) { | |
| 29 | - if (this.isRepeatSubmit(request)) { | |
| 30 | - AjaxResult ajaxResult = AjaxResult.error("不允许重复提交,请稍后再试"); | |
| 31 | - ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult)); | |
| 32 | - return false; | |
| 33 | - } | |
| 34 | - } | |
| 35 | - return true; | |
| 36 | - } else { | |
| 37 | - return super.preHandle(request, response, handler); | |
| 38 | - } | |
| 39 | - } | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 验证是否重复提交由子类实现具体的防重复提交的规则 | |
| 43 | - * | |
| 44 | - * @param request | |
| 45 | - * @return | |
| 46 | - * @throws Exception | |
| 47 | - */ | |
| 48 | - public abstract boolean isRepeatSubmit(HttpServletRequest request); | |
| 49 | -} |
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java deleted
| 1 | -package com.ruoyi.framework.interceptor.impl; | |
| 2 | - | |
| 3 | -import java.util.HashMap; | |
| 4 | -import java.util.Map; | |
| 5 | -import java.util.concurrent.TimeUnit; | |
| 6 | -import javax.servlet.http.HttpServletRequest; | |
| 7 | - | |
| 8 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | -import org.springframework.beans.factory.annotation.Value; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | -import com.alibaba.fastjson.JSONObject; | |
| 12 | -import com.ruoyi.common.constant.Constants; | |
| 13 | -import com.ruoyi.common.core.redis.RedisCache; | |
| 14 | -import com.ruoyi.common.filter.RepeatedlyRequestWrapper; | |
| 15 | -import com.ruoyi.common.utils.StringUtils; | |
| 16 | -import com.ruoyi.common.utils.http.HttpHelper; | |
| 17 | -import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * 判断请求url和数据是否和上一次相同, | |
| 21 | - * 如果和上次相同,则是重复提交表单。 有效时间为10秒内。 | |
| 22 | - * | |
| 23 | - * @author ruoyi | |
| 24 | - */ | |
| 25 | -@Component | |
| 26 | -public class SameUrlDataInterceptor extends RepeatSubmitInterceptor { | |
| 27 | - public final String REPEAT_PARAMS = "repeatParams"; | |
| 28 | - | |
| 29 | - public final String REPEAT_TIME = "repeatTime"; | |
| 30 | - | |
| 31 | - // 令牌自定义标识 | |
| 32 | - @Value("${token.header}") | |
| 33 | - private String header; | |
| 34 | - | |
| 35 | - @Autowired | |
| 36 | - private RedisCache redisCache; | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 间隔时间,单位:秒 默认10秒 | |
| 40 | - * <p> | |
| 41 | - * 两次相同参数的请求,如果间隔时间大于该参数,系统不会认定为重复提交的数据 | |
| 42 | - */ | |
| 43 | - private int intervalTime = 10; | |
| 44 | - | |
| 45 | - public void setIntervalTime(int intervalTime) { | |
| 46 | - this.intervalTime = intervalTime; | |
| 47 | - } | |
| 48 | - | |
| 49 | - @SuppressWarnings("unchecked") | |
| 50 | - @Override | |
| 51 | - public boolean isRepeatSubmit(HttpServletRequest request) { | |
| 52 | - String nowParams = ""; | |
| 53 | - if (request instanceof RepeatedlyRequestWrapper) { | |
| 54 | - RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; | |
| 55 | - nowParams = HttpHelper.getBodyString(repeatedlyRequest); | |
| 56 | - } | |
| 57 | - | |
| 58 | - // body参数为空,获取Parameter的数据 | |
| 59 | - if (StringUtils.isEmpty(nowParams)) { | |
| 60 | - nowParams = JSONObject.toJSONString(request.getParameterMap()); | |
| 61 | - } | |
| 62 | - Map<String, Object> nowDataMap = new HashMap<String, Object>(); | |
| 63 | - nowDataMap.put(REPEAT_PARAMS, nowParams); | |
| 64 | - nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); | |
| 65 | - | |
| 66 | - // 请求地址(作为存放cache的key值) | |
| 67 | - String url = request.getRequestURI(); | |
| 68 | - | |
| 69 | - // 唯一值(没有消息头则使用请求地址) | |
| 70 | - String submitKey = request.getHeader(header); | |
| 71 | - if (StringUtils.isEmpty(submitKey)) { | |
| 72 | - submitKey = url; | |
| 73 | - } | |
| 74 | - | |
| 75 | - // 唯一标识(指定key + 消息头) | |
| 76 | - String cache_repeat_key = Constants.REPEAT_SUBMIT_KEY + submitKey; | |
| 77 | - | |
| 78 | - Object sessionObj = redisCache.getCacheObject(cache_repeat_key); | |
| 79 | - if (sessionObj != null) { | |
| 80 | - Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; | |
| 81 | - if (sessionMap.containsKey(url)) { | |
| 82 | - Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url); | |
| 83 | - if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap)) { | |
| 84 | - return true; | |
| 85 | - } | |
| 86 | - } | |
| 87 | - } | |
| 88 | - Map<String, Object> cacheMap = new HashMap<String, Object>(); | |
| 89 | - cacheMap.put(url, nowDataMap); | |
| 90 | - redisCache.setCacheObject(cache_repeat_key, cacheMap, intervalTime, TimeUnit.SECONDS); | |
| 91 | - return false; | |
| 92 | - } | |
| 93 | - | |
| 94 | - /** | |
| 95 | - * 判断参数是否相同 | |
| 96 | - */ | |
| 97 | - private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap) { | |
| 98 | - String nowParams = (String) nowMap.get(REPEAT_PARAMS); | |
| 99 | - String preParams = (String) preMap.get(REPEAT_PARAMS); | |
| 100 | - return nowParams.equals(preParams); | |
| 101 | - } | |
| 102 | - | |
| 103 | - /** | |
| 104 | - * 判断两次间隔时间 | |
| 105 | - */ | |
| 106 | - private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap) { | |
| 107 | - long time1 = (Long) nowMap.get(REPEAT_TIME); | |
| 108 | - long time2 = (Long) preMap.get(REPEAT_TIME); | |
| 109 | - if ((time1 - time2) < (this.intervalTime * 1000)) { | |
| 110 | - return true; | |
| 111 | - } | |
| 112 | - return false; | |
| 113 | - } | |
| 114 | -} |
ruoyi-generator/pom.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 5 | - <parent> | |
| 6 | - <artifactId>ruoyi</artifactId> | |
| 7 | - <groupId>com.ruoyi</groupId> | |
| 8 | - <version>3.3.0</version> | |
| 9 | - </parent> | |
| 10 | - <modelVersion>4.0.0</modelVersion> | |
| 11 | - | |
| 12 | - <artifactId>ruoyi-generator</artifactId> | |
| 13 | - | |
| 14 | - <description> | |
| 15 | - generator代码生成 | |
| 16 | - </description> | |
| 17 | - | |
| 18 | - <dependencies> | |
| 19 | - | |
| 20 | - <!--velocity代码生成使用模板 --> | |
| 21 | - <dependency> | |
| 22 | - <groupId>org.apache.velocity</groupId> | |
| 23 | - <artifactId>velocity</artifactId> | |
| 24 | - </dependency> | |
| 25 | - | |
| 26 | - <!-- 通用工具--> | |
| 27 | - <dependency> | |
| 28 | - <groupId>com.ruoyi</groupId> | |
| 29 | - <artifactId>ruoyi-common</artifactId> | |
| 30 | - </dependency> | |
| 31 | - | |
| 32 | - </dependencies> | |
| 33 | - | |
| 34 | -</project> | |
| 35 | 0 | \ No newline at end of file |
ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java deleted
| 1 | -package com.ruoyi.generator.config; | |
| 2 | - | |
| 3 | -import org.springframework.beans.factory.annotation.Value; | |
| 4 | -import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 5 | -import org.springframework.context.annotation.PropertySource; | |
| 6 | -import org.springframework.stereotype.Component; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 读取代码生成相关配置 | |
| 10 | - * | |
| 11 | - * @author ruoyi | |
| 12 | - */ | |
| 13 | -@Component | |
| 14 | -@ConfigurationProperties(prefix = "gen") | |
| 15 | -@PropertySource(value = { "classpath:generator.yml" }) | |
| 16 | -public class GenConfig | |
| 17 | -{ | |
| 18 | - /** 作者 */ | |
| 19 | - public static String author; | |
| 20 | - | |
| 21 | - /** 生成包路径 */ | |
| 22 | - public static String packageName; | |
| 23 | - | |
| 24 | - /** 自动去除表前缀,默认是false */ | |
| 25 | - public static boolean autoRemovePre; | |
| 26 | - | |
| 27 | - /** 表前缀(类名不会包含表前缀) */ | |
| 28 | - public static String tablePrefix; | |
| 29 | - | |
| 30 | - public static String getAuthor() | |
| 31 | - { | |
| 32 | - return author; | |
| 33 | - } | |
| 34 | - | |
| 35 | - @Value("${author}") | |
| 36 | - public void setAuthor(String author) | |
| 37 | - { | |
| 38 | - GenConfig.author = author; | |
| 39 | - } | |
| 40 | - | |
| 41 | - public static String getPackageName() | |
| 42 | - { | |
| 43 | - return packageName; | |
| 44 | - } | |
| 45 | - | |
| 46 | - @Value("${packageName}") | |
| 47 | - public void setPackageName(String packageName) | |
| 48 | - { | |
| 49 | - GenConfig.packageName = packageName; | |
| 50 | - } | |
| 51 | - | |
| 52 | - public static boolean getAutoRemovePre() | |
| 53 | - { | |
| 54 | - return autoRemovePre; | |
| 55 | - } | |
| 56 | - | |
| 57 | - @Value("${autoRemovePre}") | |
| 58 | - public void setAutoRemovePre(boolean autoRemovePre) | |
| 59 | - { | |
| 60 | - GenConfig.autoRemovePre = autoRemovePre; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public static String getTablePrefix() | |
| 64 | - { | |
| 65 | - return tablePrefix; | |
| 66 | - } | |
| 67 | - | |
| 68 | - @Value("${tablePrefix}") | |
| 69 | - public void setTablePrefix(String tablePrefix) | |
| 70 | - { | |
| 71 | - GenConfig.tablePrefix = tablePrefix; | |
| 72 | - } | |
| 73 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java deleted
| 1 | -package com.ruoyi.generator.controller; | |
| 2 | - | |
| 3 | -import java.io.IOException; | |
| 4 | -import java.util.HashMap; | |
| 5 | -import java.util.List; | |
| 6 | -import java.util.Map; | |
| 7 | -import javax.servlet.http.HttpServletResponse; | |
| 8 | -import org.apache.commons.io.IOUtils; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 11 | -import org.springframework.validation.annotation.Validated; | |
| 12 | -import org.springframework.web.bind.annotation.DeleteMapping; | |
| 13 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 14 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 15 | -import org.springframework.web.bind.annotation.PostMapping; | |
| 16 | -import org.springframework.web.bind.annotation.PutMapping; | |
| 17 | -import org.springframework.web.bind.annotation.RequestBody; | |
| 18 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | -import org.springframework.web.bind.annotation.RestController; | |
| 20 | -import com.ruoyi.common.annotation.Log; | |
| 21 | -import com.ruoyi.common.core.controller.BaseController; | |
| 22 | -import com.ruoyi.common.core.domain.AjaxResult; | |
| 23 | -import com.ruoyi.common.core.page.TableDataInfo; | |
| 24 | -import com.ruoyi.common.core.text.Convert; | |
| 25 | -import com.ruoyi.common.enums.BusinessType; | |
| 26 | -import com.ruoyi.generator.domain.GenTable; | |
| 27 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 28 | -import com.ruoyi.generator.service.IGenTableColumnService; | |
| 29 | -import com.ruoyi.generator.service.IGenTableService; | |
| 30 | - | |
| 31 | -/** | |
| 32 | - * 代码生成 操作处理 | |
| 33 | - * | |
| 34 | - * @author ruoyi | |
| 35 | - */ | |
| 36 | -@RestController | |
| 37 | -@RequestMapping("/tool/gen") | |
| 38 | -public class GenController extends BaseController | |
| 39 | -{ | |
| 40 | - @Autowired | |
| 41 | - private IGenTableService genTableService; | |
| 42 | - | |
| 43 | - @Autowired | |
| 44 | - private IGenTableColumnService genTableColumnService; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 查询代码生成列表 | |
| 48 | - */ | |
| 49 | - @PreAuthorize("@ss.hasPermi('tool:gen:list')") | |
| 50 | - @GetMapping("/list") | |
| 51 | - public TableDataInfo genList(GenTable genTable) | |
| 52 | - { | |
| 53 | - startPage(); | |
| 54 | - List<GenTable> list = genTableService.selectGenTableList(genTable); | |
| 55 | - return getDataTable(list); | |
| 56 | - } | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * 修改代码生成业务 | |
| 60 | - */ | |
| 61 | - @PreAuthorize("@ss.hasPermi('tool:gen:query')") | |
| 62 | - @GetMapping(value = "/{talbleId}") | |
| 63 | - public AjaxResult getInfo(@PathVariable Long talbleId) | |
| 64 | - { | |
| 65 | - GenTable table = genTableService.selectGenTableById(talbleId); | |
| 66 | - List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); | |
| 67 | - Map<String, Object> map = new HashMap<String, Object>(); | |
| 68 | - map.put("info", table); | |
| 69 | - map.put("rows", list); | |
| 70 | - return AjaxResult.success(map); | |
| 71 | - } | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * 查询数据库列表 | |
| 75 | - */ | |
| 76 | - @PreAuthorize("@ss.hasPermi('tool:gen:list')") | |
| 77 | - @GetMapping("/db/list") | |
| 78 | - public TableDataInfo dataList(GenTable genTable) | |
| 79 | - { | |
| 80 | - startPage(); | |
| 81 | - List<GenTable> list = genTableService.selectDbTableList(genTable); | |
| 82 | - return getDataTable(list); | |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * 查询数据表字段列表 | |
| 87 | - */ | |
| 88 | - @PreAuthorize("@ss.hasPermi('tool:gen:list')") | |
| 89 | - @GetMapping(value = "/column/{talbleId}") | |
| 90 | - public TableDataInfo columnList(Long tableId) | |
| 91 | - { | |
| 92 | - TableDataInfo dataInfo = new TableDataInfo(); | |
| 93 | - List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); | |
| 94 | - dataInfo.setRows(list); | |
| 95 | - dataInfo.setTotal(list.size()); | |
| 96 | - return dataInfo; | |
| 97 | - } | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * 导入表结构(保存) | |
| 101 | - */ | |
| 102 | - @PreAuthorize("@ss.hasPermi('tool:gen:list')") | |
| 103 | - @Log(title = "代码生成", businessType = BusinessType.IMPORT) | |
| 104 | - @PostMapping("/importTable") | |
| 105 | - public AjaxResult importTableSave(String tables) | |
| 106 | - { | |
| 107 | - String[] tableNames = Convert.toStrArray(tables); | |
| 108 | - // 查询表信息 | |
| 109 | - List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); | |
| 110 | - genTableService.importGenTable(tableList); | |
| 111 | - return AjaxResult.success(); | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | - * 修改保存代码生成业务 | |
| 116 | - */ | |
| 117 | - @PreAuthorize("@ss.hasPermi('tool:gen:edit')") | |
| 118 | - @Log(title = "代码生成", businessType = BusinessType.UPDATE) | |
| 119 | - @PutMapping | |
| 120 | - public AjaxResult editSave(@Validated @RequestBody GenTable genTable) | |
| 121 | - { | |
| 122 | - genTableService.validateEdit(genTable); | |
| 123 | - genTableService.updateGenTable(genTable); | |
| 124 | - return AjaxResult.success(); | |
| 125 | - } | |
| 126 | - | |
| 127 | - /** | |
| 128 | - * 删除代码生成 | |
| 129 | - */ | |
| 130 | - @PreAuthorize("@ss.hasPermi('tool:gen:remove')") | |
| 131 | - @Log(title = "代码生成", businessType = BusinessType.DELETE) | |
| 132 | - @DeleteMapping("/{tableIds}") | |
| 133 | - public AjaxResult remove(@PathVariable Long[] tableIds) | |
| 134 | - { | |
| 135 | - genTableService.deleteGenTableByIds(tableIds); | |
| 136 | - return AjaxResult.success(); | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * 预览代码 | |
| 141 | - */ | |
| 142 | - @PreAuthorize("@ss.hasPermi('tool:gen:preview')") | |
| 143 | - @GetMapping("/preview/{tableId}") | |
| 144 | - public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException | |
| 145 | - { | |
| 146 | - Map<String, String> dataMap = genTableService.previewCode(tableId); | |
| 147 | - return AjaxResult.success(dataMap); | |
| 148 | - } | |
| 149 | - | |
| 150 | - /** | |
| 151 | - * 生成代码(下载方式) | |
| 152 | - */ | |
| 153 | - @PreAuthorize("@ss.hasPermi('tool:gen:code')") | |
| 154 | - @Log(title = "代码生成", businessType = BusinessType.GENCODE) | |
| 155 | - @GetMapping("/download/{tableName}") | |
| 156 | - public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException | |
| 157 | - { | |
| 158 | - byte[] data = genTableService.downloadCode(tableName); | |
| 159 | - genCode(response, data); | |
| 160 | - } | |
| 161 | - | |
| 162 | - /** | |
| 163 | - * 生成代码(自定义路径) | |
| 164 | - */ | |
| 165 | - @PreAuthorize("@ss.hasPermi('tool:gen:code')") | |
| 166 | - @Log(title = "代码生成", businessType = BusinessType.GENCODE) | |
| 167 | - @GetMapping("/genCode/{tableName}") | |
| 168 | - public AjaxResult genCode(@PathVariable("tableName") String tableName) | |
| 169 | - { | |
| 170 | - genTableService.generatorCode(tableName); | |
| 171 | - return AjaxResult.success(); | |
| 172 | - } | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * 同步数据库 | |
| 176 | - */ | |
| 177 | - @PreAuthorize("@ss.hasPermi('tool:gen:edit')") | |
| 178 | - @Log(title = "代码生成", businessType = BusinessType.UPDATE) | |
| 179 | - @GetMapping("/synchDb/{tableName}") | |
| 180 | - public AjaxResult synchDb(@PathVariable("tableName") String tableName) | |
| 181 | - { | |
| 182 | - genTableService.synchDb(tableName); | |
| 183 | - return AjaxResult.success(); | |
| 184 | - } | |
| 185 | - | |
| 186 | - /** | |
| 187 | - * 批量生成代码 | |
| 188 | - */ | |
| 189 | - @PreAuthorize("@ss.hasPermi('tool:gen:code')") | |
| 190 | - @Log(title = "代码生成", businessType = BusinessType.GENCODE) | |
| 191 | - @GetMapping("/batchGenCode") | |
| 192 | - public void batchGenCode(HttpServletResponse response, String tables) throws IOException | |
| 193 | - { | |
| 194 | - String[] tableNames = Convert.toStrArray(tables); | |
| 195 | - byte[] data = genTableService.downloadCode(tableNames); | |
| 196 | - genCode(response, data); | |
| 197 | - } | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * 生成zip文件 | |
| 201 | - */ | |
| 202 | - private void genCode(HttpServletResponse response, byte[] data) throws IOException | |
| 203 | - { | |
| 204 | - response.reset(); | |
| 205 | - response.addHeader("Access-Control-Allow-Origin", "*"); | |
| 206 | - response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); | |
| 207 | - response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); | |
| 208 | - response.addHeader("Content-Length", "" + data.length); | |
| 209 | - response.setContentType("application/octet-stream; charset=UTF-8"); | |
| 210 | - IOUtils.write(data, response.getOutputStream()); | |
| 211 | - } | |
| 212 | -} | |
| 213 | 0 | \ No newline at end of file |
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java deleted
| 1 | -package com.ruoyi.generator.domain; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import javax.validation.Valid; | |
| 5 | -import javax.validation.constraints.NotBlank; | |
| 6 | -import org.apache.commons.lang3.ArrayUtils; | |
| 7 | -import com.ruoyi.common.constant.GenConstants; | |
| 8 | -import com.ruoyi.common.core.domain.BaseEntity; | |
| 9 | -import com.ruoyi.common.utils.StringUtils; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 业务表 gen_table | |
| 13 | - * | |
| 14 | - * @author ruoyi | |
| 15 | - */ | |
| 16 | -public class GenTable extends BaseEntity | |
| 17 | -{ | |
| 18 | - private static final long serialVersionUID = 1L; | |
| 19 | - | |
| 20 | - /** 编号 */ | |
| 21 | - private Long tableId; | |
| 22 | - | |
| 23 | - /** 表名称 */ | |
| 24 | - @NotBlank(message = "表名称不能为空") | |
| 25 | - private String tableName; | |
| 26 | - | |
| 27 | - /** 表描述 */ | |
| 28 | - @NotBlank(message = "表描述不能为空") | |
| 29 | - private String tableComment; | |
| 30 | - | |
| 31 | - /** 实体类名称(首字母大写) */ | |
| 32 | - @NotBlank(message = "实体类名称不能为空") | |
| 33 | - private String className; | |
| 34 | - | |
| 35 | - /** 使用的模板(crud单表操作 tree树表操作) */ | |
| 36 | - private String tplCategory; | |
| 37 | - | |
| 38 | - /** 生成包路径 */ | |
| 39 | - @NotBlank(message = "生成包路径不能为空") | |
| 40 | - private String packageName; | |
| 41 | - | |
| 42 | - /** 生成模块名 */ | |
| 43 | - @NotBlank(message = "生成模块名不能为空") | |
| 44 | - private String moduleName; | |
| 45 | - | |
| 46 | - /** 生成业务名 */ | |
| 47 | - @NotBlank(message = "生成业务名不能为空") | |
| 48 | - private String businessName; | |
| 49 | - | |
| 50 | - /** 生成功能名 */ | |
| 51 | - @NotBlank(message = "生成功能名不能为空") | |
| 52 | - private String functionName; | |
| 53 | - | |
| 54 | - /** 生成作者 */ | |
| 55 | - @NotBlank(message = "作者不能为空") | |
| 56 | - private String functionAuthor; | |
| 57 | - | |
| 58 | - /** 生成代码方式(0zip压缩包 1自定义路径) */ | |
| 59 | - private String genType; | |
| 60 | - | |
| 61 | - /** 生成路径(不填默认项目路径) */ | |
| 62 | - private String genPath; | |
| 63 | - | |
| 64 | - /** 主键信息 */ | |
| 65 | - private GenTableColumn pkColumn; | |
| 66 | - | |
| 67 | - /** 表列信息 */ | |
| 68 | - @Valid | |
| 69 | - private List<GenTableColumn> columns; | |
| 70 | - | |
| 71 | - /** 其它生成选项 */ | |
| 72 | - private String options; | |
| 73 | - | |
| 74 | - /** 树编码字段 */ | |
| 75 | - private String treeCode; | |
| 76 | - | |
| 77 | - /** 树父编码字段 */ | |
| 78 | - private String treeParentCode; | |
| 79 | - | |
| 80 | - /** 树名称字段 */ | |
| 81 | - private String treeName; | |
| 82 | - | |
| 83 | - /** 上级菜单ID字段 */ | |
| 84 | - private String parentMenuId; | |
| 85 | - | |
| 86 | - /** 上级菜单名称字段 */ | |
| 87 | - private String parentMenuName; | |
| 88 | - | |
| 89 | - public boolean isTree() | |
| 90 | - { | |
| 91 | - return isTree(this.tplCategory); | |
| 92 | - } | |
| 93 | - | |
| 94 | - public static boolean isTree(String tplCategory) | |
| 95 | - { | |
| 96 | - return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); | |
| 97 | - } | |
| 98 | - | |
| 99 | - public boolean isCrud() | |
| 100 | - { | |
| 101 | - return isCrud(this.tplCategory); | |
| 102 | - } | |
| 103 | - | |
| 104 | - public static boolean isCrud(String tplCategory) | |
| 105 | - { | |
| 106 | - return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); | |
| 107 | - } | |
| 108 | - | |
| 109 | - public boolean isSuperColumn(String javaField) | |
| 110 | - { | |
| 111 | - return isSuperColumn(this.tplCategory, javaField); | |
| 112 | - } | |
| 113 | - | |
| 114 | - public static boolean isSuperColumn(String tplCategory, String javaField) | |
| 115 | - { | |
| 116 | - if (isTree(tplCategory)) | |
| 117 | - { | |
| 118 | - return StringUtils.equalsAnyIgnoreCase(javaField, | |
| 119 | - ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); | |
| 120 | - } | |
| 121 | - return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); | |
| 122 | - } | |
| 123 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java deleted
| 1 | -package com.ruoyi.generator.domain; | |
| 2 | - | |
| 3 | -import javax.validation.constraints.NotBlank; | |
| 4 | -import com.ruoyi.common.core.domain.BaseEntity; | |
| 5 | -import com.ruoyi.common.utils.StringUtils; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 代码生成业务字段表 gen_table_column | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - */ | |
| 12 | -public class GenTableColumn extends BaseEntity | |
| 13 | -{ | |
| 14 | - private static final long serialVersionUID = 1L; | |
| 15 | - | |
| 16 | - /** 编号 */ | |
| 17 | - private Long columnId; | |
| 18 | - | |
| 19 | - /** 归属表编号 */ | |
| 20 | - private Long tableId; | |
| 21 | - | |
| 22 | - /** 列名称 */ | |
| 23 | - private String columnName; | |
| 24 | - | |
| 25 | - /** 列描述 */ | |
| 26 | - private String columnComment; | |
| 27 | - | |
| 28 | - /** 列类型 */ | |
| 29 | - private String columnType; | |
| 30 | - | |
| 31 | - /** JAVA类型 */ | |
| 32 | - private String javaType; | |
| 33 | - | |
| 34 | - /** JAVA字段名 */ | |
| 35 | - @NotBlank(message = "Java属性不能为空") | |
| 36 | - private String javaField; | |
| 37 | - | |
| 38 | - /** 是否主键(1是) */ | |
| 39 | - private String isPk; | |
| 40 | - | |
| 41 | - /** 是否自增(1是) */ | |
| 42 | - private String isIncrement; | |
| 43 | - | |
| 44 | - /** 是否必填(1是) */ | |
| 45 | - private String isRequired; | |
| 46 | - | |
| 47 | - /** 是否为插入字段(1是) */ | |
| 48 | - private String isInsert; | |
| 49 | - | |
| 50 | - /** 是否编辑字段(1是) */ | |
| 51 | - private String isEdit; | |
| 52 | - | |
| 53 | - /** 是否列表字段(1是) */ | |
| 54 | - private String isList; | |
| 55 | - | |
| 56 | - /** 是否查询字段(1是) */ | |
| 57 | - private String isQuery; | |
| 58 | - | |
| 59 | - /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */ | |
| 60 | - private String queryType; | |
| 61 | - | |
| 62 | - /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件、editor富文本控件) */ | |
| 63 | - private String htmlType; | |
| 64 | - | |
| 65 | - /** 字典类型 */ | |
| 66 | - private String dictType; | |
| 67 | - | |
| 68 | - /** 排序 */ | |
| 69 | - private Integer sort; | |
| 70 | - | |
| 71 | - public void setColumnId(Long columnId) | |
| 72 | - { | |
| 73 | - this.columnId = columnId; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public Long getColumnId() | |
| 77 | - { | |
| 78 | - return columnId; | |
| 79 | - } | |
| 80 | - | |
| 81 | - public void setTableId(Long tableId) | |
| 82 | - { | |
| 83 | - this.tableId = tableId; | |
| 84 | - } | |
| 85 | - | |
| 86 | - public Long getTableId() | |
| 87 | - { | |
| 88 | - return tableId; | |
| 89 | - } | |
| 90 | - | |
| 91 | - public void setColumnName(String columnName) | |
| 92 | - { | |
| 93 | - this.columnName = columnName; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public String getColumnName() | |
| 97 | - { | |
| 98 | - return columnName; | |
| 99 | - } | |
| 100 | - | |
| 101 | - public void setColumnComment(String columnComment) | |
| 102 | - { | |
| 103 | - this.columnComment = columnComment; | |
| 104 | - } | |
| 105 | - | |
| 106 | - public String getColumnComment() | |
| 107 | - { | |
| 108 | - return columnComment; | |
| 109 | - } | |
| 110 | - | |
| 111 | - public void setColumnType(String columnType) | |
| 112 | - { | |
| 113 | - this.columnType = columnType; | |
| 114 | - } | |
| 115 | - | |
| 116 | - public String getColumnType() | |
| 117 | - { | |
| 118 | - return columnType; | |
| 119 | - } | |
| 120 | - | |
| 121 | - public void setJavaType(String javaType) | |
| 122 | - { | |
| 123 | - this.javaType = javaType; | |
| 124 | - } | |
| 125 | - | |
| 126 | - public String getJavaType() | |
| 127 | - { | |
| 128 | - return javaType; | |
| 129 | - } | |
| 130 | - | |
| 131 | - public void setJavaField(String javaField) | |
| 132 | - { | |
| 133 | - this.javaField = javaField; | |
| 134 | - } | |
| 135 | - | |
| 136 | - public String getJavaField() | |
| 137 | - { | |
| 138 | - return javaField; | |
| 139 | - } | |
| 140 | - | |
| 141 | - public void setIsPk(String isPk) | |
| 142 | - { | |
| 143 | - this.isPk = isPk; | |
| 144 | - } | |
| 145 | - | |
| 146 | - public String getIsPk() | |
| 147 | - { | |
| 148 | - return isPk; | |
| 149 | - } | |
| 150 | - | |
| 151 | - public boolean isPk() | |
| 152 | - { | |
| 153 | - return isPk(this.isPk); | |
| 154 | - } | |
| 155 | - | |
| 156 | - public boolean isPk(String isPk) | |
| 157 | - { | |
| 158 | - return isPk != null && StringUtils.equals("1", isPk); | |
| 159 | - } | |
| 160 | - | |
| 161 | - public String getIsIncrement() | |
| 162 | - { | |
| 163 | - return isIncrement; | |
| 164 | - } | |
| 165 | - | |
| 166 | - public void setIsIncrement(String isIncrement) | |
| 167 | - { | |
| 168 | - this.isIncrement = isIncrement; | |
| 169 | - } | |
| 170 | - | |
| 171 | - public boolean isIncrement() | |
| 172 | - { | |
| 173 | - return isIncrement(this.isIncrement); | |
| 174 | - } | |
| 175 | - | |
| 176 | - public boolean isIncrement(String isIncrement) | |
| 177 | - { | |
| 178 | - return isIncrement != null && StringUtils.equals("1", isIncrement); | |
| 179 | - } | |
| 180 | - | |
| 181 | - public void setIsRequired(String isRequired) | |
| 182 | - { | |
| 183 | - this.isRequired = isRequired; | |
| 184 | - } | |
| 185 | - | |
| 186 | - public String getIsRequired() | |
| 187 | - { | |
| 188 | - return isRequired; | |
| 189 | - } | |
| 190 | - | |
| 191 | - public boolean isRequired() | |
| 192 | - { | |
| 193 | - return isRequired(this.isRequired); | |
| 194 | - } | |
| 195 | - | |
| 196 | - public boolean isRequired(String isRequired) | |
| 197 | - { | |
| 198 | - return isRequired != null && StringUtils.equals("1", isRequired); | |
| 199 | - } | |
| 200 | - | |
| 201 | - public void setIsInsert(String isInsert) | |
| 202 | - { | |
| 203 | - this.isInsert = isInsert; | |
| 204 | - } | |
| 205 | - | |
| 206 | - public String getIsInsert() | |
| 207 | - { | |
| 208 | - return isInsert; | |
| 209 | - } | |
| 210 | - | |
| 211 | - public boolean isInsert() | |
| 212 | - { | |
| 213 | - return isInsert(this.isInsert); | |
| 214 | - } | |
| 215 | - | |
| 216 | - public boolean isInsert(String isInsert) | |
| 217 | - { | |
| 218 | - return isInsert != null && StringUtils.equals("1", isInsert); | |
| 219 | - } | |
| 220 | - | |
| 221 | - public void setIsEdit(String isEdit) | |
| 222 | - { | |
| 223 | - this.isEdit = isEdit; | |
| 224 | - } | |
| 225 | - | |
| 226 | - public String getIsEdit() | |
| 227 | - { | |
| 228 | - return isEdit; | |
| 229 | - } | |
| 230 | - | |
| 231 | - public boolean isEdit() | |
| 232 | - { | |
| 233 | - return isInsert(this.isEdit); | |
| 234 | - } | |
| 235 | - | |
| 236 | - public boolean isEdit(String isEdit) | |
| 237 | - { | |
| 238 | - return isEdit != null && StringUtils.equals("1", isEdit); | |
| 239 | - } | |
| 240 | - | |
| 241 | - public void setIsList(String isList) | |
| 242 | - { | |
| 243 | - this.isList = isList; | |
| 244 | - } | |
| 245 | - | |
| 246 | - public String getIsList() | |
| 247 | - { | |
| 248 | - return isList; | |
| 249 | - } | |
| 250 | - | |
| 251 | - public boolean isList() | |
| 252 | - { | |
| 253 | - return isList(this.isList); | |
| 254 | - } | |
| 255 | - | |
| 256 | - public boolean isList(String isList) | |
| 257 | - { | |
| 258 | - return isList != null && StringUtils.equals("1", isList); | |
| 259 | - } | |
| 260 | - | |
| 261 | - public void setIsQuery(String isQuery) | |
| 262 | - { | |
| 263 | - this.isQuery = isQuery; | |
| 264 | - } | |
| 265 | - | |
| 266 | - public String getIsQuery() | |
| 267 | - { | |
| 268 | - return isQuery; | |
| 269 | - } | |
| 270 | - | |
| 271 | - public boolean isQuery() | |
| 272 | - { | |
| 273 | - return isQuery(this.isQuery); | |
| 274 | - } | |
| 275 | - | |
| 276 | - public boolean isQuery(String isQuery) | |
| 277 | - { | |
| 278 | - return isQuery != null && StringUtils.equals("1", isQuery); | |
| 279 | - } | |
| 280 | - | |
| 281 | - public void setQueryType(String queryType) | |
| 282 | - { | |
| 283 | - this.queryType = queryType; | |
| 284 | - } | |
| 285 | - | |
| 286 | - public String getQueryType() | |
| 287 | - { | |
| 288 | - return queryType; | |
| 289 | - } | |
| 290 | - | |
| 291 | - public String getHtmlType() | |
| 292 | - { | |
| 293 | - return htmlType; | |
| 294 | - } | |
| 295 | - | |
| 296 | - public void setHtmlType(String htmlType) | |
| 297 | - { | |
| 298 | - this.htmlType = htmlType; | |
| 299 | - } | |
| 300 | - | |
| 301 | - public void setDictType(String dictType) | |
| 302 | - { | |
| 303 | - this.dictType = dictType; | |
| 304 | - } | |
| 305 | - | |
| 306 | - public String getDictType() | |
| 307 | - { | |
| 308 | - return dictType; | |
| 309 | - } | |
| 310 | - | |
| 311 | - public void setSort(Integer sort) | |
| 312 | - { | |
| 313 | - this.sort = sort; | |
| 314 | - } | |
| 315 | - | |
| 316 | - public Integer getSort() | |
| 317 | - { | |
| 318 | - return sort; | |
| 319 | - } | |
| 320 | - | |
| 321 | - public boolean isSuperColumn() | |
| 322 | - { | |
| 323 | - return isSuperColumn(this.javaField); | |
| 324 | - } | |
| 325 | - | |
| 326 | - public static boolean isSuperColumn(String javaField) | |
| 327 | - { | |
| 328 | - return StringUtils.equalsAnyIgnoreCase(javaField, | |
| 329 | - // BaseEntity | |
| 330 | - "createBy", "createTime", "updateBy", "updateTime", "remark", | |
| 331 | - // TreeEntity | |
| 332 | - "parentName", "parentId", "orderNum", "ancestors"); | |
| 333 | - } | |
| 334 | - | |
| 335 | - public boolean isUsableColumn() | |
| 336 | - { | |
| 337 | - return isUsableColumn(javaField); | |
| 338 | - } | |
| 339 | - | |
| 340 | - public static boolean isUsableColumn(String javaField) | |
| 341 | - { | |
| 342 | - // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 | |
| 343 | - return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); | |
| 344 | - } | |
| 345 | - | |
| 346 | - public String readConverterExp() | |
| 347 | - { | |
| 348 | - String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); | |
| 349 | - StringBuffer sb = new StringBuffer(); | |
| 350 | - if (StringUtils.isNotEmpty(remarks)) | |
| 351 | - { | |
| 352 | - for (String value : remarks.split(" ")) | |
| 353 | - { | |
| 354 | - if (StringUtils.isNotEmpty(value)) | |
| 355 | - { | |
| 356 | - Object startStr = value.subSequence(0, 1); | |
| 357 | - String endStr = value.substring(1); | |
| 358 | - sb.append("").append(startStr).append("=").append(endStr).append(","); | |
| 359 | - } | |
| 360 | - } | |
| 361 | - return sb.deleteCharAt(sb.length() - 1).toString(); | |
| 362 | - } | |
| 363 | - else | |
| 364 | - { | |
| 365 | - return this.columnComment; | |
| 366 | - } | |
| 367 | - } | |
| 368 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java deleted
| 1 | -package com.ruoyi.generator.mapper; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 业务字段 数据层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface GenTableColumnMapper | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 根据表名称查询列信息 | |
| 15 | - * | |
| 16 | - * @param tableName 表名称 | |
| 17 | - * @return 列信息 | |
| 18 | - */ | |
| 19 | - public List<GenTableColumn> selectDbTableColumnsByName(String tableName); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 查询业务字段列表 | |
| 23 | - * | |
| 24 | - * @param tableId 业务字段编号 | |
| 25 | - * @return 业务字段集合 | |
| 26 | - */ | |
| 27 | - public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 新增业务字段 | |
| 31 | - * | |
| 32 | - * @param genTableColumn 业务字段信息 | |
| 33 | - * @return 结果 | |
| 34 | - */ | |
| 35 | - public int insertGenTableColumn(GenTableColumn genTableColumn); | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * 修改业务字段 | |
| 39 | - * | |
| 40 | - * @param genTableColumn 业务字段信息 | |
| 41 | - * @return 结果 | |
| 42 | - */ | |
| 43 | - public int updateGenTableColumn(GenTableColumn genTableColumn); | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 删除业务字段 | |
| 47 | - * | |
| 48 | - * @param genTableColumns 列数据 | |
| 49 | - * @return 结果 | |
| 50 | - */ | |
| 51 | - public int deleteGenTableColumns(List<GenTableColumn> genTableColumns); | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * 批量删除业务字段 | |
| 55 | - * | |
| 56 | - * @param ids 需要删除的数据ID | |
| 57 | - * @return 结果 | |
| 58 | - */ | |
| 59 | - public int deleteGenTableColumnByIds(Long[] ids); | |
| 60 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java deleted
| 1 | -package com.ruoyi.generator.mapper; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import com.ruoyi.generator.domain.GenTable; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 业务 数据层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface GenTableMapper | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 查询业务列表 | |
| 15 | - * | |
| 16 | - * @param genTable 业务信息 | |
| 17 | - * @return 业务集合 | |
| 18 | - */ | |
| 19 | - public List<GenTable> selectGenTableList(GenTable genTable); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 查询据库列表 | |
| 23 | - * | |
| 24 | - * @param genTable 业务信息 | |
| 25 | - * @return 数据库表集合 | |
| 26 | - */ | |
| 27 | - public List<GenTable> selectDbTableList(GenTable genTable); | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 查询据库列表 | |
| 31 | - * | |
| 32 | - * @param tableNames 表名称组 | |
| 33 | - * @return 数据库表集合 | |
| 34 | - */ | |
| 35 | - public List<GenTable> selectDbTableListByNames(String[] tableNames); | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * 查询表ID业务信息 | |
| 39 | - * | |
| 40 | - * @param id 业务ID | |
| 41 | - * @return 业务信息 | |
| 42 | - */ | |
| 43 | - public GenTable selectGenTableById(Long id); | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 查询表名称业务信息 | |
| 47 | - * | |
| 48 | - * @param tableName 表名称 | |
| 49 | - * @return 业务信息 | |
| 50 | - */ | |
| 51 | - public GenTable selectGenTableByName(String tableName); | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * 新增业务 | |
| 55 | - * | |
| 56 | - * @param genTable 业务信息 | |
| 57 | - * @return 结果 | |
| 58 | - */ | |
| 59 | - public int insertGenTable(GenTable genTable); | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * 修改业务 | |
| 63 | - * | |
| 64 | - * @param genTable 业务信息 | |
| 65 | - * @return 结果 | |
| 66 | - */ | |
| 67 | - public int updateGenTable(GenTable genTable); | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * 批量删除业务 | |
| 71 | - * | |
| 72 | - * @param ids 需要删除的数据ID | |
| 73 | - * @return 结果 | |
| 74 | - */ | |
| 75 | - public int deleteGenTableByIds(Long[] ids); | |
| 76 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java deleted
| 1 | -package com.ruoyi.generator.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | -import org.springframework.stereotype.Service; | |
| 6 | -import com.ruoyi.common.core.text.Convert; | |
| 7 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 8 | -import com.ruoyi.generator.mapper.GenTableColumnMapper; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * 业务字段 服务层实现 | |
| 12 | - * | |
| 13 | - * @author ruoyi | |
| 14 | - */ | |
| 15 | -@Service | |
| 16 | -public class GenTableColumnServiceImpl implements IGenTableColumnService | |
| 17 | -{ | |
| 18 | - @Autowired | |
| 19 | - private GenTableColumnMapper genTableColumnMapper; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 查询业务字段列表 | |
| 23 | - * | |
| 24 | - * @param tableId 业务字段编号 | |
| 25 | - * @return 业务字段集合 | |
| 26 | - */ | |
| 27 | - @Override | |
| 28 | - public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) | |
| 29 | - { | |
| 30 | - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); | |
| 31 | - } | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * 新增业务字段 | |
| 35 | - * | |
| 36 | - * @param genTableColumn 业务字段信息 | |
| 37 | - * @return 结果 | |
| 38 | - */ | |
| 39 | - @Override | |
| 40 | - public int insertGenTableColumn(GenTableColumn genTableColumn) | |
| 41 | - { | |
| 42 | - return genTableColumnMapper.insertGenTableColumn(genTableColumn); | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 修改业务字段 | |
| 47 | - * | |
| 48 | - * @param genTableColumn 业务字段信息 | |
| 49 | - * @return 结果 | |
| 50 | - */ | |
| 51 | - @Override | |
| 52 | - public int updateGenTableColumn(GenTableColumn genTableColumn) | |
| 53 | - { | |
| 54 | - return genTableColumnMapper.updateGenTableColumn(genTableColumn); | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * 删除业务字段对象 | |
| 59 | - * | |
| 60 | - * @param ids 需要删除的数据ID | |
| 61 | - * @return 结果 | |
| 62 | - */ | |
| 63 | - @Override | |
| 64 | - public int deleteGenTableColumnByIds(String ids) | |
| 65 | - { | |
| 66 | - return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); | |
| 67 | - } | |
| 68 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java deleted
| 1 | -package com.ruoyi.generator.service; | |
| 2 | - | |
| 3 | -import java.io.ByteArrayOutputStream; | |
| 4 | -import java.io.File; | |
| 5 | -import java.io.IOException; | |
| 6 | -import java.io.StringWriter; | |
| 7 | -import java.util.LinkedHashMap; | |
| 8 | -import java.util.List; | |
| 9 | -import java.util.Map; | |
| 10 | -import java.util.stream.Collectors; | |
| 11 | -import java.util.zip.ZipEntry; | |
| 12 | -import java.util.zip.ZipOutputStream; | |
| 13 | -import org.apache.commons.io.IOUtils; | |
| 14 | -import org.apache.velocity.Template; | |
| 15 | -import org.apache.velocity.VelocityContext; | |
| 16 | -import org.apache.velocity.app.Velocity; | |
| 17 | -import org.slf4j.Logger; | |
| 18 | -import org.slf4j.LoggerFactory; | |
| 19 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | -import org.springframework.stereotype.Service; | |
| 21 | -import org.springframework.transaction.annotation.Transactional; | |
| 22 | -import com.alibaba.fastjson.JSON; | |
| 23 | -import com.alibaba.fastjson.JSONObject; | |
| 24 | -import com.ruoyi.common.constant.Constants; | |
| 25 | -import com.ruoyi.common.constant.GenConstants; | |
| 26 | -import com.ruoyi.common.core.text.CharsetKit; | |
| 27 | -import com.ruoyi.common.exception.CustomException; | |
| 28 | -import com.ruoyi.common.utils.SecurityUtils; | |
| 29 | -import com.ruoyi.common.utils.StringUtils; | |
| 30 | -import com.ruoyi.common.utils.file.FileUtils; | |
| 31 | -import com.ruoyi.generator.domain.GenTable; | |
| 32 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 33 | -import com.ruoyi.generator.mapper.GenTableColumnMapper; | |
| 34 | -import com.ruoyi.generator.mapper.GenTableMapper; | |
| 35 | -import com.ruoyi.generator.util.GenUtils; | |
| 36 | -import com.ruoyi.generator.util.VelocityInitializer; | |
| 37 | -import com.ruoyi.generator.util.VelocityUtils; | |
| 38 | - | |
| 39 | -/** | |
| 40 | - * 业务 服务层实现 | |
| 41 | - * | |
| 42 | - * @author ruoyi | |
| 43 | - */ | |
| 44 | -@Service | |
| 45 | -public class GenTableServiceImpl implements IGenTableService | |
| 46 | -{ | |
| 47 | - private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); | |
| 48 | - | |
| 49 | - @Autowired | |
| 50 | - private GenTableMapper genTableMapper; | |
| 51 | - | |
| 52 | - @Autowired | |
| 53 | - private GenTableColumnMapper genTableColumnMapper; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * 查询业务信息 | |
| 57 | - * | |
| 58 | - * @param id 业务ID | |
| 59 | - * @return 业务信息 | |
| 60 | - */ | |
| 61 | - @Override | |
| 62 | - public GenTable selectGenTableById(Long id) | |
| 63 | - { | |
| 64 | - GenTable genTable = genTableMapper.selectGenTableById(id); | |
| 65 | - setTableFromOptions(genTable); | |
| 66 | - return genTable; | |
| 67 | - } | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * 查询业务列表 | |
| 71 | - * | |
| 72 | - * @param genTable 业务信息 | |
| 73 | - * @return 业务集合 | |
| 74 | - */ | |
| 75 | - @Override | |
| 76 | - public List<GenTable> selectGenTableList(GenTable genTable) | |
| 77 | - { | |
| 78 | - return genTableMapper.selectGenTableList(genTable); | |
| 79 | - } | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * 查询据库列表 | |
| 83 | - * | |
| 84 | - * @param genTable 业务信息 | |
| 85 | - * @return 数据库表集合 | |
| 86 | - */ | |
| 87 | - @Override | |
| 88 | - public List<GenTable> selectDbTableList(GenTable genTable) | |
| 89 | - { | |
| 90 | - return genTableMapper.selectDbTableList(genTable); | |
| 91 | - } | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 查询据库列表 | |
| 95 | - * | |
| 96 | - * @param tableNames 表名称组 | |
| 97 | - * @return 数据库表集合 | |
| 98 | - */ | |
| 99 | - @Override | |
| 100 | - public List<GenTable> selectDbTableListByNames(String[] tableNames) | |
| 101 | - { | |
| 102 | - return genTableMapper.selectDbTableListByNames(tableNames); | |
| 103 | - } | |
| 104 | - | |
| 105 | - /** | |
| 106 | - * 修改业务 | |
| 107 | - * | |
| 108 | - * @param genTable 业务信息 | |
| 109 | - * @return 结果 | |
| 110 | - */ | |
| 111 | - @Override | |
| 112 | - @Transactional | |
| 113 | - public void updateGenTable(GenTable genTable) | |
| 114 | - { | |
| 115 | - String options = JSON.toJSONString(genTable.getParams()); | |
| 116 | - genTable.setOptions(options); | |
| 117 | - int row = genTableMapper.updateGenTable(genTable); | |
| 118 | - if (row > 0) | |
| 119 | - { | |
| 120 | - for (GenTableColumn cenTableColumn : genTable.getColumns()) | |
| 121 | - { | |
| 122 | - genTableColumnMapper.updateGenTableColumn(cenTableColumn); | |
| 123 | - } | |
| 124 | - } | |
| 125 | - } | |
| 126 | - | |
| 127 | - /** | |
| 128 | - * 删除业务对象 | |
| 129 | - * | |
| 130 | - * @param tableIds 需要删除的数据ID | |
| 131 | - * @return 结果 | |
| 132 | - */ | |
| 133 | - @Override | |
| 134 | - @Transactional | |
| 135 | - public void deleteGenTableByIds(Long[] tableIds) | |
| 136 | - { | |
| 137 | - genTableMapper.deleteGenTableByIds(tableIds); | |
| 138 | - genTableColumnMapper.deleteGenTableColumnByIds(tableIds); | |
| 139 | - } | |
| 140 | - | |
| 141 | - /** | |
| 142 | - * 导入表结构 | |
| 143 | - * | |
| 144 | - * @param tableList 导入表列表 | |
| 145 | - */ | |
| 146 | - @Override | |
| 147 | - @Transactional | |
| 148 | - public void importGenTable(List<GenTable> tableList) | |
| 149 | - { | |
| 150 | - String operName = SecurityUtils.getUsername(); | |
| 151 | - try | |
| 152 | - { | |
| 153 | - for (GenTable table : tableList) | |
| 154 | - { | |
| 155 | - String tableName = table.getTableName(); | |
| 156 | - GenUtils.initTable(table, operName); | |
| 157 | - int row = genTableMapper.insertGenTable(table); | |
| 158 | - if (row > 0) | |
| 159 | - { | |
| 160 | - // 保存列信息 | |
| 161 | - List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | |
| 162 | - for (GenTableColumn column : genTableColumns) | |
| 163 | - { | |
| 164 | - GenUtils.initColumnField(column, table); | |
| 165 | - genTableColumnMapper.insertGenTableColumn(column); | |
| 166 | - } | |
| 167 | - } | |
| 168 | - } | |
| 169 | - } | |
| 170 | - catch (Exception e) | |
| 171 | - { | |
| 172 | - throw new CustomException("导入失败:" + e.getMessage()); | |
| 173 | - } | |
| 174 | - } | |
| 175 | - | |
| 176 | - /** | |
| 177 | - * 预览代码 | |
| 178 | - * | |
| 179 | - * @param tableId 表编号 | |
| 180 | - * @return 预览数据列表 | |
| 181 | - */ | |
| 182 | - @Override | |
| 183 | - public Map<String, String> previewCode(Long tableId) | |
| 184 | - { | |
| 185 | - Map<String, String> dataMap = new LinkedHashMap<>(); | |
| 186 | - // 查询表信息 | |
| 187 | - GenTable table = genTableMapper.selectGenTableById(tableId); | |
| 188 | - // 查询列信息 | |
| 189 | - List<GenTableColumn> columns = table.getColumns(); | |
| 190 | - setPkColumn(table, columns); | |
| 191 | - VelocityInitializer.initVelocity(); | |
| 192 | - | |
| 193 | - VelocityContext context = VelocityUtils.prepareContext(table); | |
| 194 | - | |
| 195 | - // 获取模板列表 | |
| 196 | - List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | |
| 197 | - for (String template : templates) | |
| 198 | - { | |
| 199 | - // 渲染模板 | |
| 200 | - StringWriter sw = new StringWriter(); | |
| 201 | - Template tpl = Velocity.getTemplate(template, Constants.UTF8); | |
| 202 | - tpl.merge(context, sw); | |
| 203 | - dataMap.put(template, sw.toString()); | |
| 204 | - } | |
| 205 | - return dataMap; | |
| 206 | - } | |
| 207 | - | |
| 208 | - /** | |
| 209 | - * 生成代码(下载方式) | |
| 210 | - * | |
| 211 | - * @param tableName 表名称 | |
| 212 | - * @return 数据 | |
| 213 | - */ | |
| 214 | - @Override | |
| 215 | - public byte[] downloadCode(String tableName) | |
| 216 | - { | |
| 217 | - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
| 218 | - ZipOutputStream zip = new ZipOutputStream(outputStream); | |
| 219 | - generatorCode(tableName, zip); | |
| 220 | - IOUtils.closeQuietly(zip); | |
| 221 | - return outputStream.toByteArray(); | |
| 222 | - } | |
| 223 | - | |
| 224 | - /** | |
| 225 | - * 生成代码(自定义路径) | |
| 226 | - * | |
| 227 | - * @param tableName 表名称 | |
| 228 | - */ | |
| 229 | - @Override | |
| 230 | - public void generatorCode(String tableName) | |
| 231 | - { | |
| 232 | - // 查询表信息 | |
| 233 | - GenTable table = genTableMapper.selectGenTableByName(tableName); | |
| 234 | - // 查询列信息 | |
| 235 | - List<GenTableColumn> columns = table.getColumns(); | |
| 236 | - setPkColumn(table, columns); | |
| 237 | - | |
| 238 | - VelocityInitializer.initVelocity(); | |
| 239 | - | |
| 240 | - VelocityContext context = VelocityUtils.prepareContext(table); | |
| 241 | - | |
| 242 | - // 获取模板列表 | |
| 243 | - List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | |
| 244 | - for (String template : templates) | |
| 245 | - { | |
| 246 | - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) | |
| 247 | - { | |
| 248 | - // 渲染模板 | |
| 249 | - StringWriter sw = new StringWriter(); | |
| 250 | - Template tpl = Velocity.getTemplate(template, Constants.UTF8); | |
| 251 | - tpl.merge(context, sw); | |
| 252 | - try | |
| 253 | - { | |
| 254 | - String path = getGenPath(table, template); | |
| 255 | - FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); | |
| 256 | - } | |
| 257 | - catch (IOException e) | |
| 258 | - { | |
| 259 | - throw new CustomException("渲染模板失败,表名:" + table.getTableName()); | |
| 260 | - } | |
| 261 | - } | |
| 262 | - } | |
| 263 | - } | |
| 264 | - | |
| 265 | - /** | |
| 266 | - * 同步数据库 | |
| 267 | - * | |
| 268 | - * @param tableName 表名称 | |
| 269 | - */ | |
| 270 | - @Override | |
| 271 | - @Transactional | |
| 272 | - public void synchDb(String tableName) | |
| 273 | - { | |
| 274 | - GenTable table = genTableMapper.selectGenTableByName(tableName); | |
| 275 | - List<GenTableColumn> tableColumns = table.getColumns(); | |
| 276 | - List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); | |
| 277 | - | |
| 278 | - List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | |
| 279 | - List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); | |
| 280 | - | |
| 281 | - dbTableColumns.forEach(column -> { | |
| 282 | - if (!tableColumnNames.contains(column.getColumnName())) | |
| 283 | - { | |
| 284 | - GenUtils.initColumnField(column, table); | |
| 285 | - genTableColumnMapper.insertGenTableColumn(column); | |
| 286 | - } | |
| 287 | - }); | |
| 288 | - | |
| 289 | - List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); | |
| 290 | - if (StringUtils.isNotEmpty(delColumns)) | |
| 291 | - { | |
| 292 | - genTableColumnMapper.deleteGenTableColumns(delColumns); | |
| 293 | - } | |
| 294 | - } | |
| 295 | - | |
| 296 | - /** | |
| 297 | - * 批量生成代码(下载方式) | |
| 298 | - * | |
| 299 | - * @param tableNames 表数组 | |
| 300 | - * @return 数据 | |
| 301 | - */ | |
| 302 | - @Override | |
| 303 | - public byte[] downloadCode(String[] tableNames) | |
| 304 | - { | |
| 305 | - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
| 306 | - ZipOutputStream zip = new ZipOutputStream(outputStream); | |
| 307 | - for (String tableName : tableNames) | |
| 308 | - { | |
| 309 | - generatorCode(tableName, zip); | |
| 310 | - } | |
| 311 | - IOUtils.closeQuietly(zip); | |
| 312 | - return outputStream.toByteArray(); | |
| 313 | - } | |
| 314 | - | |
| 315 | - /** | |
| 316 | - * 查询表信息并生成代码 | |
| 317 | - */ | |
| 318 | - private void generatorCode(String tableName, ZipOutputStream zip) | |
| 319 | - { | |
| 320 | - // 查询表信息 | |
| 321 | - GenTable table = genTableMapper.selectGenTableByName(tableName); | |
| 322 | - // 查询列信息 | |
| 323 | - List<GenTableColumn> columns = table.getColumns(); | |
| 324 | - setPkColumn(table, columns); | |
| 325 | - | |
| 326 | - VelocityInitializer.initVelocity(); | |
| 327 | - | |
| 328 | - VelocityContext context = VelocityUtils.prepareContext(table); | |
| 329 | - | |
| 330 | - // 获取模板列表 | |
| 331 | - List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | |
| 332 | - for (String template : templates) | |
| 333 | - { | |
| 334 | - // 渲染模板 | |
| 335 | - StringWriter sw = new StringWriter(); | |
| 336 | - Template tpl = Velocity.getTemplate(template, Constants.UTF8); | |
| 337 | - tpl.merge(context, sw); | |
| 338 | - try | |
| 339 | - { | |
| 340 | - // 添加到zip | |
| 341 | - zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); | |
| 342 | - IOUtils.write(sw.toString(), zip, Constants.UTF8); | |
| 343 | - IOUtils.closeQuietly(sw); | |
| 344 | - zip.flush(); | |
| 345 | - zip.closeEntry(); | |
| 346 | - } | |
| 347 | - catch (IOException e) | |
| 348 | - { | |
| 349 | - log.error("渲染模板失败,表名:" + table.getTableName(), e); | |
| 350 | - } | |
| 351 | - } | |
| 352 | - } | |
| 353 | - | |
| 354 | - /** | |
| 355 | - * 修改保存参数校验 | |
| 356 | - * | |
| 357 | - * @param genTable 业务信息 | |
| 358 | - */ | |
| 359 | - @Override | |
| 360 | - public void validateEdit(GenTable genTable) | |
| 361 | - { | |
| 362 | - if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) | |
| 363 | - { | |
| 364 | - String options = JSON.toJSONString(genTable.getParams()); | |
| 365 | - JSONObject paramsObj = JSONObject.parseObject(options); | |
| 366 | - if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) | |
| 367 | - { | |
| 368 | - throw new CustomException("树编码字段不能为空"); | |
| 369 | - } | |
| 370 | - else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) | |
| 371 | - { | |
| 372 | - throw new CustomException("树父编码字段不能为空"); | |
| 373 | - } | |
| 374 | - else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) | |
| 375 | - { | |
| 376 | - throw new CustomException("树名称字段不能为空"); | |
| 377 | - } | |
| 378 | - } | |
| 379 | - } | |
| 380 | - | |
| 381 | - /** | |
| 382 | - * 设置主键列信息 | |
| 383 | - * | |
| 384 | - * @param table 业务表信息 | |
| 385 | - * @param columns 业务字段列表 | |
| 386 | - */ | |
| 387 | - public void setPkColumn(GenTable table, List<GenTableColumn> columns) | |
| 388 | - { | |
| 389 | - for (GenTableColumn column : columns) | |
| 390 | - { | |
| 391 | - if (column.isPk()) | |
| 392 | - { | |
| 393 | - table.setPkColumn(column); | |
| 394 | - break; | |
| 395 | - } | |
| 396 | - } | |
| 397 | - if (StringUtils.isNull(table.getPkColumn())) | |
| 398 | - { | |
| 399 | - table.setPkColumn(columns.get(0)); | |
| 400 | - } | |
| 401 | - } | |
| 402 | - | |
| 403 | - /** | |
| 404 | - * 设置代码生成其他选项值 | |
| 405 | - * | |
| 406 | - * @param genTable 设置后的生成对象 | |
| 407 | - */ | |
| 408 | - public void setTableFromOptions(GenTable genTable) | |
| 409 | - { | |
| 410 | - JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); | |
| 411 | - if (StringUtils.isNotNull(paramsObj)) | |
| 412 | - { | |
| 413 | - String treeCode = paramsObj.getString(GenConstants.TREE_CODE); | |
| 414 | - String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); | |
| 415 | - String treeName = paramsObj.getString(GenConstants.TREE_NAME); | |
| 416 | - String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); | |
| 417 | - String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); | |
| 418 | - | |
| 419 | - genTable.setTreeCode(treeCode); | |
| 420 | - genTable.setTreeParentCode(treeParentCode); | |
| 421 | - genTable.setTreeName(treeName); | |
| 422 | - genTable.setParentMenuId(parentMenuId); | |
| 423 | - genTable.setParentMenuName(parentMenuName); | |
| 424 | - } | |
| 425 | - } | |
| 426 | - | |
| 427 | - /** | |
| 428 | - * 获取代码生成地址 | |
| 429 | - * | |
| 430 | - * @param table 业务表信息 | |
| 431 | - * @param template 模板文件路径 | |
| 432 | - * @return 生成地址 | |
| 433 | - */ | |
| 434 | - public static String getGenPath(GenTable table, String template) | |
| 435 | - { | |
| 436 | - String genPath = table.getGenPath(); | |
| 437 | - if (StringUtils.equals(genPath, "/")) | |
| 438 | - { | |
| 439 | - return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); | |
| 440 | - } | |
| 441 | - return genPath + File.separator + VelocityUtils.getFileName(template, table); | |
| 442 | - } | |
| 443 | -} | |
| 444 | 0 | \ No newline at end of file |
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java deleted
| 1 | -package com.ruoyi.generator.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 业务字段 服务层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface IGenTableColumnService | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 查询业务字段列表 | |
| 15 | - * | |
| 16 | - * @param tableId 业务字段编号 | |
| 17 | - * @return 业务字段集合 | |
| 18 | - */ | |
| 19 | - public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 新增业务字段 | |
| 23 | - * | |
| 24 | - * @param genTableColumn 业务字段信息 | |
| 25 | - * @return 结果 | |
| 26 | - */ | |
| 27 | - public int insertGenTableColumn(GenTableColumn genTableColumn); | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 修改业务字段 | |
| 31 | - * | |
| 32 | - * @param genTableColumn 业务字段信息 | |
| 33 | - * @return 结果 | |
| 34 | - */ | |
| 35 | - public int updateGenTableColumn(GenTableColumn genTableColumn); | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * 删除业务字段信息 | |
| 39 | - * | |
| 40 | - * @param ids 需要删除的数据ID | |
| 41 | - * @return 结果 | |
| 42 | - */ | |
| 43 | - public int deleteGenTableColumnByIds(String ids); | |
| 44 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java deleted
| 1 | -package com.ruoyi.generator.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import java.util.Map; | |
| 5 | -import com.ruoyi.generator.domain.GenTable; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 业务 服务层 | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - */ | |
| 12 | -public interface IGenTableService | |
| 13 | -{ | |
| 14 | - /** | |
| 15 | - * 查询业务列表 | |
| 16 | - * | |
| 17 | - * @param genTable 业务信息 | |
| 18 | - * @return 业务集合 | |
| 19 | - */ | |
| 20 | - public List<GenTable> selectGenTableList(GenTable genTable); | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * 查询据库列表 | |
| 24 | - * | |
| 25 | - * @param genTable 业务信息 | |
| 26 | - * @return 数据库表集合 | |
| 27 | - */ | |
| 28 | - public List<GenTable> selectDbTableList(GenTable genTable); | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * 查询据库列表 | |
| 32 | - * | |
| 33 | - * @param tableNames 表名称组 | |
| 34 | - * @return 数据库表集合 | |
| 35 | - */ | |
| 36 | - public List<GenTable> selectDbTableListByNames(String[] tableNames); | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 查询业务信息 | |
| 40 | - * | |
| 41 | - * @param id 业务ID | |
| 42 | - * @return 业务信息 | |
| 43 | - */ | |
| 44 | - public GenTable selectGenTableById(Long id); | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 修改业务 | |
| 48 | - * | |
| 49 | - * @param genTable 业务信息 | |
| 50 | - * @return 结果 | |
| 51 | - */ | |
| 52 | - public void updateGenTable(GenTable genTable); | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 删除业务信息 | |
| 56 | - * | |
| 57 | - * @param tableIds 需要删除的表数据ID | |
| 58 | - * @return 结果 | |
| 59 | - */ | |
| 60 | - public void deleteGenTableByIds(Long[] tableIds); | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * 导入表结构 | |
| 64 | - * | |
| 65 | - * @param tableList 导入表列表 | |
| 66 | - */ | |
| 67 | - public void importGenTable(List<GenTable> tableList); | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * 预览代码 | |
| 71 | - * | |
| 72 | - * @param tableId 表编号 | |
| 73 | - * @return 预览数据列表 | |
| 74 | - */ | |
| 75 | - public Map<String, String> previewCode(Long tableId); | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * 生成代码(下载方式) | |
| 79 | - * | |
| 80 | - * @param tableName 表名称 | |
| 81 | - * @return 数据 | |
| 82 | - */ | |
| 83 | - public byte[] downloadCode(String tableName); | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * 生成代码(自定义路径) | |
| 87 | - * | |
| 88 | - * @param tableName 表名称 | |
| 89 | - * @return 数据 | |
| 90 | - */ | |
| 91 | - public void generatorCode(String tableName); | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 同步数据库 | |
| 95 | - * | |
| 96 | - * @param tableName 表名称 | |
| 97 | - */ | |
| 98 | - public void synchDb(String tableName); | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * 批量生成代码(下载方式) | |
| 102 | - * | |
| 103 | - * @param tableNames 表数组 | |
| 104 | - * @return 数据 | |
| 105 | - */ | |
| 106 | - public byte[] downloadCode(String[] tableNames); | |
| 107 | - | |
| 108 | - /** | |
| 109 | - * 修改保存参数校验 | |
| 110 | - * | |
| 111 | - * @param genTable 业务信息 | |
| 112 | - */ | |
| 113 | - public void validateEdit(GenTable genTable); | |
| 114 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java deleted
| 1 | -package com.ruoyi.generator.util; | |
| 2 | - | |
| 3 | -import java.util.Arrays; | |
| 4 | -import org.apache.commons.lang3.RegExUtils; | |
| 5 | -import com.ruoyi.common.constant.GenConstants; | |
| 6 | -import com.ruoyi.common.utils.StringUtils; | |
| 7 | -import com.ruoyi.generator.config.GenConfig; | |
| 8 | -import com.ruoyi.generator.domain.GenTable; | |
| 9 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 代码生成器 工具类 | |
| 13 | - * | |
| 14 | - * @author ruoyi | |
| 15 | - */ | |
| 16 | -public class GenUtils | |
| 17 | -{ | |
| 18 | - /** | |
| 19 | - * 初始化表信息 | |
| 20 | - */ | |
| 21 | - public static void initTable(GenTable genTable, String operName) | |
| 22 | - { | |
| 23 | - genTable.setClassName(convertClassName(genTable.getTableName())); | |
| 24 | - genTable.setPackageName(GenConfig.getPackageName()); | |
| 25 | - genTable.setModuleName(getModuleName(GenConfig.getPackageName())); | |
| 26 | - genTable.setBusinessName(getBusinessName(genTable.getTableName())); | |
| 27 | - genTable.setFunctionName(replaceText(genTable.getTableComment())); | |
| 28 | - genTable.setFunctionAuthor(GenConfig.getAuthor()); | |
| 29 | - genTable.setCreateBy(operName); | |
| 30 | - } | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * 初始化列属性字段 | |
| 34 | - */ | |
| 35 | - public static void initColumnField(GenTableColumn column, GenTable table) | |
| 36 | - { | |
| 37 | - String dataType = getDbType(column.getColumnType()); | |
| 38 | - String columnName = column.getColumnName(); | |
| 39 | - column.setTableId(table.getTableId()); | |
| 40 | - column.setCreateBy(table.getCreateBy()); | |
| 41 | - // 设置java字段名 | |
| 42 | - column.setJavaField(StringUtils.toCamelCase(columnName)); | |
| 43 | - // 设置默认类型 | |
| 44 | - column.setJavaType(GenConstants.TYPE_STRING); | |
| 45 | - | |
| 46 | - if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) | |
| 47 | - { | |
| 48 | - // 字符串长度超过500设置为文本域 | |
| 49 | - Integer columnLength = getColumnLength(column.getColumnType()); | |
| 50 | - String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; | |
| 51 | - column.setHtmlType(htmlType); | |
| 52 | - } | |
| 53 | - else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) | |
| 54 | - { | |
| 55 | - column.setJavaType(GenConstants.TYPE_DATE); | |
| 56 | - column.setHtmlType(GenConstants.HTML_DATETIME); | |
| 57 | - } | |
| 58 | - else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) | |
| 59 | - { | |
| 60 | - column.setHtmlType(GenConstants.HTML_INPUT); | |
| 61 | - | |
| 62 | - // 如果是浮点型 统一用BigDecimal | |
| 63 | - String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); | |
| 64 | - if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) | |
| 65 | - { | |
| 66 | - column.setJavaType(GenConstants.TYPE_BIGDECIMAL); | |
| 67 | - } | |
| 68 | - // 如果是整形 | |
| 69 | - else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) | |
| 70 | - { | |
| 71 | - column.setJavaType(GenConstants.TYPE_INTEGER); | |
| 72 | - } | |
| 73 | - // 长整形 | |
| 74 | - else | |
| 75 | - { | |
| 76 | - column.setJavaType(GenConstants.TYPE_LONG); | |
| 77 | - } | |
| 78 | - } | |
| 79 | - | |
| 80 | - // 插入字段(默认所有字段都需要插入) | |
| 81 | - column.setIsInsert(GenConstants.REQUIRE); | |
| 82 | - | |
| 83 | - // 编辑字段 | |
| 84 | - if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) | |
| 85 | - { | |
| 86 | - column.setIsEdit(GenConstants.REQUIRE); | |
| 87 | - } | |
| 88 | - // 列表字段 | |
| 89 | - if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) | |
| 90 | - { | |
| 91 | - column.setIsList(GenConstants.REQUIRE); | |
| 92 | - } | |
| 93 | - // 查询字段 | |
| 94 | - if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) | |
| 95 | - { | |
| 96 | - column.setIsQuery(GenConstants.REQUIRE); | |
| 97 | - } | |
| 98 | - | |
| 99 | - // 查询字段类型 | |
| 100 | - if (StringUtils.endsWithIgnoreCase(columnName, "name")) | |
| 101 | - { | |
| 102 | - column.setQueryType(GenConstants.QUERY_LIKE); | |
| 103 | - } | |
| 104 | - // 状态字段设置单选框 | |
| 105 | - if (StringUtils.endsWithIgnoreCase(columnName, "status")) | |
| 106 | - { | |
| 107 | - column.setHtmlType(GenConstants.HTML_RADIO); | |
| 108 | - } | |
| 109 | - // 类型&性别字段设置下拉框 | |
| 110 | - else if (StringUtils.endsWithIgnoreCase(columnName, "type") | |
| 111 | - || StringUtils.endsWithIgnoreCase(columnName, "sex")) | |
| 112 | - { | |
| 113 | - column.setHtmlType(GenConstants.HTML_SELECT); | |
| 114 | - } | |
| 115 | - // 文件字段设置上传控件 | |
| 116 | - else if (StringUtils.endsWithIgnoreCase(columnName, "image")) | |
| 117 | - { | |
| 118 | - column.setHtmlType(GenConstants.HTML_UPLOAD_IMAGE); | |
| 119 | - } | |
| 120 | - // 内容字段设置富文本控件 | |
| 121 | - else if (StringUtils.endsWithIgnoreCase(columnName, "content")) | |
| 122 | - { | |
| 123 | - column.setHtmlType(GenConstants.HTML_EDITOR); | |
| 124 | - } | |
| 125 | - } | |
| 126 | - | |
| 127 | - /** | |
| 128 | - * 校验数组是否包含指定值 | |
| 129 | - * | |
| 130 | - * @param arr 数组 | |
| 131 | - * @param targetValue 值 | |
| 132 | - * @return 是否包含 | |
| 133 | - */ | |
| 134 | - public static boolean arraysContains(String[] arr, String targetValue) | |
| 135 | - { | |
| 136 | - return Arrays.asList(arr).contains(targetValue); | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * 获取模块名 | |
| 141 | - * | |
| 142 | - * @param packageName 包名 | |
| 143 | - * @return 模块名 | |
| 144 | - */ | |
| 145 | - public static String getModuleName(String packageName) | |
| 146 | - { | |
| 147 | - int lastIndex = packageName.lastIndexOf("."); | |
| 148 | - int nameLength = packageName.length(); | |
| 149 | - String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); | |
| 150 | - return moduleName; | |
| 151 | - } | |
| 152 | - | |
| 153 | - /** | |
| 154 | - * 获取业务名 | |
| 155 | - * | |
| 156 | - * @param tableName 表名 | |
| 157 | - * @return 业务名 | |
| 158 | - */ | |
| 159 | - public static String getBusinessName(String tableName) | |
| 160 | - { | |
| 161 | - int lastIndex = tableName.lastIndexOf("_"); | |
| 162 | - int nameLength = tableName.length(); | |
| 163 | - String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); | |
| 164 | - return businessName; | |
| 165 | - } | |
| 166 | - | |
| 167 | - /** | |
| 168 | - * 表名转换成Java类名 | |
| 169 | - * | |
| 170 | - * @param tableName 表名称 | |
| 171 | - * @return 类名 | |
| 172 | - */ | |
| 173 | - public static String convertClassName(String tableName) | |
| 174 | - { | |
| 175 | - boolean autoRemovePre = GenConfig.getAutoRemovePre(); | |
| 176 | - String tablePrefix = GenConfig.getTablePrefix(); | |
| 177 | - if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) | |
| 178 | - { | |
| 179 | - String[] searchList = StringUtils.split(tablePrefix, ","); | |
| 180 | - tableName = replaceFirst(tableName, searchList); | |
| 181 | - } | |
| 182 | - return StringUtils.convertToCamelCase(tableName); | |
| 183 | - } | |
| 184 | - | |
| 185 | - /** | |
| 186 | - * 批量替换前缀 | |
| 187 | - * | |
| 188 | - * @param replacementm 替换值 | |
| 189 | - * @param searchList 替换列表 | |
| 190 | - * @return | |
| 191 | - */ | |
| 192 | - public static String replaceFirst(String replacementm, String[] searchList) | |
| 193 | - { | |
| 194 | - String text = replacementm; | |
| 195 | - for (String searchString : searchList) | |
| 196 | - { | |
| 197 | - if (replacementm.startsWith(searchString)) | |
| 198 | - { | |
| 199 | - text = replacementm.replaceFirst(searchString, ""); | |
| 200 | - break; | |
| 201 | - } | |
| 202 | - } | |
| 203 | - return text; | |
| 204 | - } | |
| 205 | - | |
| 206 | - /** | |
| 207 | - * 关键字替换 | |
| 208 | - * | |
| 209 | - * @param text 需要被替换的名字 | |
| 210 | - * @return 替换后的名字 | |
| 211 | - */ | |
| 212 | - public static String replaceText(String text) | |
| 213 | - { | |
| 214 | - return RegExUtils.replaceAll(text, "(?:表|若依)", ""); | |
| 215 | - } | |
| 216 | - | |
| 217 | - /** | |
| 218 | - * 获取数据库类型字段 | |
| 219 | - * | |
| 220 | - * @param columnType 列类型 | |
| 221 | - * @return 截取后的列类型 | |
| 222 | - */ | |
| 223 | - public static String getDbType(String columnType) | |
| 224 | - { | |
| 225 | - if (StringUtils.indexOf(columnType, "(") > 0) | |
| 226 | - { | |
| 227 | - return StringUtils.substringBefore(columnType, "("); | |
| 228 | - } | |
| 229 | - else | |
| 230 | - { | |
| 231 | - return columnType; | |
| 232 | - } | |
| 233 | - } | |
| 234 | - | |
| 235 | - /** | |
| 236 | - * 获取字段长度 | |
| 237 | - * | |
| 238 | - * @param columnType 列类型 | |
| 239 | - * @return 截取后的列类型 | |
| 240 | - */ | |
| 241 | - public static Integer getColumnLength(String columnType) | |
| 242 | - { | |
| 243 | - if (StringUtils.indexOf(columnType, "(") > 0) | |
| 244 | - { | |
| 245 | - String length = StringUtils.substringBetween(columnType, "(", ")"); | |
| 246 | - return Integer.valueOf(length); | |
| 247 | - } | |
| 248 | - else | |
| 249 | - { | |
| 250 | - return 0; | |
| 251 | - } | |
| 252 | - } | |
| 253 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java deleted
| 1 | -package com.ruoyi.generator.util; | |
| 2 | - | |
| 3 | -import java.util.Properties; | |
| 4 | -import org.apache.velocity.app.Velocity; | |
| 5 | -import com.ruoyi.common.constant.Constants; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * VelocityEngine工厂 | |
| 9 | - * | |
| 10 | - * @author RuoYi | |
| 11 | - */ | |
| 12 | -public class VelocityInitializer | |
| 13 | -{ | |
| 14 | - /** | |
| 15 | - * 初始化vm方法 | |
| 16 | - */ | |
| 17 | - public static void initVelocity() | |
| 18 | - { | |
| 19 | - Properties p = new Properties(); | |
| 20 | - try | |
| 21 | - { | |
| 22 | - // 加载classpath目录下的vm文件 | |
| 23 | - p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | |
| 24 | - // 定义字符集 | |
| 25 | - p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8); | |
| 26 | - p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8); | |
| 27 | - // 初始化Velocity引擎,指定配置Properties | |
| 28 | - Velocity.init(p); | |
| 29 | - } | |
| 30 | - catch (Exception e) | |
| 31 | - { | |
| 32 | - throw new RuntimeException(e); | |
| 33 | - } | |
| 34 | - } | |
| 35 | -} |
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java deleted
| 1 | -package com.ruoyi.generator.util; | |
| 2 | - | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.HashSet; | |
| 5 | -import java.util.List; | |
| 6 | - | |
| 7 | -import org.apache.velocity.VelocityContext; | |
| 8 | -import com.alibaba.fastjson.JSONObject; | |
| 9 | -import com.ruoyi.common.constant.GenConstants; | |
| 10 | -import com.ruoyi.common.utils.DateUtils; | |
| 11 | -import com.ruoyi.common.utils.StringUtils; | |
| 12 | -import com.ruoyi.generator.domain.GenTable; | |
| 13 | -import com.ruoyi.generator.domain.GenTableColumn; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 模板处理工具类 | |
| 17 | - * | |
| 18 | - * @author ruoyi | |
| 19 | - */ | |
| 20 | -public class VelocityUtils { | |
| 21 | - /** | |
| 22 | - * 项目空间路径 | |
| 23 | - */ | |
| 24 | - private static final String PROJECT_PATH = "main/java"; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * mybatis空间路径 | |
| 28 | - */ | |
| 29 | - private static final String MYBATIS_PATH = "main/resources/mapper"; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 默认上级菜单,系统工具 | |
| 33 | - */ | |
| 34 | - private static final String DEFAULT_PARENT_MENU_ID = "3"; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 设置模板变量信息 | |
| 38 | - * | |
| 39 | - * @return 模板列表 | |
| 40 | - */ | |
| 41 | - public static VelocityContext prepareContext(GenTable genTable) { | |
| 42 | - String moduleName = genTable.getModuleName(); | |
| 43 | - String businessName = genTable.getBusinessName(); | |
| 44 | - String packageName = genTable.getPackageName(); | |
| 45 | - String tplCategory = genTable.getTplCategory(); | |
| 46 | - String functionName = genTable.getFunctionName(); | |
| 47 | - | |
| 48 | - VelocityContext velocityContext = new VelocityContext(); | |
| 49 | - velocityContext.put("tplCategory", genTable.getTplCategory()); | |
| 50 | - velocityContext.put("tableName", genTable.getTableName()); | |
| 51 | - velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); | |
| 52 | - velocityContext.put("ClassName", genTable.getClassName()); | |
| 53 | - velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); | |
| 54 | - velocityContext.put("moduleName", genTable.getModuleName()); | |
| 55 | - velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); | |
| 56 | - velocityContext.put("businessName", genTable.getBusinessName()); | |
| 57 | - velocityContext.put("basePackage", getPackagePrefix(packageName)); | |
| 58 | - velocityContext.put("packageName", packageName); | |
| 59 | - velocityContext.put("author", genTable.getFunctionAuthor()); | |
| 60 | - velocityContext.put("datetime", DateUtils.getDate()); | |
| 61 | - velocityContext.put("pkColumn", genTable.getPkColumn()); | |
| 62 | - velocityContext.put("importList", getImportList(genTable.getColumns())); | |
| 63 | - velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); | |
| 64 | - velocityContext.put("columns", genTable.getColumns()); | |
| 65 | - velocityContext.put("table", genTable); | |
| 66 | - setMenuVelocityContext(velocityContext, genTable); | |
| 67 | - if (GenConstants.TPL_TREE.equals(tplCategory)) { | |
| 68 | - setTreeVelocityContext(velocityContext, genTable); | |
| 69 | - } | |
| 70 | - return velocityContext; | |
| 71 | - } | |
| 72 | - | |
| 73 | - public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { | |
| 74 | - String options = genTable.getOptions(); | |
| 75 | - JSONObject paramsObj = JSONObject.parseObject(options); | |
| 76 | - String parentMenuId = getParentMenuId(paramsObj); | |
| 77 | - context.put("parentMenuId", parentMenuId); | |
| 78 | - } | |
| 79 | - | |
| 80 | - public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { | |
| 81 | - String options = genTable.getOptions(); | |
| 82 | - JSONObject paramsObj = JSONObject.parseObject(options); | |
| 83 | - String treeCode = getTreecode(paramsObj); | |
| 84 | - String treeParentCode = getTreeParentCode(paramsObj); | |
| 85 | - String treeName = getTreeName(paramsObj); | |
| 86 | - | |
| 87 | - context.put("treeCode", treeCode); | |
| 88 | - context.put("treeParentCode", treeParentCode); | |
| 89 | - context.put("treeName", treeName); | |
| 90 | - context.put("expandColumn", getExpandColumn(genTable)); | |
| 91 | - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { | |
| 92 | - context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); | |
| 93 | - } | |
| 94 | - if (paramsObj.containsKey(GenConstants.TREE_NAME)) { | |
| 95 | - context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); | |
| 96 | - } | |
| 97 | - } | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * 获取模板信息 | |
| 101 | - * | |
| 102 | - * @return 模板列表 | |
| 103 | - */ | |
| 104 | - public static List<String> getTemplateList(String tplCategory) { | |
| 105 | - List<String> templates = new ArrayList<String>(); | |
| 106 | - templates.add("vm/java/domain.java.vm"); | |
| 107 | - templates.add("vm/java/mapper.java.vm"); | |
| 108 | - templates.add("vm/java/service.java.vm"); | |
| 109 | - templates.add("vm/java/serviceImpl.java.vm"); | |
| 110 | - templates.add("vm/java/controller.java.vm"); | |
| 111 | - templates.add("vm/xml/mapper.xml.vm"); | |
| 112 | - templates.add("vm/sql/sql.vm"); | |
| 113 | - templates.add("vm/js/api.js.vm"); | |
| 114 | - if (GenConstants.TPL_CRUD.equals(tplCategory)) { | |
| 115 | - templates.add("vm/vue/index.vue.vm"); | |
| 116 | - } else if (GenConstants.TPL_TREE.equals(tplCategory)) { | |
| 117 | - templates.add("vm/vue/index-tree.vue.vm"); | |
| 118 | - } | |
| 119 | - return templates; | |
| 120 | - } | |
| 121 | - | |
| 122 | - /** | |
| 123 | - * 获取文件名 | |
| 124 | - */ | |
| 125 | - public static String getFileName(String template, GenTable genTable) { | |
| 126 | - // 文件名称 | |
| 127 | - String fileName = ""; | |
| 128 | - // 包路径 | |
| 129 | - String packageName = genTable.getPackageName(); | |
| 130 | - // 模块名 | |
| 131 | - String moduleName = genTable.getModuleName(); | |
| 132 | - // 大写类名 | |
| 133 | - String className = genTable.getClassName(); | |
| 134 | - // 业务名称 | |
| 135 | - String businessName = genTable.getBusinessName(); | |
| 136 | - | |
| 137 | - String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); | |
| 138 | - String mybatisPath = MYBATIS_PATH + "/" + moduleName; | |
| 139 | - String vuePath = "vue"; | |
| 140 | - | |
| 141 | - if (template.contains("domain.java.vm")) { | |
| 142 | - fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); | |
| 143 | - } else if (template.contains("mapper.java.vm")) { | |
| 144 | - fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); | |
| 145 | - } else if (template.contains("service.java.vm")) { | |
| 146 | - fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); | |
| 147 | - } else if (template.contains("serviceImpl.java.vm")) { | |
| 148 | - fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); | |
| 149 | - } else if (template.contains("controller.java.vm")) { | |
| 150 | - fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); | |
| 151 | - } else if (template.contains("mapper.xml.vm")) { | |
| 152 | - fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); | |
| 153 | - } else if (template.contains("sql.vm")) { | |
| 154 | - fileName = businessName + "Menu.sql"; | |
| 155 | - } else if (template.contains("api.js.vm")) { | |
| 156 | - fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); | |
| 157 | - } else if (template.contains("index.vue.vm")) { | |
| 158 | - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); | |
| 159 | - } else if (template.contains("index-tree.vue.vm")) { | |
| 160 | - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); | |
| 161 | - } | |
| 162 | - return fileName; | |
| 163 | - } | |
| 164 | - | |
| 165 | - /** | |
| 166 | - * 获取包前缀 | |
| 167 | - * | |
| 168 | - * @param packageName 包名称 | |
| 169 | - * @return 包前缀名称 | |
| 170 | - */ | |
| 171 | - public static String getPackagePrefix(String packageName) { | |
| 172 | - int lastIndex = packageName.lastIndexOf("."); | |
| 173 | - String basePackage = StringUtils.substring(packageName, 0, lastIndex); | |
| 174 | - return basePackage; | |
| 175 | - } | |
| 176 | - | |
| 177 | - /** | |
| 178 | - * 根据列类型获取导入包 | |
| 179 | - * | |
| 180 | - * @param columns 列集合 | |
| 181 | - * @return 返回需要导入的包列表 | |
| 182 | - */ | |
| 183 | - public static HashSet<String> getImportList(List<GenTableColumn> columns) { | |
| 184 | - HashSet<String> importList = new HashSet<String>(); | |
| 185 | - for (GenTableColumn column : columns) { | |
| 186 | - if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { | |
| 187 | - importList.add("java.util.Date"); | |
| 188 | - importList.add("com.fasterxml.jackson.annotation.JsonFormat"); | |
| 189 | - } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { | |
| 190 | - importList.add("java.math.BigDecimal"); | |
| 191 | - } | |
| 192 | - } | |
| 193 | - return importList; | |
| 194 | - } | |
| 195 | - | |
| 196 | - /** | |
| 197 | - * 获取权限前缀 | |
| 198 | - * | |
| 199 | - * @param moduleName 模块名称 | |
| 200 | - * @param businessName 业务名称 | |
| 201 | - * @return 返回权限前缀 | |
| 202 | - */ | |
| 203 | - public static String getPermissionPrefix(String moduleName, String businessName) { | |
| 204 | - return StringUtils.format("{}:{}", moduleName, businessName); | |
| 205 | - } | |
| 206 | - | |
| 207 | - /** | |
| 208 | - * 获取上级菜单ID字段 | |
| 209 | - * | |
| 210 | - * @param paramsObj 生成其他选项 | |
| 211 | - * @return 上级菜单ID字段 | |
| 212 | - */ | |
| 213 | - public static String getParentMenuId(JSONObject paramsObj) { | |
| 214 | - if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) { | |
| 215 | - return paramsObj.getString(GenConstants.PARENT_MENU_ID); | |
| 216 | - } | |
| 217 | - return DEFAULT_PARENT_MENU_ID; | |
| 218 | - } | |
| 219 | - | |
| 220 | - /** | |
| 221 | - * 获取树编码 | |
| 222 | - * | |
| 223 | - * @param paramsObj 生成其他选项 | |
| 224 | - * @return 树编码 | |
| 225 | - */ | |
| 226 | - public static String getTreecode(JSONObject paramsObj) { | |
| 227 | - if (paramsObj.containsKey(GenConstants.TREE_CODE)) { | |
| 228 | - return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); | |
| 229 | - } | |
| 230 | - return StringUtils.EMPTY; | |
| 231 | - } | |
| 232 | - | |
| 233 | - /** | |
| 234 | - * 获取树父编码 | |
| 235 | - * | |
| 236 | - * @param paramsObj 生成其他选项 | |
| 237 | - * @return 树父编码 | |
| 238 | - */ | |
| 239 | - public static String getTreeParentCode(JSONObject paramsObj) { | |
| 240 | - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { | |
| 241 | - return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); | |
| 242 | - } | |
| 243 | - return StringUtils.EMPTY; | |
| 244 | - } | |
| 245 | - | |
| 246 | - /** | |
| 247 | - * 获取树名称 | |
| 248 | - * | |
| 249 | - * @param paramsObj 生成其他选项 | |
| 250 | - * @return 树名称 | |
| 251 | - */ | |
| 252 | - public static String getTreeName(JSONObject paramsObj) { | |
| 253 | - if (paramsObj.containsKey(GenConstants.TREE_NAME)) { | |
| 254 | - return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); | |
| 255 | - } | |
| 256 | - return StringUtils.EMPTY; | |
| 257 | - } | |
| 258 | - | |
| 259 | - /** | |
| 260 | - * 获取需要在哪一列上面显示展开按钮 | |
| 261 | - * | |
| 262 | - * @param genTable 业务表对象 | |
| 263 | - * @return 展开按钮列序号 | |
| 264 | - */ | |
| 265 | - public static int getExpandColumn(GenTable genTable) { | |
| 266 | - String options = genTable.getOptions(); | |
| 267 | - JSONObject paramsObj = JSONObject.parseObject(options); | |
| 268 | - String treeName = paramsObj.getString(GenConstants.TREE_NAME); | |
| 269 | - int num = 0; | |
| 270 | - for (GenTableColumn column : genTable.getColumns()) { | |
| 271 | - if (column.isList()) { | |
| 272 | - num++; | |
| 273 | - String columnName = column.getColumnName(); | |
| 274 | - if (columnName.equals(treeName)) { | |
| 275 | - break; | |
| 276 | - } | |
| 277 | - } | |
| 278 | - } | |
| 279 | - return num; | |
| 280 | - } | |
| 281 | -} |
ruoyi-generator/src/main/resources/generator.yml deleted
ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8" ?> | |
| 2 | -<!DOCTYPE mapper | |
| 3 | -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
| 4 | -"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 5 | -<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper"> | |
| 6 | - | |
| 7 | - <resultMap type="GenTableColumn" id="GenTableColumnResult"> | |
| 8 | - <id property="columnId" column="column_id" /> | |
| 9 | - <result property="tableId" column="table_id" /> | |
| 10 | - <result property="columnName" column="column_name" /> | |
| 11 | - <result property="columnComment" column="column_comment" /> | |
| 12 | - <result property="columnType" column="column_type" /> | |
| 13 | - <result property="javaType" column="java_type" /> | |
| 14 | - <result property="javaField" column="java_field" /> | |
| 15 | - <result property="isPk" column="is_pk" /> | |
| 16 | - <result property="isIncrement" column="is_increment" /> | |
| 17 | - <result property="isRequired" column="is_required" /> | |
| 18 | - <result property="isInsert" column="is_insert" /> | |
| 19 | - <result property="isEdit" column="is_edit" /> | |
| 20 | - <result property="isList" column="is_list" /> | |
| 21 | - <result property="isQuery" column="is_query" /> | |
| 22 | - <result property="queryType" column="query_type" /> | |
| 23 | - <result property="htmlType" column="html_type" /> | |
| 24 | - <result property="dictType" column="dict_type" /> | |
| 25 | - <result property="sort" column="sort" /> | |
| 26 | - <result property="createBy" column="create_by" /> | |
| 27 | - <result property="createTime" column="create_time" /> | |
| 28 | - <result property="updateBy" column="update_by" /> | |
| 29 | - <result property="updateTime" column="update_time" /> | |
| 30 | - </resultMap> | |
| 31 | - | |
| 32 | - <sql id="selectGenTableColumnVo"> | |
| 33 | - select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column | |
| 34 | - </sql> | |
| 35 | - | |
| 36 | - <select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult"> | |
| 37 | - <include refid="selectGenTableColumnVo"/> | |
| 38 | - where table_id = #{tableId} | |
| 39 | - order by sort | |
| 40 | - </select> | |
| 41 | - | |
| 42 | - <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> | |
| 43 | - select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type | |
| 44 | - from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) | |
| 45 | - order by ordinal_position | |
| 46 | - </select> | |
| 47 | - | |
| 48 | - <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> | |
| 49 | - insert into gen_table_column ( | |
| 50 | - <if test="tableId != null and tableId != ''">table_id,</if> | |
| 51 | - <if test="columnName != null and columnName != ''">column_name,</if> | |
| 52 | - <if test="columnComment != null and columnComment != ''">column_comment,</if> | |
| 53 | - <if test="columnType != null and columnType != ''">column_type,</if> | |
| 54 | - <if test="javaType != null and javaType != ''">java_type,</if> | |
| 55 | - <if test="javaField != null and javaField != ''">java_field,</if> | |
| 56 | - <if test="isPk != null and isPk != ''">is_pk,</if> | |
| 57 | - <if test="isIncrement != null and isIncrement != ''">is_increment,</if> | |
| 58 | - <if test="isRequired != null and isRequired != ''">is_required,</if> | |
| 59 | - <if test="isInsert != null and isInsert != ''">is_insert,</if> | |
| 60 | - <if test="isEdit != null and isEdit != ''">is_edit,</if> | |
| 61 | - <if test="isList != null and isList != ''">is_list,</if> | |
| 62 | - <if test="isQuery != null and isQuery != ''">is_query,</if> | |
| 63 | - <if test="queryType != null and queryType != ''">query_type,</if> | |
| 64 | - <if test="htmlType != null and htmlType != ''">html_type,</if> | |
| 65 | - <if test="dictType != null and dictType != ''">dict_type,</if> | |
| 66 | - <if test="sort != null">sort,</if> | |
| 67 | - <if test="createBy != null and createBy != ''">create_by,</if> | |
| 68 | - create_time | |
| 69 | - )values( | |
| 70 | - <if test="tableId != null and tableId != ''">#{tableId},</if> | |
| 71 | - <if test="columnName != null and columnName != ''">#{columnName},</if> | |
| 72 | - <if test="columnComment != null and columnComment != ''">#{columnComment},</if> | |
| 73 | - <if test="columnType != null and columnType != ''">#{columnType},</if> | |
| 74 | - <if test="javaType != null and javaType != ''">#{javaType},</if> | |
| 75 | - <if test="javaField != null and javaField != ''">#{javaField},</if> | |
| 76 | - <if test="isPk != null and isPk != ''">#{isPk},</if> | |
| 77 | - <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> | |
| 78 | - <if test="isRequired != null and isRequired != ''">#{isRequired},</if> | |
| 79 | - <if test="isInsert != null and isInsert != ''">#{isInsert},</if> | |
| 80 | - <if test="isEdit != null and isEdit != ''">#{isEdit},</if> | |
| 81 | - <if test="isList != null and isList != ''">#{isList},</if> | |
| 82 | - <if test="isQuery != null and isQuery != ''">#{isQuery},</if> | |
| 83 | - <if test="queryType != null and queryType != ''">#{queryType},</if> | |
| 84 | - <if test="htmlType != null and htmlType != ''">#{htmlType},</if> | |
| 85 | - <if test="dictType != null and dictType != ''">#{dictType},</if> | |
| 86 | - <if test="sort != null">#{sort},</if> | |
| 87 | - <if test="createBy != null and createBy != ''">#{createBy},</if> | |
| 88 | - sysdate() | |
| 89 | - ) | |
| 90 | - </insert> | |
| 91 | - | |
| 92 | - <update id="updateGenTableColumn" parameterType="GenTableColumn"> | |
| 93 | - update gen_table_column | |
| 94 | - <set> | |
| 95 | - column_comment = #{columnComment}, | |
| 96 | - java_type = #{javaType}, | |
| 97 | - java_field = #{javaField}, | |
| 98 | - is_insert = #{isInsert}, | |
| 99 | - is_edit = #{isEdit}, | |
| 100 | - is_list = #{isList}, | |
| 101 | - is_query = #{isQuery}, | |
| 102 | - is_required = #{isRequired}, | |
| 103 | - query_type = #{queryType}, | |
| 104 | - html_type = #{htmlType}, | |
| 105 | - dict_type = #{dictType}, | |
| 106 | - sort = #{sort}, | |
| 107 | - update_by = #{updateBy}, | |
| 108 | - update_time = sysdate() | |
| 109 | - </set> | |
| 110 | - where column_id = #{columnId} | |
| 111 | - </update> | |
| 112 | - | |
| 113 | - <delete id="deleteGenTableColumnByIds" parameterType="Long"> | |
| 114 | - delete from gen_table_column where table_id in | |
| 115 | - <foreach collection="array" item="tableId" open="(" separator="," close=")"> | |
| 116 | - #{tableId} | |
| 117 | - </foreach> | |
| 118 | - </delete> | |
| 119 | - | |
| 120 | - <delete id="deleteGenTableColumns"> | |
| 121 | - delete from gen_table_column where column_id in | |
| 122 | - <foreach collection="list" item="item" open="(" separator="," close=")"> | |
| 123 | - #{item.columnId} | |
| 124 | - </foreach> | |
| 125 | - </delete> | |
| 126 | - | |
| 127 | -</mapper> | |
| 128 | 0 | \ No newline at end of file |
ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8" ?> | |
| 2 | -<!DOCTYPE mapper | |
| 3 | -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
| 4 | -"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 5 | -<mapper namespace="com.ruoyi.generator.mapper.GenTableMapper"> | |
| 6 | - | |
| 7 | - <resultMap type="GenTable" id="GenTableResult"> | |
| 8 | - <id property="tableId" column="table_id" /> | |
| 9 | - <result property="tableName" column="table_name" /> | |
| 10 | - <result property="tableComment" column="table_comment" /> | |
| 11 | - <result property="className" column="class_name" /> | |
| 12 | - <result property="tplCategory" column="tpl_category" /> | |
| 13 | - <result property="packageName" column="package_name" /> | |
| 14 | - <result property="moduleName" column="module_name" /> | |
| 15 | - <result property="businessName" column="business_name" /> | |
| 16 | - <result property="functionName" column="function_name" /> | |
| 17 | - <result property="functionAuthor" column="function_author" /> | |
| 18 | - <result property="genType" column="gen_type" /> | |
| 19 | - <result property="genPath" column="gen_path" /> | |
| 20 | - <result property="options" column="options" /> | |
| 21 | - <result property="createBy" column="create_by" /> | |
| 22 | - <result property="createTime" column="create_time" /> | |
| 23 | - <result property="updateBy" column="update_by" /> | |
| 24 | - <result property="updateTime" column="update_time" /> | |
| 25 | - <result property="remark" column="remark" /> | |
| 26 | - <collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" /> | |
| 27 | - </resultMap> | |
| 28 | - | |
| 29 | - <resultMap type="GenTableColumn" id="GenTableColumnResult"> | |
| 30 | - <id property="columnId" column="column_id" /> | |
| 31 | - <result property="tableId" column="table_id" /> | |
| 32 | - <result property="columnName" column="column_name" /> | |
| 33 | - <result property="columnComment" column="column_comment" /> | |
| 34 | - <result property="columnType" column="column_type" /> | |
| 35 | - <result property="javaType" column="java_type" /> | |
| 36 | - <result property="javaField" column="java_field" /> | |
| 37 | - <result property="isPk" column="is_pk" /> | |
| 38 | - <result property="isIncrement" column="is_increment" /> | |
| 39 | - <result property="isRequired" column="is_required" /> | |
| 40 | - <result property="isInsert" column="is_insert" /> | |
| 41 | - <result property="isEdit" column="is_edit" /> | |
| 42 | - <result property="isList" column="is_list" /> | |
| 43 | - <result property="isQuery" column="is_query" /> | |
| 44 | - <result property="queryType" column="query_type" /> | |
| 45 | - <result property="htmlType" column="html_type" /> | |
| 46 | - <result property="dictType" column="dict_type" /> | |
| 47 | - <result property="sort" column="sort" /> | |
| 48 | - <result property="createBy" column="create_by" /> | |
| 49 | - <result property="createTime" column="create_time" /> | |
| 50 | - <result property="updateBy" column="update_by" /> | |
| 51 | - <result property="updateTime" column="update_time" /> | |
| 52 | - </resultMap> | |
| 53 | - | |
| 54 | - <sql id="selectGenTableVo"> | |
| 55 | - select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table | |
| 56 | - </sql> | |
| 57 | - | |
| 58 | - <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> | |
| 59 | - <include refid="selectGenTableVo"/> | |
| 60 | - <where> | |
| 61 | - <if test="tableName != null and tableName != ''"> | |
| 62 | - AND lower(table_name) like lower(concat('%', #{tableName}, '%')) | |
| 63 | - </if> | |
| 64 | - <if test="tableComment != null and tableComment != ''"> | |
| 65 | - AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) | |
| 66 | - </if> | |
| 67 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | |
| 68 | - AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | |
| 69 | - </if> | |
| 70 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | |
| 71 | - AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | |
| 72 | - </if> | |
| 73 | - </where> | |
| 74 | - </select> | |
| 75 | - | |
| 76 | - <select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> | |
| 77 | - select table_name, table_comment, create_time, update_time from information_schema.tables | |
| 78 | - where table_schema = (select database()) | |
| 79 | - AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' | |
| 80 | - AND table_name NOT IN (select table_name from gen_table) | |
| 81 | - <if test="tableName != null and tableName != ''"> | |
| 82 | - AND lower(table_name) like lower(concat('%', #{tableName}, '%')) | |
| 83 | - </if> | |
| 84 | - <if test="tableComment != null and tableComment != ''"> | |
| 85 | - AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) | |
| 86 | - </if> | |
| 87 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | |
| 88 | - AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | |
| 89 | - </if> | |
| 90 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | |
| 91 | - AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | |
| 92 | - </if> | |
| 93 | - </select> | |
| 94 | - | |
| 95 | - <select id="selectDbTableListByNames" resultMap="GenTableResult"> | |
| 96 | - select table_name, table_comment, create_time, update_time from information_schema.tables | |
| 97 | - where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database()) | |
| 98 | - and table_name in | |
| 99 | - <foreach collection="array" item="name" open="(" separator="," close=")"> | |
| 100 | - #{name} | |
| 101 | - </foreach> | |
| 102 | - </select> | |
| 103 | - | |
| 104 | - <select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> | |
| 105 | - select table_name, table_comment, create_time, update_time from information_schema.tables | |
| 106 | - where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database()) | |
| 107 | - and table_name = #{tableName} | |
| 108 | - </select> | |
| 109 | - | |
| 110 | - <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> | |
| 111 | - SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, | |
| 112 | - c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | |
| 113 | - FROM gen_table t | |
| 114 | - LEFT JOIN gen_table_column c ON t.table_id = c.table_id | |
| 115 | - where t.table_id = #{tableId} order by c.sort | |
| 116 | - </select> | |
| 117 | - | |
| 118 | - <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> | |
| 119 | - SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, | |
| 120 | - c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | |
| 121 | - FROM gen_table t | |
| 122 | - LEFT JOIN gen_table_column c ON t.table_id = c.table_id | |
| 123 | - where t.table_name = #{tableName} order by c.sort | |
| 124 | - </select> | |
| 125 | - | |
| 126 | - <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> | |
| 127 | - insert into gen_table ( | |
| 128 | - <if test="tableName != null">table_name,</if> | |
| 129 | - <if test="tableComment != null and tableComment != ''">table_comment,</if> | |
| 130 | - <if test="className != null and className != ''">class_name,</if> | |
| 131 | - <if test="tplCategory != null and tplCategory != ''">tpl_category,</if> | |
| 132 | - <if test="packageName != null and packageName != ''">package_name,</if> | |
| 133 | - <if test="moduleName != null and moduleName != ''">module_name,</if> | |
| 134 | - <if test="businessName != null and businessName != ''">business_name,</if> | |
| 135 | - <if test="functionName != null and functionName != ''">function_name,</if> | |
| 136 | - <if test="functionAuthor != null and functionAuthor != ''">function_author,</if> | |
| 137 | - <if test="genType != null and genType != ''">gen_type,</if> | |
| 138 | - <if test="genPath != null and genPath != ''">gen_path,</if> | |
| 139 | - <if test="remark != null and remark != ''">remark,</if> | |
| 140 | - <if test="createBy != null and createBy != ''">create_by,</if> | |
| 141 | - create_time | |
| 142 | - )values( | |
| 143 | - <if test="tableName != null">#{tableName},</if> | |
| 144 | - <if test="tableComment != null and tableComment != ''">#{tableComment},</if> | |
| 145 | - <if test="className != null and className != ''">#{className},</if> | |
| 146 | - <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> | |
| 147 | - <if test="packageName != null and packageName != ''">#{packageName},</if> | |
| 148 | - <if test="moduleName != null and moduleName != ''">#{moduleName},</if> | |
| 149 | - <if test="businessName != null and businessName != ''">#{businessName},</if> | |
| 150 | - <if test="functionName != null and functionName != ''">#{functionName},</if> | |
| 151 | - <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> | |
| 152 | - <if test="genType != null and genType != ''">#{genType},</if> | |
| 153 | - <if test="genPath != null and genPath != ''">#{genPath},</if> | |
| 154 | - <if test="remark != null and remark != ''">#{remark},</if> | |
| 155 | - <if test="createBy != null and createBy != ''">#{createBy},</if> | |
| 156 | - sysdate() | |
| 157 | - ) | |
| 158 | - </insert> | |
| 159 | - | |
| 160 | - <update id="updateGenTable" parameterType="GenTable"> | |
| 161 | - update gen_table | |
| 162 | - <set> | |
| 163 | - <if test="tableName != null">table_name = #{tableName},</if> | |
| 164 | - <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> | |
| 165 | - <if test="className != null and className != ''">class_name = #{className},</if> | |
| 166 | - <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> | |
| 167 | - <if test="genType != null and genType != ''">gen_type = #{genType},</if> | |
| 168 | - <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if> | |
| 169 | - <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> | |
| 170 | - <if test="packageName != null and packageName != ''">package_name = #{packageName},</if> | |
| 171 | - <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> | |
| 172 | - <if test="businessName != null and businessName != ''">business_name = #{businessName},</if> | |
| 173 | - <if test="functionName != null and functionName != ''">function_name = #{functionName},</if> | |
| 174 | - <if test="options != null and options != ''">options = #{options},</if> | |
| 175 | - <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | |
| 176 | - <if test="remark != null">remark = #{remark},</if> | |
| 177 | - update_time = sysdate() | |
| 178 | - </set> | |
| 179 | - where table_id = #{tableId} | |
| 180 | - </update> | |
| 181 | - | |
| 182 | - <delete id="deleteGenTableByIds" parameterType="Long"> | |
| 183 | - delete from gen_table where table_id in | |
| 184 | - <foreach collection="array" item="tableId" open="(" separator="," close=")"> | |
| 185 | - #{tableId} | |
| 186 | - </foreach> | |
| 187 | - </delete> | |
| 188 | - | |
| 189 | -</mapper> | |
| 190 | 0 | \ No newline at end of file |
ruoyi-generator/src/main/resources/vm/java/controller.java.vm deleted
| 1 | -package ${packageName}.controller; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 5 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 7 | -import org.springframework.web.bind.annotation.PostMapping; | |
| 8 | -import org.springframework.web.bind.annotation.PutMapping; | |
| 9 | -import org.springframework.web.bind.annotation.DeleteMapping; | |
| 10 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 11 | -import org.springframework.web.bind.annotation.RequestBody; | |
| 12 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 13 | -import org.springframework.web.bind.annotation.RestController; | |
| 14 | -import com.ruoyi.common.annotation.Log; | |
| 15 | -import com.ruoyi.common.core.controller.BaseController; | |
| 16 | -import com.ruoyi.common.core.domain.AjaxResult; | |
| 17 | -import com.ruoyi.common.enums.BusinessType; | |
| 18 | -import ${packageName}.domain.${ClassName}; | |
| 19 | -import ${packageName}.service.I${ClassName}Service; | |
| 20 | -import com.ruoyi.common.utils.poi.ExcelUtil; | |
| 21 | -#if($table.crud) | |
| 22 | -import com.ruoyi.common.core.page.TableDataInfo; | |
| 23 | -#elseif($table.tree) | |
| 24 | -#end | |
| 25 | - | |
| 26 | -/** | |
| 27 | - * ${functionName}Controller | |
| 28 | - * | |
| 29 | - * @author ${author} | |
| 30 | - * @date ${datetime} | |
| 31 | - */ | |
| 32 | -@RestController | |
| 33 | -@RequestMapping("/${moduleName}/${businessName}") | |
| 34 | -public class ${ClassName}Controller extends BaseController | |
| 35 | -{ | |
| 36 | - @Autowired | |
| 37 | - private I${ClassName}Service ${className}Service; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * 查询${functionName}列表 | |
| 41 | - */ | |
| 42 | - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") | |
| 43 | - @GetMapping("/list") | |
| 44 | -#if($table.crud) | |
| 45 | - public TableDataInfo list(${ClassName} ${className}) | |
| 46 | - { | |
| 47 | - startPage(); | |
| 48 | - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); | |
| 49 | - return getDataTable(list); | |
| 50 | - } | |
| 51 | -#elseif($table.tree) | |
| 52 | - public AjaxResult list(${ClassName} ${className}) | |
| 53 | - { | |
| 54 | - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); | |
| 55 | - return AjaxResult.success(list); | |
| 56 | - } | |
| 57 | -#end | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * 导出${functionName}列表 | |
| 61 | - */ | |
| 62 | - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") | |
| 63 | - @Log(title = "${functionName}", businessType = BusinessType.EXPORT) | |
| 64 | - @GetMapping("/export") | |
| 65 | - public AjaxResult export(${ClassName} ${className}) | |
| 66 | - { | |
| 67 | - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); | |
| 68 | - ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class); | |
| 69 | - return util.exportExcel(list, "${businessName}"); | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * 获取${functionName}详细信息 | |
| 74 | - */ | |
| 75 | - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')") | |
| 76 | - @GetMapping(value = "/{${pkColumn.javaField}}") | |
| 77 | - public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) | |
| 78 | - { | |
| 79 | - return AjaxResult.success(${className}Service.select${ClassName}ById(${pkColumn.javaField})); | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * 新增${functionName} | |
| 84 | - */ | |
| 85 | - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") | |
| 86 | - @Log(title = "${functionName}", businessType = BusinessType.INSERT) | |
| 87 | - @PostMapping | |
| 88 | - public AjaxResult add(@RequestBody ${ClassName} ${className}) | |
| 89 | - { | |
| 90 | - return toAjax(${className}Service.insert${ClassName}(${className})); | |
| 91 | - } | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 修改${functionName} | |
| 95 | - */ | |
| 96 | - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") | |
| 97 | - @Log(title = "${functionName}", businessType = BusinessType.UPDATE) | |
| 98 | - @PutMapping | |
| 99 | - public AjaxResult edit(@RequestBody ${ClassName} ${className}) | |
| 100 | - { | |
| 101 | - return toAjax(${className}Service.update${ClassName}(${className})); | |
| 102 | - } | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * 删除${functionName} | |
| 106 | - */ | |
| 107 | - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") | |
| 108 | - @Log(title = "${functionName}", businessType = BusinessType.DELETE) | |
| 109 | - @DeleteMapping("/{${pkColumn.javaField}s}") | |
| 110 | - public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) | |
| 111 | - { | |
| 112 | - return toAjax(${className}Service.delete${ClassName}ByIds(${pkColumn.javaField}s)); | |
| 113 | - } | |
| 114 | -} |
ruoyi-generator/src/main/resources/vm/java/domain.java.vm deleted
| 1 | -package ${packageName}.domain; | |
| 2 | - | |
| 3 | -#foreach ($import in $importList) | |
| 4 | -import ${import}; | |
| 5 | -#end | |
| 6 | -import org.apache.commons.lang3.builder.ToStringBuilder; | |
| 7 | -import org.apache.commons.lang3.builder.ToStringStyle; | |
| 8 | -import com.ruoyi.common.annotation.Excel; | |
| 9 | -#if($table.crud) | |
| 10 | -import com.ruoyi.common.core.domain.BaseEntity; | |
| 11 | -#elseif($table.tree) | |
| 12 | -import com.ruoyi.common.core.domain.TreeEntity; | |
| 13 | -#end | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * ${functionName}对象 ${tableName} | |
| 17 | - * | |
| 18 | - * @author ${author} | |
| 19 | - * @date ${datetime} | |
| 20 | - */ | |
| 21 | -#if($table.crud) | |
| 22 | -#set($Entity="BaseEntity") | |
| 23 | -#elseif($table.tree) | |
| 24 | -#set($Entity="TreeEntity") | |
| 25 | -#end | |
| 26 | -public class ${ClassName} extends ${Entity} | |
| 27 | -{ | |
| 28 | - private static final long serialVersionUID = 1L; | |
| 29 | - | |
| 30 | -#foreach ($column in $columns) | |
| 31 | -#if(!$table.isSuperColumn($column.javaField)) | |
| 32 | - /** $column.columnComment */ | |
| 33 | -#if($column.list) | |
| 34 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 35 | -#if($parentheseIndex != -1) | |
| 36 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 37 | -#else | |
| 38 | -#set($comment=$column.columnComment) | |
| 39 | -#end | |
| 40 | -#if($parentheseIndex != -1) | |
| 41 | - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") | |
| 42 | -#elseif($column.javaType == 'Date') | |
| 43 | - @JsonFormat(pattern = "yyyy-MM-dd") | |
| 44 | - @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") | |
| 45 | -#else | |
| 46 | - @Excel(name = "${comment}") | |
| 47 | -#end | |
| 48 | -#end | |
| 49 | - private $column.javaType $column.javaField; | |
| 50 | - | |
| 51 | -#end | |
| 52 | -#end | |
| 53 | -#foreach ($column in $columns) | |
| 54 | -#if(!$table.isSuperColumn($column.javaField)) | |
| 55 | -#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) | |
| 56 | -#set($AttrName=$column.javaField) | |
| 57 | -#else | |
| 58 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 59 | -#end | |
| 60 | - public void set${AttrName}($column.javaType $column.javaField) | |
| 61 | - { | |
| 62 | - this.$column.javaField = $column.javaField; | |
| 63 | - } | |
| 64 | - | |
| 65 | - public $column.javaType get${AttrName}() | |
| 66 | - { | |
| 67 | - return $column.javaField; | |
| 68 | - } | |
| 69 | -#end | |
| 70 | -#end | |
| 71 | - | |
| 72 | - @Override | |
| 73 | - public String toString() { | |
| 74 | - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | |
| 75 | -#foreach ($column in $columns) | |
| 76 | -#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) | |
| 77 | -#set($AttrName=$column.javaField) | |
| 78 | -#else | |
| 79 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 80 | -#end | |
| 81 | - .append("${column.javaField}", get${AttrName}()) | |
| 82 | -#end | |
| 83 | - .toString(); | |
| 84 | - } | |
| 85 | -} |
ruoyi-generator/src/main/resources/vm/java/mapper.java.vm deleted
| 1 | -package ${packageName}.mapper; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import ${packageName}.domain.${ClassName}; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * ${functionName}Mapper接口 | |
| 8 | - * | |
| 9 | - * @author ${author} | |
| 10 | - * @date ${datetime} | |
| 11 | - */ | |
| 12 | -public interface ${ClassName}Mapper | |
| 13 | -{ | |
| 14 | - /** | |
| 15 | - * 查询${functionName} | |
| 16 | - * | |
| 17 | - * @param ${pkColumn.javaField} ${functionName}ID | |
| 18 | - * @return ${functionName} | |
| 19 | - */ | |
| 20 | - public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * 查询${functionName}列表 | |
| 24 | - * | |
| 25 | - * @param ${className} ${functionName} | |
| 26 | - * @return ${functionName}集合 | |
| 27 | - */ | |
| 28 | - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * 新增${functionName} | |
| 32 | - * | |
| 33 | - * @param ${className} ${functionName} | |
| 34 | - * @return 结果 | |
| 35 | - */ | |
| 36 | - public int insert${ClassName}(${ClassName} ${className}); | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 修改${functionName} | |
| 40 | - * | |
| 41 | - * @param ${className} ${functionName} | |
| 42 | - * @return 结果 | |
| 43 | - */ | |
| 44 | - public int update${ClassName}(${ClassName} ${className}); | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 删除${functionName} | |
| 48 | - * | |
| 49 | - * @param ${pkColumn.javaField} ${functionName}ID | |
| 50 | - * @return 结果 | |
| 51 | - */ | |
| 52 | - public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 批量删除${functionName} | |
| 56 | - * | |
| 57 | - * @param ${pkColumn.javaField}s 需要删除的数据ID | |
| 58 | - * @return 结果 | |
| 59 | - */ | |
| 60 | - public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); | |
| 61 | -} |
ruoyi-generator/src/main/resources/vm/java/service.java.vm deleted
| 1 | -package ${packageName}.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import ${packageName}.domain.${ClassName}; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * ${functionName}Service接口 | |
| 8 | - * | |
| 9 | - * @author ${author} | |
| 10 | - * @date ${datetime} | |
| 11 | - */ | |
| 12 | -public interface I${ClassName}Service | |
| 13 | -{ | |
| 14 | - /** | |
| 15 | - * 查询${functionName} | |
| 16 | - * | |
| 17 | - * @param ${pkColumn.javaField} ${functionName}ID | |
| 18 | - * @return ${functionName} | |
| 19 | - */ | |
| 20 | - public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * 查询${functionName}列表 | |
| 24 | - * | |
| 25 | - * @param ${className} ${functionName} | |
| 26 | - * @return ${functionName}集合 | |
| 27 | - */ | |
| 28 | - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * 新增${functionName} | |
| 32 | - * | |
| 33 | - * @param ${className} ${functionName} | |
| 34 | - * @return 结果 | |
| 35 | - */ | |
| 36 | - public int insert${ClassName}(${ClassName} ${className}); | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 修改${functionName} | |
| 40 | - * | |
| 41 | - * @param ${className} ${functionName} | |
| 42 | - * @return 结果 | |
| 43 | - */ | |
| 44 | - public int update${ClassName}(${ClassName} ${className}); | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 批量删除${functionName} | |
| 48 | - * | |
| 49 | - * @param ${pkColumn.javaField}s 需要删除的${functionName}ID | |
| 50 | - * @return 结果 | |
| 51 | - */ | |
| 52 | - public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 删除${functionName}信息 | |
| 56 | - * | |
| 57 | - * @param ${pkColumn.javaField} ${functionName}ID | |
| 58 | - * @return 结果 | |
| 59 | - */ | |
| 60 | - public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | |
| 61 | -} |
ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm deleted
| 1 | -package ${packageName}.service.impl; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -#foreach ($column in $columns) | |
| 5 | -#if($column.javaField == 'createTime' || $column.javaField == 'updateTime') | |
| 6 | -import com.ruoyi.common.utils.DateUtils; | |
| 7 | -#break | |
| 8 | -#end | |
| 9 | -#end | |
| 10 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | -import org.springframework.stereotype.Service; | |
| 12 | -import ${packageName}.mapper.${ClassName}Mapper; | |
| 13 | -import ${packageName}.domain.${ClassName}; | |
| 14 | -import ${packageName}.service.I${ClassName}Service; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * ${functionName}Service业务层处理 | |
| 18 | - * | |
| 19 | - * @author ${author} | |
| 20 | - * @date ${datetime} | |
| 21 | - */ | |
| 22 | -@Service | |
| 23 | -public class ${ClassName}ServiceImpl implements I${ClassName}Service | |
| 24 | -{ | |
| 25 | - @Autowired | |
| 26 | - private ${ClassName}Mapper ${className}Mapper; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 查询${functionName} | |
| 30 | - * | |
| 31 | - * @param ${pkColumn.javaField} ${functionName}ID | |
| 32 | - * @return ${functionName} | |
| 33 | - */ | |
| 34 | - @Override | |
| 35 | - public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) | |
| 36 | - { | |
| 37 | - return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField}); | |
| 38 | - } | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * 查询${functionName}列表 | |
| 42 | - * | |
| 43 | - * @param ${className} ${functionName} | |
| 44 | - * @return ${functionName} | |
| 45 | - */ | |
| 46 | - @Override | |
| 47 | - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) | |
| 48 | - { | |
| 49 | - return ${className}Mapper.select${ClassName}List(${className}); | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 新增${functionName} | |
| 54 | - * | |
| 55 | - * @param ${className} ${functionName} | |
| 56 | - * @return 结果 | |
| 57 | - */ | |
| 58 | - @Override | |
| 59 | - public int insert${ClassName}(${ClassName} ${className}) | |
| 60 | - { | |
| 61 | -#foreach ($column in $columns) | |
| 62 | -#if($column.javaField == 'createTime') | |
| 63 | - ${className}.setCreateTime(DateUtils.getNowDate()); | |
| 64 | -#end | |
| 65 | -#end | |
| 66 | - return ${className}Mapper.insert${ClassName}(${className}); | |
| 67 | - } | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * 修改${functionName} | |
| 71 | - * | |
| 72 | - * @param ${className} ${functionName} | |
| 73 | - * @return 结果 | |
| 74 | - */ | |
| 75 | - @Override | |
| 76 | - public int update${ClassName}(${ClassName} ${className}) | |
| 77 | - { | |
| 78 | -#foreach ($column in $columns) | |
| 79 | -#if($column.javaField == 'updateTime') | |
| 80 | - ${className}.setUpdateTime(DateUtils.getNowDate()); | |
| 81 | -#end | |
| 82 | -#end | |
| 83 | - return ${className}Mapper.update${ClassName}(${className}); | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * 批量删除${functionName} | |
| 88 | - * | |
| 89 | - * @param ${pkColumn.javaField}s 需要删除的${functionName}ID | |
| 90 | - * @return 结果 | |
| 91 | - */ | |
| 92 | - @Override | |
| 93 | - public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) | |
| 94 | - { | |
| 95 | - return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s); | |
| 96 | - } | |
| 97 | - | |
| 98 | - /** | |
| 99 | - * 删除${functionName}信息 | |
| 100 | - * | |
| 101 | - * @param ${pkColumn.javaField} ${functionName}ID | |
| 102 | - * @return 结果 | |
| 103 | - */ | |
| 104 | - @Override | |
| 105 | - public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) | |
| 106 | - { | |
| 107 | - return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); | |
| 108 | - } | |
| 109 | -} |
ruoyi-generator/src/main/resources/vm/sql/sql.vm deleted
| 1 | --- 菜单 SQL | |
| 2 | -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) | |
| 3 | -values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单'); | |
| 4 | - | |
| 5 | --- 按钮父菜单ID | |
| 6 | -SELECT @parentId := LAST_INSERT_ID(); | |
| 7 | - | |
| 8 | --- 按钮 SQL | |
| 9 | -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) | |
| 10 | -values('${functionName}查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, ''); | |
| 11 | - | |
| 12 | -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) | |
| 13 | -values('${functionName}新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, ''); | |
| 14 | - | |
| 15 | -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) | |
| 16 | -values('${functionName}修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, ''); | |
| 17 | - | |
| 18 | -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) | |
| 19 | -values('${functionName}删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, ''); | |
| 20 | - | |
| 21 | -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) | |
| 22 | -values('${functionName}导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, ''); | |
| 23 | 0 | \ No newline at end of file |
ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm deleted
| 1 | -<template> | |
| 2 | - <div class="app-container"> | |
| 3 | - <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> | |
| 4 | -#foreach($column in $columns) | |
| 5 | -#if($column.query) | |
| 6 | -#set($dictType=$column.dictType) | |
| 7 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 8 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 9 | -#if($parentheseIndex != -1) | |
| 10 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 11 | -#else | |
| 12 | -#set($comment=$column.columnComment) | |
| 13 | -#end | |
| 14 | -#if($column.htmlType == "input") | |
| 15 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 16 | - <el-input | |
| 17 | - v-model="queryParams.${column.javaField}" | |
| 18 | - placeholder="请输入${comment}" | |
| 19 | - clearable | |
| 20 | - size="small" | |
| 21 | - @keyup.enter.native="handleQuery" | |
| 22 | - /> | |
| 23 | - </el-form-item> | |
| 24 | -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType) | |
| 25 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 26 | - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> | |
| 27 | - <el-option | |
| 28 | - v-for="dict in ${column.javaField}Options" | |
| 29 | - :key="dict.dictValue" | |
| 30 | - :label="dict.dictLabel" | |
| 31 | - :value="dict.dictValue" | |
| 32 | - /> | |
| 33 | - </el-select> | |
| 34 | - </el-form-item> | |
| 35 | -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType) | |
| 36 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 37 | - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> | |
| 38 | - <el-option label="请选择字典生成" value="" /> | |
| 39 | - </el-select> | |
| 40 | - </el-form-item> | |
| 41 | -#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN") | |
| 42 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 43 | - <el-date-picker clearable size="small" | |
| 44 | - v-model="queryParams.${column.javaField}" | |
| 45 | - type="date" | |
| 46 | - value-format="yyyy-MM-dd" | |
| 47 | - placeholder="选择${comment}"> | |
| 48 | - </el-date-picker> | |
| 49 | - </el-form-item> | |
| 50 | -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 51 | - <el-form-item label="${comment}"> | |
| 52 | - <el-date-picker | |
| 53 | - v-model="daterange${AttrName}" | |
| 54 | - size="small" | |
| 55 | - style="width: 240px" | |
| 56 | - value-format="yyyy-MM-dd" | |
| 57 | - type="daterange" | |
| 58 | - range-separator="-" | |
| 59 | - start-placeholder="开始日期" | |
| 60 | - end-placeholder="结束日期" | |
| 61 | - ></el-date-picker> | |
| 62 | - </el-form-item> | |
| 63 | -#end | |
| 64 | -#end | |
| 65 | -#end | |
| 66 | - <el-form-item> | |
| 67 | - <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | |
| 68 | - <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | |
| 69 | - </el-form-item> | |
| 70 | - </el-form> | |
| 71 | - | |
| 72 | - <el-row :gutter="10" class="mb8"> | |
| 73 | - <el-col :span="1.5"> | |
| 74 | - <el-button | |
| 75 | - type="primary" | |
| 76 | - icon="el-icon-plus" | |
| 77 | - size="mini" | |
| 78 | - @click="handleAdd" | |
| 79 | - v-hasPermi="['${moduleName}:${businessName}:add']" | |
| 80 | - >新增</el-button> | |
| 81 | - </el-col> | |
| 82 | - <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 83 | - </el-row> | |
| 84 | - | |
| 85 | - <el-table | |
| 86 | - v-loading="loading" | |
| 87 | - :data="${businessName}List" | |
| 88 | - row-key="${treeCode}" | |
| 89 | - default-expand-all | |
| 90 | - :tree-props="{children: 'children', hasChildren: 'hasChildren'}" | |
| 91 | - > | |
| 92 | -#foreach($column in $columns) | |
| 93 | -#set($javaField=$column.javaField) | |
| 94 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 95 | -#if($parentheseIndex != -1) | |
| 96 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 97 | -#else | |
| 98 | -#set($comment=$column.columnComment) | |
| 99 | -#end | |
| 100 | -#if($column.pk) | |
| 101 | -#elseif($column.list && $column.htmlType == "datetime") | |
| 102 | - <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> | |
| 103 | - <template slot-scope="scope"> | |
| 104 | - <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span> | |
| 105 | - </template> | |
| 106 | - </el-table-column> | |
| 107 | -#elseif($column.list && "" != $column.dictType) | |
| 108 | - <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" /> | |
| 109 | -#elseif($column.list && "" != $javaField) | |
| 110 | - <el-table-column label="${comment}" align="center" prop="${javaField}" /> | |
| 111 | -#end | |
| 112 | -#end | |
| 113 | - <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 114 | - <template slot-scope="scope"> | |
| 115 | - <el-button | |
| 116 | - size="mini" | |
| 117 | - type="text" | |
| 118 | - icon="el-icon-edit" | |
| 119 | - @click="handleUpdate(scope.row)" | |
| 120 | - v-hasPermi="['${moduleName}:${businessName}:edit']" | |
| 121 | - >修改</el-button> | |
| 122 | - <el-button | |
| 123 | - size="mini" | |
| 124 | - type="text" | |
| 125 | - icon="el-icon-delete" | |
| 126 | - @click="handleDelete(scope.row)" | |
| 127 | - v-hasPermi="['${moduleName}:${businessName}:remove']" | |
| 128 | - >删除</el-button> | |
| 129 | - </template> | |
| 130 | - </el-table-column> | |
| 131 | - </el-table> | |
| 132 | - | |
| 133 | - <!-- 添加或修改${functionName}对话框 --> | |
| 134 | - <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | |
| 135 | - <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 136 | -#foreach($column in $columns) | |
| 137 | -#set($field=$column.javaField) | |
| 138 | -#if($column.insert && !$column.pk) | |
| 139 | -#if(($column.usableColumn) || (!$column.superColumn)) | |
| 140 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 141 | -#if($parentheseIndex != -1) | |
| 142 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 143 | -#else | |
| 144 | -#set($comment=$column.columnComment) | |
| 145 | -#end | |
| 146 | -#set($dictType=$column.dictType) | |
| 147 | -#if("" != $treeParentCode && $column.javaField == $treeParentCode) | |
| 148 | - <el-form-item label="${comment}" prop="${treeParentCode}"> | |
| 149 | - <treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="请选择${comment}" /> | |
| 150 | - </el-form-item> | |
| 151 | -#elseif($column.htmlType == "input") | |
| 152 | - <el-form-item label="${comment}" prop="${field}"> | |
| 153 | - <el-input v-model="form.${field}" placeholder="请输入${comment}" /> | |
| 154 | - </el-form-item> | |
| 155 | -#elseif($column.htmlType == "uploadImage") | |
| 156 | - <el-form-item label="${comment}"> | |
| 157 | - <uploadImage v-model="form.${field}"/> | |
| 158 | - </el-form-item> | |
| 159 | -#elseif($column.htmlType == "editor") | |
| 160 | - <el-form-item label="${comment}"> | |
| 161 | - <editor v-model="form.${field}" :min-height="192"/> | |
| 162 | - </el-form-item> | |
| 163 | -#elseif($column.htmlType == "select" && "" != $dictType) | |
| 164 | - <el-form-item label="${comment}" prop="${field}"> | |
| 165 | - <el-select v-model="form.${field}" placeholder="请选择${comment}"> | |
| 166 | - <el-option | |
| 167 | - v-for="dict in ${field}Options" | |
| 168 | - :key="dict.dictValue" | |
| 169 | - :label="dict.dictLabel" | |
| 170 | - #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end | |
| 171 | - | |
| 172 | - ></el-option> | |
| 173 | - </el-select> | |
| 174 | - </el-form-item> | |
| 175 | -#elseif($column.htmlType == "select" && $dictType) | |
| 176 | - <el-form-item label="${comment}" prop="${field}"> | |
| 177 | - <el-select v-model="form.${field}" placeholder="请选择${comment}"> | |
| 178 | - <el-option label="请选择字典生成" value="" /> | |
| 179 | - </el-select> | |
| 180 | - </el-form-item> | |
| 181 | -#elseif($column.htmlType == "checkbox" && "" != $dictType) | |
| 182 | - <el-form-item label="${comment}"> | |
| 183 | - <el-checkbox-group v-model="form.${field}"> | |
| 184 | - <el-checkbox | |
| 185 | - v-for="dict in ${field}Options" | |
| 186 | - :key="dict.dictValue" | |
| 187 | - :label="dict.dictValue"> | |
| 188 | - {{dict.dictLabel}} | |
| 189 | - </el-checkbox> | |
| 190 | - </el-checkbox-group> | |
| 191 | - </el-form-item> | |
| 192 | -#elseif($column.htmlType == "checkbox" && $dictType) | |
| 193 | - <el-form-item label="${comment}"> | |
| 194 | - <el-checkbox-group v-model="form.${field}"> | |
| 195 | - <el-checkbox>请选择字典生成</el-checkbox> | |
| 196 | - </el-checkbox-group> | |
| 197 | - </el-form-item> | |
| 198 | -#elseif($column.htmlType == "radio" && "" != $dictType) | |
| 199 | - <el-form-item label="${comment}"> | |
| 200 | - <el-radio-group v-model="form.${field}"> | |
| 201 | - <el-radio | |
| 202 | - v-for="dict in ${field}Options" | |
| 203 | - :key="dict.dictValue" | |
| 204 | - #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end | |
| 205 | - | |
| 206 | - >{{dict.dictLabel}}</el-radio> | |
| 207 | - </el-radio-group> | |
| 208 | - </el-form-item> | |
| 209 | -#elseif($column.htmlType == "radio" && $dictType) | |
| 210 | - <el-form-item label="${comment}"> | |
| 211 | - <el-radio-group v-model="form.${field}"> | |
| 212 | - <el-radio label="1">请选择字典生成</el-radio> | |
| 213 | - </el-radio-group> | |
| 214 | - </el-form-item> | |
| 215 | -#elseif($column.htmlType == "datetime") | |
| 216 | - <el-form-item label="${comment}" prop="${field}"> | |
| 217 | - <el-date-picker clearable size="small" | |
| 218 | - v-model="form.${field}" | |
| 219 | - type="date" | |
| 220 | - value-format="yyyy-MM-dd" | |
| 221 | - placeholder="选择${comment}"> | |
| 222 | - </el-date-picker> | |
| 223 | - </el-form-item> | |
| 224 | -#elseif($column.htmlType == "textarea") | |
| 225 | - <el-form-item label="${comment}" prop="${field}"> | |
| 226 | - <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" /> | |
| 227 | - </el-form-item> | |
| 228 | -#end | |
| 229 | -#end | |
| 230 | -#end | |
| 231 | -#end | |
| 232 | - </el-form> | |
| 233 | - <div slot="footer" class="dialog-footer"> | |
| 234 | - <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 235 | - <el-button @click="cancel">取 消</el-button> | |
| 236 | - </div> | |
| 237 | - </el-dialog> | |
| 238 | - </div> | |
| 239 | -</template> | |
| 240 | - | |
| 241 | -<script> | |
| 242 | -import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}"; | |
| 243 | -import Treeselect from "@riophae/vue-treeselect"; | |
| 244 | -import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | |
| 245 | -#foreach($column in $columns) | |
| 246 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage") | |
| 247 | -import UploadImage from '@/components/UploadImage'; | |
| 248 | -#break | |
| 249 | -#end | |
| 250 | -#end | |
| 251 | -#foreach($column in $columns) | |
| 252 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor") | |
| 253 | -import Editor from '@/components/Editor'; | |
| 254 | -#break | |
| 255 | -#end | |
| 256 | -#end | |
| 257 | - | |
| 258 | -export default { | |
| 259 | - name: "${BusinessName}", | |
| 260 | - components: { | |
| 261 | -#foreach($column in $columns) | |
| 262 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage") | |
| 263 | - UploadImage, | |
| 264 | -#break | |
| 265 | -#end | |
| 266 | -#end | |
| 267 | -#foreach($column in $columns) | |
| 268 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor") | |
| 269 | - Editor, | |
| 270 | -#break | |
| 271 | -#end | |
| 272 | -#end | |
| 273 | - Treeselect | |
| 274 | - }, | |
| 275 | - data() { | |
| 276 | - return { | |
| 277 | - // 遮罩层 | |
| 278 | - loading: true, | |
| 279 | - // 显示搜索条件 | |
| 280 | - showSearch: true, | |
| 281 | - // ${functionName}表格数据 | |
| 282 | - ${businessName}List: [], | |
| 283 | - // ${functionName}树选项 | |
| 284 | - ${businessName}Options: [], | |
| 285 | - // 弹出层标题 | |
| 286 | - title: "", | |
| 287 | - // 是否显示弹出层 | |
| 288 | - open: false, | |
| 289 | -#foreach ($column in $columns) | |
| 290 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 291 | -#if($parentheseIndex != -1) | |
| 292 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 293 | -#else | |
| 294 | -#set($comment=$column.columnComment) | |
| 295 | -#end | |
| 296 | -#if(${column.dictType} != '') | |
| 297 | - // $comment字典 | |
| 298 | - ${column.javaField}Options: [], | |
| 299 | -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 300 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 301 | - // $comment时间范围 | |
| 302 | - daterange${AttrName}: [], | |
| 303 | -#end | |
| 304 | -#end | |
| 305 | - // 查询参数 | |
| 306 | - queryParams: { | |
| 307 | -#foreach ($column in $columns) | |
| 308 | -#if($column.query) | |
| 309 | - $column.javaField: null#if($velocityCount != $columns.size()),#end | |
| 310 | - | |
| 311 | -#end | |
| 312 | -#end | |
| 313 | - }, | |
| 314 | - // 表单参数 | |
| 315 | - form: {}, | |
| 316 | - // 表单校验 | |
| 317 | - rules: { | |
| 318 | -#foreach ($column in $columns) | |
| 319 | -#if($column.required) | |
| 320 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 321 | -#if($parentheseIndex != -1) | |
| 322 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 323 | -#else | |
| 324 | -#set($comment=$column.columnComment) | |
| 325 | -#end | |
| 326 | - $column.javaField: [ | |
| 327 | - { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end } | |
| 328 | - ]#if($velocityCount != $columns.size()),#end | |
| 329 | - | |
| 330 | -#end | |
| 331 | -#end | |
| 332 | - } | |
| 333 | - }; | |
| 334 | - }, | |
| 335 | - created() { | |
| 336 | - this.getList(); | |
| 337 | -#foreach ($column in $columns) | |
| 338 | -#if(${column.dictType} != '') | |
| 339 | - this.getDicts("${column.dictType}").then(response => { | |
| 340 | - this.${column.javaField}Options = response.data; | |
| 341 | - }); | |
| 342 | -#end | |
| 343 | -#end | |
| 344 | - }, | |
| 345 | - methods: { | |
| 346 | - /** 查询${functionName}列表 */ | |
| 347 | - getList() { | |
| 348 | - this.loading = true; | |
| 349 | -#foreach ($column in $columns) | |
| 350 | -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 351 | - this.queryParams.params = {}; | |
| 352 | -#break | |
| 353 | -#end | |
| 354 | -#end | |
| 355 | -#foreach ($column in $columns) | |
| 356 | -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 357 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 358 | - if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) { | |
| 359 | - this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0]; | |
| 360 | - this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1]; | |
| 361 | - } | |
| 362 | -#end | |
| 363 | -#end | |
| 364 | - list${BusinessName}(this.queryParams).then(response => { | |
| 365 | - this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}"); | |
| 366 | - this.loading = false; | |
| 367 | - }); | |
| 368 | - }, | |
| 369 | - /** 转换${functionName}数据结构 */ | |
| 370 | - normalizer(node) { | |
| 371 | - if (node.children && !node.children.length) { | |
| 372 | - delete node.children; | |
| 373 | - } | |
| 374 | - return { | |
| 375 | - id: node.${treeCode}, | |
| 376 | - label: node.${treeName}, | |
| 377 | - children: node.children | |
| 378 | - }; | |
| 379 | - }, | |
| 380 | - /** 查询部门下拉树结构 */ | |
| 381 | - getTreeselect() { | |
| 382 | - list${BusinessName}().then(response => { | |
| 383 | - this.${businessName}Options = []; | |
| 384 | - const data = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] }; | |
| 385 | - data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}"); | |
| 386 | - this.${businessName}Options.push(data); | |
| 387 | - }); | |
| 388 | - }, | |
| 389 | -#foreach ($column in $columns) | |
| 390 | -#if(${column.dictType} != '') | |
| 391 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 392 | -#if($parentheseIndex != -1) | |
| 393 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 394 | -#else | |
| 395 | -#set($comment=$column.columnComment) | |
| 396 | -#end | |
| 397 | - // $comment字典翻译 | |
| 398 | - ${column.javaField}Format(row, column) { | |
| 399 | - return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField}); | |
| 400 | - }, | |
| 401 | -#end | |
| 402 | -#end | |
| 403 | - // 取消按钮 | |
| 404 | - cancel() { | |
| 405 | - this.open = false; | |
| 406 | - this.reset(); | |
| 407 | - }, | |
| 408 | - // 表单重置 | |
| 409 | - reset() { | |
| 410 | - this.form = { | |
| 411 | -#foreach ($column in $columns) | |
| 412 | -#if($column.htmlType == "radio") | |
| 413 | - $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end | |
| 414 | - | |
| 415 | -#elseif($column.htmlType == "checkbox") | |
| 416 | - $column.javaField: []#if($velocityCount != $columns.size()),#end | |
| 417 | - | |
| 418 | -#else | |
| 419 | - $column.javaField: null#if($velocityCount != $columns.size()),#end | |
| 420 | - | |
| 421 | -#end | |
| 422 | -#end | |
| 423 | - }; | |
| 424 | - this.resetForm("form"); | |
| 425 | - }, | |
| 426 | - /** 搜索按钮操作 */ | |
| 427 | - handleQuery() { | |
| 428 | - this.getList(); | |
| 429 | - }, | |
| 430 | - /** 重置按钮操作 */ | |
| 431 | - resetQuery() { | |
| 432 | -#foreach ($column in $columns) | |
| 433 | -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 434 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 435 | - this.daterange${AttrName} = []; | |
| 436 | -#end | |
| 437 | -#end | |
| 438 | - this.resetForm("queryForm"); | |
| 439 | - this.handleQuery(); | |
| 440 | - }, | |
| 441 | - /** 新增按钮操作 */ | |
| 442 | - handleAdd() { | |
| 443 | - this.reset(); | |
| 444 | - this.getTreeselect(); | |
| 445 | - this.open = true; | |
| 446 | - this.title = "添加${functionName}"; | |
| 447 | - }, | |
| 448 | - /** 修改按钮操作 */ | |
| 449 | - handleUpdate(row) { | |
| 450 | - this.reset(); | |
| 451 | - this.getTreeselect(); | |
| 452 | - if (row != null) { | |
| 453 | - this.form.${treeParentCode} = row.${treeCode}; | |
| 454 | - } | |
| 455 | - get${BusinessName}(row.${pkColumn.javaField}).then(response => { | |
| 456 | - this.form = response.data; | |
| 457 | -#foreach ($column in $columns) | |
| 458 | -#if($column.htmlType == "checkbox") | |
| 459 | - this.form.$column.javaField = this.form.${column.javaField}.split(","); | |
| 460 | -#end | |
| 461 | -#end | |
| 462 | - this.open = true; | |
| 463 | - this.title = "修改${functionName}"; | |
| 464 | - }); | |
| 465 | - }, | |
| 466 | - /** 提交按钮 */ | |
| 467 | - submitForm() { | |
| 468 | - this.#[[$]]#refs["form"].validate(valid => { | |
| 469 | - if (valid) { | |
| 470 | -#foreach ($column in $columns) | |
| 471 | -#if($column.htmlType == "checkbox") | |
| 472 | - this.form.$column.javaField = this.form.${column.javaField}.join(","); | |
| 473 | -#end | |
| 474 | -#end | |
| 475 | - if (this.form.${pkColumn.javaField} != null) { | |
| 476 | - update${BusinessName}(this.form).then(response => { | |
| 477 | - this.msgSuccess("修改成功"); | |
| 478 | - this.open = false; | |
| 479 | - this.getList(); | |
| 480 | - }); | |
| 481 | - } else { | |
| 482 | - add${BusinessName}(this.form).then(response => { | |
| 483 | - this.msgSuccess("新增成功"); | |
| 484 | - this.open = false; | |
| 485 | - this.getList(); | |
| 486 | - }); | |
| 487 | - } | |
| 488 | - } | |
| 489 | - }); | |
| 490 | - }, | |
| 491 | - /** 删除按钮操作 */ | |
| 492 | - handleDelete(row) { | |
| 493 | - this.$confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?', "警告", { | |
| 494 | - confirmButtonText: "确定", | |
| 495 | - cancelButtonText: "取消", | |
| 496 | - type: "warning" | |
| 497 | - }).then(function() { | |
| 498 | - return del${BusinessName}(row.${pkColumn.javaField}); | |
| 499 | - }).then(() => { | |
| 500 | - this.getList(); | |
| 501 | - this.msgSuccess("删除成功"); | |
| 502 | - }) | |
| 503 | - } | |
| 504 | - } | |
| 505 | -}; | |
| 506 | -</script> |
ruoyi-generator/src/main/resources/vm/vue/index.vue.vm deleted
| 1 | -<template> | |
| 2 | - <div class="app-container"> | |
| 3 | - <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> | |
| 4 | -#foreach($column in $columns) | |
| 5 | -#if($column.query) | |
| 6 | -#set($dictType=$column.dictType) | |
| 7 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 8 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 9 | -#if($parentheseIndex != -1) | |
| 10 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 11 | -#else | |
| 12 | -#set($comment=$column.columnComment) | |
| 13 | -#end | |
| 14 | -#if($column.htmlType == "input") | |
| 15 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 16 | - <el-input | |
| 17 | - v-model="queryParams.${column.javaField}" | |
| 18 | - placeholder="请输入${comment}" | |
| 19 | - clearable | |
| 20 | - size="small" | |
| 21 | - @keyup.enter.native="handleQuery" | |
| 22 | - /> | |
| 23 | - </el-form-item> | |
| 24 | -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType) | |
| 25 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 26 | - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> | |
| 27 | - <el-option | |
| 28 | - v-for="dict in ${column.javaField}Options" | |
| 29 | - :key="dict.dictValue" | |
| 30 | - :label="dict.dictLabel" | |
| 31 | - :value="dict.dictValue" | |
| 32 | - /> | |
| 33 | - </el-select> | |
| 34 | - </el-form-item> | |
| 35 | -#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType) | |
| 36 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 37 | - <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> | |
| 38 | - <el-option label="请选择字典生成" value="" /> | |
| 39 | - </el-select> | |
| 40 | - </el-form-item> | |
| 41 | -#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN") | |
| 42 | - <el-form-item label="${comment}" prop="${column.javaField}"> | |
| 43 | - <el-date-picker clearable size="small" | |
| 44 | - v-model="queryParams.${column.javaField}" | |
| 45 | - type="date" | |
| 46 | - value-format="yyyy-MM-dd" | |
| 47 | - placeholder="选择${comment}"> | |
| 48 | - </el-date-picker> | |
| 49 | - </el-form-item> | |
| 50 | -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 51 | - <el-form-item label="${comment}"> | |
| 52 | - <el-date-picker | |
| 53 | - v-model="daterange${AttrName}" | |
| 54 | - size="small" | |
| 55 | - style="width: 240px" | |
| 56 | - value-format="yyyy-MM-dd" | |
| 57 | - type="daterange" | |
| 58 | - range-separator="-" | |
| 59 | - start-placeholder="开始日期" | |
| 60 | - end-placeholder="结束日期" | |
| 61 | - ></el-date-picker> | |
| 62 | - </el-form-item> | |
| 63 | -#end | |
| 64 | -#end | |
| 65 | -#end | |
| 66 | - <el-form-item> | |
| 67 | - <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | |
| 68 | - <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | |
| 69 | - </el-form-item> | |
| 70 | - </el-form> | |
| 71 | - | |
| 72 | - <el-row :gutter="10" class="mb8"> | |
| 73 | - <el-col :span="1.5"> | |
| 74 | - <el-button | |
| 75 | - type="primary" | |
| 76 | - icon="el-icon-plus" | |
| 77 | - size="mini" | |
| 78 | - @click="handleAdd" | |
| 79 | - v-hasPermi="['${moduleName}:${businessName}:add']" | |
| 80 | - >新增</el-button> | |
| 81 | - </el-col> | |
| 82 | - <el-col :span="1.5"> | |
| 83 | - <el-button | |
| 84 | - type="success" | |
| 85 | - icon="el-icon-edit" | |
| 86 | - size="mini" | |
| 87 | - :disabled="single" | |
| 88 | - @click="handleUpdate" | |
| 89 | - v-hasPermi="['${moduleName}:${businessName}:edit']" | |
| 90 | - >修改</el-button> | |
| 91 | - </el-col> | |
| 92 | - <el-col :span="1.5"> | |
| 93 | - <el-button | |
| 94 | - type="danger" | |
| 95 | - icon="el-icon-delete" | |
| 96 | - size="mini" | |
| 97 | - :disabled="multiple" | |
| 98 | - @click="handleDelete" | |
| 99 | - v-hasPermi="['${moduleName}:${businessName}:remove']" | |
| 100 | - >删除</el-button> | |
| 101 | - </el-col> | |
| 102 | - <el-col :span="1.5"> | |
| 103 | - <el-button | |
| 104 | - type="warning" | |
| 105 | - icon="el-icon-download" | |
| 106 | - size="mini" | |
| 107 | - @click="handleExport" | |
| 108 | - v-hasPermi="['${moduleName}:${businessName}:export']" | |
| 109 | - >导出</el-button> | |
| 110 | - </el-col> | |
| 111 | - <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 112 | - </el-row> | |
| 113 | - | |
| 114 | - <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange"> | |
| 115 | - <el-table-column type="selection" width="55" align="center" /> | |
| 116 | -#foreach($column in $columns) | |
| 117 | -#set($javaField=$column.javaField) | |
| 118 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 119 | -#if($parentheseIndex != -1) | |
| 120 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 121 | -#else | |
| 122 | -#set($comment=$column.columnComment) | |
| 123 | -#end | |
| 124 | -#if($column.pk) | |
| 125 | - <el-table-column label="${comment}" align="center" prop="${javaField}" /> | |
| 126 | -#elseif($column.list && $column.htmlType == "datetime") | |
| 127 | - <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> | |
| 128 | - <template slot-scope="scope"> | |
| 129 | - <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span> | |
| 130 | - </template> | |
| 131 | - </el-table-column> | |
| 132 | -#elseif($column.list && "" != $column.dictType) | |
| 133 | - <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" /> | |
| 134 | -#elseif($column.list && "" != $javaField) | |
| 135 | - <el-table-column label="${comment}" align="center" prop="${javaField}" /> | |
| 136 | -#end | |
| 137 | -#end | |
| 138 | - <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 139 | - <template slot-scope="scope"> | |
| 140 | - <el-button | |
| 141 | - size="mini" | |
| 142 | - type="text" | |
| 143 | - icon="el-icon-edit" | |
| 144 | - @click="handleUpdate(scope.row)" | |
| 145 | - v-hasPermi="['${moduleName}:${businessName}:edit']" | |
| 146 | - >修改</el-button> | |
| 147 | - <el-button | |
| 148 | - size="mini" | |
| 149 | - type="text" | |
| 150 | - icon="el-icon-delete" | |
| 151 | - @click="handleDelete(scope.row)" | |
| 152 | - v-hasPermi="['${moduleName}:${businessName}:remove']" | |
| 153 | - >删除</el-button> | |
| 154 | - </template> | |
| 155 | - </el-table-column> | |
| 156 | - </el-table> | |
| 157 | - | |
| 158 | - <pagination | |
| 159 | - v-show="total>0" | |
| 160 | - :total="total" | |
| 161 | - :page.sync="queryParams.pageNum" | |
| 162 | - :limit.sync="queryParams.pageSize" | |
| 163 | - @pagination="getList" | |
| 164 | - /> | |
| 165 | - | |
| 166 | - <!-- 添加或修改${functionName}对话框 --> | |
| 167 | - <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | |
| 168 | - <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 169 | -#foreach($column in $columns) | |
| 170 | -#set($field=$column.javaField) | |
| 171 | -#if($column.insert && !$column.pk) | |
| 172 | -#if(($column.usableColumn) || (!$column.superColumn)) | |
| 173 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 174 | -#if($parentheseIndex != -1) | |
| 175 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 176 | -#else | |
| 177 | -#set($comment=$column.columnComment) | |
| 178 | -#end | |
| 179 | -#set($dictType=$column.dictType) | |
| 180 | -#if($column.htmlType == "input") | |
| 181 | - <el-form-item label="${comment}" prop="${field}"> | |
| 182 | - <el-input v-model="form.${field}" placeholder="请输入${comment}" /> | |
| 183 | - </el-form-item> | |
| 184 | -#elseif($column.htmlType == "uploadImage") | |
| 185 | - <el-form-item label="${comment}"> | |
| 186 | - <uploadImage v-model="form.${field}"/> | |
| 187 | - </el-form-item> | |
| 188 | -#elseif($column.htmlType == "editor") | |
| 189 | - <el-form-item label="${comment}"> | |
| 190 | - <editor v-model="form.${field}" :min-height="192"/> | |
| 191 | - </el-form-item> | |
| 192 | -#elseif($column.htmlType == "select" && "" != $dictType) | |
| 193 | - <el-form-item label="${comment}" prop="${field}"> | |
| 194 | - <el-select v-model="form.${field}" placeholder="请选择${comment}"> | |
| 195 | - <el-option | |
| 196 | - v-for="dict in ${field}Options" | |
| 197 | - :key="dict.dictValue" | |
| 198 | - :label="dict.dictLabel" | |
| 199 | - #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end | |
| 200 | - | |
| 201 | - ></el-option> | |
| 202 | - </el-select> | |
| 203 | - </el-form-item> | |
| 204 | -#elseif($column.htmlType == "select" && $dictType) | |
| 205 | - <el-form-item label="${comment}" prop="${field}"> | |
| 206 | - <el-select v-model="form.${field}" placeholder="请选择${comment}"> | |
| 207 | - <el-option label="请选择字典生成" value="" /> | |
| 208 | - </el-select> | |
| 209 | - </el-form-item> | |
| 210 | -#elseif($column.htmlType == "checkbox" && "" != $dictType) | |
| 211 | - <el-form-item label="${comment}"> | |
| 212 | - <el-checkbox-group v-model="form.${field}"> | |
| 213 | - <el-checkbox | |
| 214 | - v-for="dict in ${field}Options" | |
| 215 | - :key="dict.dictValue" | |
| 216 | - :label="dict.dictValue"> | |
| 217 | - {{dict.dictLabel}} | |
| 218 | - </el-checkbox> | |
| 219 | - </el-checkbox-group> | |
| 220 | - </el-form-item> | |
| 221 | -#elseif($column.htmlType == "checkbox" && $dictType) | |
| 222 | - <el-form-item label="${comment}"> | |
| 223 | - <el-checkbox-group v-model="form.${field}"> | |
| 224 | - <el-checkbox>请选择字典生成</el-checkbox> | |
| 225 | - </el-checkbox-group> | |
| 226 | - </el-form-item> | |
| 227 | -#elseif($column.htmlType == "radio" && "" != $dictType) | |
| 228 | - <el-form-item label="${comment}"> | |
| 229 | - <el-radio-group v-model="form.${field}"> | |
| 230 | - <el-radio | |
| 231 | - v-for="dict in ${field}Options" | |
| 232 | - :key="dict.dictValue" | |
| 233 | - #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end | |
| 234 | - | |
| 235 | - >{{dict.dictLabel}}</el-radio> | |
| 236 | - </el-radio-group> | |
| 237 | - </el-form-item> | |
| 238 | -#elseif($column.htmlType == "radio" && $dictType) | |
| 239 | - <el-form-item label="${comment}"> | |
| 240 | - <el-radio-group v-model="form.${field}"> | |
| 241 | - <el-radio label="1">请选择字典生成</el-radio> | |
| 242 | - </el-radio-group> | |
| 243 | - </el-form-item> | |
| 244 | -#elseif($column.htmlType == "datetime") | |
| 245 | - <el-form-item label="${comment}" prop="${field}"> | |
| 246 | - <el-date-picker clearable size="small" | |
| 247 | - v-model="form.${field}" | |
| 248 | - type="date" | |
| 249 | - value-format="yyyy-MM-dd" | |
| 250 | - placeholder="选择${comment}"> | |
| 251 | - </el-date-picker> | |
| 252 | - </el-form-item> | |
| 253 | -#elseif($column.htmlType == "textarea") | |
| 254 | - <el-form-item label="${comment}" prop="${field}"> | |
| 255 | - <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" /> | |
| 256 | - </el-form-item> | |
| 257 | -#end | |
| 258 | -#end | |
| 259 | -#end | |
| 260 | -#end | |
| 261 | - </el-form> | |
| 262 | - <div slot="footer" class="dialog-footer"> | |
| 263 | - <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 264 | - <el-button @click="cancel">取 消</el-button> | |
| 265 | - </div> | |
| 266 | - </el-dialog> | |
| 267 | - </div> | |
| 268 | -</template> | |
| 269 | - | |
| 270 | -<script> | |
| 271 | -import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}"; | |
| 272 | -#foreach($column in $columns) | |
| 273 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage") | |
| 274 | -import UploadImage from '@/components/UploadImage'; | |
| 275 | -#break | |
| 276 | -#end | |
| 277 | -#end | |
| 278 | -#foreach($column in $columns) | |
| 279 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor") | |
| 280 | -import Editor from '@/components/Editor'; | |
| 281 | -#break | |
| 282 | -#end | |
| 283 | -#end | |
| 284 | - | |
| 285 | -export default { | |
| 286 | - name: "${BusinessName}", | |
| 287 | - components: { | |
| 288 | -#foreach($column in $columns) | |
| 289 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage") | |
| 290 | - UploadImage, | |
| 291 | -#break | |
| 292 | -#end | |
| 293 | -#end | |
| 294 | -#foreach($column in $columns) | |
| 295 | -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor") | |
| 296 | - Editor, | |
| 297 | -#break | |
| 298 | -#end | |
| 299 | -#end | |
| 300 | - }, | |
| 301 | - data() { | |
| 302 | - return { | |
| 303 | - // 遮罩层 | |
| 304 | - loading: true, | |
| 305 | - // 选中数组 | |
| 306 | - ids: [], | |
| 307 | - // 非单个禁用 | |
| 308 | - single: true, | |
| 309 | - // 非多个禁用 | |
| 310 | - multiple: true, | |
| 311 | - // 显示搜索条件 | |
| 312 | - showSearch: true, | |
| 313 | - // 总条数 | |
| 314 | - total: 0, | |
| 315 | - // ${functionName}表格数据 | |
| 316 | - ${businessName}List: [], | |
| 317 | - // 弹出层标题 | |
| 318 | - title: "", | |
| 319 | - // 是否显示弹出层 | |
| 320 | - open: false, | |
| 321 | -#foreach ($column in $columns) | |
| 322 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 323 | -#if($parentheseIndex != -1) | |
| 324 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 325 | -#else | |
| 326 | -#set($comment=$column.columnComment) | |
| 327 | -#end | |
| 328 | -#if(${column.dictType} != '') | |
| 329 | - // $comment字典 | |
| 330 | - ${column.javaField}Options: [], | |
| 331 | -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 332 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 333 | - // $comment时间范围 | |
| 334 | - daterange${AttrName}: [], | |
| 335 | -#end | |
| 336 | -#end | |
| 337 | - // 查询参数 | |
| 338 | - queryParams: { | |
| 339 | - pageNum: 1, | |
| 340 | - pageSize: 10, | |
| 341 | -#foreach ($column in $columns) | |
| 342 | -#if($column.query) | |
| 343 | - $column.javaField: null#if($velocityCount != $columns.size()),#end | |
| 344 | - | |
| 345 | -#end | |
| 346 | -#end | |
| 347 | - }, | |
| 348 | - // 表单参数 | |
| 349 | - form: {}, | |
| 350 | - // 表单校验 | |
| 351 | - rules: { | |
| 352 | -#foreach ($column in $columns) | |
| 353 | -#if($column.required) | |
| 354 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 355 | -#if($parentheseIndex != -1) | |
| 356 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 357 | -#else | |
| 358 | -#set($comment=$column.columnComment) | |
| 359 | -#end | |
| 360 | - $column.javaField: [ | |
| 361 | - { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end } | |
| 362 | - ]#if($velocityCount != $columns.size()),#end | |
| 363 | - | |
| 364 | -#end | |
| 365 | -#end | |
| 366 | - } | |
| 367 | - }; | |
| 368 | - }, | |
| 369 | - created() { | |
| 370 | - this.getList(); | |
| 371 | -#foreach ($column in $columns) | |
| 372 | -#if(${column.dictType} != '') | |
| 373 | - this.getDicts("${column.dictType}").then(response => { | |
| 374 | - this.${column.javaField}Options = response.data; | |
| 375 | - }); | |
| 376 | -#end | |
| 377 | -#end | |
| 378 | - }, | |
| 379 | - methods: { | |
| 380 | - /** 查询${functionName}列表 */ | |
| 381 | - getList() { | |
| 382 | - this.loading = true; | |
| 383 | -#foreach ($column in $columns) | |
| 384 | -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 385 | - this.queryParams.params = {}; | |
| 386 | -#break | |
| 387 | -#end | |
| 388 | -#end | |
| 389 | -#foreach ($column in $columns) | |
| 390 | -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 391 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 392 | - if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) { | |
| 393 | - this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0]; | |
| 394 | - this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1]; | |
| 395 | - } | |
| 396 | -#end | |
| 397 | -#end | |
| 398 | - list${BusinessName}(this.queryParams).then(response => { | |
| 399 | - this.${businessName}List = response.rows; | |
| 400 | - this.total = response.total; | |
| 401 | - this.loading = false; | |
| 402 | - }); | |
| 403 | - }, | |
| 404 | -#foreach ($column in $columns) | |
| 405 | -#if(${column.dictType} != '') | |
| 406 | -#set($parentheseIndex=$column.columnComment.indexOf("(")) | |
| 407 | -#if($parentheseIndex != -1) | |
| 408 | -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | |
| 409 | -#else | |
| 410 | -#set($comment=$column.columnComment) | |
| 411 | -#end | |
| 412 | - // $comment字典翻译 | |
| 413 | - ${column.javaField}Format(row, column) { | |
| 414 | - return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField}); | |
| 415 | - }, | |
| 416 | -#end | |
| 417 | -#end | |
| 418 | - // 取消按钮 | |
| 419 | - cancel() { | |
| 420 | - this.open = false; | |
| 421 | - this.reset(); | |
| 422 | - }, | |
| 423 | - // 表单重置 | |
| 424 | - reset() { | |
| 425 | - this.form = { | |
| 426 | -#foreach ($column in $columns) | |
| 427 | -#if($column.htmlType == "radio") | |
| 428 | - $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end | |
| 429 | - | |
| 430 | -#elseif($column.htmlType == "checkbox") | |
| 431 | - $column.javaField: []#if($velocityCount != $columns.size()),#end | |
| 432 | - | |
| 433 | -#else | |
| 434 | - $column.javaField: null#if($velocityCount != $columns.size()),#end | |
| 435 | - | |
| 436 | -#end | |
| 437 | -#end | |
| 438 | - }; | |
| 439 | - this.resetForm("form"); | |
| 440 | - }, | |
| 441 | - /** 搜索按钮操作 */ | |
| 442 | - handleQuery() { | |
| 443 | - this.queryParams.pageNum = 1; | |
| 444 | - this.getList(); | |
| 445 | - }, | |
| 446 | - /** 重置按钮操作 */ | |
| 447 | - resetQuery() { | |
| 448 | -#foreach ($column in $columns) | |
| 449 | -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") | |
| 450 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 451 | - this.daterange${AttrName} = []; | |
| 452 | -#end | |
| 453 | -#end | |
| 454 | - this.resetForm("queryForm"); | |
| 455 | - this.handleQuery(); | |
| 456 | - }, | |
| 457 | - // 多选框选中数据 | |
| 458 | - handleSelectionChange(selection) { | |
| 459 | - this.ids = selection.map(item => item.${pkColumn.javaField}) | |
| 460 | - this.single = selection.length!==1 | |
| 461 | - this.multiple = !selection.length | |
| 462 | - }, | |
| 463 | - /** 新增按钮操作 */ | |
| 464 | - handleAdd() { | |
| 465 | - this.reset(); | |
| 466 | - this.open = true; | |
| 467 | - this.title = "添加${functionName}"; | |
| 468 | - }, | |
| 469 | - /** 修改按钮操作 */ | |
| 470 | - handleUpdate(row) { | |
| 471 | - this.reset(); | |
| 472 | - const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids | |
| 473 | - get${BusinessName}(${pkColumn.javaField}).then(response => { | |
| 474 | - this.form = response.data; | |
| 475 | -#foreach ($column in $columns) | |
| 476 | -#if($column.htmlType == "checkbox") | |
| 477 | - this.form.$column.javaField = this.form.${column.javaField}.split(","); | |
| 478 | -#end | |
| 479 | -#end | |
| 480 | - this.open = true; | |
| 481 | - this.title = "修改${functionName}"; | |
| 482 | - }); | |
| 483 | - }, | |
| 484 | - /** 提交按钮 */ | |
| 485 | - submitForm() { | |
| 486 | - this.#[[$]]#refs["form"].validate(valid => { | |
| 487 | - if (valid) { | |
| 488 | -#foreach ($column in $columns) | |
| 489 | -#if($column.htmlType == "checkbox") | |
| 490 | - this.form.$column.javaField = this.form.${column.javaField}.join(","); | |
| 491 | -#end | |
| 492 | -#end | |
| 493 | - if (this.form.${pkColumn.javaField} != null) { | |
| 494 | - update${BusinessName}(this.form).then(response => { | |
| 495 | - this.msgSuccess("修改成功"); | |
| 496 | - this.open = false; | |
| 497 | - this.getList(); | |
| 498 | - }); | |
| 499 | - } else { | |
| 500 | - add${BusinessName}(this.form).then(response => { | |
| 501 | - this.msgSuccess("新增成功"); | |
| 502 | - this.open = false; | |
| 503 | - this.getList(); | |
| 504 | - }); | |
| 505 | - } | |
| 506 | - } | |
| 507 | - }); | |
| 508 | - }, | |
| 509 | - /** 删除按钮操作 */ | |
| 510 | - handleDelete(row) { | |
| 511 | - const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids; | |
| 512 | - this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", { | |
| 513 | - confirmButtonText: "确定", | |
| 514 | - cancelButtonText: "取消", | |
| 515 | - type: "warning" | |
| 516 | - }).then(function() { | |
| 517 | - return del${BusinessName}(${pkColumn.javaField}s); | |
| 518 | - }).then(() => { | |
| 519 | - this.getList(); | |
| 520 | - this.msgSuccess("删除成功"); | |
| 521 | - }) | |
| 522 | - }, | |
| 523 | - /** 导出按钮操作 */ | |
| 524 | - handleExport() { | |
| 525 | - const queryParams = this.queryParams; | |
| 526 | - this.$confirm('是否确认导出所有${functionName}数据项?', "警告", { | |
| 527 | - confirmButtonText: "确定", | |
| 528 | - cancelButtonText: "取消", | |
| 529 | - type: "warning" | |
| 530 | - }).then(function() { | |
| 531 | - return export${BusinessName}(queryParams); | |
| 532 | - }).then(response => { | |
| 533 | - this.download(response.msg); | |
| 534 | - }) | |
| 535 | - } | |
| 536 | - } | |
| 537 | -}; | |
| 538 | -</script> |
ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm deleted
| 1 | -<?xml version="1.0" encoding="UTF-8" ?> | |
| 2 | -<!DOCTYPE mapper | |
| 3 | -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
| 4 | -"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 5 | -<mapper namespace="${packageName}.mapper.${ClassName}Mapper"> | |
| 6 | - | |
| 7 | - <resultMap type="${ClassName}" id="${ClassName}Result"> | |
| 8 | -#foreach ($column in $columns) | |
| 9 | - <result property="${column.javaField}" column="${column.columnName}" /> | |
| 10 | -#end | |
| 11 | - </resultMap> | |
| 12 | - | |
| 13 | - <sql id="select${ClassName}Vo"> | |
| 14 | - select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} | |
| 15 | - </sql> | |
| 16 | - | |
| 17 | - <select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result"> | |
| 18 | - <include refid="select${ClassName}Vo"/> | |
| 19 | - <where> | |
| 20 | -#foreach($column in $columns) | |
| 21 | -#set($queryType=$column.queryType) | |
| 22 | -#set($javaField=$column.javaField) | |
| 23 | -#set($javaType=$column.javaType) | |
| 24 | -#set($columnName=$column.columnName) | |
| 25 | -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 26 | -#if($column.query) | |
| 27 | -#if($column.queryType == "EQ") | |
| 28 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if> | |
| 29 | -#elseif($queryType == "NE") | |
| 30 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if> | |
| 31 | -#elseif($queryType == "GT") | |
| 32 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if> | |
| 33 | -#elseif($queryType == "GTE") | |
| 34 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if> | |
| 35 | -#elseif($queryType == "LT") | |
| 36 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if> | |
| 37 | -#elseif($queryType == "LTE") | |
| 38 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if> | |
| 39 | -#elseif($queryType == "LIKE") | |
| 40 | - <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if> | |
| 41 | -#elseif($queryType == "BETWEEN") | |
| 42 | - <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if> | |
| 43 | -#end | |
| 44 | -#end | |
| 45 | -#end | |
| 46 | - </where> | |
| 47 | - </select> | |
| 48 | - | |
| 49 | - <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}Result"> | |
| 50 | - <include refid="select${ClassName}Vo"/> | |
| 51 | - where ${pkColumn.columnName} = #{${pkColumn.javaField}} | |
| 52 | - </select> | |
| 53 | - | |
| 54 | - <insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> | |
| 55 | - insert into ${tableName} | |
| 56 | - <trim prefix="(" suffix=")" suffixOverrides=","> | |
| 57 | -#foreach($column in $columns) | |
| 58 | -#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) | |
| 59 | - <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if> | |
| 60 | -#end | |
| 61 | -#end | |
| 62 | - </trim> | |
| 63 | - <trim prefix="values (" suffix=")" suffixOverrides=","> | |
| 64 | -#foreach($column in $columns) | |
| 65 | -#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) | |
| 66 | - <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if> | |
| 67 | -#end | |
| 68 | -#end | |
| 69 | - </trim> | |
| 70 | - </insert> | |
| 71 | - | |
| 72 | - <update id="update${ClassName}" parameterType="${ClassName}"> | |
| 73 | - update ${tableName} | |
| 74 | - <trim prefix="SET" suffixOverrides=","> | |
| 75 | -#foreach($column in $columns) | |
| 76 | -#if($column.columnName != $pkColumn.columnName) | |
| 77 | - <if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if> | |
| 78 | -#end | |
| 79 | -#end | |
| 80 | - </trim> | |
| 81 | - where ${pkColumn.columnName} = #{${pkColumn.javaField}} | |
| 82 | - </update> | |
| 83 | - | |
| 84 | - <delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}"> | |
| 85 | - delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} | |
| 86 | - </delete> | |
| 87 | - | |
| 88 | - <delete id="delete${ClassName}ByIds" parameterType="String"> | |
| 89 | - delete from ${tableName} where ${pkColumn.columnName} in | |
| 90 | - <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")"> | |
| 91 | - #{${pkColumn.javaField}} | |
| 92 | - </foreach> | |
| 93 | - </delete> | |
| 94 | - | |
| 95 | -</mapper> | |
| 96 | 0 | \ No newline at end of file |
ruoyi-quartz/pom.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 5 | - <parent> | |
| 6 | - <artifactId>ruoyi</artifactId> | |
| 7 | - <groupId>com.ruoyi</groupId> | |
| 8 | - <version>3.3.0</version> | |
| 9 | - </parent> | |
| 10 | - <modelVersion>4.0.0</modelVersion> | |
| 11 | - | |
| 12 | - <artifactId>ruoyi-quartz</artifactId> | |
| 13 | - | |
| 14 | - <description> | |
| 15 | - quartz定时任务 | |
| 16 | - </description> | |
| 17 | - | |
| 18 | - <dependencies> | |
| 19 | - | |
| 20 | - <!-- 定时任务 --> | |
| 21 | - <dependency> | |
| 22 | - <groupId>org.quartz-scheduler</groupId> | |
| 23 | - <artifactId>quartz</artifactId> | |
| 24 | - <exclusions> | |
| 25 | - <exclusion> | |
| 26 | - <groupId>com.mchange</groupId> | |
| 27 | - <artifactId>c3p0</artifactId> | |
| 28 | - </exclusion> | |
| 29 | - </exclusions> | |
| 30 | - </dependency> | |
| 31 | - </dependencies> | |
| 32 | - | |
| 33 | -</project> |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java deleted
| 1 | -package com.ruoyi.quartz.config; | |
| 2 | - | |
| 3 | -import org.springframework.context.annotation.Bean; | |
| 4 | -import org.springframework.context.annotation.Configuration; | |
| 5 | -import org.springframework.scheduling.quartz.SchedulerFactoryBean; | |
| 6 | -import javax.sql.DataSource; | |
| 7 | -import java.util.Properties; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 定时任务配置 | |
| 11 | - * | |
| 12 | - * @author ruoyi | |
| 13 | - */ | |
| 14 | -@Configuration | |
| 15 | -public class ScheduleConfig | |
| 16 | -{ | |
| 17 | - @Bean | |
| 18 | - public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) | |
| 19 | - { | |
| 20 | - SchedulerFactoryBean factory = new SchedulerFactoryBean(); | |
| 21 | - factory.setDataSource(dataSource); | |
| 22 | - | |
| 23 | - // quartz参数 | |
| 24 | - Properties prop = new Properties(); | |
| 25 | - prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler"); | |
| 26 | - prop.put("org.quartz.scheduler.instanceId", "AUTO"); | |
| 27 | - // 线程池配置 | |
| 28 | - prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); | |
| 29 | - prop.put("org.quartz.threadPool.threadCount", "20"); | |
| 30 | - prop.put("org.quartz.threadPool.threadPriority", "5"); | |
| 31 | - // JobStore配置 | |
| 32 | - prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); | |
| 33 | - // 集群配置 | |
| 34 | - prop.put("org.quartz.jobStore.isClustered", "true"); | |
| 35 | - prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); | |
| 36 | - prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); | |
| 37 | - prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); | |
| 38 | - | |
| 39 | - // sqlserver 启用 | |
| 40 | - // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); | |
| 41 | - prop.put("org.quartz.jobStore.misfireThreshold", "12000"); | |
| 42 | - prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); | |
| 43 | - factory.setQuartzProperties(prop); | |
| 44 | - | |
| 45 | - factory.setSchedulerName("RuoyiScheduler"); | |
| 46 | - // 延时启动 | |
| 47 | - factory.setStartupDelay(1); | |
| 48 | - factory.setApplicationContextSchedulerContextKey("applicationContextKey"); | |
| 49 | - // 可选,QuartzScheduler | |
| 50 | - // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 | |
| 51 | - factory.setOverwriteExistingJobs(true); | |
| 52 | - // 设置自动启动,默认为true | |
| 53 | - factory.setAutoStartup(true); | |
| 54 | - | |
| 55 | - return factory; | |
| 56 | - } | |
| 57 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java deleted
| 1 | -package com.ruoyi.quartz.controller; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import org.quartz.SchedulerException; | |
| 5 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | -import org.springframework.web.bind.annotation.DeleteMapping; | |
| 8 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 9 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 10 | -import org.springframework.web.bind.annotation.PostMapping; | |
| 11 | -import org.springframework.web.bind.annotation.PutMapping; | |
| 12 | -import org.springframework.web.bind.annotation.RequestBody; | |
| 13 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | -import org.springframework.web.bind.annotation.RestController; | |
| 15 | -import com.ruoyi.common.annotation.Log; | |
| 16 | -import com.ruoyi.common.core.controller.BaseController; | |
| 17 | -import com.ruoyi.common.core.domain.AjaxResult; | |
| 18 | -import com.ruoyi.common.core.page.TableDataInfo; | |
| 19 | -import com.ruoyi.common.enums.BusinessType; | |
| 20 | -import com.ruoyi.common.exception.job.TaskException; | |
| 21 | -import com.ruoyi.common.utils.SecurityUtils; | |
| 22 | -import com.ruoyi.common.utils.poi.ExcelUtil; | |
| 23 | -import com.ruoyi.quartz.domain.SysJob; | |
| 24 | -import com.ruoyi.quartz.service.ISysJobService; | |
| 25 | -import com.ruoyi.quartz.util.CronUtils; | |
| 26 | - | |
| 27 | -/** | |
| 28 | - * 调度任务信息操作处理 | |
| 29 | - * | |
| 30 | - * @author ruoyi | |
| 31 | - */ | |
| 32 | -@RestController | |
| 33 | -@RequestMapping("/monitor/job") | |
| 34 | -public class SysJobController extends BaseController | |
| 35 | -{ | |
| 36 | - @Autowired | |
| 37 | - private ISysJobService jobService; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * 查询定时任务列表 | |
| 41 | - */ | |
| 42 | - @PreAuthorize("@ss.hasPermi('monitor:job:list')") | |
| 43 | - @GetMapping("/list") | |
| 44 | - public TableDataInfo list(SysJob sysJob) | |
| 45 | - { | |
| 46 | - startPage(); | |
| 47 | - List<SysJob> list = jobService.selectJobList(sysJob); | |
| 48 | - return getDataTable(list); | |
| 49 | - } | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * 导出定时任务列表 | |
| 53 | - */ | |
| 54 | - @PreAuthorize("@ss.hasPermi('monitor:job:export')") | |
| 55 | - @Log(title = "定时任务", businessType = BusinessType.EXPORT) | |
| 56 | - @GetMapping("/export") | |
| 57 | - public AjaxResult export(SysJob sysJob) | |
| 58 | - { | |
| 59 | - List<SysJob> list = jobService.selectJobList(sysJob); | |
| 60 | - ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); | |
| 61 | - return util.exportExcel(list, "定时任务"); | |
| 62 | - } | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * 获取定时任务详细信息 | |
| 66 | - */ | |
| 67 | - @PreAuthorize("@ss.hasPermi('monitor:job:query')") | |
| 68 | - @GetMapping(value = "/{jobId}") | |
| 69 | - public AjaxResult getInfo(@PathVariable("jobId") Long jobId) | |
| 70 | - { | |
| 71 | - return AjaxResult.success(jobService.selectJobById(jobId)); | |
| 72 | - } | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * 新增定时任务 | |
| 76 | - */ | |
| 77 | - @PreAuthorize("@ss.hasPermi('monitor:job:add')") | |
| 78 | - @Log(title = "定时任务", businessType = BusinessType.INSERT) | |
| 79 | - @PostMapping | |
| 80 | - public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException | |
| 81 | - { | |
| 82 | - if (!CronUtils.isValid(sysJob.getCronExpression())) | |
| 83 | - { | |
| 84 | - return AjaxResult.error("cron表达式不正确"); | |
| 85 | - } | |
| 86 | - sysJob.setCreateBy(SecurityUtils.getUsername()); | |
| 87 | - return toAjax(jobService.insertJob(sysJob)); | |
| 88 | - } | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * 修改定时任务 | |
| 92 | - */ | |
| 93 | - @PreAuthorize("@ss.hasPermi('monitor:job:edit')") | |
| 94 | - @Log(title = "定时任务", businessType = BusinessType.UPDATE) | |
| 95 | - @PutMapping | |
| 96 | - public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException | |
| 97 | - { | |
| 98 | - if (!CronUtils.isValid(sysJob.getCronExpression())) | |
| 99 | - { | |
| 100 | - return AjaxResult.error("cron表达式不正确"); | |
| 101 | - } | |
| 102 | - sysJob.setUpdateBy(SecurityUtils.getUsername()); | |
| 103 | - return toAjax(jobService.updateJob(sysJob)); | |
| 104 | - } | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * 定时任务状态修改 | |
| 108 | - */ | |
| 109 | - @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") | |
| 110 | - @Log(title = "定时任务", businessType = BusinessType.UPDATE) | |
| 111 | - @PutMapping("/changeStatus") | |
| 112 | - public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException | |
| 113 | - { | |
| 114 | - SysJob newJob = jobService.selectJobById(job.getJobId()); | |
| 115 | - newJob.setStatus(job.getStatus()); | |
| 116 | - return toAjax(jobService.changeStatus(newJob)); | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * 定时任务立即执行一次 | |
| 121 | - */ | |
| 122 | - @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") | |
| 123 | - @Log(title = "定时任务", businessType = BusinessType.UPDATE) | |
| 124 | - @PutMapping("/run") | |
| 125 | - public AjaxResult run(@RequestBody SysJob job) throws SchedulerException | |
| 126 | - { | |
| 127 | - jobService.run(job); | |
| 128 | - return AjaxResult.success(); | |
| 129 | - } | |
| 130 | - | |
| 131 | - /** | |
| 132 | - * 删除定时任务 | |
| 133 | - */ | |
| 134 | - @PreAuthorize("@ss.hasPermi('monitor:job:remove')") | |
| 135 | - @Log(title = "定时任务", businessType = BusinessType.DELETE) | |
| 136 | - @DeleteMapping("/{jobIds}") | |
| 137 | - public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException | |
| 138 | - { | |
| 139 | - jobService.deleteJobByIds(jobIds); | |
| 140 | - return AjaxResult.success(); | |
| 141 | - } | |
| 142 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java deleted
| 1 | -package com.ruoyi.quartz.controller; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 6 | -import org.springframework.web.bind.annotation.DeleteMapping; | |
| 7 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 8 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 9 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 10 | -import org.springframework.web.bind.annotation.RestController; | |
| 11 | -import com.ruoyi.common.annotation.Log; | |
| 12 | -import com.ruoyi.common.core.controller.BaseController; | |
| 13 | -import com.ruoyi.common.core.domain.AjaxResult; | |
| 14 | -import com.ruoyi.common.core.page.TableDataInfo; | |
| 15 | -import com.ruoyi.common.enums.BusinessType; | |
| 16 | -import com.ruoyi.common.utils.poi.ExcelUtil; | |
| 17 | -import com.ruoyi.quartz.domain.SysJobLog; | |
| 18 | -import com.ruoyi.quartz.service.ISysJobLogService; | |
| 19 | - | |
| 20 | -/** | |
| 21 | - * 调度日志操作处理 | |
| 22 | - * | |
| 23 | - * @author ruoyi | |
| 24 | - */ | |
| 25 | -@RestController | |
| 26 | -@RequestMapping("/monitor/jobLog") | |
| 27 | -public class SysJobLogController extends BaseController | |
| 28 | -{ | |
| 29 | - @Autowired | |
| 30 | - private ISysJobLogService jobLogService; | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * 查询定时任务调度日志列表 | |
| 34 | - */ | |
| 35 | - @PreAuthorize("@ss.hasPermi('monitor:job:list')") | |
| 36 | - @GetMapping("/list") | |
| 37 | - public TableDataInfo list(SysJobLog sysJobLog) | |
| 38 | - { | |
| 39 | - startPage(); | |
| 40 | - List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); | |
| 41 | - return getDataTable(list); | |
| 42 | - } | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 导出定时任务调度日志列表 | |
| 46 | - */ | |
| 47 | - @PreAuthorize("@ss.hasPermi('monitor:job:export')") | |
| 48 | - @Log(title = "任务调度日志", businessType = BusinessType.EXPORT) | |
| 49 | - @GetMapping("/export") | |
| 50 | - public AjaxResult export(SysJobLog sysJobLog) | |
| 51 | - { | |
| 52 | - List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); | |
| 53 | - ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class); | |
| 54 | - return util.exportExcel(list, "调度日志"); | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * 根据调度编号获取详细信息 | |
| 59 | - */ | |
| 60 | - @PreAuthorize("@ss.hasPermi('monitor:job:query')") | |
| 61 | - @GetMapping(value = "/{configId}") | |
| 62 | - public AjaxResult getInfo(@PathVariable Long jobLogId) | |
| 63 | - { | |
| 64 | - return AjaxResult.success(jobLogService.selectJobLogById(jobLogId)); | |
| 65 | - } | |
| 66 | - | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * 删除定时任务调度日志 | |
| 70 | - */ | |
| 71 | - @PreAuthorize("@ss.hasPermi('monitor:job:remove')") | |
| 72 | - @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE) | |
| 73 | - @DeleteMapping("/{jobLogIds}") | |
| 74 | - public AjaxResult remove(@PathVariable Long[] jobLogIds) | |
| 75 | - { | |
| 76 | - return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); | |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 清空定时任务调度日志 | |
| 81 | - */ | |
| 82 | - @PreAuthorize("@ss.hasPermi('monitor:job:remove')") | |
| 83 | - @Log(title = "调度日志", businessType = BusinessType.CLEAN) | |
| 84 | - @DeleteMapping("/clean") | |
| 85 | - public AjaxResult clean() | |
| 86 | - { | |
| 87 | - jobLogService.cleanJobLog(); | |
| 88 | - return AjaxResult.success(); | |
| 89 | - } | |
| 90 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJob.java deleted
| 1 | -package com.ruoyi.quartz.domain; | |
| 2 | - | |
| 3 | -import java.io.Serializable; | |
| 4 | -import java.util.Date; | |
| 5 | -import javax.validation.constraints.NotBlank; | |
| 6 | -import javax.validation.constraints.Size; | |
| 7 | -import org.apache.commons.lang3.builder.ToStringBuilder; | |
| 8 | -import org.apache.commons.lang3.builder.ToStringStyle; | |
| 9 | -import com.fasterxml.jackson.annotation.JsonFormat; | |
| 10 | -import com.ruoyi.common.annotation.Excel; | |
| 11 | -import com.ruoyi.common.annotation.Excel.ColumnType; | |
| 12 | -import com.ruoyi.common.constant.ScheduleConstants; | |
| 13 | -import com.ruoyi.common.core.domain.BaseEntity; | |
| 14 | -import com.ruoyi.common.utils.StringUtils; | |
| 15 | -import com.ruoyi.quartz.util.CronUtils; | |
| 16 | - | |
| 17 | -/** | |
| 18 | - * 定时任务调度表 sys_job | |
| 19 | - * | |
| 20 | - * @author ruoyi | |
| 21 | - */ | |
| 22 | -public class SysJob extends BaseEntity implements Serializable | |
| 23 | -{ | |
| 24 | - private static final long serialVersionUID = 1L; | |
| 25 | - | |
| 26 | - /** 任务ID */ | |
| 27 | - @Excel(name = "任务序号", cellType = ColumnType.NUMERIC) | |
| 28 | - private Long jobId; | |
| 29 | - | |
| 30 | - /** 任务名称 */ | |
| 31 | - @Excel(name = "任务名称") | |
| 32 | - private String jobName; | |
| 33 | - | |
| 34 | - /** 任务组名 */ | |
| 35 | - @Excel(name = "任务组名") | |
| 36 | - private String jobGroup; | |
| 37 | - | |
| 38 | - /** 调用目标字符串 */ | |
| 39 | - @Excel(name = "调用目标字符串") | |
| 40 | - private String invokeTarget; | |
| 41 | - | |
| 42 | - /** cron执行表达式 */ | |
| 43 | - @Excel(name = "执行表达式 ") | |
| 44 | - private String cronExpression; | |
| 45 | - | |
| 46 | - /** cron计划策略 */ | |
| 47 | - @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行") | |
| 48 | - private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT; | |
| 49 | - | |
| 50 | - /** 是否并发执行(0允许 1禁止) */ | |
| 51 | - @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止") | |
| 52 | - private String concurrent; | |
| 53 | - | |
| 54 | - /** 任务状态(0正常 1暂停) */ | |
| 55 | - @Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停") | |
| 56 | - private String status; | |
| 57 | - | |
| 58 | - @NotBlank(message = "任务名称不能为空") | |
| 59 | - @Size(min = 0, max = 64, message = "任务名称不能超过64个字符") | |
| 60 | - public String getJobName() | |
| 61 | - { | |
| 62 | - return jobName; | |
| 63 | - } | |
| 64 | - | |
| 65 | - @NotBlank(message = "调用目标字符串不能为空") | |
| 66 | - @Size(min = 0, max = 500, message = "调用目标字符串长度不能超过500个字符") | |
| 67 | - public String getInvokeTarget() | |
| 68 | - { | |
| 69 | - return invokeTarget; | |
| 70 | - } | |
| 71 | - | |
| 72 | - @NotBlank(message = "Cron执行表达式不能为空") | |
| 73 | - @Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符") | |
| 74 | - public String getCronExpression() | |
| 75 | - { | |
| 76 | - return cronExpression; | |
| 77 | - } | |
| 78 | - | |
| 79 | - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |
| 80 | - public Date getNextValidTime() | |
| 81 | - { | |
| 82 | - if (StringUtils.isNotEmpty(cronExpression)) | |
| 83 | - { | |
| 84 | - return CronUtils.getNextExecution(cronExpression); | |
| 85 | - } | |
| 86 | - return null; | |
| 87 | - } | |
| 88 | - | |
| 89 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/domain/SysJobLog.java deleted
| 1 | -package com.ruoyi.quartz.domain; | |
| 2 | - | |
| 3 | -import java.util.Date; | |
| 4 | -import org.apache.commons.lang3.builder.ToStringBuilder; | |
| 5 | -import org.apache.commons.lang3.builder.ToStringStyle; | |
| 6 | -import com.ruoyi.common.annotation.Excel; | |
| 7 | -import com.ruoyi.common.core.domain.BaseEntity; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 定时任务调度日志表 sys_job_log | |
| 11 | - * | |
| 12 | - * @author ruoyi | |
| 13 | - */ | |
| 14 | -public class SysJobLog extends BaseEntity | |
| 15 | -{ | |
| 16 | - private static final long serialVersionUID = 1L; | |
| 17 | - | |
| 18 | - /** ID */ | |
| 19 | - @Excel(name = "日志序号") | |
| 20 | - private Long jobLogId; | |
| 21 | - | |
| 22 | - /** 任务名称 */ | |
| 23 | - @Excel(name = "任务名称") | |
| 24 | - private String jobName; | |
| 25 | - | |
| 26 | - /** 任务组名 */ | |
| 27 | - @Excel(name = "任务组名") | |
| 28 | - private String jobGroup; | |
| 29 | - | |
| 30 | - /** 调用目标字符串 */ | |
| 31 | - @Excel(name = "调用目标字符串") | |
| 32 | - private String invokeTarget; | |
| 33 | - | |
| 34 | - /** 日志信息 */ | |
| 35 | - @Excel(name = "日志信息") | |
| 36 | - private String jobMessage; | |
| 37 | - | |
| 38 | - /** 执行状态(0正常 1失败) */ | |
| 39 | - @Excel(name = "执行状态", readConverterExp = "0=正常,1=失败") | |
| 40 | - private String status; | |
| 41 | - | |
| 42 | - /** 异常信息 */ | |
| 43 | - @Excel(name = "异常信息") | |
| 44 | - private String exceptionInfo; | |
| 45 | - | |
| 46 | - /** 开始时间 */ | |
| 47 | - private Date startTime; | |
| 48 | - | |
| 49 | - /** 停止时间 */ | |
| 50 | - private Date stopTime; | |
| 51 | - | |
| 52 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobLogMapper.java deleted
| 1 | -package com.ruoyi.quartz.mapper; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import com.ruoyi.quartz.domain.SysJobLog; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 调度任务日志信息 数据层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface SysJobLogMapper | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 获取quartz调度器日志的计划任务 | |
| 15 | - * | |
| 16 | - * @param jobLog 调度日志信息 | |
| 17 | - * @return 调度任务日志集合 | |
| 18 | - */ | |
| 19 | - public List<SysJobLog> selectJobLogList(SysJobLog jobLog); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 查询所有调度任务日志 | |
| 23 | - * | |
| 24 | - * @return 调度任务日志列表 | |
| 25 | - */ | |
| 26 | - public List<SysJobLog> selectJobLogAll(); | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 通过调度任务日志ID查询调度信息 | |
| 30 | - * | |
| 31 | - * @param jobLogId 调度任务日志ID | |
| 32 | - * @return 调度任务日志对象信息 | |
| 33 | - */ | |
| 34 | - public SysJobLog selectJobLogById(Long jobLogId); | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 新增任务日志 | |
| 38 | - * | |
| 39 | - * @param jobLog 调度日志信息 | |
| 40 | - * @return 结果 | |
| 41 | - */ | |
| 42 | - public int insertJobLog(SysJobLog jobLog); | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 批量删除调度日志信息 | |
| 46 | - * | |
| 47 | - * @param logIds 需要删除的数据ID | |
| 48 | - * @return 结果 | |
| 49 | - */ | |
| 50 | - public int deleteJobLogByIds(Long[] logIds); | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 删除任务日志 | |
| 54 | - * | |
| 55 | - * @param jobId 调度日志ID | |
| 56 | - * @return 结果 | |
| 57 | - */ | |
| 58 | - public int deleteJobLogById(Long jobId); | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * 清空任务日志 | |
| 62 | - */ | |
| 63 | - public void cleanJobLog(); | |
| 64 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper/SysJobMapper.java deleted
| 1 | -package com.ruoyi.quartz.mapper; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import com.ruoyi.quartz.domain.SysJob; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 调度任务信息 数据层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface SysJobMapper | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 查询调度任务日志集合 | |
| 15 | - * | |
| 16 | - * @param job 调度信息 | |
| 17 | - * @return 操作日志集合 | |
| 18 | - */ | |
| 19 | - public List<SysJob> selectJobList(SysJob job); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 查询所有调度任务 | |
| 23 | - * | |
| 24 | - * @return 调度任务列表 | |
| 25 | - */ | |
| 26 | - public List<SysJob> selectJobAll(); | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 通过调度ID查询调度任务信息 | |
| 30 | - * | |
| 31 | - * @param jobId 调度ID | |
| 32 | - * @return 角色对象信息 | |
| 33 | - */ | |
| 34 | - public SysJob selectJobById(Long jobId); | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 通过调度ID删除调度任务信息 | |
| 38 | - * | |
| 39 | - * @param jobId 调度ID | |
| 40 | - * @return 结果 | |
| 41 | - */ | |
| 42 | - public int deleteJobById(Long jobId); | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 批量删除调度任务信息 | |
| 46 | - * | |
| 47 | - * @param ids 需要删除的数据ID | |
| 48 | - * @return 结果 | |
| 49 | - */ | |
| 50 | - public int deleteJobByIds(Long[] ids); | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 修改调度任务信息 | |
| 54 | - * | |
| 55 | - * @param job 调度任务信息 | |
| 56 | - * @return 结果 | |
| 57 | - */ | |
| 58 | - public int updateJob(SysJob job); | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * 新增调度任务信息 | |
| 62 | - * | |
| 63 | - * @param job 调度任务信息 | |
| 64 | - * @return 结果 | |
| 65 | - */ | |
| 66 | - public int insertJob(SysJob job); | |
| 67 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobLogService.java deleted
| 1 | -package com.ruoyi.quartz.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import com.ruoyi.quartz.domain.SysJobLog; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 定时任务调度日志信息信息 服务层 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -public interface ISysJobLogService | |
| 12 | -{ | |
| 13 | - /** | |
| 14 | - * 获取quartz调度器日志的计划任务 | |
| 15 | - * | |
| 16 | - * @param jobLog 调度日志信息 | |
| 17 | - * @return 调度任务日志集合 | |
| 18 | - */ | |
| 19 | - public List<SysJobLog> selectJobLogList(SysJobLog jobLog); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 通过调度任务日志ID查询调度信息 | |
| 23 | - * | |
| 24 | - * @param jobLogId 调度任务日志ID | |
| 25 | - * @return 调度任务日志对象信息 | |
| 26 | - */ | |
| 27 | - public SysJobLog selectJobLogById(Long jobLogId); | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * 新增任务日志 | |
| 31 | - * | |
| 32 | - * @param jobLog 调度日志信息 | |
| 33 | - */ | |
| 34 | - public void addJobLog(SysJobLog jobLog); | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 批量删除调度日志信息 | |
| 38 | - * | |
| 39 | - * @param logIds 需要删除的日志ID | |
| 40 | - * @return 结果 | |
| 41 | - */ | |
| 42 | - public int deleteJobLogByIds(Long[] logIds); | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 删除任务日志 | |
| 46 | - * | |
| 47 | - * @param jobId 调度日志ID | |
| 48 | - * @return 结果 | |
| 49 | - */ | |
| 50 | - public int deleteJobLogById(Long jobId); | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 清空任务日志 | |
| 54 | - */ | |
| 55 | - public void cleanJobLog(); | |
| 56 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java deleted
| 1 | -package com.ruoyi.quartz.service; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import org.quartz.SchedulerException; | |
| 5 | -import com.ruoyi.common.exception.job.TaskException; | |
| 6 | -import com.ruoyi.quartz.domain.SysJob; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 定时任务调度信息信息 服务层 | |
| 10 | - * | |
| 11 | - * @author ruoyi | |
| 12 | - */ | |
| 13 | -public interface ISysJobService | |
| 14 | -{ | |
| 15 | - /** | |
| 16 | - * 获取quartz调度器的计划任务 | |
| 17 | - * | |
| 18 | - * @param job 调度信息 | |
| 19 | - * @return 调度任务集合 | |
| 20 | - */ | |
| 21 | - public List<SysJob> selectJobList(SysJob job); | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 通过调度任务ID查询调度信息 | |
| 25 | - * | |
| 26 | - * @param jobId 调度任务ID | |
| 27 | - * @return 调度任务对象信息 | |
| 28 | - */ | |
| 29 | - public SysJob selectJobById(Long jobId); | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 暂停任务 | |
| 33 | - * | |
| 34 | - * @param job 调度信息 | |
| 35 | - * @return 结果 | |
| 36 | - */ | |
| 37 | - public int pauseJob(SysJob job) throws SchedulerException; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * 恢复任务 | |
| 41 | - * | |
| 42 | - * @param job 调度信息 | |
| 43 | - * @return 结果 | |
| 44 | - */ | |
| 45 | - public int resumeJob(SysJob job) throws SchedulerException; | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * 删除任务后,所对应的trigger也将被删除 | |
| 49 | - * | |
| 50 | - * @param job 调度信息 | |
| 51 | - * @return 结果 | |
| 52 | - */ | |
| 53 | - public int deleteJob(SysJob job) throws SchedulerException; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * 批量删除调度信息 | |
| 57 | - * | |
| 58 | - * @param jobIds 需要删除的任务ID | |
| 59 | - * @return 结果 | |
| 60 | - */ | |
| 61 | - public void deleteJobByIds(Long[] jobIds) throws SchedulerException; | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 任务调度状态修改 | |
| 65 | - * | |
| 66 | - * @param job 调度信息 | |
| 67 | - * @return 结果 | |
| 68 | - */ | |
| 69 | - public int changeStatus(SysJob job) throws SchedulerException; | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * 立即运行任务 | |
| 73 | - * | |
| 74 | - * @param job 调度信息 | |
| 75 | - * @return 结果 | |
| 76 | - */ | |
| 77 | - public void run(SysJob job) throws SchedulerException; | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 新增任务 | |
| 81 | - * | |
| 82 | - * @param job 调度信息 | |
| 83 | - * @return 结果 | |
| 84 | - */ | |
| 85 | - public int insertJob(SysJob job) throws SchedulerException, TaskException; | |
| 86 | - | |
| 87 | - /** | |
| 88 | - * 更新任务 | |
| 89 | - * | |
| 90 | - * @param job 调度信息 | |
| 91 | - * @return 结果 | |
| 92 | - */ | |
| 93 | - public int updateJob(SysJob job) throws SchedulerException, TaskException; | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * 校验cron表达式是否有效 | |
| 97 | - * | |
| 98 | - * @param cronExpression 表达式 | |
| 99 | - * @return 结果 | |
| 100 | - */ | |
| 101 | - public boolean checkCronExpressionIsValid(String cronExpression); | |
| 102 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java deleted
| 1 | -package com.ruoyi.quartz.service.impl; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | -import org.springframework.stereotype.Service; | |
| 6 | -import com.ruoyi.quartz.domain.SysJobLog; | |
| 7 | -import com.ruoyi.quartz.mapper.SysJobLogMapper; | |
| 8 | -import com.ruoyi.quartz.service.ISysJobLogService; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * 定时任务调度日志信息 服务层 | |
| 12 | - * | |
| 13 | - * @author ruoyi | |
| 14 | - */ | |
| 15 | -@Service | |
| 16 | -public class SysJobLogServiceImpl implements ISysJobLogService | |
| 17 | -{ | |
| 18 | - @Autowired | |
| 19 | - private SysJobLogMapper jobLogMapper; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 获取quartz调度器日志的计划任务 | |
| 23 | - * | |
| 24 | - * @param jobLog 调度日志信息 | |
| 25 | - * @return 调度任务日志集合 | |
| 26 | - */ | |
| 27 | - @Override | |
| 28 | - public List<SysJobLog> selectJobLogList(SysJobLog jobLog) | |
| 29 | - { | |
| 30 | - return jobLogMapper.selectJobLogList(jobLog); | |
| 31 | - } | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * 通过调度任务日志ID查询调度信息 | |
| 35 | - * | |
| 36 | - * @param jobLogId 调度任务日志ID | |
| 37 | - * @return 调度任务日志对象信息 | |
| 38 | - */ | |
| 39 | - @Override | |
| 40 | - public SysJobLog selectJobLogById(Long jobLogId) | |
| 41 | - { | |
| 42 | - return jobLogMapper.selectJobLogById(jobLogId); | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 新增任务日志 | |
| 47 | - * | |
| 48 | - * @param jobLog 调度日志信息 | |
| 49 | - */ | |
| 50 | - @Override | |
| 51 | - public void addJobLog(SysJobLog jobLog) | |
| 52 | - { | |
| 53 | - jobLogMapper.insertJobLog(jobLog); | |
| 54 | - } | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * 批量删除调度日志信息 | |
| 58 | - * | |
| 59 | - * @param logIds 需要删除的数据ID | |
| 60 | - * @return 结果 | |
| 61 | - */ | |
| 62 | - @Override | |
| 63 | - public int deleteJobLogByIds(Long[] logIds) | |
| 64 | - { | |
| 65 | - return jobLogMapper.deleteJobLogByIds(logIds); | |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * 删除任务日志 | |
| 70 | - * | |
| 71 | - * @param jobId 调度日志ID | |
| 72 | - */ | |
| 73 | - @Override | |
| 74 | - public int deleteJobLogById(Long jobId) | |
| 75 | - { | |
| 76 | - return jobLogMapper.deleteJobLogById(jobId); | |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 清空任务日志 | |
| 81 | - */ | |
| 82 | - @Override | |
| 83 | - public void cleanJobLog() | |
| 84 | - { | |
| 85 | - jobLogMapper.cleanJobLog(); | |
| 86 | - } | |
| 87 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java deleted
| 1 | -package com.ruoyi.quartz.service.impl; | |
| 2 | - | |
| 3 | -import java.util.List; | |
| 4 | -import javax.annotation.PostConstruct; | |
| 5 | -import org.quartz.JobDataMap; | |
| 6 | -import org.quartz.JobKey; | |
| 7 | -import org.quartz.Scheduler; | |
| 8 | -import org.quartz.SchedulerException; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Service; | |
| 11 | -import org.springframework.transaction.annotation.Transactional; | |
| 12 | -import com.ruoyi.common.constant.ScheduleConstants; | |
| 13 | -import com.ruoyi.common.exception.job.TaskException; | |
| 14 | -import com.ruoyi.quartz.domain.SysJob; | |
| 15 | -import com.ruoyi.quartz.mapper.SysJobMapper; | |
| 16 | -import com.ruoyi.quartz.service.ISysJobService; | |
| 17 | -import com.ruoyi.quartz.util.CronUtils; | |
| 18 | -import com.ruoyi.quartz.util.ScheduleUtils; | |
| 19 | - | |
| 20 | -/** | |
| 21 | - * 定时任务调度信息 服务层 | |
| 22 | - * | |
| 23 | - * @author ruoyi | |
| 24 | - */ | |
| 25 | -@Service | |
| 26 | -public class SysJobServiceImpl implements ISysJobService | |
| 27 | -{ | |
| 28 | - @Autowired | |
| 29 | - private Scheduler scheduler; | |
| 30 | - | |
| 31 | - @Autowired | |
| 32 | - private SysJobMapper jobMapper; | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) | |
| 36 | - */ | |
| 37 | - @PostConstruct | |
| 38 | - public void init() throws SchedulerException, TaskException | |
| 39 | - { | |
| 40 | - scheduler.clear(); | |
| 41 | - List<SysJob> jobList = jobMapper.selectJobAll(); | |
| 42 | - for (SysJob job : jobList) | |
| 43 | - { | |
| 44 | - ScheduleUtils.createScheduleJob(scheduler, job); | |
| 45 | - } | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * 获取quartz调度器的计划任务列表 | |
| 50 | - * | |
| 51 | - * @param job 调度信息 | |
| 52 | - * @return | |
| 53 | - */ | |
| 54 | - @Override | |
| 55 | - public List<SysJob> selectJobList(SysJob job) | |
| 56 | - { | |
| 57 | - return jobMapper.selectJobList(job); | |
| 58 | - } | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * 通过调度任务ID查询调度信息 | |
| 62 | - * | |
| 63 | - * @param jobId 调度任务ID | |
| 64 | - * @return 调度任务对象信息 | |
| 65 | - */ | |
| 66 | - @Override | |
| 67 | - public SysJob selectJobById(Long jobId) | |
| 68 | - { | |
| 69 | - return jobMapper.selectJobById(jobId); | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * 暂停任务 | |
| 74 | - * | |
| 75 | - * @param job 调度信息 | |
| 76 | - */ | |
| 77 | - @Override | |
| 78 | - @Transactional | |
| 79 | - public int pauseJob(SysJob job) throws SchedulerException | |
| 80 | - { | |
| 81 | - Long jobId = job.getJobId(); | |
| 82 | - String jobGroup = job.getJobGroup(); | |
| 83 | - job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); | |
| 84 | - int rows = jobMapper.updateJob(job); | |
| 85 | - if (rows > 0) | |
| 86 | - { | |
| 87 | - scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | |
| 88 | - } | |
| 89 | - return rows; | |
| 90 | - } | |
| 91 | - | |
| 92 | - /** | |
| 93 | - * 恢复任务 | |
| 94 | - * | |
| 95 | - * @param job 调度信息 | |
| 96 | - */ | |
| 97 | - @Override | |
| 98 | - @Transactional | |
| 99 | - public int resumeJob(SysJob job) throws SchedulerException | |
| 100 | - { | |
| 101 | - Long jobId = job.getJobId(); | |
| 102 | - String jobGroup = job.getJobGroup(); | |
| 103 | - job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); | |
| 104 | - int rows = jobMapper.updateJob(job); | |
| 105 | - if (rows > 0) | |
| 106 | - { | |
| 107 | - scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | |
| 108 | - } | |
| 109 | - return rows; | |
| 110 | - } | |
| 111 | - | |
| 112 | - /** | |
| 113 | - * 删除任务后,所对应的trigger也将被删除 | |
| 114 | - * | |
| 115 | - * @param job 调度信息 | |
| 116 | - */ | |
| 117 | - @Override | |
| 118 | - @Transactional | |
| 119 | - public int deleteJob(SysJob job) throws SchedulerException | |
| 120 | - { | |
| 121 | - Long jobId = job.getJobId(); | |
| 122 | - String jobGroup = job.getJobGroup(); | |
| 123 | - int rows = jobMapper.deleteJobById(jobId); | |
| 124 | - if (rows > 0) | |
| 125 | - { | |
| 126 | - scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | |
| 127 | - } | |
| 128 | - return rows; | |
| 129 | - } | |
| 130 | - | |
| 131 | - /** | |
| 132 | - * 批量删除调度信息 | |
| 133 | - * | |
| 134 | - * @param jobIds 需要删除的任务ID | |
| 135 | - * @return 结果 | |
| 136 | - */ | |
| 137 | - @Override | |
| 138 | - @Transactional | |
| 139 | - public void deleteJobByIds(Long[] jobIds) throws SchedulerException | |
| 140 | - { | |
| 141 | - for (Long jobId : jobIds) | |
| 142 | - { | |
| 143 | - SysJob job = jobMapper.selectJobById(jobId); | |
| 144 | - deleteJob(job); | |
| 145 | - } | |
| 146 | - } | |
| 147 | - | |
| 148 | - /** | |
| 149 | - * 任务调度状态修改 | |
| 150 | - * | |
| 151 | - * @param job 调度信息 | |
| 152 | - */ | |
| 153 | - @Override | |
| 154 | - @Transactional | |
| 155 | - public int changeStatus(SysJob job) throws SchedulerException | |
| 156 | - { | |
| 157 | - int rows = 0; | |
| 158 | - String status = job.getStatus(); | |
| 159 | - if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) | |
| 160 | - { | |
| 161 | - rows = resumeJob(job); | |
| 162 | - } | |
| 163 | - else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) | |
| 164 | - { | |
| 165 | - rows = pauseJob(job); | |
| 166 | - } | |
| 167 | - return rows; | |
| 168 | - } | |
| 169 | - | |
| 170 | - /** | |
| 171 | - * 立即运行任务 | |
| 172 | - * | |
| 173 | - * @param job 调度信息 | |
| 174 | - */ | |
| 175 | - @Override | |
| 176 | - @Transactional | |
| 177 | - public void run(SysJob job) throws SchedulerException | |
| 178 | - { | |
| 179 | - Long jobId = job.getJobId(); | |
| 180 | - String jobGroup = job.getJobGroup(); | |
| 181 | - SysJob properties = selectJobById(job.getJobId()); | |
| 182 | - // 参数 | |
| 183 | - JobDataMap dataMap = new JobDataMap(); | |
| 184 | - dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); | |
| 185 | - scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap); | |
| 186 | - } | |
| 187 | - | |
| 188 | - /** | |
| 189 | - * 新增任务 | |
| 190 | - * | |
| 191 | - * @param job 调度信息 调度信息 | |
| 192 | - */ | |
| 193 | - @Override | |
| 194 | - @Transactional | |
| 195 | - public int insertJob(SysJob job) throws SchedulerException, TaskException | |
| 196 | - { | |
| 197 | - job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); | |
| 198 | - int rows = jobMapper.insertJob(job); | |
| 199 | - if (rows > 0) | |
| 200 | - { | |
| 201 | - ScheduleUtils.createScheduleJob(scheduler, job); | |
| 202 | - } | |
| 203 | - return rows; | |
| 204 | - } | |
| 205 | - | |
| 206 | - /** | |
| 207 | - * 更新任务的时间表达式 | |
| 208 | - * | |
| 209 | - * @param job 调度信息 | |
| 210 | - */ | |
| 211 | - @Override | |
| 212 | - @Transactional | |
| 213 | - public int updateJob(SysJob job) throws SchedulerException, TaskException | |
| 214 | - { | |
| 215 | - SysJob properties = selectJobById(job.getJobId()); | |
| 216 | - int rows = jobMapper.updateJob(job); | |
| 217 | - if (rows > 0) | |
| 218 | - { | |
| 219 | - updateSchedulerJob(job, properties.getJobGroup()); | |
| 220 | - } | |
| 221 | - return rows; | |
| 222 | - } | |
| 223 | - | |
| 224 | - /** | |
| 225 | - * 更新任务 | |
| 226 | - * | |
| 227 | - * @param job 任务对象 | |
| 228 | - * @param jobGroup 任务组名 | |
| 229 | - */ | |
| 230 | - public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException | |
| 231 | - { | |
| 232 | - Long jobId = job.getJobId(); | |
| 233 | - // 判断是否存在 | |
| 234 | - JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); | |
| 235 | - if (scheduler.checkExists(jobKey)) | |
| 236 | - { | |
| 237 | - // 防止创建时存在数据问题 先移除,然后在执行创建操作 | |
| 238 | - scheduler.deleteJob(jobKey); | |
| 239 | - } | |
| 240 | - ScheduleUtils.createScheduleJob(scheduler, job); | |
| 241 | - } | |
| 242 | - | |
| 243 | - /** | |
| 244 | - * 校验cron表达式是否有效 | |
| 245 | - * | |
| 246 | - * @param cronExpression 表达式 | |
| 247 | - * @return 结果 | |
| 248 | - */ | |
| 249 | - @Override | |
| 250 | - public boolean checkCronExpressionIsValid(String cronExpression) | |
| 251 | - { | |
| 252 | - return CronUtils.isValid(cronExpression); | |
| 253 | - } | |
| 254 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java deleted
| 1 | -package com.ruoyi.quartz.task; | |
| 2 | - | |
| 3 | -import org.springframework.stereotype.Component; | |
| 4 | -import com.ruoyi.common.utils.StringUtils; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 定时任务调度测试 | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - */ | |
| 11 | -@Component("ryTask") | |
| 12 | -public class RyTask | |
| 13 | -{ | |
| 14 | - public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) | |
| 15 | - { | |
| 16 | - System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); | |
| 17 | - } | |
| 18 | - | |
| 19 | - public void ryParams(String params) | |
| 20 | - { | |
| 21 | - System.out.println("执行有参方法:" + params); | |
| 22 | - } | |
| 23 | - | |
| 24 | - public void ryNoParams() | |
| 25 | - { | |
| 26 | - System.out.println("执行无参方法"); | |
| 27 | - } | |
| 28 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import java.util.Date; | |
| 4 | -import org.quartz.Job; | |
| 5 | -import org.quartz.JobExecutionContext; | |
| 6 | -import org.quartz.JobExecutionException; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import com.ruoyi.common.constant.Constants; | |
| 10 | -import com.ruoyi.common.constant.ScheduleConstants; | |
| 11 | -import com.ruoyi.common.utils.ExceptionUtil; | |
| 12 | -import com.ruoyi.common.utils.StringUtils; | |
| 13 | -import com.ruoyi.common.utils.bean.BeanUtils; | |
| 14 | -import com.ruoyi.common.utils.spring.SpringUtils; | |
| 15 | -import com.ruoyi.quartz.domain.SysJob; | |
| 16 | -import com.ruoyi.quartz.domain.SysJobLog; | |
| 17 | -import com.ruoyi.quartz.service.ISysJobLogService; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * 抽象quartz调用 | |
| 21 | - * | |
| 22 | - * @author ruoyi | |
| 23 | - */ | |
| 24 | -public abstract class AbstractQuartzJob implements Job | |
| 25 | -{ | |
| 26 | - private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 线程本地变量 | |
| 30 | - */ | |
| 31 | - private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); | |
| 32 | - | |
| 33 | - @Override | |
| 34 | - public void execute(JobExecutionContext context) throws JobExecutionException | |
| 35 | - { | |
| 36 | - SysJob sysJob = new SysJob(); | |
| 37 | - BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); | |
| 38 | - try | |
| 39 | - { | |
| 40 | - before(context, sysJob); | |
| 41 | - if (sysJob != null) | |
| 42 | - { | |
| 43 | - doExecute(context, sysJob); | |
| 44 | - } | |
| 45 | - after(context, sysJob, null); | |
| 46 | - } | |
| 47 | - catch (Exception e) | |
| 48 | - { | |
| 49 | - log.error("任务执行异常 - :", e); | |
| 50 | - after(context, sysJob, e); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 执行前 | |
| 56 | - * | |
| 57 | - * @param context 工作执行上下文对象 | |
| 58 | - * @param sysJob 系统计划任务 | |
| 59 | - */ | |
| 60 | - protected void before(JobExecutionContext context, SysJob sysJob) | |
| 61 | - { | |
| 62 | - threadLocal.set(new Date()); | |
| 63 | - } | |
| 64 | - | |
| 65 | - /** | |
| 66 | - * 执行后 | |
| 67 | - * | |
| 68 | - * @param context 工作执行上下文对象 | |
| 69 | - * @param sysJob 系统计划任务 | |
| 70 | - */ | |
| 71 | - protected void after(JobExecutionContext context, SysJob sysJob, Exception e) | |
| 72 | - { | |
| 73 | - Date startTime = threadLocal.get(); | |
| 74 | - threadLocal.remove(); | |
| 75 | - | |
| 76 | - final SysJobLog sysJobLog = new SysJobLog(); | |
| 77 | - sysJobLog.setJobName(sysJob.getJobName()); | |
| 78 | - sysJobLog.setJobGroup(sysJob.getJobGroup()); | |
| 79 | - sysJobLog.setInvokeTarget(sysJob.getInvokeTarget()); | |
| 80 | - sysJobLog.setStartTime(startTime); | |
| 81 | - sysJobLog.setStopTime(new Date()); | |
| 82 | - long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); | |
| 83 | - sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); | |
| 84 | - if (e != null) | |
| 85 | - { | |
| 86 | - sysJobLog.setStatus(Constants.FAIL); | |
| 87 | - String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); | |
| 88 | - sysJobLog.setExceptionInfo(errorMsg); | |
| 89 | - } | |
| 90 | - else | |
| 91 | - { | |
| 92 | - sysJobLog.setStatus(Constants.SUCCESS); | |
| 93 | - } | |
| 94 | - | |
| 95 | - // 写入数据库当中 | |
| 96 | - SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); | |
| 97 | - } | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * 执行方法,由子类重载 | |
| 101 | - * | |
| 102 | - * @param context 工作执行上下文对象 | |
| 103 | - * @param sysJob 系统计划任务 | |
| 104 | - * @throws Exception 执行过程中的异常 | |
| 105 | - */ | |
| 106 | - protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; | |
| 107 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import java.text.ParseException; | |
| 4 | -import java.util.Date; | |
| 5 | -import org.quartz.CronExpression; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * cron表达式工具类 | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - * | |
| 12 | - */ | |
| 13 | -public class CronUtils | |
| 14 | -{ | |
| 15 | - /** | |
| 16 | - * 返回一个布尔值代表一个给定的Cron表达式的有效性 | |
| 17 | - * | |
| 18 | - * @param cronExpression Cron表达式 | |
| 19 | - * @return boolean 表达式是否有效 | |
| 20 | - */ | |
| 21 | - public static boolean isValid(String cronExpression) | |
| 22 | - { | |
| 23 | - return CronExpression.isValidExpression(cronExpression); | |
| 24 | - } | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 返回一个字符串值,表示该消息无效Cron表达式给出有效性 | |
| 28 | - * | |
| 29 | - * @param cronExpression Cron表达式 | |
| 30 | - * @return String 无效时返回表达式错误描述,如果有效返回null | |
| 31 | - */ | |
| 32 | - public static String getInvalidMessage(String cronExpression) | |
| 33 | - { | |
| 34 | - try | |
| 35 | - { | |
| 36 | - new CronExpression(cronExpression); | |
| 37 | - return null; | |
| 38 | - } | |
| 39 | - catch (ParseException pe) | |
| 40 | - { | |
| 41 | - return pe.getMessage(); | |
| 42 | - } | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 返回下一个执行时间根据给定的Cron表达式 | |
| 47 | - * | |
| 48 | - * @param cronExpression Cron表达式 | |
| 49 | - * @return Date 下次Cron表达式执行时间 | |
| 50 | - */ | |
| 51 | - public static Date getNextExecution(String cronExpression) | |
| 52 | - { | |
| 53 | - try | |
| 54 | - { | |
| 55 | - CronExpression cron = new CronExpression(cronExpression); | |
| 56 | - return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); | |
| 57 | - } | |
| 58 | - catch (ParseException e) | |
| 59 | - { | |
| 60 | - throw new IllegalArgumentException(e.getMessage()); | |
| 61 | - } | |
| 62 | - } | |
| 63 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/JobInvokeUtil.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import java.lang.reflect.InvocationTargetException; | |
| 4 | -import java.lang.reflect.Method; | |
| 5 | -import java.util.LinkedList; | |
| 6 | -import java.util.List; | |
| 7 | -import com.ruoyi.common.utils.StringUtils; | |
| 8 | -import com.ruoyi.common.utils.spring.SpringUtils; | |
| 9 | -import com.ruoyi.quartz.domain.SysJob; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 任务执行工具 | |
| 13 | - * | |
| 14 | - * @author ruoyi | |
| 15 | - */ | |
| 16 | -public class JobInvokeUtil | |
| 17 | -{ | |
| 18 | - /** | |
| 19 | - * 执行方法 | |
| 20 | - * | |
| 21 | - * @param sysJob 系统任务 | |
| 22 | - */ | |
| 23 | - public static void invokeMethod(SysJob sysJob) throws Exception | |
| 24 | - { | |
| 25 | - String invokeTarget = sysJob.getInvokeTarget(); | |
| 26 | - String beanName = getBeanName(invokeTarget); | |
| 27 | - String methodName = getMethodName(invokeTarget); | |
| 28 | - List<Object[]> methodParams = getMethodParams(invokeTarget); | |
| 29 | - | |
| 30 | - if (!isValidClassName(beanName)) | |
| 31 | - { | |
| 32 | - Object bean = SpringUtils.getBean(beanName); | |
| 33 | - invokeMethod(bean, methodName, methodParams); | |
| 34 | - } | |
| 35 | - else | |
| 36 | - { | |
| 37 | - Object bean = Class.forName(beanName).newInstance(); | |
| 38 | - invokeMethod(bean, methodName, methodParams); | |
| 39 | - } | |
| 40 | - } | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * 调用任务方法 | |
| 44 | - * | |
| 45 | - * @param bean 目标对象 | |
| 46 | - * @param methodName 方法名称 | |
| 47 | - * @param methodParams 方法参数 | |
| 48 | - */ | |
| 49 | - private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) | |
| 50 | - throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, | |
| 51 | - InvocationTargetException | |
| 52 | - { | |
| 53 | - if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) | |
| 54 | - { | |
| 55 | - Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); | |
| 56 | - method.invoke(bean, getMethodParamsValue(methodParams)); | |
| 57 | - } | |
| 58 | - else | |
| 59 | - { | |
| 60 | - Method method = bean.getClass().getDeclaredMethod(methodName); | |
| 61 | - method.invoke(bean); | |
| 62 | - } | |
| 63 | - } | |
| 64 | - | |
| 65 | - /** | |
| 66 | - * 校验是否为为class包名 | |
| 67 | - * | |
| 68 | - * @param str 名称 | |
| 69 | - * @return true是 false否 | |
| 70 | - */ | |
| 71 | - public static boolean isValidClassName(String invokeTarget) | |
| 72 | - { | |
| 73 | - return StringUtils.countMatches(invokeTarget, ".") > 1; | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * 获取bean名称 | |
| 78 | - * | |
| 79 | - * @param invokeTarget 目标字符串 | |
| 80 | - * @return bean名称 | |
| 81 | - */ | |
| 82 | - public static String getBeanName(String invokeTarget) | |
| 83 | - { | |
| 84 | - String beanName = StringUtils.substringBefore(invokeTarget, "("); | |
| 85 | - return StringUtils.substringBeforeLast(beanName, "."); | |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * 获取bean方法 | |
| 90 | - * | |
| 91 | - * @param invokeTarget 目标字符串 | |
| 92 | - * @return method方法 | |
| 93 | - */ | |
| 94 | - public static String getMethodName(String invokeTarget) | |
| 95 | - { | |
| 96 | - String methodName = StringUtils.substringBefore(invokeTarget, "("); | |
| 97 | - return StringUtils.substringAfterLast(methodName, "."); | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * 获取method方法参数相关列表 | |
| 102 | - * | |
| 103 | - * @param invokeTarget 目标字符串 | |
| 104 | - * @return method方法相关参数列表 | |
| 105 | - */ | |
| 106 | - public static List<Object[]> getMethodParams(String invokeTarget) | |
| 107 | - { | |
| 108 | - String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); | |
| 109 | - if (StringUtils.isEmpty(methodStr)) | |
| 110 | - { | |
| 111 | - return null; | |
| 112 | - } | |
| 113 | - String[] methodParams = methodStr.split(","); | |
| 114 | - List<Object[]> classs = new LinkedList<>(); | |
| 115 | - for (int i = 0; i < methodParams.length; i++) | |
| 116 | - { | |
| 117 | - String str = StringUtils.trimToEmpty(methodParams[i]); | |
| 118 | - // String字符串类型,包含' | |
| 119 | - if (StringUtils.contains(str, "'")) | |
| 120 | - { | |
| 121 | - classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class }); | |
| 122 | - } | |
| 123 | - // boolean布尔类型,等于true或者false | |
| 124 | - else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false")) | |
| 125 | - { | |
| 126 | - classs.add(new Object[] { Boolean.valueOf(str), Boolean.class }); | |
| 127 | - } | |
| 128 | - // long长整形,包含L | |
| 129 | - else if (StringUtils.containsIgnoreCase(str, "L")) | |
| 130 | - { | |
| 131 | - classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class }); | |
| 132 | - } | |
| 133 | - // double浮点类型,包含D | |
| 134 | - else if (StringUtils.containsIgnoreCase(str, "D")) | |
| 135 | - { | |
| 136 | - classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class }); | |
| 137 | - } | |
| 138 | - // 其他类型归类为整形 | |
| 139 | - else | |
| 140 | - { | |
| 141 | - classs.add(new Object[] { Integer.valueOf(str), Integer.class }); | |
| 142 | - } | |
| 143 | - } | |
| 144 | - return classs; | |
| 145 | - } | |
| 146 | - | |
| 147 | - /** | |
| 148 | - * 获取参数类型 | |
| 149 | - * | |
| 150 | - * @param methodParams 参数相关列表 | |
| 151 | - * @return 参数类型列表 | |
| 152 | - */ | |
| 153 | - public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) | |
| 154 | - { | |
| 155 | - Class<?>[] classs = new Class<?>[methodParams.size()]; | |
| 156 | - int index = 0; | |
| 157 | - for (Object[] os : methodParams) | |
| 158 | - { | |
| 159 | - classs[index] = (Class<?>) os[1]; | |
| 160 | - index++; | |
| 161 | - } | |
| 162 | - return classs; | |
| 163 | - } | |
| 164 | - | |
| 165 | - /** | |
| 166 | - * 获取参数值 | |
| 167 | - * | |
| 168 | - * @param methodParams 参数相关列表 | |
| 169 | - * @return 参数值列表 | |
| 170 | - */ | |
| 171 | - public static Object[] getMethodParamsValue(List<Object[]> methodParams) | |
| 172 | - { | |
| 173 | - Object[] classs = new Object[methodParams.size()]; | |
| 174 | - int index = 0; | |
| 175 | - for (Object[] os : methodParams) | |
| 176 | - { | |
| 177 | - classs[index] = (Object) os[0]; | |
| 178 | - index++; | |
| 179 | - } | |
| 180 | - return classs; | |
| 181 | - } | |
| 182 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/QuartzDisallowConcurrentExecution.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import org.quartz.DisallowConcurrentExecution; | |
| 4 | -import org.quartz.JobExecutionContext; | |
| 5 | -import com.ruoyi.quartz.domain.SysJob; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 定时任务处理(禁止并发执行) | |
| 9 | - * | |
| 10 | - * @author ruoyi | |
| 11 | - * | |
| 12 | - */ | |
| 13 | -@DisallowConcurrentExecution | |
| 14 | -public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob | |
| 15 | -{ | |
| 16 | - @Override | |
| 17 | - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception | |
| 18 | - { | |
| 19 | - JobInvokeUtil.invokeMethod(sysJob); | |
| 20 | - } | |
| 21 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/QuartzJobExecution.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import org.quartz.JobExecutionContext; | |
| 4 | -import com.ruoyi.quartz.domain.SysJob; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 定时任务处理(允许并发执行) | |
| 8 | - * | |
| 9 | - * @author ruoyi | |
| 10 | - * | |
| 11 | - */ | |
| 12 | -public class QuartzJobExecution extends AbstractQuartzJob | |
| 13 | -{ | |
| 14 | - @Override | |
| 15 | - protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception | |
| 16 | - { | |
| 17 | - JobInvokeUtil.invokeMethod(sysJob); | |
| 18 | - } | |
| 19 | -} |
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/ScheduleUtils.java deleted
| 1 | -package com.ruoyi.quartz.util; | |
| 2 | - | |
| 3 | -import org.quartz.CronScheduleBuilder; | |
| 4 | -import org.quartz.CronTrigger; | |
| 5 | -import org.quartz.Job; | |
| 6 | -import org.quartz.JobBuilder; | |
| 7 | -import org.quartz.JobDetail; | |
| 8 | -import org.quartz.JobKey; | |
| 9 | -import org.quartz.Scheduler; | |
| 10 | -import org.quartz.SchedulerException; | |
| 11 | -import org.quartz.TriggerBuilder; | |
| 12 | -import org.quartz.TriggerKey; | |
| 13 | -import com.ruoyi.common.constant.ScheduleConstants; | |
| 14 | -import com.ruoyi.common.exception.job.TaskException; | |
| 15 | -import com.ruoyi.common.exception.job.TaskException.Code; | |
| 16 | -import com.ruoyi.quartz.domain.SysJob; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * 定时任务工具类 | |
| 20 | - * | |
| 21 | - * @author ruoyi | |
| 22 | - * | |
| 23 | - */ | |
| 24 | -public class ScheduleUtils | |
| 25 | -{ | |
| 26 | - /** | |
| 27 | - * 得到quartz任务类 | |
| 28 | - * | |
| 29 | - * @param sysJob 执行计划 | |
| 30 | - * @return 具体执行任务类 | |
| 31 | - */ | |
| 32 | - private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) | |
| 33 | - { | |
| 34 | - boolean isConcurrent = "0".equals(sysJob.getConcurrent()); | |
| 35 | - return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 构建任务触发对象 | |
| 40 | - */ | |
| 41 | - public static TriggerKey getTriggerKey(Long jobId, String jobGroup) | |
| 42 | - { | |
| 43 | - return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); | |
| 44 | - } | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 构建任务键对象 | |
| 48 | - */ | |
| 49 | - public static JobKey getJobKey(Long jobId, String jobGroup) | |
| 50 | - { | |
| 51 | - return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 创建定时任务 | |
| 56 | - */ | |
| 57 | - public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException | |
| 58 | - { | |
| 59 | - Class<? extends Job> jobClass = getQuartzJobClass(job); | |
| 60 | - // 构建job信息 | |
| 61 | - Long jobId = job.getJobId(); | |
| 62 | - String jobGroup = job.getJobGroup(); | |
| 63 | - JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); | |
| 64 | - | |
| 65 | - // 表达式调度构建器 | |
| 66 | - CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); | |
| 67 | - cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); | |
| 68 | - | |
| 69 | - // 按新的cronExpression表达式构建一个新的trigger | |
| 70 | - CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) | |
| 71 | - .withSchedule(cronScheduleBuilder).build(); | |
| 72 | - | |
| 73 | - // 放入参数,运行时的方法可以获取 | |
| 74 | - jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); | |
| 75 | - | |
| 76 | - // 判断是否存在 | |
| 77 | - if (scheduler.checkExists(getJobKey(jobId, jobGroup))) | |
| 78 | - { | |
| 79 | - // 防止创建时存在数据问题 先移除,然后在执行创建操作 | |
| 80 | - scheduler.deleteJob(getJobKey(jobId, jobGroup)); | |
| 81 | - } | |
| 82 | - | |
| 83 | - scheduler.scheduleJob(jobDetail, trigger); | |
| 84 | - | |
| 85 | - // 暂停任务 | |
| 86 | - if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) | |
| 87 | - { | |
| 88 | - scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | |
| 89 | - } | |
| 90 | - } | |
| 91 | - | |
| 92 | - /** | |
| 93 | - * 设置定时任务策略 | |
| 94 | - */ | |
| 95 | - public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) | |
| 96 | - throws TaskException | |
| 97 | - { | |
| 98 | - switch (job.getMisfirePolicy()) | |
| 99 | - { | |
| 100 | - case ScheduleConstants.MISFIRE_DEFAULT: | |
| 101 | - return cb; | |
| 102 | - case ScheduleConstants.MISFIRE_IGNORE_MISFIRES: | |
| 103 | - return cb.withMisfireHandlingInstructionIgnoreMisfires(); | |
| 104 | - case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED: | |
| 105 | - return cb.withMisfireHandlingInstructionFireAndProceed(); | |
| 106 | - case ScheduleConstants.MISFIRE_DO_NOTHING: | |
| 107 | - return cb.withMisfireHandlingInstructionDoNothing(); | |
| 108 | - default: | |
| 109 | - throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() | |
| 110 | - + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR); | |
| 111 | - } | |
| 112 | - } | |
| 113 | -} |
ruoyi-quartz/src/main/resources/mapper/quartz/SysJobLogMapper.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8" ?> | |
| 2 | -<!DOCTYPE mapper | |
| 3 | -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
| 4 | -"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 5 | -<mapper namespace="com.ruoyi.quartz.mapper.SysJobLogMapper"> | |
| 6 | - | |
| 7 | - <resultMap type="SysJobLog" id="SysJobLogResult"> | |
| 8 | - <id property="jobLogId" column="job_log_id" /> | |
| 9 | - <result property="jobName" column="job_name" /> | |
| 10 | - <result property="jobGroup" column="job_group" /> | |
| 11 | - <result property="invokeTarget" column="invoke_target" /> | |
| 12 | - <result property="jobMessage" column="job_message" /> | |
| 13 | - <result property="status" column="status" /> | |
| 14 | - <result property="exceptionInfo" column="exception_info" /> | |
| 15 | - <result property="createTime" column="create_time" /> | |
| 16 | - </resultMap> | |
| 17 | - | |
| 18 | - <sql id="selectJobLogVo"> | |
| 19 | - select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time | |
| 20 | - from sys_job_log | |
| 21 | - </sql> | |
| 22 | - | |
| 23 | - <select id="selectJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult"> | |
| 24 | - <include refid="selectJobLogVo"/> | |
| 25 | - <where> | |
| 26 | - <if test="jobName != null and jobName != ''"> | |
| 27 | - AND job_name like concat('%', #{jobName}, '%') | |
| 28 | - </if> | |
| 29 | - <if test="jobGroup != null and jobGroup != ''"> | |
| 30 | - AND job_group = #{jobGroup} | |
| 31 | - </if> | |
| 32 | - <if test="status != null and status != ''"> | |
| 33 | - AND status = #{status} | |
| 34 | - </if> | |
| 35 | - <if test="invokeTarget != null and invokeTarget != ''"> | |
| 36 | - AND invoke_target like concat('%', #{invokeTarget}, '%') | |
| 37 | - </if> | |
| 38 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | |
| 39 | - and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | |
| 40 | - </if> | |
| 41 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | |
| 42 | - and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | |
| 43 | - </if> | |
| 44 | - </where> | |
| 45 | - </select> | |
| 46 | - | |
| 47 | - <select id="selectJobLogAll" resultMap="SysJobLogResult"> | |
| 48 | - <include refid="selectJobLogVo"/> | |
| 49 | - </select> | |
| 50 | - | |
| 51 | - <select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult"> | |
| 52 | - <include refid="selectJobLogVo"/> | |
| 53 | - where job_log_id = #{jobLogId} | |
| 54 | - </select> | |
| 55 | - | |
| 56 | - <delete id="deleteJobLogById" parameterType="Long"> | |
| 57 | - delete from sys_job_log where job_log_id = #{jobLogId} | |
| 58 | - </delete> | |
| 59 | - | |
| 60 | - <delete id="deleteJobLogByIds" parameterType="Long"> | |
| 61 | - delete from sys_job_log where job_log_id in | |
| 62 | - <foreach collection="array" item="jobLogId" open="(" separator="," close=")"> | |
| 63 | - #{jobLogId} | |
| 64 | - </foreach> | |
| 65 | - </delete> | |
| 66 | - | |
| 67 | - <update id="cleanJobLog"> | |
| 68 | - truncate table sys_job_log | |
| 69 | - </update> | |
| 70 | - | |
| 71 | - <insert id="insertJobLog" parameterType="SysJobLog"> | |
| 72 | - insert into sys_job_log( | |
| 73 | - <if test="jobLogId != null and jobLogId != 0">job_log_id,</if> | |
| 74 | - <if test="jobName != null and jobName != ''">job_name,</if> | |
| 75 | - <if test="jobGroup != null and jobGroup != ''">job_group,</if> | |
| 76 | - <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if> | |
| 77 | - <if test="jobMessage != null and jobMessage != ''">job_message,</if> | |
| 78 | - <if test="status != null and status != ''">status,</if> | |
| 79 | - <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if> | |
| 80 | - create_time | |
| 81 | - )values( | |
| 82 | - <if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if> | |
| 83 | - <if test="jobName != null and jobName != ''">#{jobName},</if> | |
| 84 | - <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if> | |
| 85 | - <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if> | |
| 86 | - <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if> | |
| 87 | - <if test="status != null and status != ''">#{status},</if> | |
| 88 | - <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if> | |
| 89 | - sysdate() | |
| 90 | - ) | |
| 91 | - </insert> | |
| 92 | - | |
| 93 | -</mapper> | |
| 94 | 0 | \ No newline at end of file |
ruoyi-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8" ?> | |
| 2 | -<!DOCTYPE mapper | |
| 3 | -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
| 4 | -"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 5 | -<mapper namespace="com.ruoyi.quartz.mapper.SysJobMapper"> | |
| 6 | - | |
| 7 | - <resultMap type="SysJob" id="SysJobResult"> | |
| 8 | - <id property="jobId" column="job_id" /> | |
| 9 | - <result property="jobName" column="job_name" /> | |
| 10 | - <result property="jobGroup" column="job_group" /> | |
| 11 | - <result property="invokeTarget" column="invoke_target" /> | |
| 12 | - <result property="cronExpression" column="cron_expression" /> | |
| 13 | - <result property="misfirePolicy" column="misfire_policy" /> | |
| 14 | - <result property="concurrent" column="concurrent" /> | |
| 15 | - <result property="status" column="status" /> | |
| 16 | - <result property="createBy" column="create_by" /> | |
| 17 | - <result property="createTime" column="create_time" /> | |
| 18 | - <result property="updateBy" column="update_by" /> | |
| 19 | - <result property="updateTime" column="update_time" /> | |
| 20 | - <result property="remark" column="remark" /> | |
| 21 | - </resultMap> | |
| 22 | - | |
| 23 | - <sql id="selectJobVo"> | |
| 24 | - select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark | |
| 25 | - from sys_job | |
| 26 | - </sql> | |
| 27 | - | |
| 28 | - <select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult"> | |
| 29 | - <include refid="selectJobVo"/> | |
| 30 | - <where> | |
| 31 | - <if test="jobName != null and jobName != ''"> | |
| 32 | - AND job_name like concat('%', #{jobName}, '%') | |
| 33 | - </if> | |
| 34 | - <if test="jobGroup != null and jobGroup != ''"> | |
| 35 | - AND job_group = #{jobGroup} | |
| 36 | - </if> | |
| 37 | - <if test="status != null and status != ''"> | |
| 38 | - AND status = #{status} | |
| 39 | - </if> | |
| 40 | - <if test="invokeTarget != null and invokeTarget != ''"> | |
| 41 | - AND invoke_target like concat('%', #{invokeTarget}, '%') | |
| 42 | - </if> | |
| 43 | - </where> | |
| 44 | - </select> | |
| 45 | - | |
| 46 | - <select id="selectJobAll" resultMap="SysJobResult"> | |
| 47 | - <include refid="selectJobVo"/> | |
| 48 | - </select> | |
| 49 | - | |
| 50 | - <select id="selectJobById" parameterType="Long" resultMap="SysJobResult"> | |
| 51 | - <include refid="selectJobVo"/> | |
| 52 | - where job_id = #{jobId} | |
| 53 | - </select> | |
| 54 | - | |
| 55 | - <delete id="deleteJobById" parameterType="Long"> | |
| 56 | - delete from sys_job where job_id = #{jobId} | |
| 57 | - </delete> | |
| 58 | - | |
| 59 | - <delete id="deleteJobByIds" parameterType="Long"> | |
| 60 | - delete from sys_job where job_id in | |
| 61 | - <foreach collection="array" item="jobId" open="(" separator="," close=")"> | |
| 62 | - #{jobId} | |
| 63 | - </foreach> | |
| 64 | - </delete> | |
| 65 | - | |
| 66 | - <update id="updateJob" parameterType="SysJob"> | |
| 67 | - update sys_job | |
| 68 | - <set> | |
| 69 | - <if test="jobName != null and jobName != ''">job_name = #{jobName},</if> | |
| 70 | - <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if> | |
| 71 | - <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if> | |
| 72 | - <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if> | |
| 73 | - <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if> | |
| 74 | - <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if> | |
| 75 | - <if test="status !=null">status = #{status},</if> | |
| 76 | - <if test="remark != null and remark != ''">remark = #{remark},</if> | |
| 77 | - <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | |
| 78 | - update_time = sysdate() | |
| 79 | - </set> | |
| 80 | - where job_id = #{jobId} | |
| 81 | - </update> | |
| 82 | - | |
| 83 | - <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId"> | |
| 84 | - insert into sys_job( | |
| 85 | - <if test="jobId != null and jobId != 0">job_id,</if> | |
| 86 | - <if test="jobName != null and jobName != ''">job_name,</if> | |
| 87 | - <if test="jobGroup != null and jobGroup != ''">job_group,</if> | |
| 88 | - <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if> | |
| 89 | - <if test="cronExpression != null and cronExpression != ''">cron_expression,</if> | |
| 90 | - <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if> | |
| 91 | - <if test="concurrent != null and concurrent != ''">concurrent,</if> | |
| 92 | - <if test="status != null and status != ''">status,</if> | |
| 93 | - <if test="remark != null and remark != ''">remark,</if> | |
| 94 | - <if test="createBy != null and createBy != ''">create_by,</if> | |
| 95 | - create_time | |
| 96 | - )values( | |
| 97 | - <if test="jobId != null and jobId != 0">#{jobId},</if> | |
| 98 | - <if test="jobName != null and jobName != ''">#{jobName},</if> | |
| 99 | - <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if> | |
| 100 | - <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if> | |
| 101 | - <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if> | |
| 102 | - <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if> | |
| 103 | - <if test="concurrent != null and concurrent != ''">#{concurrent},</if> | |
| 104 | - <if test="status != null and status != ''">#{status},</if> | |
| 105 | - <if test="remark != null and remark != ''">#{remark},</if> | |
| 106 | - <if test="createBy != null and createBy != ''">#{createBy},</if> | |
| 107 | - sysdate() | |
| 108 | - ) | |
| 109 | - </insert> | |
| 110 | - | |
| 111 | -</mapper> | |
| 112 | 0 | \ No newline at end of file |
ruoyi-ui/.env.development
ruoyi-ui/.env.production
ruoyi-ui/.env.staging
ruoyi-ui/README.md deleted
| 1 | -## 开发 | |
| 2 | - | |
| 3 | -```bash | |
| 4 | -# 克隆项目 | |
| 5 | -git clone https://gitee.com/y_project/RuoYi-Vue | |
| 6 | - | |
| 7 | -# 进入项目目录 | |
| 8 | -cd ruoyi-ui | |
| 9 | - | |
| 10 | -# 安装依赖 | |
| 11 | -npm install | |
| 12 | - | |
| 13 | -# 建议不要直接使用 cnpm 安装依赖,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题 | |
| 14 | -npm install --registry=https://registry.npm.taobao.org | |
| 15 | - | |
| 16 | -# 启动服务 | |
| 17 | -npm run dev | |
| 18 | -``` | |
| 19 | - | |
| 20 | -浏览器访问 http://localhost:80 | |
| 21 | - | |
| 22 | -## 发布 | |
| 23 | - | |
| 24 | -```bash | |
| 25 | -# 构建测试环境 | |
| 26 | -npm run build:stage | |
| 27 | - | |
| 28 | -# 构建生产环境 | |
| 29 | -npm run build:prod | |
| 30 | -``` | |
| 31 | 0 | \ No newline at end of file |
ruoyi-ui/package.json
| 1 | 1 | { |
| 2 | 2 | "name": "ruoyi", |
| 3 | 3 | "version": "3.3.0", |
| 4 | - "description": "若依管理系统", | |
| 5 | - "author": "若依", | |
| 4 | + "description": "芋道管理系统", | |
| 5 | + "author": "芋道", | |
| 6 | 6 | "license": "MIT", |
| 7 | 7 | "scripts": { |
| 8 | 8 | "dev": "vue-cli-service serve", |
| ... | ... | @@ -33,7 +33,7 @@ |
| 33 | 33 | ], |
| 34 | 34 | "repository": { |
| 35 | 35 | "type": "git", |
| 36 | - "url": "https://gitee.com/y_project/RuoYi-Vue.git" | |
| 36 | + "url": "https://github.com/YunaiV/ruoyi-vue-pro" | |
| 37 | 37 | }, |
| 38 | 38 | "dependencies": { |
| 39 | 39 | "@riophae/vue-treeselect": "0.4.0", |
| ... | ... | @@ -41,10 +41,10 @@ |
| 41 | 41 | "clipboard": "2.0.6", |
| 42 | 42 | "core-js": "3.8.1", |
| 43 | 43 | "echarts": "4.9.0", |
| 44 | - "element-ui": "2.14.1", | |
| 44 | + "element-ui": "2.15.0", | |
| 45 | 45 | "file-saver": "2.0.4", |
| 46 | 46 | "fuse.js": "6.4.3", |
| 47 | - "highlight.js": "10.4.1", | |
| 47 | + "highlight.js": "9.18.5", | |
| 48 | 48 | "js-beautify": "1.13.0", |
| 49 | 49 | "js-cookie": "2.2.1", |
| 50 | 50 | "jsencrypt": "3.0.0-rc.1", | ... | ... |
ruoyi-ui/src/api/infra/apiAccessLog.js
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 获得API 访问日志分页 | |
| 4 | +export function getApiAccessLogPage(query) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/api-access-log/page', | |
| 7 | + method: 'get', | |
| 8 | + params: query | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 导出API 访问日志 Excel | |
| 13 | +export function exportApiAccessLogExcel(query) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/api-access-log/export-excel', | |
| 16 | + method: 'get', | |
| 17 | + params: query, | |
| 18 | + responseType: 'blob' | |
| 19 | + }) | |
| 20 | +} | ... | ... |
ruoyi-ui/src/api/infra/apiErrorLog.js
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 更新 API 错误日志的处理状态 | |
| 4 | +export function updateApiErrorLogProcess(id, processStatus) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/api-error-log/update-status?id=' + id + '&processStatus=' + processStatus, | |
| 7 | + method: 'put', | |
| 8 | + }) | |
| 9 | +} | |
| 10 | + | |
| 11 | +// 获得API 错误日志分页 | |
| 12 | +export function getApiErrorLogPage(query) { | |
| 13 | + return request({ | |
| 14 | + url: '/infra/api-error-log/page', | |
| 15 | + method: 'get', | |
| 16 | + params: query | |
| 17 | + }) | |
| 18 | +} | |
| 19 | + | |
| 20 | +// 导出API 错误日志 Excel | |
| 21 | +export function exportApiErrorLogExcel(query) { | |
| 22 | + return request({ | |
| 23 | + url: '/infra/api-error-log/export-excel', | |
| 24 | + method: 'get', | |
| 25 | + params: query, | |
| 26 | + responseType: 'blob' | |
| 27 | + }) | |
| 28 | +} | ... | ... |
ruoyi-ui/src/api/infra/dbDoc.js
0 → 100644
| 1 | +// 导出参数 | |
| 2 | +import request from "@/utils/request"; | |
| 3 | + | |
| 4 | +export function exportHtml() { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/db-doc/export-html', | |
| 7 | + method: 'get', | |
| 8 | + responseType: 'blob' | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +export function exportWord() { | |
| 13 | + return request({ | |
| 14 | + url: '/infra/db-doc/export-word', | |
| 15 | + method: 'get', | |
| 16 | + responseType: 'blob' | |
| 17 | + }) | |
| 18 | +} | |
| 19 | + | |
| 20 | +export function exportMarkdown() { | |
| 21 | + return request({ | |
| 22 | + url: '/infra/db-doc/export-markdown', | |
| 23 | + method: 'get', | |
| 24 | + responseType: 'blob' | |
| 25 | + }) | |
| 26 | +} | ... | ... |
ruoyi-ui/src/api/infra/file.js
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 删除文件 | |
| 4 | +export function deleteFile(id) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/file/delete?id=' + id, | |
| 7 | + method: 'delete' | |
| 8 | + }) | |
| 9 | +} | |
| 10 | + | |
| 11 | +// 获得文件分页 | |
| 12 | +export function getFilePage(query) { | |
| 13 | + return request({ | |
| 14 | + url: '/infra/file/page', | |
| 15 | + method: 'get', | |
| 16 | + params: query | |
| 17 | + }) | |
| 18 | +} | ... | ... |
ruoyi-ui/src/api/monitor/job.js renamed to ruoyi-ui/src/api/infra/job.js
| ... | ... | @@ -3,7 +3,7 @@ import request from '@/utils/request' |
| 3 | 3 | // 查询定时任务调度列表 |
| 4 | 4 | export function listJob(query) { |
| 5 | 5 | return request({ |
| 6 | - url: '/monitor/job/list', | |
| 6 | + url: '/infra/job/page', | |
| 7 | 7 | method: 'get', |
| 8 | 8 | params: query |
| 9 | 9 | }) |
| ... | ... | @@ -12,7 +12,7 @@ export function listJob(query) { |
| 12 | 12 | // 查询定时任务调度详细 |
| 13 | 13 | export function getJob(jobId) { |
| 14 | 14 | return request({ |
| 15 | - url: '/monitor/job/' + jobId, | |
| 15 | + url: '/infra/job/get?id=' + jobId, | |
| 16 | 16 | method: 'get' |
| 17 | 17 | }) |
| 18 | 18 | } |
| ... | ... | @@ -20,7 +20,7 @@ export function getJob(jobId) { |
| 20 | 20 | // 新增定时任务调度 |
| 21 | 21 | export function addJob(data) { |
| 22 | 22 | return request({ |
| 23 | - url: '/monitor/job', | |
| 23 | + url: '/infra/job/create', | |
| 24 | 24 | method: 'post', |
| 25 | 25 | data: data |
| 26 | 26 | }) |
| ... | ... | @@ -29,7 +29,7 @@ export function addJob(data) { |
| 29 | 29 | // 修改定时任务调度 |
| 30 | 30 | export function updateJob(data) { |
| 31 | 31 | return request({ |
| 32 | - url: '/monitor/job', | |
| 32 | + url: '/infra/job/update', | |
| 33 | 33 | method: 'put', |
| 34 | 34 | data: data |
| 35 | 35 | }) |
| ... | ... | @@ -38,7 +38,7 @@ export function updateJob(data) { |
| 38 | 38 | // 删除定时任务调度 |
| 39 | 39 | export function delJob(jobId) { |
| 40 | 40 | return request({ |
| 41 | - url: '/monitor/job/' + jobId, | |
| 41 | + url: '/infra/job/delete?id=' + jobId, | |
| 42 | 42 | method: 'delete' |
| 43 | 43 | }) |
| 44 | 44 | } |
| ... | ... | @@ -46,35 +46,38 @@ export function delJob(jobId) { |
| 46 | 46 | // 导出定时任务调度 |
| 47 | 47 | export function exportJob(query) { |
| 48 | 48 | return request({ |
| 49 | - url: '/monitor/job/export', | |
| 49 | + url: '/infra/job/export-excel', | |
| 50 | 50 | method: 'get', |
| 51 | - params: query | |
| 51 | + params: query, | |
| 52 | + responseType: 'blob' | |
| 52 | 53 | }) |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | 56 | // 任务状态修改 |
| 56 | -export function changeJobStatus(jobId, status) { | |
| 57 | - const data = { | |
| 58 | - jobId, | |
| 59 | - status | |
| 60 | - } | |
| 57 | +export function updateJobStatus(jobId, status) { | |
| 61 | 58 | return request({ |
| 62 | - url: '/monitor/job/changeStatus', | |
| 59 | + url: '/infra/job/update-status', | |
| 63 | 60 | method: 'put', |
| 64 | - data: data | |
| 61 | + headers:{ | |
| 62 | + 'Content-type': 'application/x-www-form-urlencoded' | |
| 63 | + }, | |
| 64 | + data: 'id=' + jobId + "&status=" + status, | |
| 65 | 65 | }) |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | // 定时任务立即执行一次 |
| 70 | -export function runJob(jobId, jobGroup) { | |
| 71 | - const data = { | |
| 72 | - jobId, | |
| 73 | - jobGroup | |
| 74 | - } | |
| 70 | +export function runJob(jobId) { | |
| 75 | 71 | return request({ |
| 76 | - url: '/monitor/job/run', | |
| 77 | - method: 'put', | |
| 78 | - data: data | |
| 72 | + url: '/infra/job/trigger?id=' + jobId, | |
| 73 | + method: 'put' | |
| 74 | + }) | |
| 75 | +} | |
| 76 | + | |
| 77 | +// 获得定时任务的下 n 次执行时间 | |
| 78 | +export function getJobNextTimes(jobId) { | |
| 79 | + return request({ | |
| 80 | + url: '/infra/job/get_next_times?id=' + jobId, | |
| 81 | + method: 'get' | |
| 79 | 82 | }) |
| 80 | -} | |
| 81 | 83 | \ No newline at end of file |
| 84 | +} | ... | ... |
ruoyi-ui/src/api/infra/jobLog.js
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 获得定时任务 | |
| 4 | +export function getJobLog(id) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/job-log/get?id=' + id, | |
| 7 | + method: 'get' | |
| 8 | + }) | |
| 9 | +} | |
| 10 | + | |
| 11 | +// 获得定时任务分页 | |
| 12 | +export function getJobLogPage(query) { | |
| 13 | + return request({ | |
| 14 | + url: '/infra/job-log/page', | |
| 15 | + method: 'get', | |
| 16 | + params: query | |
| 17 | + }) | |
| 18 | +} | |
| 19 | + | |
| 20 | +// 导出定时任务 Excel | |
| 21 | +export function exportJobLogExcel(query) { | |
| 22 | + return request({ | |
| 23 | + url: '/infra/job-log/export-excel', | |
| 24 | + method: 'get', | |
| 25 | + params: query, | |
| 26 | + responseType: 'blob' | |
| 27 | + }) | |
| 28 | +} | ... | ... |
ruoyi-ui/src/api/monitor/cache.js renamed to ruoyi-ui/src/api/infra/redis.js
| 1 | -import request from '@/utils/request' | |
| 2 | - | |
| 3 | -// 查询缓存详细 | |
| 4 | -export function getCache() { | |
| 5 | - return request({ | |
| 6 | - url: '/monitor/cache', | |
| 7 | - method: 'get' | |
| 8 | - }) | |
| 9 | -} | |
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 查询缓存详细 | |
| 4 | +export function getCache() { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/redis/get-monitor-info', | |
| 7 | + method: 'get' | |
| 8 | + }) | |
| 9 | +} | |
| 10 | + | |
| 11 | +// TODO | |
| 12 | +export function getKeyList() { | |
| 13 | + return request({ | |
| 14 | + url: '/infra/redis/get-key-list', | |
| 15 | + method: 'get' | |
| 16 | + }) | |
| 17 | +} | ... | ... |
ruoyi-ui/src/api/monitor/jobLog.js deleted
| 1 | -import request from '@/utils/request' | |
| 2 | - | |
| 3 | -// 查询调度日志列表 | |
| 4 | -export function listJobLog(query) { | |
| 5 | - return request({ | |
| 6 | - url: '/monitor/jobLog/list', | |
| 7 | - method: 'get', | |
| 8 | - params: query | |
| 9 | - }) | |
| 10 | -} | |
| 11 | - | |
| 12 | -// 删除调度日志 | |
| 13 | -export function delJobLog(jobLogId) { | |
| 14 | - return request({ | |
| 15 | - url: '/monitor/jobLog/' + jobLogId, | |
| 16 | - method: 'delete' | |
| 17 | - }) | |
| 18 | -} | |
| 19 | - | |
| 20 | -// 清空调度日志 | |
| 21 | -export function cleanJobLog() { | |
| 22 | - return request({ | |
| 23 | - url: '/monitor/jobLog/clean', | |
| 24 | - method: 'delete' | |
| 25 | - }) | |
| 26 | -} | |
| 27 | - | |
| 28 | -// 导出调度日志 | |
| 29 | -export function exportJobLog(query) { | |
| 30 | - return request({ | |
| 31 | - url: '/monitor/jobLog/export', | |
| 32 | - method: 'get', | |
| 33 | - params: query | |
| 34 | - }) | |
| 35 | -} | |
| 36 | 0 | \ No newline at end of file |