已重命名265个文件
已修改1个文件
已添加11个文件
已删除2个文件
对比新文件 |
| | |
| | | @echo off
|
| | | echo.
|
| | | echo [ÐÅÏ¢] ÔËÐÐWeb¹¤³Ì¡£
|
| | | echo.
|
| | |
|
| | | cd %~dp0
|
| | | cd ../ruoyi-admin/target
|
| | |
|
| | | set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
| | |
|
| | | java -jar %JAVA_OPTS% ruoyi-admin.jar
|
| | |
|
| | | cd bin
|
| | | pause |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | | |
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <version>3.0.0</version>
|
| | |
|
| | | <name>ruoyi</name>
|
| | | <url>http://www.ruoyi.vip</url>
|
| | | <description>若依管理系统</description>
|
| | | |
| | | <properties>
|
| | | <ruoyi.version>3.0.0</ruoyi.version>
|
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
| | | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
| | | <java.version>1.8</java.version>
|
| | | <mybatis.boot.version>1.3.2</mybatis.boot.version>
|
| | | <druid.version>1.1.14</druid.version>
|
| | | <bitwalker.version>1.19</bitwalker.version>
|
| | | <swagger.version>2.9.2</swagger.version>
|
| | | <pagehelper.boot.version>1.2.5</pagehelper.boot.version>
|
| | | <fastjson.version>1.2.70</fastjson.version>
|
| | | <oshi.version>3.9.1</oshi.version>
|
| | | <commons.io.version>2.5</commons.io.version>
|
| | | <commons.fileupload.version>1.3.3</commons.fileupload.version>
|
| | | <poi.version>3.17</poi.version>
|
| | | <velocity.version>1.7</velocity.version>
|
| | | <jwt.version>0.9.0</jwt.version>
|
| | | </properties>
|
| | | |
| | | <!-- 依赖声明 -->
|
| | | <dependencyManagement>
|
| | | <dependencies>
|
| | | |
| | | <!-- SpringBoot的依赖配置-->
|
| | | <dependency>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-dependencies</artifactId>
|
| | | <version>2.1.1.RELEASE</version>
|
| | | <type>pom</type>
|
| | | <scope>import</scope>
|
| | | </dependency>
|
| | | |
| | | <!--阿里数据库连接池 -->
|
| | | <dependency>
|
| | | <groupId>com.alibaba</groupId>
|
| | | <artifactId>druid-spring-boot-starter</artifactId>
|
| | | <version>${druid.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 解析客户端操作系统、浏览器等 -->
|
| | | <dependency>
|
| | | <groupId>eu.bitwalker</groupId>
|
| | | <artifactId>UserAgentUtils</artifactId>
|
| | | <version>${bitwalker.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- pagehelper 分页插件 -->
|
| | | <dependency>
|
| | | <groupId>com.github.pagehelper</groupId>
|
| | | <artifactId>pagehelper-spring-boot-starter</artifactId>
|
| | | <version>${pagehelper.boot.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 获取系统信息 -->
|
| | | <dependency>
|
| | | <groupId>com.github.oshi</groupId>
|
| | | <artifactId>oshi-core</artifactId>
|
| | | <version>${oshi.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- swagger2-->
|
| | | <dependency>
|
| | | <groupId>io.springfox</groupId>
|
| | | <artifactId>springfox-swagger2</artifactId>
|
| | | <version>${swagger.version}</version>
|
| | | <exclusions>
|
| | | <exclusion>
|
| | | <groupId>io.swagger</groupId>
|
| | | <artifactId>swagger-annotations</artifactId>
|
| | | </exclusion>
|
| | | <exclusion>
|
| | | <groupId>io.swagger</groupId>
|
| | | <artifactId>swagger-models</artifactId>
|
| | | </exclusion>
|
| | | </exclusions>
|
| | | </dependency>
|
| | | |
| | | <!-- swagger2-UI-->
|
| | | <dependency>
|
| | | <groupId>io.springfox</groupId>
|
| | | <artifactId>springfox-swagger-ui</artifactId>
|
| | | <version>${swagger.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!--io常用工具类 -->
|
| | | <dependency>
|
| | | <groupId>commons-io</groupId>
|
| | | <artifactId>commons-io</artifactId>
|
| | | <version>${commons.io.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!--文件上传工具类 -->
|
| | | <dependency>
|
| | | <groupId>commons-fileupload</groupId>
|
| | | <artifactId>commons-fileupload</artifactId>
|
| | | <version>${commons.fileupload.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- excel工具 -->
|
| | | <dependency>
|
| | | <groupId>org.apache.poi</groupId>
|
| | | <artifactId>poi-ooxml</artifactId>
|
| | | <version>${poi.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!--velocity代码生成使用模板 -->
|
| | | <dependency>
|
| | | <groupId>org.apache.velocity</groupId>
|
| | | <artifactId>velocity</artifactId>
|
| | | <version>${velocity.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 阿里JSON解析器 -->
|
| | | <dependency>
|
| | | <groupId>com.alibaba</groupId>
|
| | | <artifactId>fastjson</artifactId>
|
| | | <version>${fastjson.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!--Token生成与解析-->
|
| | | <dependency>
|
| | | <groupId>io.jsonwebtoken</groupId>
|
| | | <artifactId>jjwt</artifactId>
|
| | | <version>${jwt.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 定时任务-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-quartz</artifactId>
|
| | | <version>${ruoyi.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 代码生成-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-generator</artifactId>
|
| | | <version>${ruoyi.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 核心模块-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-framework</artifactId>
|
| | | <version>${ruoyi.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 系统模块-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-system</artifactId>
|
| | | <version>${ruoyi.version}</version>
|
| | | </dependency>
|
| | | |
| | | <!-- 通用工具-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-common</artifactId>
|
| | | <version>${ruoyi.version}</version>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | | </dependencyManagement>
|
| | |
|
| | | <modules>
|
| | | <module>ruoyi-admin</module>
|
| | | <module>ruoyi-framework</module>
|
| | | <module>ruoyi-system</module>
|
| | | <module>ruoyi-quartz</module>
|
| | | <module>ruoyi-generator</module>
|
| | | <module>ruoyi-common</module>
|
| | | </modules>
|
| | | <packaging>pom</packaging>
|
| | |
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | <build>
|
| | | <plugins>
|
| | | <plugin>
|
| | | <groupId>org.apache.maven.plugins</groupId>
|
| | | <artifactId>maven-compiler-plugin</artifactId>
|
| | | <version>3.1</version>
|
| | | <configuration>
|
| | | <source>${java.version}</source>
|
| | | <target>${java.version}</target>
|
| | | <encoding>${project.build.sourceEncoding}</encoding>
|
| | | </configuration>
|
| | | </plugin>
|
| | | </plugins>
|
| | | </build>
|
| | |
|
| | | <repositories>
|
| | | <repository>
|
| | | <id>public</id>
|
| | | <name>aliyun nexus</name>
|
| | | <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
| | | <releases>
|
| | | <enabled>true</enabled>
|
| | | </releases>
|
| | | </repository>
|
| | | </repositories>
|
| | |
|
| | | <pluginRepositories>
|
| | | <pluginRepository>
|
| | | <id>public</id>
|
| | | <name>aliyun nexus</name>
|
| | | <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
| | | <releases>
|
| | | <enabled>true</enabled>
|
| | | </releases>
|
| | | <snapshots>
|
| | | <enabled>false</enabled>
|
| | | </snapshots>
|
| | | </pluginRepository>
|
| | | </pluginRepositories>
|
| | |
|
| | | </project> |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <parent>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <version>3.0.0</version>
|
| | | </parent>
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | | <packaging>jar</packaging>
|
| | | <artifactId>ruoyi-admin</artifactId>
|
| | |
|
| | | <description>
|
| | | web服务入口
|
| | | </description>
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | <!-- spring-boot-devtools -->
|
| | | <dependency>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-devtools</artifactId>
|
| | | <optional>true</optional> <!-- 表示依赖不会传递 -->
|
| | | </dependency>
|
| | |
|
| | | <!-- swagger2-->
|
| | | <dependency>
|
| | | <groupId>io.springfox</groupId>
|
| | | <artifactId>springfox-swagger2</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!--防止进入swagger页面报类型转换错误,排除2.9.2中的引用,手动增加1.5.21版本-->
|
| | | <dependency>
|
| | | <groupId>io.swagger</groupId>
|
| | | <artifactId>swagger-annotations</artifactId>
|
| | | <version>1.5.21</version>
|
| | | </dependency>
|
| | |
|
| | | <dependency>
|
| | | <groupId>io.swagger</groupId>
|
| | | <artifactId>swagger-models</artifactId>
|
| | | <version>1.5.21</version>
|
| | | </dependency>
|
| | |
|
| | | <!-- swagger2-UI-->
|
| | | <dependency>
|
| | | <groupId>io.springfox</groupId>
|
| | | <artifactId>springfox-swagger-ui</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- Mysql驱动包 -->
|
| | | <dependency>
|
| | | <groupId>mysql</groupId>
|
| | | <artifactId>mysql-connector-java</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 核心模块-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-framework</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 定时任务-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-quartz</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 代码生成-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-generator</artifactId>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | <build>
|
| | | <plugins>
|
| | | <plugin>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-maven-plugin</artifactId>
|
| | | <version>2.1.1.RELEASE</version>
|
| | | <configuration>
|
| | | <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
|
| | | </configuration>
|
| | | <executions>
|
| | | <execution>
|
| | | <goals>
|
| | | <goal>repackage</goal>
|
| | | </goals>
|
| | | </execution>
|
| | | </executions>
|
| | | </plugin>
|
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>3.0.0</version> |
| | | <configuration>
|
| | | <failOnMissingWebXml>false</failOnMissingWebXml>
|
| | | <warName>${project.artifactId}</warName>
|
| | | </configuration> |
| | | </plugin> |
| | | </plugins>
|
| | | <finalName>${project.artifactId}</finalName>
|
| | | </build>
|
| | |
|
| | | </project> |
文件名从 ruoyi/src/main/java/com/ruoyi/project/common/CaptchaController.java 修改 |
| | |
| | | package com.ruoyi.project.common;
|
| | | package com.ruoyi.web.controller.common;
|
| | |
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.IOException;
|
| | |
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.utils.IdUtils;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.utils.VerifyCodeUtils;
|
| | | import com.ruoyi.common.utils.sign.Base64;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.uuid.IdUtils;
|
| | |
|
| | | /**
|
| | | * 验证码操作处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java 修改 |
| | |
| | | package com.ruoyi.project.common;
|
| | | package com.ruoyi.web.controller.common;
|
| | |
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
| | | import org.springframework.web.bind.annotation.PostMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.file.FileUploadUtils;
|
| | | import com.ruoyi.common.utils.file.FileUtils;
|
| | | import com.ruoyi.framework.config.RuoYiConfig;
|
| | | import com.ruoyi.framework.config.ServerConfig;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | |
|
| | | /**
|
| | | * 通用请求处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/controller/ServerController.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.controller;
|
| | | package com.ruoyi.web.controller.monitor;
|
| | |
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.domain.Server;
|
| | |
|
| | | /**
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/controller/SysLogininforController.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.controller;
|
| | | package com.ruoyi.web.controller.monitor;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.PathVariable;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.monitor.domain.SysLogininfor;
|
| | | import com.ruoyi.project.monitor.service.ISysLogininforService;
|
| | | import com.ruoyi.system.domain.SysLogininfor;
|
| | | import com.ruoyi.system.service.ISysLogininforService;
|
| | |
|
| | | /**
|
| | | * 系统访问记录
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/controller/SysOperlogController.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.controller;
|
| | | package com.ruoyi.web.controller.monitor;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.PathVariable;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | | import com.ruoyi.project.monitor.service.ISysOperLogService;
|
| | | import com.ruoyi.system.domain.SysOperLog;
|
| | | import com.ruoyi.system.service.ISysOperLogService;
|
| | |
|
| | | /**
|
| | | * 操作日志记录
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/controller/SysUserOnlineController.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.controller;
|
| | | package com.ruoyi.web.controller.monitor;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collection;
|
| | |
| | | import org.springframework.web.bind.annotation.PathVariable;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.monitor.domain.SysUserOnline;
|
| | | import com.ruoyi.project.system.service.ISysUserOnlineService;
|
| | | import com.ruoyi.system.domain.SysUserOnline;
|
| | | import com.ruoyi.system.service.ISysUserOnlineService;
|
| | |
|
| | | /**
|
| | | * 在线用户监控
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysConfigController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.annotation.RepeatSubmit;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysConfig;
|
| | | import com.ruoyi.project.system.service.ISysConfigService;
|
| | | import com.ruoyi.system.domain.SysConfig;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | |
|
| | | /**
|
| | | * 参数配置 信息操作处理
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:config:add')")
|
| | | @Log(title = "参数管理", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | @RepeatSubmit
|
| | | public AjaxResult add(@Validated @RequestBody SysConfig config)
|
| | | {
|
| | | if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysDept;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.project.system.service.ISysDeptService;
|
| | | import com.ruoyi.system.service.ISysDeptService;
|
| | |
|
| | | /**
|
| | | * 部门信息
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDictDataController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | | import com.ruoyi.project.system.service.ISysDictDataService;
|
| | | import com.ruoyi.project.system.service.ISysDictTypeService;
|
| | | import com.ruoyi.system.service.ISysDictDataService;
|
| | | import com.ruoyi.system.service.ISysDictTypeService;
|
| | |
|
| | | /**
|
| | | * 数据字典信息
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDictTypeController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictType;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysDictType;
|
| | | import com.ruoyi.project.system.service.ISysDictTypeService;
|
| | | import com.ruoyi.system.service.ISysDictTypeService;
|
| | |
|
| | | /**
|
| | | * 数据字典信息
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysLoginController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.domain.model.LoginBody;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.framework.security.LoginBody;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.SysLoginService;
|
| | | import com.ruoyi.framework.security.service.SysPermissionService;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysMenuService;
|
| | | import com.ruoyi.framework.web.service.SysLoginService;
|
| | | import com.ruoyi.framework.web.service.SysPermissionService;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | | import com.ruoyi.system.service.ISysMenuService;
|
| | |
|
| | | /**
|
| | | * 登录验证
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.project.system.service.ISysMenuService;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | | import com.ruoyi.system.service.ISysMenuService;
|
| | |
|
| | | /**
|
| | | * 菜单信息
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysNotice;
|
| | | import com.ruoyi.project.system.service.ISysNoticeService;
|
| | | import com.ruoyi.system.domain.SysNotice;
|
| | | import com.ruoyi.system.service.ISysNoticeService;
|
| | |
|
| | | /**
|
| | | * 公告 信息操作处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysPostController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysPost;
|
| | | import com.ruoyi.project.system.service.ISysPostService;
|
| | | import com.ruoyi.system.domain.SysPost;
|
| | | import com.ruoyi.system.service.ISysPostService;
|
| | |
|
| | | /**
|
| | | * 岗位信息操作处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysProfileController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.io.IOException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.file.FileUploadUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.config.RuoYiConfig;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | | import com.ruoyi.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | | * 个人信息 业务处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysRoleController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.project.system.service.ISysRoleService;
|
| | | import com.ruoyi.system.service.ISysRoleService;
|
| | |
|
| | | /**
|
| | | * 角色信息
|
| | |
| | | {
|
| | | return AjaxResult.success(roleService.selectRoleAll());
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysUserController.java 修改 |
| | |
| | | package com.ruoyi.project.system.controller;
|
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.stream.Collectors;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysPostService;
|
| | | import com.ruoyi.project.system.service.ISysRoleService;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | | import com.ruoyi.system.service.ISysPostService;
|
| | | import com.ruoyi.system.service.ISysRoleService;
|
| | | import com.ruoyi.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | | * 用户信息
|
| | |
| | | user.setUpdateBy(SecurityUtils.getUsername());
|
| | | return toAjax(userService.updateUserStatus(user));
|
| | | }
|
| | | } |
| | | }
|
对比新文件 |
| | |
| | | package com.ruoyi.web.controller.tool;
|
| | |
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | |
|
| | | /**
|
| | | * swagger 接口
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Controller
|
| | | @RequestMapping("/tool/swagger")
|
| | | public class SwaggerController extends BaseController
|
| | | {
|
| | | @PreAuthorize("@ss.hasPermi('tool:swagger:view')")
|
| | | @GetMapping()
|
| | | public String index()
|
| | | {
|
| | | return redirect("/swagger-ui.html");
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/swagger/TestController.java 修改 |
| | |
| | | package com.ruoyi.project.tool.swagger;
|
| | | package com.ruoyi.web.controller.tool;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.LinkedHashMap;
|
| | |
| | | import org.springframework.web.bind.annotation.PutMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import io.swagger.annotations.Api;
|
| | | import io.swagger.annotations.ApiImplicitParam;
|
| | | import io.swagger.annotations.ApiModel;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java 修改 |
| | |
| | | package com.ruoyi.framework.config;
|
| | | package com.ruoyi.web.core.config;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.context.annotation.Bean;
|
| | | import org.springframework.context.annotation.Configuration;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import io.swagger.annotations.ApiOperation;
|
| | | import springfox.documentation.builders.ApiInfoBuilder;
|
| | | import springfox.documentation.builders.PathSelectors;
|
文件名从 ruoyi/src/main/resources/application.yml 修改 |
| | |
| | | # 名称
|
| | | name: RuoYi
|
| | | # 版本
|
| | | version: 2.3.0
|
| | | version: 3.0.0
|
| | | # 版权年份
|
| | | copyrightYear: 2019
|
| | | # 实例演示开关
|
| | |
| | | # MyBatis配置
|
| | | mybatis:
|
| | | # 搜索指定包别名
|
| | | typeAliasesPackage: com.ruoyi.project.**.domain
|
| | | typeAliasesPackage: com.ruoyi.**.domain
|
| | | # 配置mapper的扫描,找到所有的mapper.xml映射文件
|
| | | mapperLocations: classpath*:mybatis/**/*Mapper.xml
|
| | | mapperLocations: classpath*:mapper/**/*Mapper.xml
|
| | | # 加载全局的配置文件
|
| | | configLocation: classpath:mybatis/mybatis-config.xml
|
| | |
|
| | |
| | | excludes: /system/notice/*
|
| | | # 匹配链接
|
| | | urlPatterns: /system/*,/monitor/*,/tool/*
|
| | | |
| | | # 代码生成
|
| | | gen: |
| | | # 作者
|
| | | author: ruoyi
|
| | | # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
|
| | | packageName: com.ruoyi.project.system
|
| | | # 自动去除表前缀,默认是true
|
| | | autoRemovePre: false
|
| | | # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
|
| | | tablePrefix: sys_ |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <parent>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <version>3.0.0</version>
|
| | | </parent>
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | |
|
| | | <artifactId>ruoyi-common</artifactId>
|
| | |
|
| | | <description>
|
| | | common通用工具
|
| | | </description>
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | <!-- Spring框架基本的核心工具 -->
|
| | | <dependency>
|
| | | <groupId>org.springframework</groupId>
|
| | | <artifactId>spring-context-support</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- SpringWeb模块 -->
|
| | | <dependency>
|
| | | <groupId>org.springframework</groupId>
|
| | | <artifactId>spring-web</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- spring security 安全认证 -->
|
| | | <dependency>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-starter-security</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- pagehelper 分页插件 -->
|
| | | <dependency>
|
| | | <groupId>com.github.pagehelper</groupId>
|
| | | <artifactId>pagehelper-spring-boot-starter</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 自定义验证注解 -->
|
| | | <dependency>
|
| | | <groupId>javax.validation</groupId>
|
| | | <artifactId>validation-api</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!--常用工具类 -->
|
| | | <dependency>
|
| | | <groupId>org.apache.commons</groupId>
|
| | | <artifactId>commons-lang3</artifactId>
|
| | | </dependency>
|
| | | |
| | | <!-- JSON工具类 -->
|
| | | <dependency>
|
| | | <groupId>com.fasterxml.jackson.core</groupId>
|
| | | <artifactId>jackson-databind</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 阿里JSON解析器 -->
|
| | | <dependency>
|
| | | <groupId>com.alibaba</groupId>
|
| | | <artifactId>fastjson</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- io常用工具类 -->
|
| | | <dependency>
|
| | | <groupId>commons-io</groupId>
|
| | | <artifactId>commons-io</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 文件上传工具类 -->
|
| | | <dependency>
|
| | | <groupId>commons-fileupload</groupId>
|
| | | <artifactId>commons-fileupload</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- excel工具 -->
|
| | | <dependency>
|
| | | <groupId>org.apache.poi</groupId>
|
| | | <artifactId>poi-ooxml</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- yml解析器 -->
|
| | | <dependency>
|
| | | <groupId>org.yaml</groupId>
|
| | | <artifactId>snakeyaml</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!--Token生成与解析-->
|
| | | <dependency>
|
| | | <groupId>io.jsonwebtoken</groupId>
|
| | | <artifactId>jjwt</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- redis 缓存操作 -->
|
| | | <dependency>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-starter-data-redis</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- pool 对象池 -->
|
| | | <dependency>
|
| | | <groupId>org.apache.commons</groupId>
|
| | | <artifactId>commons-pool2</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 解析客户端操作系统、浏览器等 -->
|
| | | <dependency>
|
| | | <groupId>eu.bitwalker</groupId>
|
| | | <artifactId>UserAgentUtils</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- servlet包 -->
|
| | | <dependency>
|
| | | <groupId>javax.servlet</groupId>
|
| | | <artifactId>javax.servlet-api</artifactId>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | </project> |
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataScope.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.annotation;
|
| | | package com.ruoyi.common.annotation;
|
| | |
|
| | | import java.lang.annotation.Documented;
|
| | | import java.lang.annotation.ElementType;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataSource.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.annotation;
|
| | | package com.ruoyi.common.annotation;
|
| | |
|
| | | import java.lang.annotation.Documented;
|
| | | import java.lang.annotation.ElementType;
|
| | |
| | | import java.lang.annotation.Retention;
|
| | | import java.lang.annotation.RetentionPolicy;
|
| | | import java.lang.annotation.Target;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
|
| | | import com.ruoyi.common.enums.DataSourceType;
|
| | |
|
| | | /**
|
| | | * 自定义多数据源切换注解
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/Excel.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.annotation; |
| | | |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * 自定义导出Excel数据注解 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Target(ElementType.FIELD) |
| | | public @interface Excel |
| | | { |
| | | /** |
| | | * 导出时在excel中排序 |
| | | */ |
| | | public int sort() default Integer.MAX_VALUE; |
| | | |
| | | /** |
| | | * 导出到Excel中的名字. |
| | | */ |
| | | public String name() default ""; |
| | | |
| | | /** |
| | | * 日期格式, 如: yyyy-MM-dd |
| | | */ |
| | | public String dateFormat() default ""; |
| | | |
| | | /** |
| | | * 读取内容转表达式 (如: 0=男,1=女,2=未知) |
| | | */ |
| | | public String readConverterExp() default ""; |
| | | |
| | | /** |
| | | * 导出类型(0数字 1字符串) |
| | | */ |
| | | public ColumnType cellType() default ColumnType.STRING; |
| | | |
| | | /** |
| | | * 导出时在excel中每个列的高度 单位为字符 |
| | | */ |
| | | public double height() default 14; |
| | | |
| | | /** |
| | | * 导出时在excel中每个列的宽 单位为字符 |
| | | */ |
| | | public double width() default 16; |
| | | |
| | | /** |
| | | * 文字后缀,如% 90 变成90% |
| | | */ |
| | | public String suffix() default ""; |
| | | |
| | | /** |
| | | * 当值为空时,字段的默认值 |
| | | */ |
| | | public String defaultValue() default ""; |
| | | |
| | | /** |
| | | * 提示信息 |
| | | */ |
| | | public String prompt() default ""; |
| | | |
| | | /** |
| | | * 设置只能选择不能输入的列内容. |
| | | */ |
| | | public String[] combo() default {}; |
| | | |
| | | /** |
| | | * 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写. |
| | | */ |
| | | public boolean isExport() default true; |
| | | |
| | | /** |
| | | * 另一个类中的属性名称,支持多级获取,以小数点隔开 |
| | | */ |
| | | public String targetAttr() default ""; |
| | | |
| | | /** |
| | | * 字段类型(0:导出导入;1:仅导出;2:仅导入) |
| | | */ |
| | | Type type() default Type.ALL; |
| | | |
| | | public enum Type |
| | | { |
| | | ALL(0), EXPORT(1), IMPORT(2); |
| | | private final int value; |
| | | |
| | | Type(int value) |
| | | { |
| | | this.value = value; |
| | | } |
| | | |
| | | public int value() |
| | | { |
| | | return this.value; |
| | | } |
| | | } |
| | | |
| | | public enum ColumnType |
| | | { |
| | | NUMERIC(0), STRING(1); |
| | | private final int value; |
| | | |
| | | ColumnType(int value) |
| | | { |
| | | this.value = value; |
| | | } |
| | | |
| | | public int value() |
| | | { |
| | | return this.value; |
| | | } |
| | | } |
| | | } |
| | | package com.ruoyi.common.annotation;
|
| | |
|
| | | import java.lang.annotation.ElementType;
|
| | | import java.lang.annotation.Retention;
|
| | | import java.lang.annotation.RetentionPolicy;
|
| | | import java.lang.annotation.Target;
|
| | |
|
| | | /**
|
| | | * 自定义导出Excel数据注解
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Retention(RetentionPolicy.RUNTIME)
|
| | | @Target(ElementType.FIELD)
|
| | | public @interface Excel
|
| | | {
|
| | | /**
|
| | | * 导出时在excel中排序
|
| | | */
|
| | | public int sort() default Integer.MAX_VALUE;
|
| | |
|
| | | /**
|
| | | * 导出到Excel中的名字.
|
| | | */
|
| | | public String name() default "";
|
| | |
|
| | | /**
|
| | | * 日期格式, 如: yyyy-MM-dd
|
| | | */
|
| | | public String dateFormat() default "";
|
| | |
|
| | | /**
|
| | | * 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
| | | */
|
| | | public String readConverterExp() default "";
|
| | |
|
| | | /**
|
| | | * 导出类型(0数字 1字符串)
|
| | | */
|
| | | public ColumnType cellType() default ColumnType.STRING;
|
| | |
|
| | | /**
|
| | | * 导出时在excel中每个列的高度 单位为字符
|
| | | */
|
| | | public double height() default 14;
|
| | |
|
| | | /**
|
| | | * 导出时在excel中每个列的宽 单位为字符
|
| | | */
|
| | | public double width() default 16;
|
| | |
|
| | | /**
|
| | | * 文字后缀,如% 90 变成90%
|
| | | */
|
| | | public String suffix() default "";
|
| | |
|
| | | /**
|
| | | * 当值为空时,字段的默认值
|
| | | */
|
| | | public String defaultValue() default "";
|
| | |
|
| | | /**
|
| | | * 提示信息
|
| | | */
|
| | | public String prompt() default "";
|
| | |
|
| | | /**
|
| | | * 设置只能选择不能输入的列内容.
|
| | | */
|
| | | public String[] combo() default {};
|
| | |
|
| | | /**
|
| | | * 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
| | | */
|
| | | public boolean isExport() default true;
|
| | |
|
| | | /**
|
| | | * 另一个类中的属性名称,支持多级获取,以小数点隔开
|
| | | */
|
| | | public String targetAttr() default "";
|
| | |
|
| | | /**
|
| | | * 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
| | | */
|
| | | Type type() default Type.ALL;
|
| | |
|
| | | public enum Type
|
| | | {
|
| | | ALL(0), EXPORT(1), IMPORT(2);
|
| | | private final int value;
|
| | |
|
| | | Type(int value)
|
| | | {
|
| | | this.value = value;
|
| | | }
|
| | |
|
| | | public int value()
|
| | | {
|
| | | return this.value;
|
| | | }
|
| | | }
|
| | |
|
| | | public enum ColumnType
|
| | | {
|
| | | NUMERIC(0), STRING(1);
|
| | | private final int value;
|
| | |
|
| | | ColumnType(int value)
|
| | | {
|
| | | this.value = value;
|
| | | }
|
| | |
|
| | | public int value()
|
| | | {
|
| | | return this.value;
|
| | | }
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/Excels.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.annotation; |
| | | |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * Excel注解集 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Target(ElementType.FIELD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | public @interface Excels |
| | | { |
| | | Excel[] value(); |
| | | } |
| | | package com.ruoyi.common.annotation;
|
| | |
|
| | | import java.lang.annotation.ElementType;
|
| | | import java.lang.annotation.Retention;
|
| | | import java.lang.annotation.RetentionPolicy;
|
| | | import java.lang.annotation.Target;
|
| | |
|
| | | /**
|
| | | * Excel注解集
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Target(ElementType.FIELD)
|
| | | @Retention(RetentionPolicy.RUNTIME)
|
| | | public @interface Excels
|
| | | {
|
| | | Excel[] value();
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/Log.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.annotation;
|
| | | package com.ruoyi.common.annotation;
|
| | |
|
| | | import java.lang.annotation.Documented;
|
| | | import java.lang.annotation.ElementType;
|
| | | import java.lang.annotation.Retention;
|
| | | import java.lang.annotation.RetentionPolicy;
|
| | | import java.lang.annotation.Target;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.OperatorType;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.enums.OperatorType;
|
| | |
|
| | | /**
|
| | | * 自定义操作日志记录注解
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/interceptor/annotation/RepeatSubmit.java 修改 |
| | |
| | | package com.ruoyi.framework.interceptor.annotation; |
| | | |
| | | import java.lang.annotation.Documented; |
| | | import java.lang.annotation.ElementType; |
| | | import java.lang.annotation.Inherited; |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | /** |
| | | * 自定义注解防止表单重复提交 |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | */ |
| | | @Inherited |
| | | @Target(ElementType.METHOD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface RepeatSubmit |
| | | { |
| | | |
| | | } |
| | | package com.ruoyi.common.annotation;
|
| | |
|
| | | import java.lang.annotation.Documented;
|
| | | import java.lang.annotation.ElementType;
|
| | | import java.lang.annotation.Inherited;
|
| | | import java.lang.annotation.Retention;
|
| | | import java.lang.annotation.RetentionPolicy;
|
| | | import java.lang.annotation.Target;
|
| | |
|
| | | /**
|
| | | * 自定义注解防止表单重复提交
|
| | | * |
| | | * @author ruoyi
|
| | | *
|
| | | */
|
| | | @Inherited
|
| | | @Target(ElementType.METHOD)
|
| | | @Retention(RetentionPolicy.RUNTIME)
|
| | | @Documented
|
| | | public @interface RepeatSubmit
|
| | | {
|
| | |
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/RuoYiConfig.java 修改 |
| | |
| | | package com.ruoyi.framework.config;
|
| | | package com.ruoyi.common.config;
|
| | |
|
| | | import org.springframework.boot.context.properties.ConfigurationProperties;
|
| | | import org.springframework.stereotype.Component;
|
| | |
| | | {
|
| | | return getProfile() + "/upload";
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java 修改 |
| | |
| | | package com.ruoyi.common.constant;
|
| | |
|
| | | import io.jsonwebtoken.Claims;
|
| | |
|
| | | /**
|
| | | * 通用常量信息
|
| | | *
|
| | |
| | | /**
|
| | | * 用户名称
|
| | | */
|
| | | public static final String JWT_USERNAME = Claims.SUBJECT;
|
| | | public static final String JWT_USERNAME = "sub";
|
| | |
|
| | | /**
|
| | | * 用户头像
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/constant/ScheduleConstants.java 修改 |
| | |
| | | package com.ruoyi.common.constant; |
| | | |
| | | /** |
| | | * 任务调度通用常量 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class ScheduleConstants |
| | | { |
| | | public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; |
| | | |
| | | /** 执行目标key */ |
| | | public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; |
| | | |
| | | /** 默认 */ |
| | | public static final String MISFIRE_DEFAULT = "0"; |
| | | |
| | | /** 立即触发执行 */ |
| | | public static final String MISFIRE_IGNORE_MISFIRES = "1"; |
| | | |
| | | /** 触发一次执行 */ |
| | | public static final String MISFIRE_FIRE_AND_PROCEED = "2"; |
| | | |
| | | /** 不触发立即执行 */ |
| | | public static final String MISFIRE_DO_NOTHING = "3"; |
| | | |
| | | public enum Status |
| | | { |
| | | /** |
| | | * 正常 |
| | | */ |
| | | NORMAL("0"), |
| | | /** |
| | | * 暂停 |
| | | */ |
| | | PAUSE("1"); |
| | | |
| | | private String value; |
| | | |
| | | private Status(String value) |
| | | { |
| | | this.value = value; |
| | | } |
| | | |
| | | public String getValue() |
| | | { |
| | | return value; |
| | | } |
| | | } |
| | | } |
| | | package com.ruoyi.common.constant;
|
| | |
|
| | | /**
|
| | | * 任务调度通用常量
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class ScheduleConstants
|
| | | {
|
| | | public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME";
|
| | |
|
| | | /** 执行目标key */
|
| | | public static final String TASK_PROPERTIES = "TASK_PROPERTIES";
|
| | |
|
| | | /** 默认 */
|
| | | public static final String MISFIRE_DEFAULT = "0";
|
| | |
|
| | | /** 立即触发执行 */
|
| | | public static final String MISFIRE_IGNORE_MISFIRES = "1";
|
| | |
|
| | | /** 触发一次执行 */
|
| | | public static final String MISFIRE_FIRE_AND_PROCEED = "2";
|
| | |
|
| | | /** 不触发立即执行 */
|
| | | public static final String MISFIRE_DO_NOTHING = "3";
|
| | |
|
| | | public enum Status
|
| | | {
|
| | | /**
|
| | | * 正常
|
| | | */
|
| | | NORMAL("0"),
|
| | | /**
|
| | | * 暂停
|
| | | */
|
| | | PAUSE("1");
|
| | |
|
| | | private String value;
|
| | |
|
| | | private Status(String value)
|
| | | {
|
| | | this.value = value;
|
| | | }
|
| | |
|
| | | public String getValue()
|
| | | {
|
| | | return value;
|
| | | }
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/controller/BaseController.java 修改 |
| | |
| | | package com.ruoyi.framework.web.controller;
|
| | | package com.ruoyi.common.core.controller;
|
| | |
|
| | | import java.beans.PropertyEditorSupport;
|
| | | import java.util.Date;
|
| | |
| | | import com.github.pagehelper.PageHelper;
|
| | | import com.github.pagehelper.PageInfo;
|
| | | import com.ruoyi.common.constant.HttpStatus;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.PageDomain;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.core.page.TableSupport;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.sql.SqlUtil;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.PageDomain;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.framework.web.page.TableSupport;
|
| | |
|
| | | /**
|
| | | * web层通用数据处理
|
| | |
| | | {
|
| | | return rows > 0 ? AjaxResult.success() : AjaxResult.error();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 页面跳转
|
| | | */
|
| | | public String redirect(String url)
|
| | | {
|
| | | return StringUtils.format("redirect:{}", url);
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/domain/AjaxResult.java 修改 |
| | |
| | | package com.ruoyi.framework.web.domain;
|
| | | package com.ruoyi.common.core.domain;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import com.ruoyi.common.constant.HttpStatus;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/domain/BaseEntity.java 修改 |
| | |
| | | package com.ruoyi.framework.web.domain;
|
| | | package com.ruoyi.common.core.domain;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.Date;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/domain/TreeEntity.java 修改 |
| | |
| | | package com.ruoyi.framework.web.domain;
|
| | | package com.ruoyi.common.core.domain;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/domain/TreeSelect.java 修改 |
| | |
| | | package com.ruoyi.framework.web.domain;
|
| | | package com.ruoyi.common.core.domain;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.List;
|
| | | import java.util.stream.Collectors;
|
| | | import com.fasterxml.jackson.annotation.JsonInclude;
|
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.common.core.domain.entity.SysDept;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | |
|
| | | /**
|
| | | * Treeselect树结构实体类
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysDept.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.common.core.domain.entity;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 部门表 sys_dept
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysDictData.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.common.core.domain.entity;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 字典数据表 sys_dict_data
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysDictType.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.common.core.domain.entity;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 字典类型表 sys_dict_type
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysMenu.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.common.core.domain.entity;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 菜单权限表 sys_menu
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysRole.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.common.core.domain.entity;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 角色表 sys_role
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysUser.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.common.core.domain.entity;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.fasterxml.jackson.annotation.JsonIgnore;
|
| | | import com.fasterxml.jackson.annotation.JsonProperty;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.Type;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excels;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.annotation.Excel.Type;
|
| | | import com.ruoyi.common.annotation.Excels;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 用户对象 sys_user
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/LoginBody.java 修改 |
| | |
| | | package com.ruoyi.framework.security;
|
| | | package com.ruoyi.common.core.domain.model;
|
| | |
|
| | | /**
|
| | | * 用户登录对象
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/LoginUser.java 修改 |
| | |
| | | package com.ruoyi.framework.security;
|
| | | package com.ruoyi.common.core.domain.model;
|
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.Set;
|
| | | import org.springframework.security.core.GrantedAuthority;
|
| | | import org.springframework.security.core.userdetails.UserDetails;
|
| | | import com.fasterxml.jackson.annotation.JsonIgnore;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | |
|
| | | /**
|
| | | * 登录用户身份权限
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/page/PageDomain.java 修改 |
| | |
| | | package com.ruoyi.framework.web.page;
|
| | | package com.ruoyi.common.core.page;
|
| | |
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | |
| | | {
|
| | | /** 当前记录起始索引 */
|
| | | private Integer pageNum;
|
| | |
|
| | | /** 每页显示记录数 */
|
| | | private Integer pageSize;
|
| | |
|
| | | /** 排序列 */
|
| | | private String orderByColumn;
|
| | |
|
| | | /** 排序的方向 "desc" 或者 "asc". */
|
| | | private String isAsc;
|
| | |
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/page/TableDataInfo.java 修改 |
| | |
| | | package com.ruoyi.framework.web.page;
|
| | | package com.ruoyi.common.core.page;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.List;
|
| | |
| | | {
|
| | | this.msg = msg;
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/page/TableSupport.java 修改 |
| | |
| | | package com.ruoyi.framework.web.page;
|
| | | package com.ruoyi.common.core.page;
|
| | |
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | |
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/redis/RedisCache.java 修改 |
| | |
| | | package com.ruoyi.framework.redis;
|
| | | package com.ruoyi.common.core.redis;
|
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.List;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/enums/BusinessStatus.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.enums;
|
| | | package com.ruoyi.common.enums;
|
| | |
|
| | | /**
|
| | | * 操作状态
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/enums/BusinessType.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.enums;
|
| | | package com.ruoyi.common.enums;
|
| | |
|
| | | /**
|
| | | * 业务操作类型
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/enums/DataSourceType.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.enums;
|
| | | package com.ruoyi.common.enums;
|
| | |
|
| | | /**
|
| | | * 数据源
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/enums/OperatorType.java 修改 |
| | |
| | | package com.ruoyi.framework.aspectj.lang.enums;
|
| | | package com.ruoyi.common.enums;
|
| | |
|
| | | /**
|
| | | * 操作人类别
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/exception/job/TaskException.java 修改 |
| | |
| | | package com.ruoyi.common.exception.job; |
| | | |
| | | /** |
| | | * 计划策略异常 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class TaskException extends Exception |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private Code code; |
| | | |
| | | public TaskException(String msg, Code code) |
| | | { |
| | | this(msg, code, null); |
| | | } |
| | | |
| | | public TaskException(String msg, Code code, Exception nestedEx) |
| | | { |
| | | super(msg, nestedEx); |
| | | this.code = code; |
| | | } |
| | | |
| | | public Code getCode() |
| | | { |
| | | return code; |
| | | } |
| | | |
| | | public enum Code |
| | | { |
| | | TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE |
| | | } |
| | | package com.ruoyi.common.exception.job;
|
| | |
|
| | | /**
|
| | | * 计划策略异常
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class TaskException extends Exception
|
| | | {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | private Code code;
|
| | |
|
| | | public TaskException(String msg, Code code)
|
| | | {
|
| | | this(msg, code, null);
|
| | | }
|
| | |
|
| | | public TaskException(String msg, Code code, Exception nestedEx)
|
| | | {
|
| | | super(msg, nestedEx);
|
| | | this.code = code;
|
| | | }
|
| | |
|
| | | public Code getCode()
|
| | | {
|
| | | return code;
|
| | | }
|
| | |
|
| | | public enum Code
|
| | | {
|
| | | TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE
|
| | | }
|
| | | } |
文件名从 ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java 修改 |
| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import java.io.IOException; |
| | | import javax.servlet.Filter; |
| | | import javax.servlet.FilterChain; |
| | | import javax.servlet.FilterConfig; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.ServletRequest; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.http.MediaType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * Repeatable 过滤器 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class RepeatableFilter implements Filter |
| | | { |
| | | @Override |
| | | public void init(FilterConfig filterConfig) throws ServletException |
| | | { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| | | throws IOException, ServletException |
| | | { |
| | | ServletRequest requestWrapper = null; |
| | | if (request instanceof HttpServletRequest && StringUtils.equalsAnyIgnoreCase(request.getContentType(), |
| | | MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE)) |
| | | { |
| | | requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); |
| | | } |
| | | if (null == requestWrapper) |
| | | { |
| | | chain.doFilter(request, response); |
| | | } |
| | | else |
| | | { |
| | | chain.doFilter(requestWrapper, response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void destroy() |
| | | { |
| | | |
| | | } |
| | | } |
| | | package com.ruoyi.common.filter;
|
| | |
|
| | | import java.io.IOException;
|
| | | import javax.servlet.Filter;
|
| | | import javax.servlet.FilterChain;
|
| | | import javax.servlet.FilterConfig;
|
| | | import javax.servlet.ServletException;
|
| | | import javax.servlet.ServletRequest;
|
| | | import javax.servlet.ServletResponse;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import org.springframework.http.MediaType;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | | /**
|
| | | * Repeatable 过滤器
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class RepeatableFilter implements Filter
|
| | | {
|
| | | @Override
|
| | | public void init(FilterConfig filterConfig) throws ServletException
|
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
| | | throws IOException, ServletException
|
| | | {
|
| | | ServletRequest requestWrapper = null;
|
| | | if (request instanceof HttpServletRequest && StringUtils.equalsAnyIgnoreCase(request.getContentType(),
|
| | | MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE))
|
| | | {
|
| | | requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
|
| | | }
|
| | | if (null == requestWrapper)
|
| | | {
|
| | | chain.doFilter(request, response);
|
| | | }
|
| | | else
|
| | | {
|
| | | chain.doFilter(requestWrapper, response);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void destroy()
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java 修改 |
| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import javax.servlet.ReadListener; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.ServletResponse; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletRequestWrapper; |
| | | import com.ruoyi.common.utils.http.HttpHelper; |
| | | |
| | | /** |
| | | * 构建可重复读取inputStream的request |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper |
| | | { |
| | | private final byte[] body; |
| | | |
| | | public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException |
| | | { |
| | | super(request); |
| | | request.setCharacterEncoding("UTF-8"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | |
| | | body = HttpHelper.getBodyString(request).getBytes("UTF-8"); |
| | | } |
| | | |
| | | @Override |
| | | public BufferedReader getReader() throws IOException |
| | | { |
| | | return new BufferedReader(new InputStreamReader(getInputStream())); |
| | | } |
| | | |
| | | @Override |
| | | public ServletInputStream getInputStream() throws IOException |
| | | { |
| | | |
| | | final ByteArrayInputStream bais = new ByteArrayInputStream(body); |
| | | |
| | | return new ServletInputStream() |
| | | { |
| | | |
| | | @Override |
| | | public int read() throws IOException |
| | | { |
| | | return bais.read(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isFinished() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isReady() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public void setReadListener(ReadListener readListener) |
| | | { |
| | | |
| | | } |
| | | }; |
| | | } |
| | | } |
| | | package com.ruoyi.common.filter;
|
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStreamReader;
|
| | | import javax.servlet.ReadListener;
|
| | | import javax.servlet.ServletInputStream;
|
| | | import javax.servlet.ServletResponse;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletRequestWrapper;
|
| | | import com.ruoyi.common.utils.http.HttpHelper;
|
| | |
|
| | | /**
|
| | | * 构建可重复读取inputStream的request
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper
|
| | | {
|
| | | private final byte[] body;
|
| | |
|
| | | public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException
|
| | | {
|
| | | super(request);
|
| | | request.setCharacterEncoding("UTF-8");
|
| | | response.setCharacterEncoding("UTF-8");
|
| | |
|
| | | body = HttpHelper.getBodyString(request).getBytes("UTF-8");
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BufferedReader getReader() throws IOException
|
| | | {
|
| | | return new BufferedReader(new InputStreamReader(getInputStream()));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ServletInputStream getInputStream() throws IOException
|
| | | {
|
| | |
|
| | | final ByteArrayInputStream bais = new ByteArrayInputStream(body);
|
| | |
|
| | | return new ServletInputStream()
|
| | | {
|
| | |
|
| | | @Override
|
| | | public int read() throws IOException
|
| | | {
|
| | | return bais.read();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean isFinished()
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean isReady()
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void setReadListener(ReadListener readListener)
|
| | | {
|
| | |
|
| | | }
|
| | | };
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/DictUtils.java 修改 |
| | |
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.List;
|
| | |
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | |
|
| | | /**
|
| | | * 字典工具类
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/ExceptionUtil.java 修改 |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.io.StringWriter; |
| | | import org.apache.commons.lang3.exception.ExceptionUtils; |
| | | |
| | | /** |
| | | * 错误信息处理类。 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class ExceptionUtil |
| | | { |
| | | /** |
| | | * 获取exception的详细错误信息。 |
| | | */ |
| | | public static String getExceptionMessage(Throwable e) |
| | | { |
| | | StringWriter sw = new StringWriter(); |
| | | e.printStackTrace(new PrintWriter(sw, true)); |
| | | String str = sw.toString(); |
| | | return str; |
| | | } |
| | | |
| | | public static String getRootErrorMseeage(Exception e) |
| | | { |
| | | Throwable root = ExceptionUtils.getRootCause(e); |
| | | root = (root == null ? e : root); |
| | | if (root == null) |
| | | { |
| | | return ""; |
| | | } |
| | | String msg = root.getMessage(); |
| | | if (msg == null) |
| | | { |
| | | return "null"; |
| | | } |
| | | return StringUtils.defaultString(msg); |
| | | } |
| | | } |
| | | package com.ruoyi.common.utils;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.io.StringWriter;
|
| | | import org.apache.commons.lang3.exception.ExceptionUtils;
|
| | |
|
| | | /**
|
| | | * 错误信息处理类。
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public class ExceptionUtil
|
| | | {
|
| | | /**
|
| | | * 获取exception的详细错误信息。
|
| | | */
|
| | | public static String getExceptionMessage(Throwable e)
|
| | | {
|
| | | StringWriter sw = new StringWriter();
|
| | | e.printStackTrace(new PrintWriter(sw, true));
|
| | | String str = sw.toString();
|
| | | return str;
|
| | | }
|
| | |
|
| | | public static String getRootErrorMseeage(Exception e)
|
| | | {
|
| | | Throwable root = ExceptionUtils.getRootCause(e);
|
| | | root = (root == null ? e : root);
|
| | | if (root == null)
|
| | | {
|
| | | return "";
|
| | | }
|
| | | String msg = root.getMessage();
|
| | | if (msg == null)
|
| | | {
|
| | | return "null";
|
| | | }
|
| | | return StringUtils.defaultString(msg);
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/SecurityUtils.java 修改 |
| | |
| | | import org.springframework.security.core.context.SecurityContextHolder;
|
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
| | | import com.ruoyi.common.constant.HttpStatus;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | |
|
| | | /**
|
| | | * 安全服务工具类
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/bean/BeanUtils.java 修改 |
| | |
| | | package com.ruoyi.common.utils.bean; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * Bean 工具类 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class BeanUtils extends org.springframework.beans.BeanUtils |
| | | { |
| | | /** Bean方法名中属性名开始的下标 */ |
| | | private static final int BEAN_METHOD_PROP_INDEX = 3; |
| | | |
| | | /** * 匹配getter方法的正则表达式 */ |
| | | private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)"); |
| | | |
| | | /** * 匹配setter方法的正则表达式 */ |
| | | private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)"); |
| | | |
| | | /** |
| | | * Bean属性复制工具方法。 |
| | | * |
| | | * @param dest 目标对象 |
| | | * @param src 源对象 |
| | | */ |
| | | public static void copyBeanProp(Object dest, Object src) |
| | | { |
| | | try |
| | | { |
| | | copyProperties(src, dest); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取对象的setter方法。 |
| | | * |
| | | * @param obj 对象 |
| | | * @return 对象的setter方法列表 |
| | | */ |
| | | public static List<Method> getSetterMethods(Object obj) |
| | | { |
| | | // setter方法列表 |
| | | List<Method> setterMethods = new ArrayList<Method>(); |
| | | |
| | | // 获取所有方法 |
| | | Method[] methods = obj.getClass().getMethods(); |
| | | |
| | | // 查找setter方法 |
| | | |
| | | for (Method method : methods) |
| | | { |
| | | Matcher m = SET_PATTERN.matcher(method.getName()); |
| | | if (m.matches() && (method.getParameterTypes().length == 1)) |
| | | { |
| | | setterMethods.add(method); |
| | | } |
| | | } |
| | | // 返回setter方法列表 |
| | | return setterMethods; |
| | | } |
| | | |
| | | /** |
| | | * 获取对象的getter方法。 |
| | | * |
| | | * @param obj 对象 |
| | | * @return 对象的getter方法列表 |
| | | */ |
| | | |
| | | public static List<Method> getGetterMethods(Object obj) |
| | | { |
| | | // getter方法列表 |
| | | List<Method> getterMethods = new ArrayList<Method>(); |
| | | // 获取所有方法 |
| | | Method[] methods = obj.getClass().getMethods(); |
| | | // 查找getter方法 |
| | | for (Method method : methods) |
| | | { |
| | | Matcher m = GET_PATTERN.matcher(method.getName()); |
| | | if (m.matches() && (method.getParameterTypes().length == 0)) |
| | | { |
| | | getterMethods.add(method); |
| | | } |
| | | } |
| | | // 返回getter方法列表 |
| | | return getterMethods; |
| | | } |
| | | |
| | | /** |
| | | * 检查Bean方法名中的属性名是否相等。<br> |
| | | * 如getName()和setName()属性名一样,getName()和setAge()属性名不一样。 |
| | | * |
| | | * @param m1 方法名1 |
| | | * @param m2 方法名2 |
| | | * @return 属性名一样返回true,否则返回false |
| | | */ |
| | | |
| | | public static boolean isMethodPropEquals(String m1, String m2) |
| | | { |
| | | return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX)); |
| | | } |
| | | } |
| | | package com.ruoyi.common.utils.bean;
|
| | |
|
| | | import java.lang.reflect.Method;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | /**
|
| | | * Bean 工具类
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class BeanUtils extends org.springframework.beans.BeanUtils
|
| | | {
|
| | | /** Bean方法名中属性名开始的下标 */
|
| | | private static final int BEAN_METHOD_PROP_INDEX = 3;
|
| | |
|
| | | /** * 匹配getter方法的正则表达式 */
|
| | | private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)");
|
| | |
|
| | | /** * 匹配setter方法的正则表达式 */
|
| | | private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)");
|
| | |
|
| | | /**
|
| | | * Bean属性复制工具方法。
|
| | | * |
| | | * @param dest 目标对象
|
| | | * @param src 源对象
|
| | | */
|
| | | public static void copyBeanProp(Object dest, Object src)
|
| | | {
|
| | | try
|
| | | {
|
| | | copyProperties(src, dest);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取对象的setter方法。
|
| | | * |
| | | * @param obj 对象
|
| | | * @return 对象的setter方法列表
|
| | | */
|
| | | public static List<Method> getSetterMethods(Object obj)
|
| | | {
|
| | | // setter方法列表
|
| | | List<Method> setterMethods = new ArrayList<Method>();
|
| | |
|
| | | // 获取所有方法
|
| | | Method[] methods = obj.getClass().getMethods();
|
| | |
|
| | | // 查找setter方法
|
| | |
|
| | | for (Method method : methods)
|
| | | {
|
| | | Matcher m = SET_PATTERN.matcher(method.getName());
|
| | | if (m.matches() && (method.getParameterTypes().length == 1))
|
| | | {
|
| | | setterMethods.add(method);
|
| | | }
|
| | | }
|
| | | // 返回setter方法列表
|
| | | return setterMethods;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取对象的getter方法。
|
| | | * |
| | | * @param obj 对象
|
| | | * @return 对象的getter方法列表
|
| | | */
|
| | |
|
| | | public static List<Method> getGetterMethods(Object obj)
|
| | | {
|
| | | // getter方法列表
|
| | | List<Method> getterMethods = new ArrayList<Method>();
|
| | | // 获取所有方法
|
| | | Method[] methods = obj.getClass().getMethods();
|
| | | // 查找getter方法
|
| | | for (Method method : methods)
|
| | | {
|
| | | Matcher m = GET_PATTERN.matcher(method.getName());
|
| | | if (m.matches() && (method.getParameterTypes().length == 0))
|
| | | {
|
| | | getterMethods.add(method);
|
| | | }
|
| | | }
|
| | | // 返回getter方法列表
|
| | | return getterMethods;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 检查Bean方法名中的属性名是否相等。<br>
|
| | | * 如getName()和setName()属性名一样,getName()和setAge()属性名不一样。
|
| | | * |
| | | * @param m1 方法名1
|
| | | * @param m2 方法名2
|
| | | * @return 属性名一样返回true,否则返回false
|
| | | */
|
| | |
|
| | | public static boolean isMethodPropEquals(String m1, String m2)
|
| | | {
|
| | | return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX));
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java 修改 |
| | |
| | | import java.io.IOException;
|
| | | import org.apache.commons.io.FilenameUtils;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException;
|
| | | import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
|
| | | import com.ruoyi.common.exception.file.InvalidExtensionException;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.IdUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.config.RuoYiConfig;
|
| | | import com.ruoyi.common.utils.uuid.IdUtils;
|
| | |
|
| | | /**
|
| | | * 文件上传工具类
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/html/HTMLFilter.java 修改 |
| | |
| | | package com.ruoyi.common.utils.html; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentMap; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * HTML过滤器,用于去除XSS漏洞隐患。 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public final class HTMLFilter |
| | | { |
| | | /** |
| | | * regex flag union representing /si modifiers in php |
| | | **/ |
| | | private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL; |
| | | private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL); |
| | | private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI); |
| | | private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL); |
| | | private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI); |
| | | private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI); |
| | | private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI); |
| | | private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI); |
| | | private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI); |
| | | private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?"); |
| | | private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?"); |
| | | private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?"); |
| | | private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))"); |
| | | private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL); |
| | | private static final Pattern P_END_ARROW = Pattern.compile("^>"); |
| | | private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)"); |
| | | private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)"); |
| | | private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)"); |
| | | private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)"); |
| | | private static final Pattern P_AMP = Pattern.compile("&"); |
| | | private static final Pattern P_QUOTE = Pattern.compile("\""); |
| | | private static final Pattern P_LEFT_ARROW = Pattern.compile("<"); |
| | | private static final Pattern P_RIGHT_ARROW = Pattern.compile(">"); |
| | | private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>"); |
| | | |
| | | // @xxx could grow large... maybe use sesat's ReferenceMap |
| | | private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>(); |
| | | private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * set of allowed html elements, along with allowed attributes for each element |
| | | **/ |
| | | private final Map<String, List<String>> vAllowed; |
| | | /** |
| | | * counts of open tags for each (allowable) html element |
| | | **/ |
| | | private final Map<String, Integer> vTagCounts = new HashMap<>(); |
| | | |
| | | /** |
| | | * html elements which must always be self-closing (e.g. "<img />") |
| | | **/ |
| | | private final String[] vSelfClosingTags; |
| | | /** |
| | | * html elements which must always have separate opening and closing tags (e.g. "<b></b>") |
| | | **/ |
| | | private final String[] vNeedClosingTags; |
| | | /** |
| | | * set of disallowed html elements |
| | | **/ |
| | | private final String[] vDisallowed; |
| | | /** |
| | | * attributes which should be checked for valid protocols |
| | | **/ |
| | | private final String[] vProtocolAtts; |
| | | /** |
| | | * allowed protocols |
| | | **/ |
| | | private final String[] vAllowedProtocols; |
| | | /** |
| | | * tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />") |
| | | **/ |
| | | private final String[] vRemoveBlanks; |
| | | /** |
| | | * entities allowed within html markup |
| | | **/ |
| | | private final String[] vAllowedEntities; |
| | | /** |
| | | * flag determining whether comments are allowed in input String. |
| | | */ |
| | | private final boolean stripComment; |
| | | private final boolean encodeQuotes; |
| | | /** |
| | | * flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>" |
| | | * becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped. |
| | | */ |
| | | private final boolean alwaysMakeTags; |
| | | |
| | | /** |
| | | * Default constructor. |
| | | */ |
| | | public HTMLFilter() |
| | | { |
| | | vAllowed = new HashMap<>(); |
| | | |
| | | final ArrayList<String> a_atts = new ArrayList<>(); |
| | | a_atts.add("href"); |
| | | a_atts.add("target"); |
| | | vAllowed.put("a", a_atts); |
| | | |
| | | final ArrayList<String> img_atts = new ArrayList<>(); |
| | | img_atts.add("src"); |
| | | img_atts.add("width"); |
| | | img_atts.add("height"); |
| | | img_atts.add("alt"); |
| | | vAllowed.put("img", img_atts); |
| | | |
| | | final ArrayList<String> no_atts = new ArrayList<>(); |
| | | vAllowed.put("b", no_atts); |
| | | vAllowed.put("strong", no_atts); |
| | | vAllowed.put("i", no_atts); |
| | | vAllowed.put("em", no_atts); |
| | | |
| | | vSelfClosingTags = new String[] { "img" }; |
| | | vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" }; |
| | | vDisallowed = new String[] {}; |
| | | vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp. |
| | | vProtocolAtts = new String[] { "src", "href" }; |
| | | vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" }; |
| | | vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" }; |
| | | stripComment = true; |
| | | encodeQuotes = true; |
| | | alwaysMakeTags = true; |
| | | } |
| | | |
| | | /** |
| | | * Map-parameter configurable constructor. |
| | | * |
| | | * @param conf map containing configuration. keys match field names. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public HTMLFilter(final Map<String, Object> conf) |
| | | { |
| | | |
| | | assert conf.containsKey("vAllowed") : "configuration requires vAllowed"; |
| | | assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags"; |
| | | assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags"; |
| | | assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed"; |
| | | assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols"; |
| | | assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts"; |
| | | assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks"; |
| | | assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities"; |
| | | |
| | | vAllowed = Collections.unmodifiableMap((HashMap<String, List<String>>) conf.get("vAllowed")); |
| | | vSelfClosingTags = (String[]) conf.get("vSelfClosingTags"); |
| | | vNeedClosingTags = (String[]) conf.get("vNeedClosingTags"); |
| | | vDisallowed = (String[]) conf.get("vDisallowed"); |
| | | vAllowedProtocols = (String[]) conf.get("vAllowedProtocols"); |
| | | vProtocolAtts = (String[]) conf.get("vProtocolAtts"); |
| | | vRemoveBlanks = (String[]) conf.get("vRemoveBlanks"); |
| | | vAllowedEntities = (String[]) conf.get("vAllowedEntities"); |
| | | stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true; |
| | | encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true; |
| | | alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true; |
| | | } |
| | | |
| | | private void reset() |
| | | { |
| | | vTagCounts.clear(); |
| | | } |
| | | |
| | | // --------------------------------------------------------------- |
| | | // my versions of some PHP library functions |
| | | public static String chr(final int decimal) |
| | | { |
| | | return String.valueOf((char) decimal); |
| | | } |
| | | |
| | | public static String htmlSpecialChars(final String s) |
| | | { |
| | | String result = s; |
| | | result = regexReplace(P_AMP, "&", result); |
| | | result = regexReplace(P_QUOTE, """, result); |
| | | result = regexReplace(P_LEFT_ARROW, "<", result); |
| | | result = regexReplace(P_RIGHT_ARROW, ">", result); |
| | | return result; |
| | | } |
| | | |
| | | // --------------------------------------------------------------- |
| | | |
| | | /** |
| | | * given a user submitted input String, filter out any invalid or restricted html. |
| | | * |
| | | * @param input text (i.e. submitted by a user) than may contain html |
| | | * @return "clean" version of input, with only valid, whitelisted html elements allowed |
| | | */ |
| | | public String filter(final String input) |
| | | { |
| | | reset(); |
| | | String s = input; |
| | | |
| | | s = escapeComments(s); |
| | | |
| | | s = balanceHTML(s); |
| | | |
| | | s = checkTags(s); |
| | | |
| | | s = processRemoveBlanks(s); |
| | | |
| | | s = validateEntities(s); |
| | | |
| | | return s; |
| | | } |
| | | |
| | | public boolean isAlwaysMakeTags() |
| | | { |
| | | return alwaysMakeTags; |
| | | } |
| | | |
| | | public boolean isStripComments() |
| | | { |
| | | return stripComment; |
| | | } |
| | | |
| | | private String escapeComments(final String s) |
| | | { |
| | | final Matcher m = P_COMMENTS.matcher(s); |
| | | final StringBuffer buf = new StringBuffer(); |
| | | if (m.find()) |
| | | { |
| | | final String match = m.group(1); // (.*?) |
| | | m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->")); |
| | | } |
| | | m.appendTail(buf); |
| | | |
| | | return buf.toString(); |
| | | } |
| | | |
| | | private String balanceHTML(String s) |
| | | { |
| | | if (alwaysMakeTags) |
| | | { |
| | | // |
| | | // try and form html |
| | | // |
| | | s = regexReplace(P_END_ARROW, "", s); |
| | | s = regexReplace(P_BODY_TO_END, "<$1>", s); |
| | | s = regexReplace(P_XML_CONTENT, "$1<$2", s); |
| | | |
| | | } |
| | | else |
| | | { |
| | | // |
| | | // escape stray brackets |
| | | // |
| | | s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s); |
| | | s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s); |
| | | |
| | | // |
| | | // the last regexp causes '<>' entities to appear |
| | | // (we need to do a lookahead assertion so that the last bracket can |
| | | // be used in the next pass of the regexp) |
| | | // |
| | | s = regexReplace(P_BOTH_ARROWS, "", s); |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | |
| | | private String checkTags(String s) |
| | | { |
| | | Matcher m = P_TAGS.matcher(s); |
| | | |
| | | final StringBuffer buf = new StringBuffer(); |
| | | while (m.find()) |
| | | { |
| | | String replaceStr = m.group(1); |
| | | replaceStr = processTag(replaceStr); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr)); |
| | | } |
| | | m.appendTail(buf); |
| | | |
| | | // these get tallied in processTag |
| | | // (remember to reset before subsequent calls to filter method) |
| | | final StringBuilder sBuilder = new StringBuilder(buf.toString()); |
| | | for (String key : vTagCounts.keySet()) |
| | | { |
| | | for (int ii = 0; ii < vTagCounts.get(key); ii++) |
| | | { |
| | | sBuilder.append("</").append(key).append(">"); |
| | | } |
| | | } |
| | | s = sBuilder.toString(); |
| | | |
| | | return s; |
| | | } |
| | | |
| | | private String processRemoveBlanks(final String s) |
| | | { |
| | | String result = s; |
| | | for (String tag : vRemoveBlanks) |
| | | { |
| | | if (!P_REMOVE_PAIR_BLANKS.containsKey(tag)) |
| | | { |
| | | P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">")); |
| | | } |
| | | result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result); |
| | | if (!P_REMOVE_SELF_BLANKS.containsKey(tag)) |
| | | { |
| | | P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>")); |
| | | } |
| | | result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) |
| | | { |
| | | Matcher m = regex_pattern.matcher(s); |
| | | return m.replaceAll(replacement); |
| | | } |
| | | |
| | | private String processTag(final String s) |
| | | { |
| | | // ending tags |
| | | Matcher m = P_END_TAG.matcher(s); |
| | | if (m.find()) |
| | | { |
| | | final String name = m.group(1).toLowerCase(); |
| | | if (allowed(name)) |
| | | { |
| | | if (false == inArray(name, vSelfClosingTags)) |
| | | { |
| | | if (vTagCounts.containsKey(name)) |
| | | { |
| | | vTagCounts.put(name, vTagCounts.get(name) - 1); |
| | | return "</" + name + ">"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // starting tags |
| | | m = P_START_TAG.matcher(s); |
| | | if (m.find()) |
| | | { |
| | | final String name = m.group(1).toLowerCase(); |
| | | final String body = m.group(2); |
| | | String ending = m.group(3); |
| | | |
| | | // debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" ); |
| | | if (allowed(name)) |
| | | { |
| | | final StringBuilder params = new StringBuilder(); |
| | | |
| | | final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body); |
| | | final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body); |
| | | final List<String> paramNames = new ArrayList<>(); |
| | | final List<String> paramValues = new ArrayList<>(); |
| | | while (m2.find()) |
| | | { |
| | | paramNames.add(m2.group(1)); // ([a-z0-9]+) |
| | | paramValues.add(m2.group(3)); // (.*?) |
| | | } |
| | | while (m3.find()) |
| | | { |
| | | paramNames.add(m3.group(1)); // ([a-z0-9]+) |
| | | paramValues.add(m3.group(3)); // ([^\"\\s']+) |
| | | } |
| | | |
| | | String paramName, paramValue; |
| | | for (int ii = 0; ii < paramNames.size(); ii++) |
| | | { |
| | | paramName = paramNames.get(ii).toLowerCase(); |
| | | paramValue = paramValues.get(ii); |
| | | |
| | | // debug( "paramName='" + paramName + "'" ); |
| | | // debug( "paramValue='" + paramValue + "'" ); |
| | | // debug( "allowed? " + vAllowed.get( name ).contains( paramName ) ); |
| | | |
| | | if (allowedAttribute(name, paramName)) |
| | | { |
| | | if (inArray(paramName, vProtocolAtts)) |
| | | { |
| | | paramValue = processParamProtocol(paramValue); |
| | | } |
| | | params.append(' ').append(paramName).append("=\"").append(paramValue).append("\""); |
| | | } |
| | | } |
| | | |
| | | if (inArray(name, vSelfClosingTags)) |
| | | { |
| | | ending = " /"; |
| | | } |
| | | |
| | | if (inArray(name, vNeedClosingTags)) |
| | | { |
| | | ending = ""; |
| | | } |
| | | |
| | | if (ending == null || ending.length() < 1) |
| | | { |
| | | if (vTagCounts.containsKey(name)) |
| | | { |
| | | vTagCounts.put(name, vTagCounts.get(name) + 1); |
| | | } |
| | | else |
| | | { |
| | | vTagCounts.put(name, 1); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | ending = " /"; |
| | | } |
| | | return "<" + name + params + ending + ">"; |
| | | } |
| | | else |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | // comments |
| | | m = P_COMMENT.matcher(s); |
| | | if (!stripComment && m.find()) |
| | | { |
| | | return "<" + m.group() + ">"; |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | private String processParamProtocol(String s) |
| | | { |
| | | s = decodeEntities(s); |
| | | final Matcher m = P_PROTOCOL.matcher(s); |
| | | if (m.find()) |
| | | { |
| | | final String protocol = m.group(1); |
| | | if (!inArray(protocol, vAllowedProtocols)) |
| | | { |
| | | // bad protocol, turn into local anchor link instead |
| | | s = "#" + s.substring(protocol.length() + 1); |
| | | if (s.startsWith("#//")) |
| | | { |
| | | s = "#" + s.substring(3); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | |
| | | private String decodeEntities(String s) |
| | | { |
| | | StringBuffer buf = new StringBuffer(); |
| | | |
| | | Matcher m = P_ENTITY.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String match = m.group(1); |
| | | final int decimal = Integer.decode(match).intValue(); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); |
| | | } |
| | | m.appendTail(buf); |
| | | s = buf.toString(); |
| | | |
| | | buf = new StringBuffer(); |
| | | m = P_ENTITY_UNICODE.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String match = m.group(1); |
| | | final int decimal = Integer.valueOf(match, 16).intValue(); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); |
| | | } |
| | | m.appendTail(buf); |
| | | s = buf.toString(); |
| | | |
| | | buf = new StringBuffer(); |
| | | m = P_ENCODE.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String match = m.group(1); |
| | | final int decimal = Integer.valueOf(match, 16).intValue(); |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); |
| | | } |
| | | m.appendTail(buf); |
| | | s = buf.toString(); |
| | | |
| | | s = validateEntities(s); |
| | | return s; |
| | | } |
| | | |
| | | private String validateEntities(final String s) |
| | | { |
| | | StringBuffer buf = new StringBuffer(); |
| | | |
| | | // validate entities throughout the string |
| | | Matcher m = P_VALID_ENTITIES.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String one = m.group(1); // ([^&;]*) |
| | | final String two = m.group(2); // (?=(;|&|$)) |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two))); |
| | | } |
| | | m.appendTail(buf); |
| | | |
| | | return encodeQuotes(buf.toString()); |
| | | } |
| | | |
| | | private String encodeQuotes(final String s) |
| | | { |
| | | if (encodeQuotes) |
| | | { |
| | | StringBuffer buf = new StringBuffer(); |
| | | Matcher m = P_VALID_QUOTES.matcher(s); |
| | | while (m.find()) |
| | | { |
| | | final String one = m.group(1); // (>|^) |
| | | final String two = m.group(2); // ([^<]+?) |
| | | final String three = m.group(3); // (<|$) |
| | | // 不替换双引号为",防止json格式无效 regexReplace(P_QUOTE, """, two) |
| | | m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three)); |
| | | } |
| | | m.appendTail(buf); |
| | | return buf.toString(); |
| | | } |
| | | else |
| | | { |
| | | return s; |
| | | } |
| | | } |
| | | |
| | | private String checkEntity(final String preamble, final String term) |
| | | { |
| | | |
| | | return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&" + preamble; |
| | | } |
| | | |
| | | private boolean isValidEntity(final String entity) |
| | | { |
| | | return inArray(entity, vAllowedEntities); |
| | | } |
| | | |
| | | private static boolean inArray(final String s, final String[] array) |
| | | { |
| | | for (String item : array) |
| | | { |
| | | if (item != null && item.equals(s)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private boolean allowed(final String name) |
| | | { |
| | | return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed); |
| | | } |
| | | |
| | | private boolean allowedAttribute(final String name, final String paramName) |
| | | { |
| | | return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName)); |
| | | } |
| | | package com.ruoyi.common.utils.html;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.ConcurrentHashMap;
|
| | | import java.util.concurrent.ConcurrentMap;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | /**
|
| | | * HTML过滤器,用于去除XSS漏洞隐患。
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public final class HTMLFilter
|
| | | {
|
| | | /**
|
| | | * regex flag union representing /si modifiers in php
|
| | | **/
|
| | | private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
|
| | | private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
|
| | | private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI);
|
| | | private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL);
|
| | | private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI);
|
| | | private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI);
|
| | | private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI);
|
| | | private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI);
|
| | | private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI);
|
| | | private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?");
|
| | | private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?");
|
| | | private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?");
|
| | | private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))");
|
| | | private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL);
|
| | | private static final Pattern P_END_ARROW = Pattern.compile("^>");
|
| | | private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)");
|
| | | private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)");
|
| | | private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)");
|
| | | private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)");
|
| | | private static final Pattern P_AMP = Pattern.compile("&");
|
| | | private static final Pattern P_QUOTE = Pattern.compile("\"");
|
| | | private static final Pattern P_LEFT_ARROW = Pattern.compile("<");
|
| | | private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
|
| | | private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
|
| | |
|
| | | // @xxx could grow large... maybe use sesat's ReferenceMap
|
| | | private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>();
|
| | | private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>();
|
| | |
|
| | | /**
|
| | | * set of allowed html elements, along with allowed attributes for each element
|
| | | **/
|
| | | private final Map<String, List<String>> vAllowed;
|
| | | /**
|
| | | * counts of open tags for each (allowable) html element
|
| | | **/
|
| | | private final Map<String, Integer> vTagCounts = new HashMap<>();
|
| | |
|
| | | /**
|
| | | * html elements which must always be self-closing (e.g. "<img />")
|
| | | **/
|
| | | private final String[] vSelfClosingTags;
|
| | | /**
|
| | | * html elements which must always have separate opening and closing tags (e.g. "<b></b>")
|
| | | **/
|
| | | private final String[] vNeedClosingTags;
|
| | | /**
|
| | | * set of disallowed html elements
|
| | | **/
|
| | | private final String[] vDisallowed;
|
| | | /**
|
| | | * attributes which should be checked for valid protocols
|
| | | **/
|
| | | private final String[] vProtocolAtts;
|
| | | /**
|
| | | * allowed protocols
|
| | | **/
|
| | | private final String[] vAllowedProtocols;
|
| | | /**
|
| | | * tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />")
|
| | | **/
|
| | | private final String[] vRemoveBlanks;
|
| | | /**
|
| | | * entities allowed within html markup
|
| | | **/
|
| | | private final String[] vAllowedEntities;
|
| | | /**
|
| | | * flag determining whether comments are allowed in input String.
|
| | | */
|
| | | private final boolean stripComment;
|
| | | private final boolean encodeQuotes;
|
| | | /**
|
| | | * flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
| | | * becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
| | | */
|
| | | private final boolean alwaysMakeTags;
|
| | |
|
| | | /**
|
| | | * Default constructor.
|
| | | */
|
| | | public HTMLFilter()
|
| | | {
|
| | | vAllowed = new HashMap<>();
|
| | |
|
| | | final ArrayList<String> a_atts = new ArrayList<>();
|
| | | a_atts.add("href");
|
| | | a_atts.add("target");
|
| | | vAllowed.put("a", a_atts);
|
| | |
|
| | | final ArrayList<String> img_atts = new ArrayList<>();
|
| | | img_atts.add("src");
|
| | | img_atts.add("width");
|
| | | img_atts.add("height");
|
| | | img_atts.add("alt");
|
| | | vAllowed.put("img", img_atts);
|
| | |
|
| | | final ArrayList<String> no_atts = new ArrayList<>();
|
| | | vAllowed.put("b", no_atts);
|
| | | vAllowed.put("strong", no_atts);
|
| | | vAllowed.put("i", no_atts);
|
| | | vAllowed.put("em", no_atts);
|
| | |
|
| | | vSelfClosingTags = new String[] { "img" };
|
| | | vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" };
|
| | | vDisallowed = new String[] {};
|
| | | vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp.
|
| | | vProtocolAtts = new String[] { "src", "href" };
|
| | | vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" };
|
| | | vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" };
|
| | | stripComment = true;
|
| | | encodeQuotes = true;
|
| | | alwaysMakeTags = true;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Map-parameter configurable constructor.
|
| | | *
|
| | | * @param conf map containing configuration. keys match field names.
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public HTMLFilter(final Map<String, Object> conf)
|
| | | {
|
| | |
|
| | | assert conf.containsKey("vAllowed") : "configuration requires vAllowed";
|
| | | assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags";
|
| | | assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags";
|
| | | assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed";
|
| | | assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols";
|
| | | assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts";
|
| | | assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks";
|
| | | assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities";
|
| | |
|
| | | vAllowed = Collections.unmodifiableMap((HashMap<String, List<String>>) conf.get("vAllowed"));
|
| | | vSelfClosingTags = (String[]) conf.get("vSelfClosingTags");
|
| | | vNeedClosingTags = (String[]) conf.get("vNeedClosingTags");
|
| | | vDisallowed = (String[]) conf.get("vDisallowed");
|
| | | vAllowedProtocols = (String[]) conf.get("vAllowedProtocols");
|
| | | vProtocolAtts = (String[]) conf.get("vProtocolAtts");
|
| | | vRemoveBlanks = (String[]) conf.get("vRemoveBlanks");
|
| | | vAllowedEntities = (String[]) conf.get("vAllowedEntities");
|
| | | stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true;
|
| | | encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true;
|
| | | alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true;
|
| | | }
|
| | |
|
| | | private void reset()
|
| | | {
|
| | | vTagCounts.clear();
|
| | | }
|
| | |
|
| | | // ---------------------------------------------------------------
|
| | | // my versions of some PHP library functions
|
| | | public static String chr(final int decimal)
|
| | | {
|
| | | return String.valueOf((char) decimal);
|
| | | }
|
| | |
|
| | | public static String htmlSpecialChars(final String s)
|
| | | {
|
| | | String result = s;
|
| | | result = regexReplace(P_AMP, "&", result);
|
| | | result = regexReplace(P_QUOTE, """, result);
|
| | | result = regexReplace(P_LEFT_ARROW, "<", result);
|
| | | result = regexReplace(P_RIGHT_ARROW, ">", result);
|
| | | return result;
|
| | | }
|
| | |
|
| | | // ---------------------------------------------------------------
|
| | |
|
| | | /**
|
| | | * given a user submitted input String, filter out any invalid or restricted html.
|
| | | *
|
| | | * @param input text (i.e. submitted by a user) than may contain html
|
| | | * @return "clean" version of input, with only valid, whitelisted html elements allowed
|
| | | */
|
| | | public String filter(final String input)
|
| | | {
|
| | | reset();
|
| | | String s = input;
|
| | |
|
| | | s = escapeComments(s);
|
| | |
|
| | | s = balanceHTML(s);
|
| | |
|
| | | s = checkTags(s);
|
| | |
|
| | | s = processRemoveBlanks(s);
|
| | |
|
| | | s = validateEntities(s);
|
| | |
|
| | | return s;
|
| | | }
|
| | |
|
| | | public boolean isAlwaysMakeTags()
|
| | | {
|
| | | return alwaysMakeTags;
|
| | | }
|
| | |
|
| | | public boolean isStripComments()
|
| | | {
|
| | | return stripComment;
|
| | | }
|
| | |
|
| | | private String escapeComments(final String s)
|
| | | {
|
| | | final Matcher m = P_COMMENTS.matcher(s);
|
| | | final StringBuffer buf = new StringBuffer();
|
| | | if (m.find())
|
| | | {
|
| | | final String match = m.group(1); // (.*?)
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
|
| | | }
|
| | | m.appendTail(buf);
|
| | |
|
| | | return buf.toString();
|
| | | }
|
| | |
|
| | | private String balanceHTML(String s)
|
| | | {
|
| | | if (alwaysMakeTags)
|
| | | {
|
| | | //
|
| | | // try and form html
|
| | | //
|
| | | s = regexReplace(P_END_ARROW, "", s);
|
| | | s = regexReplace(P_BODY_TO_END, "<$1>", s);
|
| | | s = regexReplace(P_XML_CONTENT, "$1<$2", s);
|
| | |
|
| | | }
|
| | | else
|
| | | {
|
| | | //
|
| | | // escape stray brackets
|
| | | //
|
| | | s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s);
|
| | | s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s);
|
| | |
|
| | | //
|
| | | // the last regexp causes '<>' entities to appear
|
| | | // (we need to do a lookahead assertion so that the last bracket can
|
| | | // be used in the next pass of the regexp)
|
| | | //
|
| | | s = regexReplace(P_BOTH_ARROWS, "", s);
|
| | | }
|
| | |
|
| | | return s;
|
| | | }
|
| | |
|
| | | private String checkTags(String s)
|
| | | {
|
| | | Matcher m = P_TAGS.matcher(s);
|
| | |
|
| | | final StringBuffer buf = new StringBuffer();
|
| | | while (m.find())
|
| | | {
|
| | | String replaceStr = m.group(1);
|
| | | replaceStr = processTag(replaceStr);
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr));
|
| | | }
|
| | | m.appendTail(buf);
|
| | |
|
| | | // these get tallied in processTag
|
| | | // (remember to reset before subsequent calls to filter method)
|
| | | final StringBuilder sBuilder = new StringBuilder(buf.toString());
|
| | | for (String key : vTagCounts.keySet())
|
| | | {
|
| | | for (int ii = 0; ii < vTagCounts.get(key); ii++)
|
| | | {
|
| | | sBuilder.append("</").append(key).append(">");
|
| | | }
|
| | | }
|
| | | s = sBuilder.toString();
|
| | |
|
| | | return s;
|
| | | }
|
| | |
|
| | | private String processRemoveBlanks(final String s)
|
| | | {
|
| | | String result = s;
|
| | | for (String tag : vRemoveBlanks)
|
| | | {
|
| | | if (!P_REMOVE_PAIR_BLANKS.containsKey(tag))
|
| | | {
|
| | | P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">"));
|
| | | }
|
| | | result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result);
|
| | | if (!P_REMOVE_SELF_BLANKS.containsKey(tag))
|
| | | {
|
| | | P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>"));
|
| | | }
|
| | | result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result);
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | |
|
| | | private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s)
|
| | | {
|
| | | Matcher m = regex_pattern.matcher(s);
|
| | | return m.replaceAll(replacement);
|
| | | }
|
| | |
|
| | | private String processTag(final String s)
|
| | | {
|
| | | // ending tags
|
| | | Matcher m = P_END_TAG.matcher(s);
|
| | | if (m.find())
|
| | | {
|
| | | final String name = m.group(1).toLowerCase();
|
| | | if (allowed(name))
|
| | | {
|
| | | if (false == inArray(name, vSelfClosingTags))
|
| | | {
|
| | | if (vTagCounts.containsKey(name))
|
| | | {
|
| | | vTagCounts.put(name, vTagCounts.get(name) - 1);
|
| | | return "</" + name + ">";
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // starting tags
|
| | | m = P_START_TAG.matcher(s);
|
| | | if (m.find())
|
| | | {
|
| | | final String name = m.group(1).toLowerCase();
|
| | | final String body = m.group(2);
|
| | | String ending = m.group(3);
|
| | |
|
| | | // debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
|
| | | if (allowed(name))
|
| | | {
|
| | | final StringBuilder params = new StringBuilder();
|
| | |
|
| | | final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body);
|
| | | final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body);
|
| | | final List<String> paramNames = new ArrayList<>();
|
| | | final List<String> paramValues = new ArrayList<>();
|
| | | while (m2.find())
|
| | | {
|
| | | paramNames.add(m2.group(1)); // ([a-z0-9]+)
|
| | | paramValues.add(m2.group(3)); // (.*?)
|
| | | }
|
| | | while (m3.find())
|
| | | {
|
| | | paramNames.add(m3.group(1)); // ([a-z0-9]+)
|
| | | paramValues.add(m3.group(3)); // ([^\"\\s']+)
|
| | | }
|
| | |
|
| | | String paramName, paramValue;
|
| | | for (int ii = 0; ii < paramNames.size(); ii++)
|
| | | {
|
| | | paramName = paramNames.get(ii).toLowerCase();
|
| | | paramValue = paramValues.get(ii);
|
| | |
|
| | | // debug( "paramName='" + paramName + "'" );
|
| | | // debug( "paramValue='" + paramValue + "'" );
|
| | | // debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
|
| | |
|
| | | if (allowedAttribute(name, paramName))
|
| | | {
|
| | | if (inArray(paramName, vProtocolAtts))
|
| | | {
|
| | | paramValue = processParamProtocol(paramValue);
|
| | | }
|
| | | params.append(' ').append(paramName).append("=\"").append(paramValue).append("\"");
|
| | | }
|
| | | }
|
| | |
|
| | | if (inArray(name, vSelfClosingTags))
|
| | | {
|
| | | ending = " /";
|
| | | }
|
| | |
|
| | | if (inArray(name, vNeedClosingTags))
|
| | | {
|
| | | ending = "";
|
| | | }
|
| | |
|
| | | if (ending == null || ending.length() < 1)
|
| | | {
|
| | | if (vTagCounts.containsKey(name))
|
| | | {
|
| | | vTagCounts.put(name, vTagCounts.get(name) + 1);
|
| | | }
|
| | | else
|
| | | {
|
| | | vTagCounts.put(name, 1);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | ending = " /";
|
| | | }
|
| | | return "<" + name + params + ending + ">";
|
| | | }
|
| | | else
|
| | | {
|
| | | return "";
|
| | | }
|
| | | }
|
| | |
|
| | | // comments
|
| | | m = P_COMMENT.matcher(s);
|
| | | if (!stripComment && m.find())
|
| | | {
|
| | | return "<" + m.group() + ">";
|
| | | }
|
| | |
|
| | | return "";
|
| | | }
|
| | |
|
| | | private String processParamProtocol(String s)
|
| | | {
|
| | | s = decodeEntities(s);
|
| | | final Matcher m = P_PROTOCOL.matcher(s);
|
| | | if (m.find())
|
| | | {
|
| | | final String protocol = m.group(1);
|
| | | if (!inArray(protocol, vAllowedProtocols))
|
| | | {
|
| | | // bad protocol, turn into local anchor link instead
|
| | | s = "#" + s.substring(protocol.length() + 1);
|
| | | if (s.startsWith("#//"))
|
| | | {
|
| | | s = "#" + s.substring(3);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return s;
|
| | | }
|
| | |
|
| | | private String decodeEntities(String s)
|
| | | {
|
| | | StringBuffer buf = new StringBuffer();
|
| | |
|
| | | Matcher m = P_ENTITY.matcher(s);
|
| | | while (m.find())
|
| | | {
|
| | | final String match = m.group(1);
|
| | | final int decimal = Integer.decode(match).intValue();
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
| | | }
|
| | | m.appendTail(buf);
|
| | | s = buf.toString();
|
| | |
|
| | | buf = new StringBuffer();
|
| | | m = P_ENTITY_UNICODE.matcher(s);
|
| | | while (m.find())
|
| | | {
|
| | | final String match = m.group(1);
|
| | | final int decimal = Integer.valueOf(match, 16).intValue();
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
| | | }
|
| | | m.appendTail(buf);
|
| | | s = buf.toString();
|
| | |
|
| | | buf = new StringBuffer();
|
| | | m = P_ENCODE.matcher(s);
|
| | | while (m.find())
|
| | | {
|
| | | final String match = m.group(1);
|
| | | final int decimal = Integer.valueOf(match, 16).intValue();
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
| | | }
|
| | | m.appendTail(buf);
|
| | | s = buf.toString();
|
| | |
|
| | | s = validateEntities(s);
|
| | | return s;
|
| | | }
|
| | |
|
| | | private String validateEntities(final String s)
|
| | | {
|
| | | StringBuffer buf = new StringBuffer();
|
| | |
|
| | | // validate entities throughout the string
|
| | | Matcher m = P_VALID_ENTITIES.matcher(s);
|
| | | while (m.find())
|
| | | {
|
| | | final String one = m.group(1); // ([^&;]*)
|
| | | final String two = m.group(2); // (?=(;|&|$))
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
|
| | | }
|
| | | m.appendTail(buf);
|
| | |
|
| | | return encodeQuotes(buf.toString());
|
| | | }
|
| | |
|
| | | private String encodeQuotes(final String s)
|
| | | {
|
| | | if (encodeQuotes)
|
| | | {
|
| | | StringBuffer buf = new StringBuffer();
|
| | | Matcher m = P_VALID_QUOTES.matcher(s);
|
| | | while (m.find())
|
| | | {
|
| | | final String one = m.group(1); // (>|^)
|
| | | final String two = m.group(2); // ([^<]+?)
|
| | | final String three = m.group(3); // (<|$)
|
| | | // 不替换双引号为",防止json格式无效 regexReplace(P_QUOTE, """, two)
|
| | | m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three));
|
| | | }
|
| | | m.appendTail(buf);
|
| | | return buf.toString();
|
| | | }
|
| | | else
|
| | | {
|
| | | return s;
|
| | | }
|
| | | }
|
| | |
|
| | | private String checkEntity(final String preamble, final String term)
|
| | | {
|
| | |
|
| | | return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&" + preamble;
|
| | | }
|
| | |
|
| | | private boolean isValidEntity(final String entity)
|
| | | {
|
| | | return inArray(entity, vAllowedEntities);
|
| | | }
|
| | |
|
| | | private static boolean inArray(final String s, final String[] array)
|
| | | {
|
| | | for (String item : array)
|
| | | {
|
| | | if (item != null && item.equals(s))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | private boolean allowed(final String name)
|
| | | {
|
| | | return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed);
|
| | | }
|
| | |
|
| | | private boolean allowedAttribute(final String name, final String paramName)
|
| | | {
|
| | | return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName));
|
| | | }
|
| | | } |
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java 修改 |
| | |
| | | package com.ruoyi.common.utils.http; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.Charset; |
| | | import javax.servlet.ServletRequest; |
| | | import org.apache.commons.lang.exception.ExceptionUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * 通用http工具封装 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class HttpHelper |
| | | { |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class); |
| | | |
| | | public static String getBodyString(ServletRequest request) |
| | | { |
| | | StringBuilder sb = new StringBuilder(); |
| | | BufferedReader reader = null; |
| | | try (InputStream inputStream = request.getInputStream()) |
| | | { |
| | | reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); |
| | | String line = ""; |
| | | while ((line = reader.readLine()) != null) |
| | | { |
| | | sb.append(line); |
| | | } |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | LOGGER.warn("getBodyString出现问题!"); |
| | | } |
| | | finally |
| | | { |
| | | if (reader != null) |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | LOGGER.error(ExceptionUtils.getFullStackTrace(e)); |
| | | } |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | } |
| | | package com.ruoyi.common.utils.http;
|
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.nio.charset.Charset;
|
| | | import javax.servlet.ServletRequest;
|
| | | import org.apache.commons.lang3.exception.ExceptionUtils;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | /**
|
| | | * 通用http工具封装
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class HttpHelper
|
| | | {
|
| | | private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class);
|
| | |
|
| | | public static String getBodyString(ServletRequest request)
|
| | | {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | BufferedReader reader = null;
|
| | | try (InputStream inputStream = request.getInputStream())
|
| | | {
|
| | | reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
|
| | | String line = "";
|
| | | while ((line = reader.readLine()) != null)
|
| | | {
|
| | | sb.append(line);
|
| | | }
|
| | | }
|
| | | catch (IOException e)
|
| | | {
|
| | | LOGGER.warn("getBodyString出现问题!");
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (reader != null)
|
| | | {
|
| | | try
|
| | | {
|
| | | reader.close();
|
| | | }
|
| | | catch (IOException e)
|
| | | {
|
| | | LOGGER.error(ExceptionUtils.getMessage(e));
|
| | | }
|
| | | }
|
| | | }
|
| | | return sb.toString();
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java 修改 |
| | |
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.http.HttpUtils;
|
| | | import com.ruoyi.framework.config.RuoYiConfig;
|
| | |
|
| | | /**
|
| | | * 获取地址类
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java 修改 |
| | |
| | | package com.ruoyi.common.utils.poi; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
| | | import org.apache.poi.ss.usermodel.BorderStyle; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.CellStyle; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.DataValidation; |
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint; |
| | | import org.apache.poi.ss.usermodel.DataValidationHelper; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.apache.poi.ss.usermodel.FillPatternType; |
| | | import org.apache.poi.ss.usermodel.Font; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.VerticalAlignment; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.reflect.ReflectUtils; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.Type; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excels; |
| | | import com.ruoyi.framework.config.RuoYiConfig; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | |
| | | /** |
| | | * Excel相关处理 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class ExcelUtil<T> |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class); |
| | | |
| | | /** |
| | | * Excel sheet最大行数,默认65536 |
| | | */ |
| | | public static final int sheetSize = 65536; |
| | | |
| | | /** |
| | | * 工作表名称 |
| | | */ |
| | | private String sheetName; |
| | | |
| | | /** |
| | | * 导出类型(EXPORT:导出数据;IMPORT:导入模板) |
| | | */ |
| | | private Type type; |
| | | |
| | | /** |
| | | * 工作薄对象 |
| | | */ |
| | | private Workbook wb; |
| | | |
| | | /** |
| | | * 工作表对象 |
| | | */ |
| | | private Sheet sheet; |
| | | |
| | | /** |
| | | * 样式列表 |
| | | */ |
| | | private Map<String, CellStyle> styles; |
| | | |
| | | /** |
| | | * 导入导出数据列表 |
| | | */ |
| | | private List<T> list; |
| | | |
| | | /** |
| | | * 注解列表 |
| | | */ |
| | | private List<Object[]> fields; |
| | | |
| | | /** |
| | | * 实体对象 |
| | | */ |
| | | public Class<T> clazz; |
| | | |
| | | public ExcelUtil(Class<T> clazz) |
| | | { |
| | | this.clazz = clazz; |
| | | } |
| | | |
| | | public void init(List<T> list, String sheetName, Type type) |
| | | { |
| | | if (list == null) |
| | | { |
| | | list = new ArrayList<T>(); |
| | | } |
| | | this.list = list; |
| | | this.sheetName = sheetName; |
| | | this.type = type; |
| | | createExcelField(); |
| | | createWorkbook(); |
| | | } |
| | | |
| | | /** |
| | | * 对excel表单默认第一个索引名转换成list |
| | | * |
| | | * @param is 输入流 |
| | | * @return 转换后集合 |
| | | */ |
| | | public List<T> importExcel(InputStream is) throws Exception |
| | | { |
| | | return importExcel(StringUtils.EMPTY, is); |
| | | } |
| | | |
| | | /** |
| | | * 对excel表单指定表格索引名转换成list |
| | | * |
| | | * @param sheetName 表格索引名 |
| | | * @param is 输入流 |
| | | * @return 转换后集合 |
| | | */ |
| | | public List<T> importExcel(String sheetName, InputStream is) throws Exception |
| | | { |
| | | this.type = Type.IMPORT; |
| | | this.wb = WorkbookFactory.create(is); |
| | | List<T> list = new ArrayList<T>(); |
| | | Sheet sheet = null; |
| | | if (StringUtils.isNotEmpty(sheetName)) |
| | | { |
| | | // 如果指定sheet名,则取指定sheet中的内容. |
| | | sheet = wb.getSheet(sheetName); |
| | | } |
| | | else |
| | | { |
| | | // 如果传入的sheet名不存在则默认指向第1个sheet. |
| | | sheet = wb.getSheetAt(0); |
| | | } |
| | | |
| | | if (sheet == null) |
| | | { |
| | | throw new IOException("文件sheet不存在"); |
| | | } |
| | | |
| | | int rows = sheet.getPhysicalNumberOfRows(); |
| | | |
| | | if (rows > 0) |
| | | { |
| | | // 定义一个map用于存放excel列的序号和field. |
| | | Map<String, Integer> cellMap = new HashMap<String, Integer>(); |
| | | // 获取表头 |
| | | Row heard = sheet.getRow(0); |
| | | for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) |
| | | { |
| | | Cell cell = heard.getCell(i); |
| | | if (StringUtils.isNotNull(cell)) |
| | | { |
| | | String value = this.getCellValue(heard, i).toString(); |
| | | cellMap.put(value, i); |
| | | } |
| | | else |
| | | { |
| | | cellMap.put(null, i); |
| | | } |
| | | } |
| | | // 有数据时才处理 得到类的所有field. |
| | | Field[] allFields = clazz.getDeclaredFields(); |
| | | // 定义一个map用于存放列的序号和field. |
| | | Map<Integer, Field> fieldsMap = new HashMap<Integer, Field>(); |
| | | for (int col = 0; col < allFields.length; col++) |
| | | { |
| | | Field field = allFields[col]; |
| | | Excel attr = field.getAnnotation(Excel.class); |
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) |
| | | { |
| | | // 设置类的私有字段属性可访问. |
| | | field.setAccessible(true); |
| | | Integer column = cellMap.get(attr.name()); |
| | | fieldsMap.put(column, field); |
| | | } |
| | | } |
| | | for (int i = 1; i < rows; i++) |
| | | { |
| | | // 从第2行开始取数据,默认第一行是表头. |
| | | Row row = sheet.getRow(i); |
| | | T entity = null; |
| | | for (Map.Entry<Integer, Field> entry : fieldsMap.entrySet()) |
| | | { |
| | | Object val = this.getCellValue(row, entry.getKey()); |
| | | |
| | | // 如果不存在实例则新建. |
| | | entity = (entity == null ? clazz.newInstance() : entity); |
| | | // 从map中得到对应列的field. |
| | | Field field = fieldsMap.get(entry.getKey()); |
| | | // 取得类型,并根据对象类型设置值. |
| | | Class<?> fieldType = field.getType(); |
| | | if (String.class == fieldType) |
| | | { |
| | | String s = Convert.toStr(val); |
| | | if (StringUtils.endsWith(s, ".0")) |
| | | { |
| | | val = StringUtils.substringBefore(s, ".0"); |
| | | } |
| | | else |
| | | { |
| | | val = Convert.toStr(val); |
| | | } |
| | | } |
| | | else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) |
| | | { |
| | | val = Convert.toInt(val); |
| | | } |
| | | else if ((Long.TYPE == fieldType) || (Long.class == fieldType)) |
| | | { |
| | | val = Convert.toLong(val); |
| | | } |
| | | else if ((Double.TYPE == fieldType) || (Double.class == fieldType)) |
| | | { |
| | | val = Convert.toDouble(val); |
| | | } |
| | | else if ((Float.TYPE == fieldType) || (Float.class == fieldType)) |
| | | { |
| | | val = Convert.toFloat(val); |
| | | } |
| | | else if (BigDecimal.class == fieldType) |
| | | { |
| | | val = Convert.toBigDecimal(val); |
| | | } |
| | | else if (Date.class == fieldType) |
| | | { |
| | | if (val instanceof String) |
| | | { |
| | | val = DateUtils.parseDate(val); |
| | | } |
| | | else if (val instanceof Double) |
| | | { |
| | | val = DateUtil.getJavaDate((Double) val); |
| | | } |
| | | } |
| | | if (StringUtils.isNotNull(fieldType)) |
| | | { |
| | | Excel attr = field.getAnnotation(Excel.class); |
| | | String propertyName = field.getName(); |
| | | if (StringUtils.isNotEmpty(attr.targetAttr())) |
| | | { |
| | | propertyName = field.getName() + "." + attr.targetAttr(); |
| | | } |
| | | else if (StringUtils.isNotEmpty(attr.readConverterExp())) |
| | | { |
| | | val = reverseByExp(String.valueOf(val), attr.readConverterExp()); |
| | | } |
| | | ReflectUtils.invokeSetter(entity, propertyName, val); |
| | | } |
| | | } |
| | | list.add(entity); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 对list数据源将其里面的数据导入到excel表单 |
| | | * |
| | | * @param list 导出数据集合 |
| | | * @param sheetName 工作表的名称 |
| | | * @return 结果 |
| | | */ |
| | | public AjaxResult exportExcel(List<T> list, String sheetName) |
| | | { |
| | | this.init(list, sheetName, Type.EXPORT); |
| | | return exportExcel(); |
| | | } |
| | | |
| | | /** |
| | | * 对list数据源将其里面的数据导入到excel表单 |
| | | * |
| | | * @param sheetName 工作表的名称 |
| | | * @return 结果 |
| | | */ |
| | | public AjaxResult importTemplateExcel(String sheetName) |
| | | { |
| | | this.init(null, sheetName, Type.IMPORT); |
| | | return exportExcel(); |
| | | } |
| | | |
| | | /** |
| | | * 对list数据源将其里面的数据导入到excel表单 |
| | | * |
| | | * @return 结果 |
| | | */ |
| | | public AjaxResult exportExcel() |
| | | { |
| | | OutputStream out = null; |
| | | try |
| | | { |
| | | // 取出一共有多少个sheet. |
| | | double sheetNo = Math.ceil(list.size() / sheetSize); |
| | | for (int index = 0; index <= sheetNo; index++) |
| | | { |
| | | createSheet(sheetNo, index); |
| | | |
| | | // 产生一行 |
| | | Row row = sheet.createRow(0); |
| | | int column = 0; |
| | | // 写入各个字段的列头名称 |
| | | for (Object[] os : fields) |
| | | { |
| | | Excel excel = (Excel) os[1]; |
| | | this.createCell(excel, row, column++); |
| | | } |
| | | if (Type.EXPORT.equals(type)) |
| | | { |
| | | fillExcelData(index, row); |
| | | } |
| | | } |
| | | String filename = encodingFilename(sheetName); |
| | | out = new FileOutputStream(getAbsoluteFile(filename)); |
| | | wb.write(out); |
| | | return AjaxResult.success(filename); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导出Excel异常{}", e.getMessage()); |
| | | throw new CustomException("导出Excel失败,请联系网站管理员!"); |
| | | } |
| | | finally |
| | | { |
| | | if (wb != null) |
| | | { |
| | | try |
| | | { |
| | | wb.close(); |
| | | } |
| | | catch (IOException e1) |
| | | { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | if (out != null) |
| | | { |
| | | try |
| | | { |
| | | out.close(); |
| | | } |
| | | catch (IOException e1) |
| | | { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 填充excel数据 |
| | | * |
| | | * @param index 序号 |
| | | * @param row 单元格行 |
| | | */ |
| | | public void fillExcelData(int index, Row row) |
| | | { |
| | | int startNo = index * sheetSize; |
| | | int endNo = Math.min(startNo + sheetSize, list.size()); |
| | | for (int i = startNo; i < endNo; i++) |
| | | { |
| | | row = sheet.createRow(i + 1 - startNo); |
| | | // 得到导出对象. |
| | | T vo = (T) list.get(i); |
| | | int column = 0; |
| | | for (Object[] os : fields) |
| | | { |
| | | Field field = (Field) os[0]; |
| | | Excel excel = (Excel) os[1]; |
| | | // 设置实体类私有属性可访问 |
| | | field.setAccessible(true); |
| | | this.addCell(excel, row, vo, field, column++); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建表格样式 |
| | | * |
| | | * @param wb 工作薄对象 |
| | | * @return 样式列表 |
| | | */ |
| | | private Map<String, CellStyle> createStyles(Workbook wb) |
| | | { |
| | | // 写入各条记录,每条记录对应excel表中的一行 |
| | | Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | | style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderTop(BorderStyle.THIN); |
| | | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderBottom(BorderStyle.THIN); |
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | Font dataFont = wb.createFont(); |
| | | dataFont.setFontName("Arial"); |
| | | dataFont.setFontHeightInPoints((short) 10); |
| | | style.setFont(dataFont); |
| | | styles.put("data", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font headerFont = wb.createFont(); |
| | | headerFont.setFontName("Arial"); |
| | | headerFont.setFontHeightInPoints((short) 10); |
| | | headerFont.setBold(true); |
| | | headerFont.setColor(IndexedColors.WHITE.getIndex()); |
| | | style.setFont(headerFont); |
| | | styles.put("header", style); |
| | | |
| | | return styles; |
| | | } |
| | | |
| | | /** |
| | | * 创建单元格 |
| | | */ |
| | | public Cell createCell(Excel attr, Row row, int column) |
| | | { |
| | | // 创建列 |
| | | Cell cell = row.createCell(column); |
| | | // 写入列信息 |
| | | cell.setCellValue(attr.name()); |
| | | setDataValidation(attr, row, column); |
| | | cell.setCellStyle(styles.get("header")); |
| | | return cell; |
| | | } |
| | | |
| | | /** |
| | | * 设置单元格信息 |
| | | * |
| | | * @param value 单元格值 |
| | | * @param attr 注解相关 |
| | | * @param cell 单元格信息 |
| | | */ |
| | | public void setCellVo(Object value, Excel attr, Cell cell) |
| | | { |
| | | if (ColumnType.STRING == attr.cellType()) |
| | | { |
| | | cell.setCellType(CellType.NUMERIC); |
| | | cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix()); |
| | | } |
| | | else if (ColumnType.NUMERIC == attr.cellType()) |
| | | { |
| | | cell.setCellType(CellType.NUMERIC); |
| | | cell.setCellValue(Integer.parseInt(value + "")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建表格样式 |
| | | */ |
| | | public void setDataValidation(Excel attr, Row row, int column) |
| | | { |
| | | if (attr.name().indexOf("注:") >= 0) |
| | | { |
| | | sheet.setColumnWidth(column, 6000); |
| | | } |
| | | else |
| | | { |
| | | // 设置列宽 |
| | | sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); |
| | | row.setHeight((short) (attr.height() * 20)); |
| | | } |
| | | // 如果设置了提示信息则鼠标放上去提示. |
| | | if (StringUtils.isNotEmpty(attr.prompt())) |
| | | { |
| | | // 这里默认设了2-101列提示. |
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | } |
| | | // 如果设置了combo属性则本列只能选择不能输入 |
| | | if (attr.combo().length > 0) |
| | | { |
| | | // 这里默认设了2-101列只能选择不能输入. |
| | | setXSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加单元格 |
| | | */ |
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column) |
| | | { |
| | | Cell cell = null; |
| | | try |
| | | { |
| | | // 设置行高 |
| | | row.setHeight((short) (attr.height() * 20)); |
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. |
| | | if (attr.isExport()) |
| | | { |
| | | // 创建cell |
| | | cell = row.createCell(column); |
| | | cell.setCellStyle(styles.get("data")); |
| | | |
| | | // 用于读取对象中的属性 |
| | | Object value = getTargetValue(vo, field, attr); |
| | | String dateFormat = attr.dateFormat(); |
| | | String readConverterExp = attr.readConverterExp(); |
| | | if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); |
| | | } |
| | | else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); |
| | | } |
| | | else |
| | | { |
| | | // 设置列类型 |
| | | setCellVo(value, attr, cell); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导出Excel失败{}", e); |
| | | } |
| | | return cell; |
| | | } |
| | | |
| | | /** |
| | | * 设置 POI XSSFSheet 单元格提示 |
| | | * |
| | | * @param sheet 表单 |
| | | * @param promptTitle 提示标题 |
| | | * @param promptContent 提示内容 |
| | | * @param firstRow 开始行 |
| | | * @param endRow 结束行 |
| | | * @param firstCol 开始列 |
| | | * @param endCol 结束列 |
| | | */ |
| | | public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | int firstCol, int endCol) |
| | | { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | DataValidationConstraint constraint = helper.createCustomConstraint("DD1"); |
| | | CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | dataValidation.createPromptBox(promptTitle, promptContent); |
| | | dataValidation.setShowPromptBox(true); |
| | | sheet.addValidationData(dataValidation); |
| | | } |
| | | |
| | | /** |
| | | * 设置某些列的值只能输入预制的数据,显示下拉框. |
| | | * |
| | | * @param sheet 要设置的sheet. |
| | | * @param textlist 下拉框显示的内容 |
| | | * @param firstRow 开始行 |
| | | * @param endRow 结束行 |
| | | * @param firstCol 开始列 |
| | | * @param endCol 结束列 |
| | | * @return 设置好的sheet. |
| | | */ |
| | | public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) |
| | | { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | // 加载下拉列表内容 |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist); |
| | | // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 |
| | | CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); |
| | | // 数据有效性对象 |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | // 处理Excel兼容性问题 |
| | | if (dataValidation instanceof XSSFDataValidation) |
| | | { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | else |
| | | { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | } |
| | | |
| | | sheet.addValidationData(dataValidation); |
| | | } |
| | | |
| | | /** |
| | | * 解析导出值 0=男,1=女,2=未知 |
| | | * |
| | | * @param propertyValue 参数值 |
| | | * @param converterExp 翻译注解 |
| | | * @return 解析后值 |
| | | * @throws Exception |
| | | */ |
| | | public static String convertByExp(String propertyValue, String converterExp) throws Exception |
| | | { |
| | | try |
| | | { |
| | | String[] convertSource = converterExp.split(","); |
| | | for (String item : convertSource) |
| | | { |
| | | String[] itemArray = item.split("="); |
| | | if (itemArray[0].equals(propertyValue)) |
| | | { |
| | | return itemArray[1]; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw e; |
| | | } |
| | | return propertyValue; |
| | | } |
| | | |
| | | /** |
| | | * 反向解析值 男=0,女=1,未知=2 |
| | | * |
| | | * @param propertyValue 参数值 |
| | | * @param converterExp 翻译注解 |
| | | * @return 解析后值 |
| | | * @throws Exception |
| | | */ |
| | | public static String reverseByExp(String propertyValue, String converterExp) throws Exception |
| | | { |
| | | try |
| | | { |
| | | String[] convertSource = converterExp.split(","); |
| | | for (String item : convertSource) |
| | | { |
| | | String[] itemArray = item.split("="); |
| | | if (itemArray[1].equals(propertyValue)) |
| | | { |
| | | return itemArray[0]; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw e; |
| | | } |
| | | return propertyValue; |
| | | } |
| | | |
| | | /** |
| | | * 编码文件名 |
| | | */ |
| | | public String encodingFilename(String filename) |
| | | { |
| | | filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx"; |
| | | return filename; |
| | | } |
| | | |
| | | /** |
| | | * 获取下载路径 |
| | | * |
| | | * @param filename 文件名称 |
| | | */ |
| | | public String getAbsoluteFile(String filename) |
| | | { |
| | | String downloadPath = RuoYiConfig.getDownloadPath() + filename; |
| | | File desc = new File(downloadPath); |
| | | if (!desc.getParentFile().exists()) |
| | | { |
| | | desc.getParentFile().mkdirs(); |
| | | } |
| | | return downloadPath; |
| | | } |
| | | |
| | | /** |
| | | * 获取bean中的属性值 |
| | | * |
| | | * @param vo 实体对象 |
| | | * @param field 字段 |
| | | * @param excel 注解 |
| | | * @return 最终的属性值 |
| | | * @throws Exception |
| | | */ |
| | | private Object getTargetValue(T vo, Field field, Excel excel) throws Exception |
| | | { |
| | | Object o = field.get(vo); |
| | | if (StringUtils.isNotEmpty(excel.targetAttr())) |
| | | { |
| | | String target = excel.targetAttr(); |
| | | if (target.indexOf(".") > -1) |
| | | { |
| | | String[] targets = target.split("[.]"); |
| | | for (String name : targets) |
| | | { |
| | | o = getValue(o, name); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | o = getValue(o, target); |
| | | } |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | /** |
| | | * 以类的属性的get方法方法形式获取值 |
| | | * |
| | | * @param o |
| | | * @param name |
| | | * @return value |
| | | * @throws Exception |
| | | */ |
| | | private Object getValue(Object o, String name) throws Exception |
| | | { |
| | | if (StringUtils.isNotEmpty(name)) |
| | | { |
| | | Class<?> clazz = o.getClass(); |
| | | String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1); |
| | | Method method = clazz.getMethod(methodName); |
| | | o = method.invoke(o); |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | /** |
| | | * 得到所有定义字段 |
| | | */ |
| | | private void createExcelField() |
| | | { |
| | | this.fields = new ArrayList<Object[]>(); |
| | | List<Field> tempFields = new ArrayList<>(); |
| | | tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); |
| | | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); |
| | | for (Field field : tempFields) |
| | | { |
| | | // 单注解 |
| | | if (field.isAnnotationPresent(Excel.class)) |
| | | { |
| | | putToField(field, field.getAnnotation(Excel.class)); |
| | | } |
| | | |
| | | // 多注解 |
| | | if (field.isAnnotationPresent(Excels.class)) |
| | | { |
| | | Excels attrs = field.getAnnotation(Excels.class); |
| | | Excel[] excels = attrs.value(); |
| | | for (Excel excel : excels) |
| | | { |
| | | putToField(field, excel); |
| | | } |
| | | } |
| | | } |
| | | this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * 放到字段集合中 |
| | | */ |
| | | private void putToField(Field field, Excel attr) |
| | | { |
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) |
| | | { |
| | | this.fields.add(new Object[] { field, attr }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建一个工作簿 |
| | | */ |
| | | public void createWorkbook() |
| | | { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | } |
| | | |
| | | /** |
| | | * 创建工作表 |
| | | * |
| | | * @param sheetNo sheet数量 |
| | | * @param index 序号 |
| | | */ |
| | | public void createSheet(double sheetNo, int index) |
| | | { |
| | | this.sheet = wb.createSheet(); |
| | | this.styles = createStyles(wb); |
| | | // 设置工作表的名称. |
| | | if (sheetNo == 0) |
| | | { |
| | | wb.setSheetName(index, sheetName); |
| | | } |
| | | else |
| | | { |
| | | wb.setSheetName(index, sheetName + index); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取单元格值 |
| | | * |
| | | * @param row 获取的行 |
| | | * @param column 获取单元格列号 |
| | | * @return 单元格值 |
| | | */ |
| | | public Object getCellValue(Row row, int column) |
| | | { |
| | | if (row == null) |
| | | { |
| | | return row; |
| | | } |
| | | Object val = ""; |
| | | try |
| | | { |
| | | Cell cell = row.getCell(column); |
| | | if (StringUtils.isNotNull(cell)) |
| | | { |
| | | if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA) |
| | | { |
| | | val = cell.getNumericCellValue(); |
| | | if (HSSFDateUtil.isCellDateFormatted(cell)) |
| | | { |
| | | val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 |
| | | } |
| | | else |
| | | { |
| | | if ((Double) val % 1 > 0) |
| | | { |
| | | val = new DecimalFormat("0.00").format(val); |
| | | } |
| | | else |
| | | { |
| | | val = new DecimalFormat("0").format(val); |
| | | } |
| | | } |
| | | } |
| | | else if (cell.getCellTypeEnum() == CellType.STRING) |
| | | { |
| | | val = cell.getStringCellValue(); |
| | | } |
| | | else if (cell.getCellTypeEnum() == CellType.BOOLEAN) |
| | | { |
| | | val = cell.getBooleanCellValue(); |
| | | } |
| | | else if (cell.getCellTypeEnum() == CellType.ERROR) |
| | | { |
| | | val = cell.getErrorCellValue(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return val; |
| | | } |
| | | return val; |
| | | } |
| | | package com.ruoyi.common.utils.poi;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.FileOutputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.OutputStream;
|
| | | import java.lang.reflect.Field;
|
| | | import java.lang.reflect.Method;
|
| | | import java.math.BigDecimal;
|
| | | import java.text.DecimalFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.UUID;
|
| | | import java.util.stream.Collectors;
|
| | | import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
| | | import org.apache.poi.ss.usermodel.BorderStyle;
|
| | | import org.apache.poi.ss.usermodel.Cell;
|
| | | import org.apache.poi.ss.usermodel.CellStyle;
|
| | | import org.apache.poi.ss.usermodel.CellType;
|
| | | import org.apache.poi.ss.usermodel.DataValidation;
|
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
| | | import org.apache.poi.ss.usermodel.DataValidationHelper;
|
| | | import org.apache.poi.ss.usermodel.DateUtil;
|
| | | import org.apache.poi.ss.usermodel.FillPatternType;
|
| | | import org.apache.poi.ss.usermodel.Font;
|
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
| | | import org.apache.poi.ss.usermodel.IndexedColors;
|
| | | import org.apache.poi.ss.usermodel.Row;
|
| | | import org.apache.poi.ss.usermodel.Sheet;
|
| | | import org.apache.poi.ss.usermodel.VerticalAlignment;
|
| | | import org.apache.poi.ss.usermodel.Workbook;
|
| | | import org.apache.poi.ss.usermodel.WorkbookFactory;
|
| | | import org.apache.poi.ss.util.CellRangeAddressList;
|
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.annotation.Excel.Type;
|
| | | import com.ruoyi.common.annotation.Excels;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.reflect.ReflectUtils;
|
| | |
|
| | | /**
|
| | | * Excel相关处理
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class ExcelUtil<T>
|
| | | {
|
| | | private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
| | |
|
| | | /**
|
| | | * Excel sheet最大行数,默认65536
|
| | | */
|
| | | public static final int sheetSize = 65536;
|
| | |
|
| | | /**
|
| | | * 工作表名称
|
| | | */
|
| | | private String sheetName;
|
| | |
|
| | | /**
|
| | | * 导出类型(EXPORT:导出数据;IMPORT:导入模板)
|
| | | */
|
| | | private Type type;
|
| | |
|
| | | /**
|
| | | * 工作薄对象
|
| | | */
|
| | | private Workbook wb;
|
| | |
|
| | | /**
|
| | | * 工作表对象
|
| | | */
|
| | | private Sheet sheet;
|
| | |
|
| | | /**
|
| | | * 样式列表
|
| | | */
|
| | | private Map<String, CellStyle> styles;
|
| | |
|
| | | /**
|
| | | * 导入导出数据列表
|
| | | */
|
| | | private List<T> list;
|
| | |
|
| | | /**
|
| | | * 注解列表
|
| | | */
|
| | | private List<Object[]> fields;
|
| | |
|
| | | /**
|
| | | * 实体对象
|
| | | */
|
| | | public Class<T> clazz;
|
| | |
|
| | | public ExcelUtil(Class<T> clazz)
|
| | | {
|
| | | this.clazz = clazz;
|
| | | }
|
| | |
|
| | | public void init(List<T> list, String sheetName, Type type)
|
| | | {
|
| | | if (list == null)
|
| | | {
|
| | | list = new ArrayList<T>();
|
| | | }
|
| | | this.list = list;
|
| | | this.sheetName = sheetName;
|
| | | this.type = type;
|
| | | createExcelField();
|
| | | createWorkbook();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对excel表单默认第一个索引名转换成list
|
| | | * |
| | | * @param is 输入流
|
| | | * @return 转换后集合
|
| | | */
|
| | | public List<T> importExcel(InputStream is) throws Exception
|
| | | {
|
| | | return importExcel(StringUtils.EMPTY, is);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对excel表单指定表格索引名转换成list
|
| | | * |
| | | * @param sheetName 表格索引名
|
| | | * @param is 输入流
|
| | | * @return 转换后集合
|
| | | */
|
| | | public List<T> importExcel(String sheetName, InputStream is) throws Exception
|
| | | {
|
| | | this.type = Type.IMPORT;
|
| | | this.wb = WorkbookFactory.create(is);
|
| | | List<T> list = new ArrayList<T>();
|
| | | Sheet sheet = null;
|
| | | if (StringUtils.isNotEmpty(sheetName))
|
| | | {
|
| | | // 如果指定sheet名,则取指定sheet中的内容.
|
| | | sheet = wb.getSheet(sheetName);
|
| | | }
|
| | | else
|
| | | {
|
| | | // 如果传入的sheet名不存在则默认指向第1个sheet.
|
| | | sheet = wb.getSheetAt(0);
|
| | | }
|
| | |
|
| | | if (sheet == null)
|
| | | {
|
| | | throw new IOException("文件sheet不存在");
|
| | | }
|
| | |
|
| | | int rows = sheet.getPhysicalNumberOfRows();
|
| | |
|
| | | if (rows > 0)
|
| | | {
|
| | | // 定义一个map用于存放excel列的序号和field.
|
| | | Map<String, Integer> cellMap = new HashMap<String, Integer>();
|
| | | // 获取表头
|
| | | Row heard = sheet.getRow(0);
|
| | | for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
|
| | | {
|
| | | Cell cell = heard.getCell(i);
|
| | | if (StringUtils.isNotNull(cell))
|
| | | {
|
| | | String value = this.getCellValue(heard, i).toString();
|
| | | cellMap.put(value, i);
|
| | | }
|
| | | else
|
| | | {
|
| | | cellMap.put(null, i);
|
| | | }
|
| | | }
|
| | | // 有数据时才处理 得到类的所有field.
|
| | | Field[] allFields = clazz.getDeclaredFields();
|
| | | // 定义一个map用于存放列的序号和field.
|
| | | Map<Integer, Field> fieldsMap = new HashMap<Integer, Field>();
|
| | | for (int col = 0; col < allFields.length; col++)
|
| | | {
|
| | | Field field = allFields[col];
|
| | | Excel attr = field.getAnnotation(Excel.class);
|
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
| | | {
|
| | | // 设置类的私有字段属性可访问.
|
| | | field.setAccessible(true);
|
| | | Integer column = cellMap.get(attr.name());
|
| | | fieldsMap.put(column, field);
|
| | | }
|
| | | }
|
| | | for (int i = 1; i < rows; i++)
|
| | | {
|
| | | // 从第2行开始取数据,默认第一行是表头.
|
| | | Row row = sheet.getRow(i);
|
| | | T entity = null;
|
| | | for (Map.Entry<Integer, Field> entry : fieldsMap.entrySet())
|
| | | {
|
| | | Object val = this.getCellValue(row, entry.getKey());
|
| | |
|
| | | // 如果不存在实例则新建.
|
| | | entity = (entity == null ? clazz.newInstance() : entity);
|
| | | // 从map中得到对应列的field.
|
| | | Field field = fieldsMap.get(entry.getKey());
|
| | | // 取得类型,并根据对象类型设置值.
|
| | | Class<?> fieldType = field.getType();
|
| | | if (String.class == fieldType)
|
| | | {
|
| | | String s = Convert.toStr(val);
|
| | | if (StringUtils.endsWith(s, ".0"))
|
| | | {
|
| | | val = StringUtils.substringBefore(s, ".0");
|
| | | }
|
| | | else
|
| | | {
|
| | | val = Convert.toStr(val);
|
| | | }
|
| | | }
|
| | | else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType))
|
| | | {
|
| | | val = Convert.toInt(val);
|
| | | }
|
| | | else if ((Long.TYPE == fieldType) || (Long.class == fieldType))
|
| | | {
|
| | | val = Convert.toLong(val);
|
| | | }
|
| | | else if ((Double.TYPE == fieldType) || (Double.class == fieldType))
|
| | | {
|
| | | val = Convert.toDouble(val);
|
| | | }
|
| | | else if ((Float.TYPE == fieldType) || (Float.class == fieldType))
|
| | | {
|
| | | val = Convert.toFloat(val);
|
| | | }
|
| | | else if (BigDecimal.class == fieldType)
|
| | | {
|
| | | val = Convert.toBigDecimal(val);
|
| | | }
|
| | | else if (Date.class == fieldType)
|
| | | {
|
| | | if (val instanceof String)
|
| | | {
|
| | | val = DateUtils.parseDate(val);
|
| | | }
|
| | | else if (val instanceof Double)
|
| | | {
|
| | | val = DateUtil.getJavaDate((Double) val);
|
| | | }
|
| | | }
|
| | | if (StringUtils.isNotNull(fieldType))
|
| | | {
|
| | | Excel attr = field.getAnnotation(Excel.class);
|
| | | String propertyName = field.getName();
|
| | | if (StringUtils.isNotEmpty(attr.targetAttr()))
|
| | | {
|
| | | propertyName = field.getName() + "." + attr.targetAttr();
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
| | | {
|
| | | val = reverseByExp(String.valueOf(val), attr.readConverterExp());
|
| | | }
|
| | | ReflectUtils.invokeSetter(entity, propertyName, val);
|
| | | }
|
| | | }
|
| | | list.add(entity);
|
| | | }
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对list数据源将其里面的数据导入到excel表单
|
| | | * |
| | | * @param list 导出数据集合
|
| | | * @param sheetName 工作表的名称
|
| | | * @return 结果
|
| | | */
|
| | | public AjaxResult exportExcel(List<T> list, String sheetName)
|
| | | {
|
| | | this.init(list, sheetName, Type.EXPORT);
|
| | | return exportExcel();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对list数据源将其里面的数据导入到excel表单
|
| | | * |
| | | * @param sheetName 工作表的名称
|
| | | * @return 结果
|
| | | */
|
| | | public AjaxResult importTemplateExcel(String sheetName)
|
| | | {
|
| | | this.init(null, sheetName, Type.IMPORT);
|
| | | return exportExcel();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对list数据源将其里面的数据导入到excel表单
|
| | | * |
| | | * @return 结果
|
| | | */
|
| | | public AjaxResult exportExcel()
|
| | | {
|
| | | OutputStream out = null;
|
| | | try
|
| | | {
|
| | | // 取出一共有多少个sheet.
|
| | | double sheetNo = Math.ceil(list.size() / sheetSize);
|
| | | for (int index = 0; index <= sheetNo; index++)
|
| | | {
|
| | | createSheet(sheetNo, index);
|
| | |
|
| | | // 产生一行
|
| | | Row row = sheet.createRow(0);
|
| | | int column = 0;
|
| | | // 写入各个字段的列头名称
|
| | | for (Object[] os : fields)
|
| | | {
|
| | | Excel excel = (Excel) os[1];
|
| | | this.createCell(excel, row, column++);
|
| | | }
|
| | | if (Type.EXPORT.equals(type))
|
| | | {
|
| | | fillExcelData(index, row);
|
| | | }
|
| | | }
|
| | | String filename = encodingFilename(sheetName);
|
| | | out = new FileOutputStream(getAbsoluteFile(filename));
|
| | | wb.write(out);
|
| | | return AjaxResult.success(filename);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("导出Excel异常{}", e.getMessage());
|
| | | throw new CustomException("导出Excel失败,请联系网站管理员!");
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (wb != null)
|
| | | {
|
| | | try
|
| | | {
|
| | | wb.close();
|
| | | }
|
| | | catch (IOException e1)
|
| | | {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | if (out != null)
|
| | | {
|
| | | try
|
| | | {
|
| | | out.close();
|
| | | }
|
| | | catch (IOException e1)
|
| | | {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 填充excel数据
|
| | | * |
| | | * @param index 序号
|
| | | * @param row 单元格行
|
| | | */
|
| | | public void fillExcelData(int index, Row row)
|
| | | {
|
| | | int startNo = index * sheetSize;
|
| | | int endNo = Math.min(startNo + sheetSize, list.size());
|
| | | for (int i = startNo; i < endNo; i++)
|
| | | {
|
| | | row = sheet.createRow(i + 1 - startNo);
|
| | | // 得到导出对象.
|
| | | T vo = (T) list.get(i);
|
| | | int column = 0;
|
| | | for (Object[] os : fields)
|
| | | {
|
| | | Field field = (Field) os[0];
|
| | | Excel excel = (Excel) os[1];
|
| | | // 设置实体类私有属性可访问
|
| | | field.setAccessible(true);
|
| | | this.addCell(excel, row, vo, field, column++);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建表格样式
|
| | | * |
| | | * @param wb 工作薄对象
|
| | | * @return 样式列表
|
| | | */
|
| | | private Map<String, CellStyle> createStyles(Workbook wb)
|
| | | {
|
| | | // 写入各条记录,每条记录对应excel表中的一行
|
| | | Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
|
| | | CellStyle style = wb.createCellStyle();
|
| | | style.setAlignment(HorizontalAlignment.CENTER);
|
| | | style.setVerticalAlignment(VerticalAlignment.CENTER);
|
| | | style.setBorderRight(BorderStyle.THIN);
|
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
| | | style.setBorderLeft(BorderStyle.THIN);
|
| | | style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
| | | style.setBorderTop(BorderStyle.THIN);
|
| | | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
| | | style.setBorderBottom(BorderStyle.THIN);
|
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
| | | Font dataFont = wb.createFont();
|
| | | dataFont.setFontName("Arial");
|
| | | dataFont.setFontHeightInPoints((short) 10);
|
| | | style.setFont(dataFont);
|
| | | styles.put("data", style);
|
| | |
|
| | | style = wb.createCellStyle();
|
| | | style.cloneStyleFrom(styles.get("data"));
|
| | | style.setAlignment(HorizontalAlignment.CENTER);
|
| | | style.setVerticalAlignment(VerticalAlignment.CENTER);
|
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
| | | Font headerFont = wb.createFont();
|
| | | headerFont.setFontName("Arial");
|
| | | headerFont.setFontHeightInPoints((short) 10);
|
| | | headerFont.setBold(true);
|
| | | headerFont.setColor(IndexedColors.WHITE.getIndex());
|
| | | style.setFont(headerFont);
|
| | | styles.put("header", style);
|
| | |
|
| | | return styles;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建单元格
|
| | | */
|
| | | public Cell createCell(Excel attr, Row row, int column)
|
| | | {
|
| | | // 创建列
|
| | | Cell cell = row.createCell(column);
|
| | | // 写入列信息
|
| | | cell.setCellValue(attr.name());
|
| | | setDataValidation(attr, row, column);
|
| | | cell.setCellStyle(styles.get("header"));
|
| | | return cell;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置单元格信息
|
| | | * |
| | | * @param value 单元格值
|
| | | * @param attr 注解相关
|
| | | * @param cell 单元格信息
|
| | | */
|
| | | public void setCellVo(Object value, Excel attr, Cell cell)
|
| | | {
|
| | | if (ColumnType.STRING == attr.cellType())
|
| | | {
|
| | | cell.setCellType(CellType.NUMERIC);
|
| | | cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix());
|
| | | }
|
| | | else if (ColumnType.NUMERIC == attr.cellType())
|
| | | {
|
| | | cell.setCellType(CellType.NUMERIC);
|
| | | cell.setCellValue(Integer.parseInt(value + ""));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建表格样式
|
| | | */
|
| | | public void setDataValidation(Excel attr, Row row, int column)
|
| | | {
|
| | | if (attr.name().indexOf("注:") >= 0)
|
| | | {
|
| | | sheet.setColumnWidth(column, 6000);
|
| | | }
|
| | | else
|
| | | {
|
| | | // 设置列宽
|
| | | sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
| | | row.setHeight((short) (attr.height() * 20));
|
| | | }
|
| | | // 如果设置了提示信息则鼠标放上去提示.
|
| | | if (StringUtils.isNotEmpty(attr.prompt()))
|
| | | {
|
| | | // 这里默认设了2-101列提示.
|
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
|
| | | }
|
| | | // 如果设置了combo属性则本列只能选择不能输入
|
| | | if (attr.combo().length > 0)
|
| | | {
|
| | | // 这里默认设了2-101列只能选择不能输入.
|
| | | setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加单元格
|
| | | */
|
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column)
|
| | | {
|
| | | Cell cell = null;
|
| | | try
|
| | | {
|
| | | // 设置行高
|
| | | row.setHeight((short) (attr.height() * 20));
|
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
|
| | | if (attr.isExport())
|
| | | {
|
| | | // 创建cell
|
| | | cell = row.createCell(column);
|
| | | cell.setCellStyle(styles.get("data"));
|
| | |
|
| | | // 用于读取对象中的属性
|
| | | Object value = getTargetValue(vo, field, attr);
|
| | | String dateFormat = attr.dateFormat();
|
| | | String readConverterExp = attr.readConverterExp();
|
| | | if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
| | | {
|
| | | cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
| | | {
|
| | | cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp));
|
| | | }
|
| | | else
|
| | | {
|
| | | // 设置列类型
|
| | | setCellVo(value, attr, cell);
|
| | | }
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("导出Excel失败{}", e);
|
| | | }
|
| | | return cell;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置 POI XSSFSheet 单元格提示
|
| | | * |
| | | * @param sheet 表单
|
| | | * @param promptTitle 提示标题
|
| | | * @param promptContent 提示内容
|
| | | * @param firstRow 开始行
|
| | | * @param endRow 结束行
|
| | | * @param firstCol 开始列
|
| | | * @param endCol 结束列
|
| | | */
|
| | | public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
|
| | | int firstCol, int endCol)
|
| | | {
|
| | | DataValidationHelper helper = sheet.getDataValidationHelper();
|
| | | DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
|
| | | CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
| | | DataValidation dataValidation = helper.createValidation(constraint, regions);
|
| | | dataValidation.createPromptBox(promptTitle, promptContent);
|
| | | dataValidation.setShowPromptBox(true);
|
| | | sheet.addValidationData(dataValidation);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置某些列的值只能输入预制的数据,显示下拉框.
|
| | | * |
| | | * @param sheet 要设置的sheet.
|
| | | * @param textlist 下拉框显示的内容
|
| | | * @param firstRow 开始行
|
| | | * @param endRow 结束行
|
| | | * @param firstCol 开始列
|
| | | * @param endCol 结束列
|
| | | * @return 设置好的sheet.
|
| | | */
|
| | | public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol)
|
| | | {
|
| | | DataValidationHelper helper = sheet.getDataValidationHelper();
|
| | | // 加载下拉列表内容
|
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
|
| | | // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
| | | CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
| | | // 数据有效性对象
|
| | | DataValidation dataValidation = helper.createValidation(constraint, regions);
|
| | | // 处理Excel兼容性问题
|
| | | if (dataValidation instanceof XSSFDataValidation)
|
| | | {
|
| | | dataValidation.setSuppressDropDownArrow(true);
|
| | | dataValidation.setShowErrorBox(true);
|
| | | }
|
| | | else
|
| | | {
|
| | | dataValidation.setSuppressDropDownArrow(false);
|
| | | }
|
| | |
|
| | | sheet.addValidationData(dataValidation);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 解析导出值 0=男,1=女,2=未知
|
| | | * |
| | | * @param propertyValue 参数值
|
| | | * @param converterExp 翻译注解
|
| | | * @return 解析后值
|
| | | * @throws Exception
|
| | | */
|
| | | public static String convertByExp(String propertyValue, String converterExp) throws Exception
|
| | | {
|
| | | try
|
| | | {
|
| | | String[] convertSource = converterExp.split(",");
|
| | | for (String item : convertSource)
|
| | | {
|
| | | String[] itemArray = item.split("=");
|
| | | if (itemArray[0].equals(propertyValue))
|
| | | {
|
| | | return itemArray[1];
|
| | | }
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | throw e;
|
| | | }
|
| | | return propertyValue;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 反向解析值 男=0,女=1,未知=2
|
| | | * |
| | | * @param propertyValue 参数值
|
| | | * @param converterExp 翻译注解
|
| | | * @return 解析后值
|
| | | * @throws Exception
|
| | | */
|
| | | public static String reverseByExp(String propertyValue, String converterExp) throws Exception
|
| | | {
|
| | | try
|
| | | {
|
| | | String[] convertSource = converterExp.split(",");
|
| | | for (String item : convertSource)
|
| | | {
|
| | | String[] itemArray = item.split("=");
|
| | | if (itemArray[1].equals(propertyValue))
|
| | | {
|
| | | return itemArray[0];
|
| | | }
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | throw e;
|
| | | }
|
| | | return propertyValue;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 编码文件名
|
| | | */
|
| | | public String encodingFilename(String filename)
|
| | | {
|
| | | filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
|
| | | return filename;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取下载路径
|
| | | * |
| | | * @param filename 文件名称
|
| | | */
|
| | | public String getAbsoluteFile(String filename)
|
| | | {
|
| | | String downloadPath = RuoYiConfig.getDownloadPath() + filename;
|
| | | File desc = new File(downloadPath);
|
| | | if (!desc.getParentFile().exists())
|
| | | {
|
| | | desc.getParentFile().mkdirs();
|
| | | }
|
| | | return downloadPath;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取bean中的属性值
|
| | | * |
| | | * @param vo 实体对象
|
| | | * @param field 字段
|
| | | * @param excel 注解
|
| | | * @return 最终的属性值
|
| | | * @throws Exception
|
| | | */
|
| | | private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
|
| | | {
|
| | | Object o = field.get(vo);
|
| | | if (StringUtils.isNotEmpty(excel.targetAttr()))
|
| | | {
|
| | | String target = excel.targetAttr();
|
| | | if (target.indexOf(".") > -1)
|
| | | {
|
| | | String[] targets = target.split("[.]");
|
| | | for (String name : targets)
|
| | | {
|
| | | o = getValue(o, name);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | o = getValue(o, target);
|
| | | }
|
| | | }
|
| | | return o;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 以类的属性的get方法方法形式获取值
|
| | | * |
| | | * @param o
|
| | | * @param name
|
| | | * @return value
|
| | | * @throws Exception
|
| | | */
|
| | | private Object getValue(Object o, String name) throws Exception
|
| | | {
|
| | | if (StringUtils.isNotEmpty(name))
|
| | | {
|
| | | Class<?> clazz = o.getClass();
|
| | | String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
|
| | | Method method = clazz.getMethod(methodName);
|
| | | o = method.invoke(o);
|
| | | }
|
| | | return o;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 得到所有定义字段
|
| | | */
|
| | | private void createExcelField()
|
| | | {
|
| | | this.fields = new ArrayList<Object[]>();
|
| | | List<Field> tempFields = new ArrayList<>();
|
| | | tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
| | | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
| | | for (Field field : tempFields)
|
| | | {
|
| | | // 单注解
|
| | | if (field.isAnnotationPresent(Excel.class))
|
| | | {
|
| | | putToField(field, field.getAnnotation(Excel.class));
|
| | | }
|
| | |
|
| | | // 多注解
|
| | | if (field.isAnnotationPresent(Excels.class))
|
| | | {
|
| | | Excels attrs = field.getAnnotation(Excels.class);
|
| | | Excel[] excels = attrs.value();
|
| | | for (Excel excel : excels)
|
| | | {
|
| | | putToField(field, excel);
|
| | | }
|
| | | }
|
| | | }
|
| | | this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList());
|
| | | }
|
| | |
|
| | | /**
|
| | | * 放到字段集合中
|
| | | */
|
| | | private void putToField(Field field, Excel attr)
|
| | | {
|
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
| | | {
|
| | | this.fields.add(new Object[] { field, attr });
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建一个工作簿
|
| | | */
|
| | | public void createWorkbook()
|
| | | {
|
| | | this.wb = new SXSSFWorkbook(500);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建工作表
|
| | | * |
| | | * @param sheetNo sheet数量
|
| | | * @param index 序号
|
| | | */
|
| | | public void createSheet(double sheetNo, int index)
|
| | | {
|
| | | this.sheet = wb.createSheet();
|
| | | this.styles = createStyles(wb);
|
| | | // 设置工作表的名称.
|
| | | if (sheetNo == 0)
|
| | | {
|
| | | wb.setSheetName(index, sheetName);
|
| | | }
|
| | | else
|
| | | {
|
| | | wb.setSheetName(index, sheetName + index);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取单元格值
|
| | | * |
| | | * @param row 获取的行
|
| | | * @param column 获取单元格列号
|
| | | * @return 单元格值
|
| | | */
|
| | | public Object getCellValue(Row row, int column)
|
| | | {
|
| | | if (row == null)
|
| | | {
|
| | | return row;
|
| | | }
|
| | | Object val = "";
|
| | | try
|
| | | {
|
| | | Cell cell = row.getCell(column);
|
| | | if (StringUtils.isNotNull(cell))
|
| | | {
|
| | | if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA)
|
| | | {
|
| | | val = cell.getNumericCellValue();
|
| | | if (HSSFDateUtil.isCellDateFormatted(cell))
|
| | | {
|
| | | val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换
|
| | | }
|
| | | else
|
| | | {
|
| | | if ((Double) val % 1 > 0)
|
| | | {
|
| | | val = new DecimalFormat("0.00").format(val);
|
| | | }
|
| | | else
|
| | | {
|
| | | val = new DecimalFormat("0").format(val);
|
| | | }
|
| | | }
|
| | | }
|
| | | else if (cell.getCellTypeEnum() == CellType.STRING)
|
| | | {
|
| | | val = cell.getStringCellValue();
|
| | | }
|
| | | else if (cell.getCellTypeEnum() == CellType.BOOLEAN)
|
| | | {
|
| | | val = cell.getBooleanCellValue();
|
| | | }
|
| | | else if (cell.getCellTypeEnum() == CellType.ERROR)
|
| | | {
|
| | | val = cell.getErrorCellValue();
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | return val;
|
| | | }
|
| | | return val;
|
| | | }
|
| | | } |
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/reflect/ReflectUtils.java 修改 |
| | |
| | | package com.ruoyi.common.utils.reflect; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Modifier; |
| | | import java.lang.reflect.ParameterizedType; |
| | | import java.lang.reflect.Type; |
| | | import java.util.Date; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.commons.lang3.Validate; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | |
| | | /** |
| | | * 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数. |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | public class ReflectUtils |
| | | { |
| | | private static final String SETTER_PREFIX = "set"; |
| | | |
| | | private static final String GETTER_PREFIX = "get"; |
| | | |
| | | private static final String CGLIB_CLASS_SEPARATOR = "$$"; |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class); |
| | | |
| | | /** |
| | | * 调用Getter方法. |
| | | * 支持多级,如:对象名.对象名.方法 |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeGetter(Object obj, String propertyName) |
| | | { |
| | | Object object = obj; |
| | | for (String name : StringUtils.split(propertyName, ".")) |
| | | { |
| | | String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); |
| | | object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); |
| | | } |
| | | return (E) object; |
| | | } |
| | | |
| | | /** |
| | | * 调用Setter方法, 仅匹配方法名。 |
| | | * 支持多级,如:对象名.对象名.方法 |
| | | */ |
| | | public static <E> void invokeSetter(Object obj, String propertyName, E value) |
| | | { |
| | | Object object = obj; |
| | | String[] names = StringUtils.split(propertyName, "."); |
| | | for (int i = 0; i < names.length; i++) |
| | | { |
| | | if (i < names.length - 1) |
| | | { |
| | | String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); |
| | | object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); |
| | | } |
| | | else |
| | | { |
| | | String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); |
| | | invokeMethodByName(object, setterMethodName, new Object[] { value }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E getFieldValue(final Object obj, final String fieldName) |
| | | { |
| | | Field field = getAccessibleField(obj, fieldName); |
| | | if (field == null) |
| | | { |
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); |
| | | return null; |
| | | } |
| | | E result = null; |
| | | try |
| | | { |
| | | result = (E) field.get(obj); |
| | | } |
| | | catch (IllegalAccessException e) |
| | | { |
| | | logger.error("不可能抛出的异常{}", e.getMessage()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数. |
| | | */ |
| | | public static <E> void setFieldValue(final Object obj, final String fieldName, final E value) |
| | | { |
| | | Field field = getAccessibleField(obj, fieldName); |
| | | if (field == null) |
| | | { |
| | | // throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); |
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | field.set(obj, value); |
| | | } |
| | | catch (IllegalAccessException e) |
| | | { |
| | | logger.error("不可能抛出的异常: {}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 直接调用对象方法, 无视private/protected修饰符. |
| | | * 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用. |
| | | * 同时匹配方法名+参数类型, |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes, |
| | | final Object[] args) |
| | | { |
| | | if (obj == null || methodName == null) |
| | | { |
| | | return null; |
| | | } |
| | | Method method = getAccessibleMethod(obj, methodName, parameterTypes); |
| | | if (method == null) |
| | | { |
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); |
| | | return null; |
| | | } |
| | | try |
| | | { |
| | | return (E) method.invoke(obj, args); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; |
| | | throw convertReflectionExceptionToUnchecked(msg, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 直接调用对象方法, 无视private/protected修饰符, |
| | | * 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用. |
| | | * 只匹配函数名,如果有多个同名函数调用第一个。 |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) |
| | | { |
| | | Method method = getAccessibleMethodByName(obj, methodName, args.length); |
| | | if (method == null) |
| | | { |
| | | // 如果为空不报错,直接返回空。 |
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); |
| | | return null; |
| | | } |
| | | try |
| | | { |
| | | // 类型转换(将参数数据类型转换为目标方法参数类型) |
| | | Class<?>[] cs = method.getParameterTypes(); |
| | | for (int i = 0; i < cs.length; i++) |
| | | { |
| | | if (args[i] != null && !args[i].getClass().equals(cs[i])) |
| | | { |
| | | if (cs[i] == String.class) |
| | | { |
| | | args[i] = Convert.toStr(args[i]); |
| | | if (StringUtils.endsWith((String) args[i], ".0")) |
| | | { |
| | | args[i] = StringUtils.substringBefore((String) args[i], ".0"); |
| | | } |
| | | } |
| | | else if (cs[i] == Integer.class) |
| | | { |
| | | args[i] = Convert.toInt(args[i]); |
| | | } |
| | | else if (cs[i] == Long.class) |
| | | { |
| | | args[i] = Convert.toLong(args[i]); |
| | | } |
| | | else if (cs[i] == Double.class) |
| | | { |
| | | args[i] = Convert.toDouble(args[i]); |
| | | } |
| | | else if (cs[i] == Float.class) |
| | | { |
| | | args[i] = Convert.toFloat(args[i]); |
| | | } |
| | | else if (cs[i] == Date.class) |
| | | { |
| | | if (args[i] instanceof String) |
| | | { |
| | | args[i] = DateUtils.parseDate(args[i]); |
| | | } |
| | | else |
| | | { |
| | | args[i] = DateUtil.getJavaDate((Double) args[i]); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return (E) method.invoke(obj, args); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; |
| | | throw convertReflectionExceptionToUnchecked(msg, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问. |
| | | * 如向上转型到Object仍无法找到, 返回null. |
| | | */ |
| | | public static Field getAccessibleField(final Object obj, final String fieldName) |
| | | { |
| | | // 为空不报错。直接返回 null |
| | | if (obj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Validate.notBlank(fieldName, "fieldName can't be blank"); |
| | | for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) |
| | | { |
| | | try |
| | | { |
| | | Field field = superClass.getDeclaredField(fieldName); |
| | | makeAccessible(field); |
| | | return field; |
| | | } |
| | | catch (NoSuchFieldException e) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. |
| | | * 如向上转型到Object仍无法找到, 返回null. |
| | | * 匹配函数名+参数类型。 |
| | | * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args) |
| | | */ |
| | | public static Method getAccessibleMethod(final Object obj, final String methodName, |
| | | final Class<?>... parameterTypes) |
| | | { |
| | | // 为空不报错。直接返回 null |
| | | if (obj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Validate.notBlank(methodName, "methodName can't be blank"); |
| | | for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) |
| | | { |
| | | try |
| | | { |
| | | Method method = searchType.getDeclaredMethod(methodName, parameterTypes); |
| | | makeAccessible(method); |
| | | return method; |
| | | } |
| | | catch (NoSuchMethodException e) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. |
| | | * 如向上转型到Object仍无法找到, 返回null. |
| | | * 只匹配函数名。 |
| | | * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args) |
| | | */ |
| | | public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum) |
| | | { |
| | | // 为空不报错。直接返回 null |
| | | if (obj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Validate.notBlank(methodName, "methodName can't be blank"); |
| | | for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) |
| | | { |
| | | Method[] methods = searchType.getDeclaredMethods(); |
| | | for (Method method : methods) |
| | | { |
| | | if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum) |
| | | { |
| | | makeAccessible(method); |
| | | return method; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。 |
| | | */ |
| | | public static void makeAccessible(Method method) |
| | | { |
| | | if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) |
| | | && !method.isAccessible()) |
| | | { |
| | | method.setAccessible(true); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。 |
| | | */ |
| | | public static void makeAccessible(Field field) |
| | | { |
| | | if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) |
| | | || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) |
| | | { |
| | | field.setAccessible(true); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处 |
| | | * 如无法找到, 返回Object.class. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> Class<T> getClassGenricType(final Class clazz) |
| | | { |
| | | return getClassGenricType(clazz, 0); |
| | | } |
| | | |
| | | /** |
| | | * 通过反射, 获得Class定义中声明的父类的泛型参数的类型. |
| | | * 如无法找到, 返回Object.class. |
| | | */ |
| | | public static Class getClassGenricType(final Class clazz, final int index) |
| | | { |
| | | Type genType = clazz.getGenericSuperclass(); |
| | | |
| | | if (!(genType instanceof ParameterizedType)) |
| | | { |
| | | logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType"); |
| | | return Object.class; |
| | | } |
| | | |
| | | Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); |
| | | |
| | | if (index >= params.length || index < 0) |
| | | { |
| | | logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " |
| | | + params.length); |
| | | return Object.class; |
| | | } |
| | | if (!(params[index] instanceof Class)) |
| | | { |
| | | logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); |
| | | return Object.class; |
| | | } |
| | | |
| | | return (Class) params[index]; |
| | | } |
| | | |
| | | public static Class<?> getUserClass(Object instance) |
| | | { |
| | | if (instance == null) |
| | | { |
| | | throw new RuntimeException("Instance must not be null"); |
| | | } |
| | | Class clazz = instance.getClass(); |
| | | if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) |
| | | { |
| | | Class<?> superClass = clazz.getSuperclass(); |
| | | if (superClass != null && !Object.class.equals(superClass)) |
| | | { |
| | | return superClass; |
| | | } |
| | | } |
| | | return clazz; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 将反射时的checked exception转换为unchecked exception. |
| | | */ |
| | | public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e) |
| | | { |
| | | if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException |
| | | || e instanceof NoSuchMethodException) |
| | | { |
| | | return new IllegalArgumentException(msg, e); |
| | | } |
| | | else if (e instanceof InvocationTargetException) |
| | | { |
| | | return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException()); |
| | | } |
| | | return new RuntimeException(msg, e); |
| | | } |
| | | } |
| | | package com.ruoyi.common.utils.reflect;
|
| | |
|
| | | import java.lang.reflect.Field;
|
| | | import java.lang.reflect.InvocationTargetException;
|
| | | import java.lang.reflect.Method;
|
| | | import java.lang.reflect.Modifier;
|
| | | import java.lang.reflect.ParameterizedType;
|
| | | import java.lang.reflect.Type;
|
| | | import java.util.Date;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.commons.lang3.Validate;
|
| | | import org.apache.poi.ss.usermodel.DateUtil;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | |
|
| | | /**
|
| | | * 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @SuppressWarnings("rawtypes")
|
| | | public class ReflectUtils
|
| | | {
|
| | | private static final String SETTER_PREFIX = "set";
|
| | |
|
| | | private static final String GETTER_PREFIX = "get";
|
| | |
|
| | | private static final String CGLIB_CLASS_SEPARATOR = "$$";
|
| | |
|
| | | private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
|
| | |
|
| | | /**
|
| | | * 调用Getter方法.
|
| | | * 支持多级,如:对象名.对象名.方法
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public static <E> E invokeGetter(Object obj, String propertyName)
|
| | | {
|
| | | Object object = obj;
|
| | | for (String name : StringUtils.split(propertyName, "."))
|
| | | {
|
| | | String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
|
| | | object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
|
| | | }
|
| | | return (E) object;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 调用Setter方法, 仅匹配方法名。
|
| | | * 支持多级,如:对象名.对象名.方法
|
| | | */
|
| | | public static <E> void invokeSetter(Object obj, String propertyName, E value)
|
| | | {
|
| | | Object object = obj;
|
| | | String[] names = StringUtils.split(propertyName, ".");
|
| | | for (int i = 0; i < names.length; i++)
|
| | | {
|
| | | if (i < names.length - 1)
|
| | | {
|
| | | String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]);
|
| | | object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
|
| | | }
|
| | | else
|
| | | {
|
| | | String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]);
|
| | | invokeMethodByName(object, setterMethodName, new Object[] { value });
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数.
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public static <E> E getFieldValue(final Object obj, final String fieldName)
|
| | | {
|
| | | Field field = getAccessibleField(obj, fieldName);
|
| | | if (field == null)
|
| | | {
|
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
|
| | | return null;
|
| | | }
|
| | | E result = null;
|
| | | try
|
| | | {
|
| | | result = (E) field.get(obj);
|
| | | }
|
| | | catch (IllegalAccessException e)
|
| | | {
|
| | | logger.error("不可能抛出的异常{}", e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数.
|
| | | */
|
| | | public static <E> void setFieldValue(final Object obj, final String fieldName, final E value)
|
| | | {
|
| | | Field field = getAccessibleField(obj, fieldName);
|
| | | if (field == null)
|
| | | {
|
| | | // throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
|
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
|
| | | return;
|
| | | }
|
| | | try
|
| | | {
|
| | | field.set(obj, value);
|
| | | }
|
| | | catch (IllegalAccessException e)
|
| | | {
|
| | | logger.error("不可能抛出的异常: {}", e.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 直接调用对象方法, 无视private/protected修饰符.
|
| | | * 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用.
|
| | | * 同时匹配方法名+参数类型,
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public static <E> E invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes,
|
| | | final Object[] args)
|
| | | {
|
| | | if (obj == null || methodName == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Method method = getAccessibleMethod(obj, methodName, parameterTypes);
|
| | | if (method == null)
|
| | | {
|
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
|
| | | return null;
|
| | | }
|
| | | try
|
| | | {
|
| | | return (E) method.invoke(obj, args);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | String msg = "method: " + method + ", obj: " + obj + ", args: " + args + "";
|
| | | throw convertReflectionExceptionToUnchecked(msg, e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 直接调用对象方法, 无视private/protected修饰符,
|
| | | * 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
|
| | | * 只匹配函数名,如果有多个同名函数调用第一个。
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args)
|
| | | {
|
| | | Method method = getAccessibleMethodByName(obj, methodName, args.length);
|
| | | if (method == null)
|
| | | {
|
| | | // 如果为空不报错,直接返回空。
|
| | | logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
|
| | | return null;
|
| | | }
|
| | | try
|
| | | {
|
| | | // 类型转换(将参数数据类型转换为目标方法参数类型)
|
| | | Class<?>[] cs = method.getParameterTypes();
|
| | | for (int i = 0; i < cs.length; i++)
|
| | | {
|
| | | if (args[i] != null && !args[i].getClass().equals(cs[i]))
|
| | | {
|
| | | if (cs[i] == String.class)
|
| | | {
|
| | | args[i] = Convert.toStr(args[i]);
|
| | | if (StringUtils.endsWith((String) args[i], ".0"))
|
| | | {
|
| | | args[i] = StringUtils.substringBefore((String) args[i], ".0");
|
| | | }
|
| | | }
|
| | | else if (cs[i] == Integer.class)
|
| | | {
|
| | | args[i] = Convert.toInt(args[i]);
|
| | | }
|
| | | else if (cs[i] == Long.class)
|
| | | {
|
| | | args[i] = Convert.toLong(args[i]);
|
| | | }
|
| | | else if (cs[i] == Double.class)
|
| | | {
|
| | | args[i] = Convert.toDouble(args[i]);
|
| | | }
|
| | | else if (cs[i] == Float.class)
|
| | | {
|
| | | args[i] = Convert.toFloat(args[i]);
|
| | | }
|
| | | else if (cs[i] == Date.class)
|
| | | {
|
| | | if (args[i] instanceof String)
|
| | | {
|
| | | args[i] = DateUtils.parseDate(args[i]);
|
| | | }
|
| | | else
|
| | | {
|
| | | args[i] = DateUtil.getJavaDate((Double) args[i]);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return (E) method.invoke(obj, args);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | String msg = "method: " + method + ", obj: " + obj + ", args: " + args + "";
|
| | | throw convertReflectionExceptionToUnchecked(msg, e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
|
| | | * 如向上转型到Object仍无法找到, 返回null.
|
| | | */
|
| | | public static Field getAccessibleField(final Object obj, final String fieldName)
|
| | | {
|
| | | // 为空不报错。直接返回 null
|
| | | if (obj == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Validate.notBlank(fieldName, "fieldName can't be blank");
|
| | | for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass())
|
| | | {
|
| | | try
|
| | | {
|
| | | Field field = superClass.getDeclaredField(fieldName);
|
| | | makeAccessible(field);
|
| | | return field;
|
| | | }
|
| | | catch (NoSuchFieldException e)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
| | | * 如向上转型到Object仍无法找到, 返回null.
|
| | | * 匹配函数名+参数类型。
|
| | | * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
|
| | | */
|
| | | public static Method getAccessibleMethod(final Object obj, final String methodName,
|
| | | final Class<?>... parameterTypes)
|
| | | {
|
| | | // 为空不报错。直接返回 null
|
| | | if (obj == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Validate.notBlank(methodName, "methodName can't be blank");
|
| | | for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass())
|
| | | {
|
| | | try
|
| | | {
|
| | | Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
|
| | | makeAccessible(method);
|
| | | return method;
|
| | | }
|
| | | catch (NoSuchMethodException e)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
| | | * 如向上转型到Object仍无法找到, 返回null.
|
| | | * 只匹配函数名。
|
| | | * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
|
| | | */
|
| | | public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum)
|
| | | {
|
| | | // 为空不报错。直接返回 null
|
| | | if (obj == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Validate.notBlank(methodName, "methodName can't be blank");
|
| | | for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass())
|
| | | {
|
| | | Method[] methods = searchType.getDeclaredMethods();
|
| | | for (Method method : methods)
|
| | | {
|
| | | if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum)
|
| | | {
|
| | | makeAccessible(method);
|
| | | return method;
|
| | | }
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
| | | */
|
| | | public static void makeAccessible(Method method)
|
| | | {
|
| | | if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
|
| | | && !method.isAccessible())
|
| | | {
|
| | | method.setAccessible(true);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
| | | */
|
| | | public static void makeAccessible(Field field)
|
| | | {
|
| | | if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
|
| | | || Modifier.isFinal(field.getModifiers())) && !field.isAccessible())
|
| | | {
|
| | | field.setAccessible(true);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处
|
| | | * 如无法找到, 返回Object.class.
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public static <T> Class<T> getClassGenricType(final Class clazz)
|
| | | {
|
| | | return getClassGenricType(clazz, 0);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过反射, 获得Class定义中声明的父类的泛型参数的类型.
|
| | | * 如无法找到, 返回Object.class.
|
| | | */
|
| | | public static Class getClassGenricType(final Class clazz, final int index)
|
| | | {
|
| | | Type genType = clazz.getGenericSuperclass();
|
| | |
|
| | | if (!(genType instanceof ParameterizedType))
|
| | | {
|
| | | logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType");
|
| | | return Object.class;
|
| | | }
|
| | |
|
| | | Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
|
| | |
|
| | | if (index >= params.length || index < 0)
|
| | | {
|
| | | logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
|
| | | + params.length);
|
| | | return Object.class;
|
| | | }
|
| | | if (!(params[index] instanceof Class))
|
| | | {
|
| | | logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
|
| | | return Object.class;
|
| | | }
|
| | |
|
| | | return (Class) params[index];
|
| | | }
|
| | |
|
| | | public static Class<?> getUserClass(Object instance)
|
| | | {
|
| | | if (instance == null)
|
| | | {
|
| | | throw new RuntimeException("Instance must not be null");
|
| | | }
|
| | | Class clazz = instance.getClass();
|
| | | if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR))
|
| | | {
|
| | | Class<?> superClass = clazz.getSuperclass();
|
| | | if (superClass != null && !Object.class.equals(superClass))
|
| | | {
|
| | | return superClass;
|
| | | }
|
| | | }
|
| | | return clazz;
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * 将反射时的checked exception转换为unchecked exception.
|
| | | */
|
| | | public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e)
|
| | | {
|
| | | if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException
|
| | | || e instanceof NoSuchMethodException)
|
| | | {
|
| | | return new IllegalArgumentException(msg, e);
|
| | | }
|
| | | else if (e instanceof InvocationTargetException)
|
| | | {
|
| | | return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException());
|
| | | }
|
| | | return new RuntimeException(msg, e);
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/IdUtils.java 修改 |
| | |
| | | package com.ruoyi.common.utils;
|
| | | package com.ruoyi.common.utils.uuid;
|
| | |
|
| | | import com.ruoyi.common.core.lang.UUID;
|
| | | import com.ruoyi.common.utils.uuid.UUID;
|
| | |
|
| | | /**
|
| | | * ID生成器工具类
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/core/lang/UUID.java 修改 |
| | |
| | | package com.ruoyi.common.core.lang;
|
| | | package com.ruoyi.common.utils.uuid;
|
| | |
|
| | | import java.security.MessageDigest;
|
| | | import java.security.NoSuchAlgorithmException;
|
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <parent>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <version>3.0.0</version>
|
| | | </parent>
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | |
|
| | | <artifactId>ruoyi-framework</artifactId>
|
| | |
|
| | | <description>
|
| | | framework框架核心
|
| | | </description>
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | <!-- SpringBoot Web容器 -->
|
| | | <dependency>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-starter-web</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- SpringBoot 拦截器 -->
|
| | | <dependency>
|
| | | <groupId>org.springframework.boot</groupId>
|
| | | <artifactId>spring-boot-starter-aop</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 阿里数据库连接池 -->
|
| | | <dependency>
|
| | | <groupId>com.alibaba</groupId>
|
| | | <artifactId>druid-spring-boot-starter</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 获取系统信息 -->
|
| | | <dependency>
|
| | | <groupId>com.github.oshi</groupId>
|
| | | <artifactId>oshi-core</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <dependency>
|
| | | <groupId>net.java.dev.jna</groupId>
|
| | | <artifactId>jna</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <dependency>
|
| | | <groupId>net.java.dev.jna</groupId>
|
| | | <artifactId>jna-platform</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 系统模块-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-system</artifactId>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | </project> |
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java 修改 |
| | |
| | | import org.aspectj.lang.annotation.Pointcut;
|
| | | import org.aspectj.lang.reflect.MethodSignature;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.annotation.DataScope;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | |
|
| | | /**
|
| | | * 数据过滤处理
|
| | |
| | | public static final String DATA_SCOPE = "dataScope";
|
| | |
|
| | | // 配置织入点
|
| | | @Pointcut("@annotation(com.ruoyi.framework.aspectj.lang.annotation.DataScope)")
|
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.DataScope)")
|
| | | public void dataScopePointCut()
|
| | | {
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java 修改 |
| | |
| | | import org.springframework.core.annotation.AnnotationUtils;
|
| | | import org.springframework.core.annotation.Order;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.annotation.DataSource;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
|
| | | import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
|
| | |
|
| | | /**
|
| | |
| | | {
|
| | | protected Logger logger = LoggerFactory.getLogger(getClass());
|
| | |
|
| | | @Pointcut("@annotation(com.ruoyi.framework.aspectj.lang.annotation.DataSource)"
|
| | | + "|| @within(com.ruoyi.framework.aspectj.lang.annotation.DataSource)")
|
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
|
| | | + "|| @within(com.ruoyi.common.annotation.DataSource)")
|
| | | public void dsPointCut()
|
| | | {
|
| | |
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java 修改 |
| | |
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.springframework.web.servlet.HandlerMapping;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.enums.BusinessStatus;
|
| | | import com.ruoyi.common.enums.HttpMethod;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.ip.IpUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessStatus;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | | import com.ruoyi.system.domain.SysOperLog;
|
| | |
|
| | | /**
|
| | | * 操作日志记录处理
|
| | |
| | | private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
|
| | |
|
| | | // 配置织入点
|
| | | @Pointcut("@annotation(com.ruoyi.framework.aspectj.lang.annotation.Log)")
|
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.Log)")
|
| | | public void logPointCut()
|
| | | {
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java 修改 |
| | |
| | | // 表示通过aop框架暴露该代理对象,AopContext能够访问
|
| | | @EnableAspectJAutoProxy(exposeProxy = true)
|
| | | // 指定要扫描的Mapper类的包的路径
|
| | | @MapperScan("com.ruoyi.project.**.mapper")
|
| | | @MapperScan("com.ruoyi.**.mapper")
|
| | | public class ApplicationConfig
|
| | | {
|
| | | /**
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/DruidConfig.java 修改 |
| | |
| | | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
| | | import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
| | | import com.alibaba.druid.util.Utils;
|
| | | import com.ruoyi.common.enums.DataSourceType;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
|
| | | import com.ruoyi.framework.config.properties.DruidProperties;
|
| | | import com.ruoyi.framework.datasource.DynamicDataSource;
|
| | |
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java 修改 |
| | |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
| | | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
| | |
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java 修改 |
| | |
| | | package com.ruoyi.framework.interceptor; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.framework.interceptor.annotation.RepeatSubmit; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | |
| | | /** |
| | | * 防止重复提交拦截器 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter |
| | | { |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception |
| | | { |
| | | if (handler instanceof HandlerMethod) |
| | | { |
| | | HandlerMethod handlerMethod = (HandlerMethod) handler; |
| | | Method method = handlerMethod.getMethod(); |
| | | RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); |
| | | if (annotation != null) |
| | | { |
| | | if (this.isRepeatSubmit(request)) |
| | | { |
| | | AjaxResult ajaxResult = AjaxResult.error("不允许重复提交,请稍后再试"); |
| | | ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult)); |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return super.preHandle(request, response, handler); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 验证是否重复提交由子类实现具体的防重复提交的规则 |
| | | * |
| | | * @param httpServletRequest |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public abstract boolean isRepeatSubmit(HttpServletRequest request); |
| | | } |
| | | package com.ruoyi.framework.interceptor;
|
| | |
|
| | | import java.lang.reflect.Method;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.web.method.HandlerMethod;
|
| | | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.annotation.RepeatSubmit;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | |
|
| | | /**
|
| | | * 防止重复提交拦截器
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Component
|
| | | public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter
|
| | | {
|
| | | @Override
|
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
|
| | | {
|
| | | if (handler instanceof HandlerMethod)
|
| | | {
|
| | | HandlerMethod handlerMethod = (HandlerMethod) handler;
|
| | | Method method = handlerMethod.getMethod();
|
| | | RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class);
|
| | | if (annotation != null)
|
| | | {
|
| | | if (this.isRepeatSubmit(request))
|
| | | {
|
| | | AjaxResult ajaxResult = AjaxResult.error("不允许重复提交,请稍后再试");
|
| | | ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult));
|
| | | return false;
|
| | | }
|
| | | }
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | return super.preHandle(request, response, handler);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 验证是否重复提交由子类实现具体的防重复提交的规则
|
| | | * |
| | | * @param httpServletRequest
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public abstract boolean isRepeatSubmit(HttpServletRequest request);
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java 修改 |
| | |
| | | package com.ruoyi.framework.interceptor.impl; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.filter.RepeatedlyRequestWrapper; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.http.HttpHelper; |
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; |
| | | import com.ruoyi.framework.redis.RedisCache; |
| | | |
| | | /** |
| | | * 判断请求url和数据是否和上一次相同, |
| | | * 如果和上次相同,则是重复提交表单。 有效时间为10秒内。 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
| | | { |
| | | public final String REPEAT_PARAMS = "repeatParams"; |
| | | |
| | | public final String REPEAT_TIME = "repeatTime"; |
| | | |
| | | public final String CACHE_REPEAT_KEY = "repeatData"; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | /** |
| | | * 间隔时间,单位:秒 默认10秒 |
| | | * |
| | | * 两次相同参数的请求,如果间隔时间大于该参数,系统不会认定为重复提交的数据 |
| | | */ |
| | | private int intervalTime = 10; |
| | | |
| | | public void setIntervalTime(int intervalTime) |
| | | { |
| | | this.intervalTime = intervalTime; |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | public boolean isRepeatSubmit(HttpServletRequest request) |
| | | { |
| | | RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; |
| | | String nowParams = HttpHelper.getBodyString(repeatedlyRequest); |
| | | |
| | | // body参数为空,获取Parameter的数据 |
| | | if (StringUtils.isEmpty(nowParams)) |
| | | { |
| | | nowParams = JSONObject.toJSONString(request.getParameterMap()); |
| | | } |
| | | Map<String, Object> nowDataMap = new HashMap<String, Object>(); |
| | | nowDataMap.put(REPEAT_PARAMS, nowParams); |
| | | nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); |
| | | |
| | | // 请求地址(作为存放cache的key值) |
| | | String url = request.getRequestURI(); |
| | | |
| | | Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY); |
| | | if (sessionObj != null) |
| | | { |
| | | Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; |
| | | if (sessionMap.containsKey(url)) |
| | | { |
| | | Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url); |
| | | if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | Map<String, Object> cacheMap = new HashMap<String, Object>(); |
| | | cacheMap.put(url, nowDataMap); |
| | | redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 判断参数是否相同 |
| | | */ |
| | | private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap) |
| | | { |
| | | String nowParams = (String) nowMap.get(REPEAT_PARAMS); |
| | | String preParams = (String) preMap.get(REPEAT_PARAMS); |
| | | return nowParams.equals(preParams); |
| | | } |
| | | |
| | | /** |
| | | * 判断两次间隔时间 |
| | | */ |
| | | private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap) |
| | | { |
| | | long time1 = (Long) nowMap.get(REPEAT_TIME); |
| | | long time2 = (Long) preMap.get(REPEAT_TIME); |
| | | if ((time1 - time2) < (this.intervalTime * 1000)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | package com.ruoyi.framework.interceptor.impl;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.TimeUnit;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.http.HttpHelper;
|
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
| | |
|
| | | /**
|
| | | * 判断请求url和数据是否和上一次相同,
|
| | | * 如果和上次相同,则是重复提交表单。 有效时间为10秒内。
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Component
|
| | | public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
|
| | | {
|
| | | public final String REPEAT_PARAMS = "repeatParams";
|
| | |
|
| | | public final String REPEAT_TIME = "repeatTime";
|
| | |
|
| | | public final String CACHE_REPEAT_KEY = "repeatData";
|
| | |
|
| | | @Autowired
|
| | | private RedisCache redisCache;
|
| | |
|
| | | /**
|
| | | * 间隔时间,单位:秒 默认10秒
|
| | | * |
| | | * 两次相同参数的请求,如果间隔时间大于该参数,系统不会认定为重复提交的数据
|
| | | */
|
| | | private int intervalTime = 10;
|
| | |
|
| | | public void setIntervalTime(int intervalTime)
|
| | | {
|
| | | this.intervalTime = intervalTime;
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public boolean isRepeatSubmit(HttpServletRequest request)
|
| | | {
|
| | | RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request;
|
| | | String nowParams = HttpHelper.getBodyString(repeatedlyRequest);
|
| | |
|
| | | // body参数为空,获取Parameter的数据
|
| | | if (StringUtils.isEmpty(nowParams))
|
| | | {
|
| | | nowParams = JSONObject.toJSONString(request.getParameterMap());
|
| | | }
|
| | | Map<String, Object> nowDataMap = new HashMap<String, Object>();
|
| | | nowDataMap.put(REPEAT_PARAMS, nowParams);
|
| | | nowDataMap.put(REPEAT_TIME, System.currentTimeMillis());
|
| | |
|
| | | // 请求地址(作为存放cache的key值)
|
| | | String url = request.getRequestURI();
|
| | |
|
| | | Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY);
|
| | | if (sessionObj != null)
|
| | | {
|
| | | Map<String, Object> sessionMap = (Map<String, Object>) sessionObj;
|
| | | if (sessionMap.containsKey(url))
|
| | | {
|
| | | Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url);
|
| | | if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | }
|
| | | Map<String, Object> cacheMap = new HashMap<String, Object>();
|
| | | cacheMap.put(url, nowDataMap);
|
| | | redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS);
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 判断参数是否相同
|
| | | */
|
| | | private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap)
|
| | | {
|
| | | String nowParams = (String) nowMap.get(REPEAT_PARAMS);
|
| | | String preParams = (String) preMap.get(REPEAT_PARAMS);
|
| | | return nowParams.equals(preParams);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 判断两次间隔时间
|
| | | */
|
| | | private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap)
|
| | | {
|
| | | long time1 = (Long) nowMap.get(REPEAT_TIME);
|
| | | long time2 = (Long) preMap.get(REPEAT_TIME);
|
| | | if ((time1 - time2) < (this.intervalTime * 1000))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java 修改 |
| | |
| | | import com.ruoyi.common.utils.ip.AddressUtils;
|
| | | import com.ruoyi.common.utils.ip.IpUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.project.monitor.domain.SysLogininfor;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | | import com.ruoyi.project.monitor.service.ISysLogininforService;
|
| | | import com.ruoyi.project.monitor.service.ISysOperLogService;
|
| | | import com.ruoyi.system.domain.SysLogininfor;
|
| | | import com.ruoyi.system.domain.SysOperLog;
|
| | | import com.ruoyi.system.service.ISysLogininforService;
|
| | | import com.ruoyi.system.service.ISysOperLogService;
|
| | | import eu.bitwalker.useragentutils.UserAgent;
|
| | |
|
| | | /**
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java 修改 |
| | |
| | | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.web.filter.OncePerRequestFilter;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | |
|
| | | /**
|
| | | * token过滤器 验证token有效性
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java 修改 |
| | |
| | | import org.springframework.stereotype.Component;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.ruoyi.common.constant.HttpStatus;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | |
|
| | | /**
|
| | | * 认证失败处理类 返回未授权
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java 修改 |
| | |
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.HttpStatus;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.service.TokenService;
|
| | |
|
| | | /**
|
| | | * 自定义退出处理类 返回成功
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java 修改 |
| | |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice;
|
| | | import org.springframework.web.servlet.NoHandlerFoundException;
|
| | | import com.ruoyi.common.constant.HttpStatus;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.exception.BaseException;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.exception.DemoModeException;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | |
|
| | | /**
|
| | | * 全局异常处理器
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/service/PermissionService.java 修改 |
| | |
| | | package com.ruoyi.framework.security.service;
|
| | | package com.ruoyi.framework.web.service;
|
| | |
|
| | | import java.util.Set;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.CollectionUtils;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | |
|
| | | /**
|
| | | * RuoYi首创 自定义权限实现,ss取自SpringSecurity首字母
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/service/SysLoginService.java 修改 |
| | |
| | | package com.ruoyi.framework.security.service;
|
| | | package com.ruoyi.framework.web.service;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.security.core.Authentication;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.exception.user.CaptchaException;
|
| | | import com.ruoyi.common.exception.user.CaptchaExpireException;
|
| | |
| | | import com.ruoyi.common.utils.MessageUtils;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | |
|
| | | /**
|
| | | * 登录校验方法
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/service/SysPermissionService.java 修改 |
| | |
| | | package com.ruoyi.framework.security.service;
|
| | | package com.ruoyi.framework.web.service;
|
| | |
|
| | | import java.util.HashSet;
|
| | | import java.util.Set;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysMenuService;
|
| | | import com.ruoyi.project.system.service.ISysRoleService;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.system.service.ISysMenuService;
|
| | | import com.ruoyi.system.service.ISysRoleService;
|
| | |
|
| | | /**
|
| | | * 用户权限处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/service/TokenService.java 修改 |
| | |
| | | package com.ruoyi.framework.security.service;
|
| | | package com.ruoyi.framework.web.service;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | |
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.utils.IdUtils;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.ip.AddressUtils;
|
| | | import com.ruoyi.common.utils.ip.IpUtils;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.common.utils.uuid.IdUtils;
|
| | | import eu.bitwalker.useragentutils.UserAgent;
|
| | | import io.jsonwebtoken.Claims;
|
| | | import io.jsonwebtoken.Jwts;
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/security/service/UserDetailsServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.framework.security.service;
|
| | | package com.ruoyi.framework.web.service;
|
| | |
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
| | | import org.springframework.security.core.userdetails.UserDetailsService;
|
| | | import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.enums.UserStatus;
|
| | | import com.ruoyi.common.exception.BaseException;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | | import com.ruoyi.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | | * 用户验证处理
|
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <parent>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <version>3.0.0</version>
|
| | | </parent>
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | |
|
| | | <artifactId>ruoyi-generator</artifactId>
|
| | |
|
| | | <description>
|
| | | generator代码生成
|
| | | </description>
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | <!--velocity代码生成使用模板 -->
|
| | | <dependency>
|
| | | <groupId>org.apache.velocity</groupId>
|
| | | <artifactId>velocity</artifactId>
|
| | | </dependency>
|
| | |
|
| | | <!-- 通用工具-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-common</artifactId>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | </project> |
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/GenConfig.java 修改 |
| | |
| | | package com.ruoyi.framework.config;
|
| | | package com.ruoyi.generator.config;
|
| | |
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.boot.context.properties.ConfigurationProperties;
|
| | | import org.springframework.context.annotation.PropertySource;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @Component
|
| | | @ConfigurationProperties(prefix = "gen")
|
| | | @PropertySource(value = { "classpath:generator.yml" })
|
| | | public class GenConfig
|
| | | {
|
| | | /** 作者 */
|
| | |
| | | /** 生成包路径 */
|
| | | public static String packageName;
|
| | |
|
| | | /** 自动去除表前缀,默认是true */
|
| | | /** 自动去除表前缀,默认是false */
|
| | | public static boolean autoRemovePre;
|
| | |
|
| | | /** 表前缀(类名不会包含表前缀) */
|
| | |
| | | return author;
|
| | | }
|
| | |
|
| | | @Value("${author}")
|
| | | public void setAuthor(String author)
|
| | | {
|
| | | GenConfig.author = author;
|
| | |
| | | return packageName;
|
| | | }
|
| | |
|
| | | @Value("${packageName}")
|
| | | public void setPackageName(String packageName)
|
| | | {
|
| | | GenConfig.packageName = packageName;
|
| | |
| | | return autoRemovePre;
|
| | | }
|
| | |
|
| | | @Value("${autoRemovePre}")
|
| | | public void setAutoRemovePre(boolean autoRemovePre)
|
| | | {
|
| | | GenConfig.autoRemovePre = autoRemovePre;
|
| | |
| | | return tablePrefix;
|
| | | }
|
| | |
|
| | | @Value("${tablePrefix}")
|
| | | public void setTablePrefix(String tablePrefix)
|
| | | {
|
| | | GenConfig.tablePrefix = tablePrefix;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.controller;
|
| | | package com.ruoyi.generator.controller;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.HashMap;
|
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTable;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.project.tool.gen.service.IGenTableColumnService;
|
| | | import com.ruoyi.project.tool.gen.service.IGenTableService;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.generator.domain.GenTable;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.service.IGenTableColumnService;
|
| | | import com.ruoyi.generator.service.IGenTableService;
|
| | |
|
| | | /**
|
| | | * 代码生成 操作处理
|
| | |
| | | response.setContentType("application/octet-stream; charset=UTF-8");
|
| | | IOUtils.write(data, response.getOutputStream());
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/domain/GenTable.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.domain;
|
| | | package com.ruoyi.generator.domain;
|
| | |
|
| | | import java.util.List;
|
| | | import javax.validation.Valid;
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import org.apache.commons.lang3.ArrayUtils;
|
| | | import com.ruoyi.common.constant.GenConstants;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 业务表 gen_table
|
| | |
| | | }
|
| | | return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/domain/GenTableColumn.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.domain;
|
| | | package com.ruoyi.generator.domain;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 代码生成业务字段表 gen_table_column
|
| | |
| | | return this.columnComment;
|
| | | }
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/mapper/GenTableColumnMapper.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.mapper;
|
| | | package com.ruoyi.generator.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | |
|
| | | /**
|
| | | * 业务字段 数据层
|
| | |
| | | * @return 结果
|
| | | */
|
| | | public int deleteGenTableColumnByIds(Long[] ids);
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/mapper/GenTableMapper.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.mapper;
|
| | | package com.ruoyi.generator.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTable;
|
| | | import com.ruoyi.generator.domain.GenTable;
|
| | |
|
| | | /**
|
| | | * 业务 数据层
|
| | |
| | | * @return 结果
|
| | | */
|
| | | public int deleteGenTableByIds(Long[] ids);
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.service;
|
| | | package com.ruoyi.generator.service;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper;
|
| | |
|
| | | /**
|
| | | * 业务字段 服务层实现
|
| | |
| | | {
|
| | | return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.service;
|
| | | package com.ruoyi.generator.service;
|
| | |
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.IOException;
|
| | |
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTable;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper;
|
| | | import com.ruoyi.project.tool.gen.mapper.GenTableMapper;
|
| | | import com.ruoyi.project.tool.gen.util.GenUtils;
|
| | | import com.ruoyi.project.tool.gen.util.VelocityInitializer;
|
| | | import com.ruoyi.project.tool.gen.util.VelocityUtils;
|
| | | import com.ruoyi.generator.domain.GenTable;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper;
|
| | | import com.ruoyi.generator.mapper.GenTableMapper;
|
| | | import com.ruoyi.generator.util.GenUtils;
|
| | | import com.ruoyi.generator.util.VelocityInitializer;
|
| | | import com.ruoyi.generator.util.VelocityUtils;
|
| | |
|
| | | /**
|
| | | * 业务 服务层实现
|
| | |
| | | genTable.setTreeName(treeName);
|
| | | }
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/IGenTableColumnService.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.service;
|
| | | package com.ruoyi.generator.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | |
|
| | | /**
|
| | | * 业务字段 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/IGenTableService.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.service;
|
| | | package com.ruoyi.generator.service;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTable;
|
| | | import com.ruoyi.generator.domain.GenTable;
|
| | |
|
| | | /**
|
| | | * 业务 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.util;
|
| | | package com.ruoyi.generator.util;
|
| | |
|
| | | import java.util.Arrays;
|
| | | import org.apache.commons.lang3.RegExUtils;
|
| | | import com.ruoyi.common.constant.GenConstants;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.config.GenConfig;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTable;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.config.GenConfig;
|
| | | import com.ruoyi.generator.domain.GenTable;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | |
|
| | | /**
|
| | | * 代码生成器 工具类
|
| | |
| | | return 0;
|
| | | }
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityInitializer.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.util;
|
| | | package com.ruoyi.generator.util;
|
| | |
|
| | | import java.util.Properties;
|
| | | import org.apache.velocity.app.Velocity;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java 修改 |
| | |
| | | package com.ruoyi.project.tool.gen.util;
|
| | | package com.ruoyi.generator.util;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashSet;
|
| | |
| | | import com.ruoyi.common.constant.GenConstants;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTable;
|
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn;
|
| | | import com.ruoyi.generator.domain.GenTable;
|
| | | import com.ruoyi.generator.domain.GenTableColumn;
|
| | |
|
| | | /**
|
| | | * 代码生成模板处理
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class VelocityUtils
|
| | | {
|
| | | /** 项目空间路径 */
|
| | | private static final String PROJECT_PATH = "main/java";
|
| | |
|
| | | /** mybatis空间路径 */
|
| | | private static final String MYBATIS_PATH = "main/resources/mybatis";
|
| | | private static final String MYBATIS_PATH = "main/resources/mapper";
|
| | |
|
| | | /**
|
| | | * 设置模板变量信息
|
| | |
| | | }
|
| | | return num;
|
| | | }
|
| | | } |
| | | }
|
对比新文件 |
| | |
| | | # 代码生成
|
| | | gen: |
| | | # 作者
|
| | | author: ruoyi
|
| | | # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
|
| | | packageName: com.ruoyi.system
|
| | | # 自动去除表前缀,默认是false
|
| | | autoRemovePre: false
|
| | | # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
|
| | | tablePrefix: sys_ |
文件名从 ruoyi/src/main/resources/mybatis/tool/GenTableColumnMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper">
|
| | | <mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">
|
| | |
|
| | | <resultMap type="GenTableColumn" id="GenTableColumnResult">
|
| | | <id property="columnId" column="column_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/tool/GenTableMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.tool.gen.mapper.GenTableMapper">
|
| | | <mapper namespace="com.ruoyi.generator.mapper.GenTableMapper">
|
| | |
|
| | | <resultMap type="GenTable" id="GenTableResult">
|
| | | <id property="tableId" column="table_id" />
|
文件名从 ruoyi/src/main/resources/vm/java/controller.java.vm 修改 |
| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import ${packageName}.domain.${ClassName};
|
| | | import ${packageName}.service.I${ClassName}Service;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | #if($table.crud)
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | #elseif($table.tree)
|
| | | #end
|
| | |
|
文件名从 ruoyi/src/main/resources/vm/java/domain.java.vm 修改 |
| | |
| | | #end
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | #if($table.crud)
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | | #elseif($table.tree)
|
| | | import com.ruoyi.framework.web.domain.TreeEntity;
|
| | | import com.ruoyi.common.core.domain.TreeEntity;
|
| | | #end
|
| | |
|
| | | /**
|
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <parent>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <version>3.0.0</version>
|
| | | </parent>
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | |
|
| | | <artifactId>ruoyi-quartz</artifactId>
|
| | |
|
| | | <description>
|
| | | quartz定时任务
|
| | | </description>
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | <!-- 定时任务 -->
|
| | | <dependency>
|
| | | <groupId>org.quartz-scheduler</groupId>
|
| | | <artifactId>quartz</artifactId>
|
| | | <exclusions>
|
| | | <exclusion>
|
| | | <groupId>com.mchange</groupId>
|
| | | <artifactId>c3p0</artifactId>
|
| | | </exclusion>
|
| | | </exclusions>
|
| | | </dependency>
|
| | |
|
| | | <!-- 通用工具-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-common</artifactId>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | </project> |
文件名从 ruoyi/src/main/java/com/ruoyi/framework/config/ScheduleConfig.java 修改 |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.quartz.SchedulerFactoryBean; |
| | | import javax.sql.DataSource; |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * 定时任务配置 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Configuration |
| | | public class ScheduleConfig |
| | | { |
| | | @Bean |
| | | public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) |
| | | { |
| | | SchedulerFactoryBean factory = new SchedulerFactoryBean(); |
| | | factory.setDataSource(dataSource); |
| | | |
| | | // quartz参数 |
| | | Properties prop = new Properties(); |
| | | prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler"); |
| | | prop.put("org.quartz.scheduler.instanceId", "AUTO"); |
| | | // 线程池配置 |
| | | prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); |
| | | prop.put("org.quartz.threadPool.threadCount", "20"); |
| | | prop.put("org.quartz.threadPool.threadPriority", "5"); |
| | | // JobStore配置 |
| | | prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); |
| | | // 集群配置 |
| | | prop.put("org.quartz.jobStore.isClustered", "true"); |
| | | prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); |
| | | prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); |
| | | prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); |
| | | |
| | | // sqlserver 启用 |
| | | // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); |
| | | prop.put("org.quartz.jobStore.misfireThreshold", "12000"); |
| | | prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); |
| | | factory.setQuartzProperties(prop); |
| | | |
| | | factory.setSchedulerName("RuoyiScheduler"); |
| | | // 延时启动 |
| | | factory.setStartupDelay(1); |
| | | factory.setApplicationContextSchedulerContextKey("applicationContextKey"); |
| | | // 可选,QuartzScheduler |
| | | // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 |
| | | factory.setOverwriteExistingJobs(true); |
| | | // 设置自动启动,默认为true |
| | | factory.setAutoStartup(true); |
| | | |
| | | return factory; |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.config;
|
| | |
|
| | | import org.springframework.context.annotation.Bean;
|
| | | import org.springframework.context.annotation.Configuration;
|
| | | import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
| | | import javax.sql.DataSource;
|
| | | import java.util.Properties;
|
| | |
|
| | | /**
|
| | | * 定时任务配置
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Configuration
|
| | | public class ScheduleConfig
|
| | | {
|
| | | @Bean
|
| | | public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
|
| | | {
|
| | | SchedulerFactoryBean factory = new SchedulerFactoryBean();
|
| | | factory.setDataSource(dataSource);
|
| | |
|
| | | // quartz参数
|
| | | Properties prop = new Properties();
|
| | | prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
|
| | | prop.put("org.quartz.scheduler.instanceId", "AUTO");
|
| | | // 线程池配置
|
| | | prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
|
| | | prop.put("org.quartz.threadPool.threadCount", "20");
|
| | | prop.put("org.quartz.threadPool.threadPriority", "5");
|
| | | // JobStore配置
|
| | | prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
|
| | | // 集群配置
|
| | | prop.put("org.quartz.jobStore.isClustered", "true");
|
| | | prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
|
| | | prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
|
| | | prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
|
| | |
|
| | | // sqlserver 启用
|
| | | // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
|
| | | prop.put("org.quartz.jobStore.misfireThreshold", "12000");
|
| | | prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
|
| | | factory.setQuartzProperties(prop);
|
| | |
|
| | | factory.setSchedulerName("RuoyiScheduler");
|
| | | // 延时启动
|
| | | factory.setStartupDelay(1);
|
| | | factory.setApplicationContextSchedulerContextKey("applicationContextKey");
|
| | | // 可选,QuartzScheduler
|
| | | // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
|
| | | factory.setOverwriteExistingJobs(true);
|
| | | // 设置自动启动,默认为true
|
| | | factory.setAutoStartup(true);
|
| | |
|
| | | return factory;
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/controller/SysJobController.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.controller; |
| | | |
| | | import java.util.List; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.job.CronUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | import com.ruoyi.project.monitor.service.ISysJobService; |
| | | |
| | | /** |
| | | * 调度任务信息操作处理 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/job") |
| | | public class SysJobController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysJobService jobService; |
| | | |
| | | /** |
| | | * 查询定时任务列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysJob sysJob) |
| | | { |
| | | startPage(); |
| | | List<SysJob> list = jobService.selectJobList(sysJob); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导出定时任务列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')") |
| | | @Log(title = "定时任务", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/export") |
| | | public AjaxResult export(SysJob sysJob) |
| | | { |
| | | List<SysJob> list = jobService.selectJobList(sysJob); |
| | | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); |
| | | return util.exportExcel(list, "定时任务"); |
| | | } |
| | | |
| | | /** |
| | | * 获取定时任务详细信息 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')") |
| | | @GetMapping(value = "/{jobId}") |
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId) |
| | | { |
| | | return AjaxResult.success(jobService.selectJobById(jobId)); |
| | | } |
| | | |
| | | /** |
| | | * 新增定时任务 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:add')") |
| | | @Log(title = "定时任务", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException |
| | | { |
| | | if (!CronUtils.isValid(sysJob.getCronExpression())) |
| | | { |
| | | return AjaxResult.error("cron表达式不正确"); |
| | | } |
| | | sysJob.setCreateBy(SecurityUtils.getUsername()); |
| | | return toAjax(jobService.insertJob(sysJob)); |
| | | } |
| | | |
| | | /** |
| | | * 修改定时任务 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:edit')") |
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException |
| | | { |
| | | if (!CronUtils.isValid(sysJob.getCronExpression())) |
| | | { |
| | | return AjaxResult.error("cron表达式不正确"); |
| | | } |
| | | sysJob.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(jobService.updateJob(sysJob)); |
| | | } |
| | | |
| | | /** |
| | | * 定时任务状态修改 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") |
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException |
| | | { |
| | | SysJob newJob = jobService.selectJobById(job.getJobId()); |
| | | newJob.setStatus(job.getStatus()); |
| | | return toAjax(jobService.changeStatus(newJob)); |
| | | } |
| | | |
| | | /** |
| | | * 定时任务立即执行一次 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") |
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/run") |
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException |
| | | { |
| | | jobService.run(job); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 删除定时任务 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| | | @Log(title = "定时任务", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{jobIds}") |
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException |
| | | { |
| | | jobService.deleteJobByIds(jobIds); |
| | | return AjaxResult.success(); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.controller;
|
| | |
|
| | | import java.util.List;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.web.bind.annotation.DeleteMapping;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.PathVariable;
|
| | | import org.springframework.web.bind.annotation.PostMapping;
|
| | | import org.springframework.web.bind.annotation.PutMapping;
|
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.service.ISysJobService;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | |
|
| | | /**
|
| | | * 调度任务信息操作处理
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @RestController
|
| | | @RequestMapping("/monitor/job")
|
| | | public class SysJobController extends BaseController
|
| | | {
|
| | | @Autowired
|
| | | private ISysJobService jobService;
|
| | |
|
| | | /**
|
| | | * 查询定时任务列表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:list')")
|
| | | @GetMapping("/list")
|
| | | public TableDataInfo list(SysJob sysJob)
|
| | | {
|
| | | startPage();
|
| | | List<SysJob> list = jobService.selectJobList(sysJob);
|
| | | return getDataTable(list);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 导出定时任务列表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.EXPORT)
|
| | | @GetMapping("/export")
|
| | | public AjaxResult export(SysJob sysJob)
|
| | | {
|
| | | List<SysJob> list = jobService.selectJobList(sysJob);
|
| | | ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
|
| | | return util.exportExcel(list, "定时任务");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取定时任务详细信息
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')")
|
| | | @GetMapping(value = "/{jobId}")
|
| | | public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
| | | {
|
| | | return AjaxResult.success(jobService.selectJobById(jobId));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 新增定时任务
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:add')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
|
| | | {
|
| | | if (!CronUtils.isValid(sysJob.getCronExpression()))
|
| | | {
|
| | | return AjaxResult.error("cron表达式不正确");
|
| | | }
|
| | | sysJob.setCreateBy(SecurityUtils.getUsername());
|
| | | return toAjax(jobService.insertJob(sysJob));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 修改定时任务
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:edit')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
|
| | | {
|
| | | if (!CronUtils.isValid(sysJob.getCronExpression()))
|
| | | {
|
| | | return AjaxResult.error("cron表达式不正确");
|
| | | }
|
| | | sysJob.setUpdateBy(SecurityUtils.getUsername());
|
| | | return toAjax(jobService.updateJob(sysJob));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 定时任务状态修改
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/changeStatus")
|
| | | public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
|
| | | {
|
| | | SysJob newJob = jobService.selectJobById(job.getJobId());
|
| | | newJob.setStatus(job.getStatus());
|
| | | return toAjax(jobService.changeStatus(newJob));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 定时任务立即执行一次
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/run")
|
| | | public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
|
| | | {
|
| | | jobService.run(job);
|
| | | return AjaxResult.success();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除定时任务
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
|
| | | @Log(title = "定时任务", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{jobIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
|
| | | {
|
| | | jobService.deleteJobByIds(jobIds);
|
| | | return AjaxResult.success();
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/controller/SysJobLogController.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.controller; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | | import com.ruoyi.project.monitor.domain.SysJobLog; |
| | | import com.ruoyi.project.monitor.service.ISysJobLogService; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | |
| | | /** |
| | | * 调度日志操作处理 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/jobLog") |
| | | public class SysJobLogController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ISysJobLogService jobLogService; |
| | | |
| | | /** |
| | | * 查询定时任务调度日志列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysJobLog sysJobLog) |
| | | { |
| | | startPage(); |
| | | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导出定时任务调度日志列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')") |
| | | @Log(title = "任务调度日志", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/export") |
| | | public AjaxResult export(SysJobLog sysJobLog) |
| | | { |
| | | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); |
| | | ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class); |
| | | return util.exportExcel(list, "调度日志"); |
| | | } |
| | | |
| | | /** |
| | | * 根据调度编号获取详细信息 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')") |
| | | @GetMapping(value = "/{configId}") |
| | | public AjaxResult getInfo(@PathVariable Long jobLogId) |
| | | { |
| | | return AjaxResult.success(jobLogService.selectJobLogById(jobLogId)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除定时任务调度日志 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| | | @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{jobLogIds}") |
| | | public AjaxResult remove(@PathVariable Long[] jobLogIds) |
| | | { |
| | | return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); |
| | | } |
| | | |
| | | /** |
| | | * 清空定时任务调度日志 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')") |
| | | @Log(title = "调度日志", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult clean() |
| | | { |
| | | jobLogService.cleanJobLog(); |
| | | return AjaxResult.success(); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.controller;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.web.bind.annotation.DeleteMapping;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.PathVariable;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.annotation.Log;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.page.TableDataInfo;
|
| | | import com.ruoyi.common.enums.BusinessType;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | |
|
| | | /**
|
| | | * 调度日志操作处理
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @RestController
|
| | | @RequestMapping("/monitor/jobLog")
|
| | | public class SysJobLogController extends BaseController
|
| | | {
|
| | | @Autowired
|
| | | private ISysJobLogService jobLogService;
|
| | |
|
| | | /**
|
| | | * 查询定时任务调度日志列表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:list')")
|
| | | @GetMapping("/list")
|
| | | public TableDataInfo list(SysJobLog sysJobLog)
|
| | | {
|
| | | startPage();
|
| | | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
|
| | | return getDataTable(list);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 导出定时任务调度日志列表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:export')")
|
| | | @Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
|
| | | @GetMapping("/export")
|
| | | public AjaxResult export(SysJobLog sysJobLog)
|
| | | {
|
| | | List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
|
| | | ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
|
| | | return util.exportExcel(list, "调度日志");
|
| | | }
|
| | | |
| | | /**
|
| | | * 根据调度编号获取详细信息
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:query')")
|
| | | @GetMapping(value = "/{configId}")
|
| | | public AjaxResult getInfo(@PathVariable Long jobLogId)
|
| | | {
|
| | | return AjaxResult.success(jobLogService.selectJobLogById(jobLogId));
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 删除定时任务调度日志
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
|
| | | @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{jobLogIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] jobLogIds)
|
| | | {
|
| | | return toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 清空定时任务调度日志
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
|
| | | @Log(title = "调度日志", businessType = BusinessType.CLEAN)
|
| | | @DeleteMapping("/clean")
|
| | | public AjaxResult clean()
|
| | | {
|
| | | jobLogService.cleanJobLog();
|
| | | return AjaxResult.success();
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/domain/SysJob.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.domain; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.Size; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.job.CronUtils; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType; |
| | | import com.ruoyi.framework.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * 定时任务调度表 sys_job |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class SysJob extends BaseEntity implements Serializable |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** 任务ID */ |
| | | @Excel(name = "任务序号", cellType = ColumnType.NUMERIC) |
| | | private Long jobId; |
| | | |
| | | /** 任务名称 */ |
| | | @Excel(name = "任务名称") |
| | | private String jobName; |
| | | |
| | | /** 任务组名 */ |
| | | @Excel(name = "任务组名") |
| | | private String jobGroup; |
| | | |
| | | /** 调用目标字符串 */ |
| | | @Excel(name = "调用目标字符串") |
| | | private String invokeTarget; |
| | | |
| | | /** cron执行表达式 */ |
| | | @Excel(name = "执行表达式 ") |
| | | private String cronExpression; |
| | | |
| | | /** cron计划策略 */ |
| | | @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行") |
| | | private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT; |
| | | |
| | | /** 是否并发执行(0允许 1禁止) */ |
| | | @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止") |
| | | private String concurrent; |
| | | |
| | | /** 任务状态(0正常 1暂停) */ |
| | | @Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停") |
| | | private String status; |
| | | |
| | | public Long getJobId() |
| | | { |
| | | return jobId; |
| | | } |
| | | |
| | | public void setJobId(Long jobId) |
| | | { |
| | | this.jobId = jobId; |
| | | } |
| | | |
| | | @NotBlank(message = "任务名称不能为空") |
| | | @Size(min = 0, max = 64, message = "任务名称不能超过64个字符") |
| | | public String getJobName() |
| | | { |
| | | return jobName; |
| | | } |
| | | |
| | | public void setJobName(String jobName) |
| | | { |
| | | this.jobName = jobName; |
| | | } |
| | | |
| | | public String getJobGroup() |
| | | { |
| | | return jobGroup; |
| | | } |
| | | |
| | | public void setJobGroup(String jobGroup) |
| | | { |
| | | this.jobGroup = jobGroup; |
| | | } |
| | | |
| | | @NotBlank(message = "调用目标字符串不能为空") |
| | | @Size(min = 0, max = 1000, message = "调用目标字符串长度不能超过500个字符") |
| | | public String getInvokeTarget() |
| | | { |
| | | return invokeTarget; |
| | | } |
| | | |
| | | public void setInvokeTarget(String invokeTarget) |
| | | { |
| | | this.invokeTarget = invokeTarget; |
| | | } |
| | | |
| | | @NotBlank(message = "Cron执行表达式不能为空") |
| | | @Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符") |
| | | public String getCronExpression() |
| | | { |
| | | return cronExpression; |
| | | } |
| | | |
| | | public void setCronExpression(String cronExpression) |
| | | { |
| | | this.cronExpression = cronExpression; |
| | | } |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | public Date getNextValidTime() |
| | | { |
| | | if (StringUtils.isNotEmpty(cronExpression)) |
| | | { |
| | | return CronUtils.getNextExecution(cronExpression); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getMisfirePolicy() |
| | | { |
| | | return misfirePolicy; |
| | | } |
| | | |
| | | public void setMisfirePolicy(String misfirePolicy) |
| | | { |
| | | this.misfirePolicy = misfirePolicy; |
| | | } |
| | | |
| | | public String getConcurrent() |
| | | { |
| | | return concurrent; |
| | | } |
| | | |
| | | public void setConcurrent(String concurrent) |
| | | { |
| | | this.concurrent = concurrent; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("jobId", getJobId()) |
| | | .append("jobName", getJobName()) |
| | | .append("jobGroup", getJobGroup()) |
| | | .append("cronExpression", getCronExpression()) |
| | | .append("nextValidTime", getNextValidTime()) |
| | | .append("misfirePolicy", getMisfirePolicy()) |
| | | .append("concurrent", getConcurrent()) |
| | | .append("status", getStatus()) |
| | | .append("createBy", getCreateBy()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("updateBy", getUpdateBy()) |
| | | .append("updateTime", getUpdateTime()) |
| | | .append("remark", getRemark()) |
| | | .toString(); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.domain;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.Date;
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.fasterxml.jackson.annotation.JsonFormat;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | |
|
| | | /**
|
| | | * 定时任务调度表 sys_job
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class SysJob extends BaseEntity implements Serializable
|
| | | {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | /** 任务ID */
|
| | | @Excel(name = "任务序号", cellType = ColumnType.NUMERIC)
|
| | | private Long jobId;
|
| | |
|
| | | /** 任务名称 */
|
| | | @Excel(name = "任务名称")
|
| | | private String jobName;
|
| | |
|
| | | /** 任务组名 */
|
| | | @Excel(name = "任务组名")
|
| | | private String jobGroup;
|
| | |
|
| | | /** 调用目标字符串 */
|
| | | @Excel(name = "调用目标字符串")
|
| | | private String invokeTarget;
|
| | |
|
| | | /** cron执行表达式 */
|
| | | @Excel(name = "执行表达式 ")
|
| | | private String cronExpression;
|
| | |
|
| | | /** cron计划策略 */
|
| | | @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行")
|
| | | private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
|
| | |
|
| | | /** 是否并发执行(0允许 1禁止) */
|
| | | @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")
|
| | | private String concurrent;
|
| | |
|
| | | /** 任务状态(0正常 1暂停) */
|
| | | @Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停")
|
| | | private String status;
|
| | |
|
| | | public Long getJobId()
|
| | | {
|
| | | return jobId;
|
| | | }
|
| | |
|
| | | public void setJobId(Long jobId)
|
| | | {
|
| | | this.jobId = jobId;
|
| | | }
|
| | |
|
| | | @NotBlank(message = "任务名称不能为空")
|
| | | @Size(min = 0, max = 64, message = "任务名称不能超过64个字符")
|
| | | public String getJobName()
|
| | | {
|
| | | return jobName;
|
| | | }
|
| | |
|
| | | public void setJobName(String jobName)
|
| | | {
|
| | | this.jobName = jobName;
|
| | | }
|
| | |
|
| | | public String getJobGroup()
|
| | | {
|
| | | return jobGroup;
|
| | | }
|
| | |
|
| | | public void setJobGroup(String jobGroup)
|
| | | {
|
| | | this.jobGroup = jobGroup;
|
| | | }
|
| | |
|
| | | @NotBlank(message = "调用目标字符串不能为空")
|
| | | @Size(min = 0, max = 1000, message = "调用目标字符串长度不能超过500个字符")
|
| | | public String getInvokeTarget()
|
| | | {
|
| | | return invokeTarget;
|
| | | }
|
| | |
|
| | | public void setInvokeTarget(String invokeTarget)
|
| | | {
|
| | | this.invokeTarget = invokeTarget;
|
| | | }
|
| | |
|
| | | @NotBlank(message = "Cron执行表达式不能为空")
|
| | | @Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符")
|
| | | public String getCronExpression()
|
| | | {
|
| | | return cronExpression;
|
| | | }
|
| | |
|
| | | public void setCronExpression(String cronExpression)
|
| | | {
|
| | | this.cronExpression = cronExpression;
|
| | | }
|
| | |
|
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
| | | public Date getNextValidTime()
|
| | | {
|
| | | if (StringUtils.isNotEmpty(cronExpression))
|
| | | {
|
| | | return CronUtils.getNextExecution(cronExpression);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public String getMisfirePolicy()
|
| | | {
|
| | | return misfirePolicy;
|
| | | }
|
| | |
|
| | | public void setMisfirePolicy(String misfirePolicy)
|
| | | {
|
| | | this.misfirePolicy = misfirePolicy;
|
| | | }
|
| | |
|
| | | public String getConcurrent()
|
| | | {
|
| | | return concurrent;
|
| | | }
|
| | |
|
| | | public void setConcurrent(String concurrent)
|
| | | {
|
| | | this.concurrent = concurrent;
|
| | | }
|
| | |
|
| | | public String getStatus()
|
| | | {
|
| | | return status;
|
| | | }
|
| | |
|
| | | public void setStatus(String status)
|
| | | {
|
| | | this.status = status;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
| | | .append("jobId", getJobId())
|
| | | .append("jobName", getJobName())
|
| | | .append("jobGroup", getJobGroup())
|
| | | .append("cronExpression", getCronExpression())
|
| | | .append("nextValidTime", getNextValidTime())
|
| | | .append("misfirePolicy", getMisfirePolicy())
|
| | | .append("concurrent", getConcurrent())
|
| | | .append("status", getStatus())
|
| | | .append("createBy", getCreateBy())
|
| | | .append("createTime", getCreateTime())
|
| | | .append("updateBy", getUpdateBy())
|
| | | .append("updateTime", getUpdateTime())
|
| | | .append("remark", getRemark())
|
| | | .toString();
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/domain/SysJobLog.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.domain; |
| | | |
| | | import java.util.Date; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel; |
| | | import com.ruoyi.framework.web.domain.BaseEntity; |
| | | |
| | | /** |
| | | * 定时任务调度日志表 sys_job_log |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class SysJobLog extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** ID */ |
| | | @Excel(name = "日志序号") |
| | | private Long jobLogId; |
| | | |
| | | /** 任务名称 */ |
| | | @Excel(name = "任务名称") |
| | | private String jobName; |
| | | |
| | | /** 任务组名 */ |
| | | @Excel(name = "任务组名") |
| | | private String jobGroup; |
| | | |
| | | /** 调用目标字符串 */ |
| | | @Excel(name = "调用目标字符串") |
| | | private String invokeTarget; |
| | | |
| | | /** 日志信息 */ |
| | | @Excel(name = "日志信息") |
| | | private String jobMessage; |
| | | |
| | | /** 执行状态(0正常 1失败) */ |
| | | @Excel(name = "执行状态", readConverterExp = "0=正常,1=失败") |
| | | private String status; |
| | | |
| | | /** 异常信息 */ |
| | | @Excel(name = "异常信息") |
| | | private String exceptionInfo; |
| | | |
| | | /** 开始时间 */ |
| | | private Date startTime; |
| | | |
| | | /** 停止时间 */ |
| | | private Date stopTime; |
| | | |
| | | public Long getJobLogId() |
| | | { |
| | | return jobLogId; |
| | | } |
| | | |
| | | public void setJobLogId(Long jobLogId) |
| | | { |
| | | this.jobLogId = jobLogId; |
| | | } |
| | | |
| | | public String getJobName() |
| | | { |
| | | return jobName; |
| | | } |
| | | |
| | | public void setJobName(String jobName) |
| | | { |
| | | this.jobName = jobName; |
| | | } |
| | | |
| | | public String getJobGroup() |
| | | { |
| | | return jobGroup; |
| | | } |
| | | |
| | | public void setJobGroup(String jobGroup) |
| | | { |
| | | this.jobGroup = jobGroup; |
| | | } |
| | | |
| | | public String getInvokeTarget() |
| | | { |
| | | return invokeTarget; |
| | | } |
| | | |
| | | public void setInvokeTarget(String invokeTarget) |
| | | { |
| | | this.invokeTarget = invokeTarget; |
| | | } |
| | | |
| | | public String getJobMessage() |
| | | { |
| | | return jobMessage; |
| | | } |
| | | |
| | | public void setJobMessage(String jobMessage) |
| | | { |
| | | this.jobMessage = jobMessage; |
| | | } |
| | | |
| | | public String getStatus() |
| | | { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(String status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getExceptionInfo() |
| | | { |
| | | return exceptionInfo; |
| | | } |
| | | |
| | | public void setExceptionInfo(String exceptionInfo) |
| | | { |
| | | this.exceptionInfo = exceptionInfo; |
| | | } |
| | | |
| | | public Date getStartTime() |
| | | { |
| | | return startTime; |
| | | } |
| | | |
| | | public void setStartTime(Date startTime) |
| | | { |
| | | this.startTime = startTime; |
| | | } |
| | | |
| | | public Date getStopTime() |
| | | { |
| | | return stopTime; |
| | | } |
| | | |
| | | public void setStopTime(Date stopTime) |
| | | { |
| | | this.stopTime = stopTime; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("jobLogId", getJobLogId()) |
| | | .append("jobName", getJobName()) |
| | | .append("jobGroup", getJobGroup()) |
| | | .append("jobMessage", getJobMessage()) |
| | | .append("status", getStatus()) |
| | | .append("exceptionInfo", getExceptionInfo()) |
| | | .append("startTime", getStartTime()) |
| | | .append("stopTime", getStopTime()) |
| | | .toString(); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.domain;
|
| | |
|
| | | import java.util.Date;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 定时任务调度日志表 sys_job_log
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class SysJobLog extends BaseEntity
|
| | | {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | /** ID */
|
| | | @Excel(name = "日志序号")
|
| | | private Long jobLogId;
|
| | |
|
| | | /** 任务名称 */
|
| | | @Excel(name = "任务名称")
|
| | | private String jobName;
|
| | |
|
| | | /** 任务组名 */
|
| | | @Excel(name = "任务组名")
|
| | | private String jobGroup;
|
| | |
|
| | | /** 调用目标字符串 */
|
| | | @Excel(name = "调用目标字符串")
|
| | | private String invokeTarget;
|
| | |
|
| | | /** 日志信息 */
|
| | | @Excel(name = "日志信息")
|
| | | private String jobMessage;
|
| | |
|
| | | /** 执行状态(0正常 1失败) */
|
| | | @Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
|
| | | private String status;
|
| | |
|
| | | /** 异常信息 */
|
| | | @Excel(name = "异常信息")
|
| | | private String exceptionInfo;
|
| | |
|
| | | /** 开始时间 */
|
| | | private Date startTime;
|
| | |
|
| | | /** 停止时间 */
|
| | | private Date stopTime;
|
| | |
|
| | | public Long getJobLogId()
|
| | | {
|
| | | return jobLogId;
|
| | | }
|
| | |
|
| | | public void setJobLogId(Long jobLogId)
|
| | | {
|
| | | this.jobLogId = jobLogId;
|
| | | }
|
| | |
|
| | | public String getJobName()
|
| | | {
|
| | | return jobName;
|
| | | }
|
| | |
|
| | | public void setJobName(String jobName)
|
| | | {
|
| | | this.jobName = jobName;
|
| | | }
|
| | |
|
| | | public String getJobGroup()
|
| | | {
|
| | | return jobGroup;
|
| | | }
|
| | |
|
| | | public void setJobGroup(String jobGroup)
|
| | | {
|
| | | this.jobGroup = jobGroup;
|
| | | }
|
| | |
|
| | | public String getInvokeTarget()
|
| | | {
|
| | | return invokeTarget;
|
| | | }
|
| | |
|
| | | public void setInvokeTarget(String invokeTarget)
|
| | | {
|
| | | this.invokeTarget = invokeTarget;
|
| | | }
|
| | |
|
| | | public String getJobMessage()
|
| | | {
|
| | | return jobMessage;
|
| | | }
|
| | |
|
| | | public void setJobMessage(String jobMessage)
|
| | | {
|
| | | this.jobMessage = jobMessage;
|
| | | }
|
| | |
|
| | | public String getStatus()
|
| | | {
|
| | | return status;
|
| | | }
|
| | |
|
| | | public void setStatus(String status)
|
| | | {
|
| | | this.status = status;
|
| | | }
|
| | |
|
| | | public String getExceptionInfo()
|
| | | {
|
| | | return exceptionInfo;
|
| | | }
|
| | |
|
| | | public void setExceptionInfo(String exceptionInfo)
|
| | | {
|
| | | this.exceptionInfo = exceptionInfo;
|
| | | }
|
| | |
|
| | | public Date getStartTime()
|
| | | {
|
| | | return startTime;
|
| | | }
|
| | |
|
| | | public void setStartTime(Date startTime)
|
| | | {
|
| | | this.startTime = startTime;
|
| | | }
|
| | | |
| | | public Date getStopTime()
|
| | | {
|
| | | return stopTime;
|
| | | }
|
| | |
|
| | | public void setStopTime(Date stopTime)
|
| | | {
|
| | | this.stopTime = stopTime;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
| | | .append("jobLogId", getJobLogId())
|
| | | .append("jobName", getJobName())
|
| | | .append("jobGroup", getJobGroup())
|
| | | .append("jobMessage", getJobMessage())
|
| | | .append("status", getStatus())
|
| | | .append("exceptionInfo", getExceptionInfo())
|
| | | .append("startTime", getStartTime())
|
| | | .append("stopTime", getStopTime())
|
| | | .toString();
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/mapper/SysJobLogMapper.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.ruoyi.project.monitor.domain.SysJobLog; |
| | | |
| | | /** |
| | | * 调度任务日志信息 数据层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysJobLogMapper |
| | | { |
| | | /** |
| | | * 获取quartz调度器日志的计划任务 |
| | | * |
| | | * @param jobLog 调度日志信息 |
| | | * @return 调度任务日志集合 |
| | | */ |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * 查询所有调度任务日志 |
| | | * |
| | | * @return 调度任务日志列表 |
| | | */ |
| | | public List<SysJobLog> selectJobLogAll(); |
| | | |
| | | /** |
| | | * 通过调度任务日志ID查询调度信息 |
| | | * |
| | | * @param jobLogId 调度任务日志ID |
| | | * @return 调度任务日志对象信息 |
| | | */ |
| | | public SysJobLog selectJobLogById(Long jobLogId); |
| | | |
| | | /** |
| | | * 新增任务日志 |
| | | * |
| | | * @param jobLog 调度日志信息 |
| | | * @return 结果 |
| | | */ |
| | | public int insertJobLog(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * 批量删除调度日志信息 |
| | | * |
| | | * @param logIds 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJobLogByIds(Long[] logIds); |
| | | |
| | | /** |
| | | * 删除任务日志 |
| | | * |
| | | * @param jobId 调度日志ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJobLogById(Long jobId); |
| | | |
| | | /** |
| | | * 清空任务日志 |
| | | */ |
| | | public void cleanJobLog(); |
| | | } |
| | | package com.ruoyi.quartz.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | |
|
| | | /**
|
| | | * 调度任务日志信息 数据层
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public interface SysJobLogMapper
|
| | | {
|
| | | /**
|
| | | * 获取quartz调度器日志的计划任务
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | * @return 调度任务日志集合
|
| | | */
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * 查询所有调度任务日志
|
| | | *
|
| | | * @return 调度任务日志列表
|
| | | */
|
| | | public List<SysJobLog> selectJobLogAll();
|
| | |
|
| | | /**
|
| | | * 通过调度任务日志ID查询调度信息
|
| | | * |
| | | * @param jobLogId 调度任务日志ID
|
| | | * @return 调度任务日志对象信息
|
| | | */
|
| | | public SysJobLog selectJobLogById(Long jobLogId);
|
| | |
|
| | | /**
|
| | | * 新增任务日志
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | * @return 结果
|
| | | */
|
| | | public int insertJobLog(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * 批量删除调度日志信息
|
| | | * |
| | | * @param logIds 需要删除的数据ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobLogByIds(Long[] logIds);
|
| | |
|
| | | /**
|
| | | * 删除任务日志
|
| | | * |
| | | * @param jobId 调度日志ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobLogById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 清空任务日志
|
| | | */
|
| | | public void cleanJobLog();
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/mapper/SysJobMapper.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | |
| | | /** |
| | | * 调度任务信息 数据层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysJobMapper |
| | | { |
| | | /** |
| | | * 查询调度任务日志集合 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 操作日志集合 |
| | | */ |
| | | public List<SysJob> selectJobList(SysJob job); |
| | | |
| | | /** |
| | | * 查询所有调度任务 |
| | | * |
| | | * @return 调度任务列表 |
| | | */ |
| | | public List<SysJob> selectJobAll(); |
| | | |
| | | /** |
| | | * 通过调度ID查询调度任务信息 |
| | | * |
| | | * @param jobId 调度ID |
| | | * @return 角色对象信息 |
| | | */ |
| | | public SysJob selectJobById(Long jobId); |
| | | |
| | | /** |
| | | * 通过调度ID删除调度任务信息 |
| | | * |
| | | * @param jobId 调度ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJobById(Long jobId); |
| | | |
| | | /** |
| | | * 批量删除调度任务信息 |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJobByIds(Long[] ids); |
| | | |
| | | /** |
| | | * 修改调度任务信息 |
| | | * |
| | | * @param job 调度任务信息 |
| | | * @return 结果 |
| | | */ |
| | | public int updateJob(SysJob job); |
| | | |
| | | /** |
| | | * 新增调度任务信息 |
| | | * |
| | | * @param job 调度任务信息 |
| | | * @return 结果 |
| | | */ |
| | | public int insertJob(SysJob job); |
| | | } |
| | | package com.ruoyi.quartz.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 调度任务信息 数据层
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public interface SysJobMapper
|
| | | {
|
| | | /**
|
| | | * 查询调度任务日志集合
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 操作日志集合
|
| | | */
|
| | | public List<SysJob> selectJobList(SysJob job);
|
| | |
|
| | | /**
|
| | | * 查询所有调度任务
|
| | | * |
| | | * @return 调度任务列表
|
| | | */
|
| | | public List<SysJob> selectJobAll();
|
| | |
|
| | | /**
|
| | | * 通过调度ID查询调度任务信息
|
| | | * |
| | | * @param jobId 调度ID
|
| | | * @return 角色对象信息
|
| | | */
|
| | | public SysJob selectJobById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 通过调度ID删除调度任务信息
|
| | | * |
| | | * @param jobId 调度ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 批量删除调度任务信息
|
| | | * |
| | | * @param ids 需要删除的数据ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobByIds(Long[] ids);
|
| | |
|
| | | /**
|
| | | * 修改调度任务信息
|
| | | * |
| | | * @param job 调度任务信息
|
| | | * @return 结果
|
| | | */
|
| | | public int updateJob(SysJob job);
|
| | |
|
| | | /**
|
| | | * 新增调度任务信息
|
| | | * |
| | | * @param job 调度任务信息
|
| | | * @return 结果
|
| | | */
|
| | | public int insertJob(SysJob job);
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/ISysJobLogService.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service; |
| | | |
| | | import java.util.List; |
| | | import com.ruoyi.project.monitor.domain.SysJobLog; |
| | | |
| | | /** |
| | | * 定时任务调度日志信息信息 服务层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface ISysJobLogService |
| | | { |
| | | /** |
| | | * 获取quartz调度器日志的计划任务 |
| | | * |
| | | * @param jobLog 调度日志信息 |
| | | * @return 调度任务日志集合 |
| | | */ |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * 通过调度任务日志ID查询调度信息 |
| | | * |
| | | * @param jobLogId 调度任务日志ID |
| | | * @return 调度任务日志对象信息 |
| | | */ |
| | | public SysJobLog selectJobLogById(Long jobLogId); |
| | | |
| | | /** |
| | | * 新增任务日志 |
| | | * |
| | | * @param jobLog 调度日志信息 |
| | | */ |
| | | public void addJobLog(SysJobLog jobLog); |
| | | |
| | | /** |
| | | * 批量删除调度日志信息 |
| | | * |
| | | * @param logIds 需要删除的日志ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJobLogByIds(Long[] logIds); |
| | | |
| | | /** |
| | | * 删除任务日志 |
| | | * |
| | | * @param jobId 调度日志ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJobLogById(Long jobId); |
| | | |
| | | /** |
| | | * 清空任务日志 |
| | | */ |
| | | public void cleanJobLog(); |
| | | } |
| | | package com.ruoyi.quartz.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | |
|
| | | /**
|
| | | * 定时任务调度日志信息信息 服务层
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public interface ISysJobLogService
|
| | | {
|
| | | /**
|
| | | * 获取quartz调度器日志的计划任务
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | * @return 调度任务日志集合
|
| | | */
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * 通过调度任务日志ID查询调度信息
|
| | | * |
| | | * @param jobLogId 调度任务日志ID
|
| | | * @return 调度任务日志对象信息
|
| | | */
|
| | | public SysJobLog selectJobLogById(Long jobLogId);
|
| | |
|
| | | /**
|
| | | * 新增任务日志
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | */
|
| | | public void addJobLog(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * 批量删除调度日志信息
|
| | | * |
| | | * @param logIds 需要删除的日志ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobLogByIds(Long[] logIds);
|
| | |
|
| | | /**
|
| | | * 删除任务日志
|
| | | * |
| | | * @param jobId 调度日志ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobLogById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 清空任务日志
|
| | | */
|
| | | public void cleanJobLog();
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/ISysJobService.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service; |
| | | |
| | | import java.util.List; |
| | | import org.quartz.SchedulerException; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | |
| | | /** |
| | | * 定时任务调度信息信息 服务层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface ISysJobService |
| | | { |
| | | /** |
| | | * 获取quartz调度器的计划任务 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 调度任务集合 |
| | | */ |
| | | public List<SysJob> selectJobList(SysJob job); |
| | | |
| | | /** |
| | | * 通过调度任务ID查询调度信息 |
| | | * |
| | | * @param jobId 调度任务ID |
| | | * @return 调度任务对象信息 |
| | | */ |
| | | public SysJob selectJobById(Long jobId); |
| | | |
| | | /** |
| | | * 暂停任务 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public int pauseJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * 恢复任务 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public int resumeJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * 删除任务后,所对应的trigger也将被删除 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public int deleteJob(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * 批量删除调度信息 |
| | | * |
| | | * @param jobIds 需要删除的任务ID |
| | | * @return 结果 |
| | | */ |
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException; |
| | | |
| | | /** |
| | | * 任务调度状态修改 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public int changeStatus(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * 立即运行任务 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public void run(SysJob job) throws SchedulerException; |
| | | |
| | | /** |
| | | * 新增任务 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException; |
| | | |
| | | /** |
| | | * 更新任务 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return 结果 |
| | | */ |
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException; |
| | | |
| | | /** |
| | | * 校验cron表达式是否有效 |
| | | * |
| | | * @param cronExpression 表达式 |
| | | * @return 结果 |
| | | */ |
| | | public boolean checkCronExpressionIsValid(String cronExpression); |
| | | } |
| | | package com.ruoyi.quartz.service;
|
| | |
|
| | | import java.util.List;
|
| | | import org.quartz.SchedulerException;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 定时任务调度信息信息 服务层
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public interface ISysJobService
|
| | | {
|
| | | /**
|
| | | * 获取quartz调度器的计划任务
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 调度任务集合
|
| | | */
|
| | | public List<SysJob> selectJobList(SysJob job);
|
| | |
|
| | | /**
|
| | | * 通过调度任务ID查询调度信息
|
| | | * |
| | | * @param jobId 调度任务ID
|
| | | * @return 调度任务对象信息
|
| | | */
|
| | | public SysJob selectJobById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 暂停任务
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public int pauseJob(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * 恢复任务
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public int resumeJob(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * 删除任务后,所对应的trigger也将被删除
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJob(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * 批量删除调度信息
|
| | | * |
| | | * @param jobIds 需要删除的任务ID
|
| | | * @return 结果
|
| | | */
|
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * 任务调度状态修改
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public int changeStatus(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * 立即运行任务
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public void run(SysJob job) throws SchedulerException;
|
| | |
|
| | | /**
|
| | | * 新增任务
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException;
|
| | |
|
| | | /**
|
| | | * 更新任务
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException;
|
| | |
|
| | | /**
|
| | | * 校验cron表达式是否有效
|
| | | * |
| | | * @param cronExpression 表达式
|
| | | * @return 结果
|
| | | */
|
| | | public boolean checkCronExpressionIsValid(String cronExpression);
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/impl/SysJobLogServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service.impl; |
| | | |
| | | import java.util.List; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.project.monitor.domain.SysJobLog; |
| | | import com.ruoyi.project.monitor.mapper.SysJobLogMapper; |
| | | import com.ruoyi.project.monitor.service.ISysJobLogService; |
| | | |
| | | /** |
| | | * 定时任务调度日志信息 服务层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysJobLogServiceImpl implements ISysJobLogService |
| | | { |
| | | @Autowired |
| | | private SysJobLogMapper jobLogMapper; |
| | | |
| | | /** |
| | | * 获取quartz调度器日志的计划任务 |
| | | * |
| | | * @param jobLog 调度日志信息 |
| | | * @return 调度任务日志集合 |
| | | */ |
| | | @Override |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog) |
| | | { |
| | | return jobLogMapper.selectJobLogList(jobLog); |
| | | } |
| | | |
| | | /** |
| | | * 通过调度任务日志ID查询调度信息 |
| | | * |
| | | * @param jobLogId 调度任务日志ID |
| | | * @return 调度任务日志对象信息 |
| | | */ |
| | | @Override |
| | | public SysJobLog selectJobLogById(Long jobLogId) |
| | | { |
| | | return jobLogMapper.selectJobLogById(jobLogId); |
| | | } |
| | | |
| | | /** |
| | | * 新增任务日志 |
| | | * |
| | | * @param jobLog 调度日志信息 |
| | | */ |
| | | @Override |
| | | public void addJobLog(SysJobLog jobLog) |
| | | { |
| | | jobLogMapper.insertJobLog(jobLog); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除调度日志信息 |
| | | * |
| | | * @param logIds 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteJobLogByIds(Long[] logIds) |
| | | { |
| | | return jobLogMapper.deleteJobLogByIds(logIds); |
| | | } |
| | | |
| | | /** |
| | | * 删除任务日志 |
| | | * |
| | | * @param jobId 调度日志ID |
| | | */ |
| | | @Override |
| | | public int deleteJobLogById(Long jobId) |
| | | { |
| | | return jobLogMapper.deleteJobLogById(jobId); |
| | | } |
| | | |
| | | /** |
| | | * 清空任务日志 |
| | | */ |
| | | @Override |
| | | public void cleanJobLog() |
| | | { |
| | | jobLogMapper.cleanJobLog(); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.mapper.SysJobLogMapper;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | |
|
| | | /**
|
| | | * 定时任务调度日志信息 服务层
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysJobLogServiceImpl implements ISysJobLogService
|
| | | {
|
| | | @Autowired
|
| | | private SysJobLogMapper jobLogMapper;
|
| | |
|
| | | /**
|
| | | * 获取quartz调度器日志的计划任务
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | * @return 调度任务日志集合
|
| | | */
|
| | | @Override
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog)
|
| | | {
|
| | | return jobLogMapper.selectJobLogList(jobLog);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过调度任务日志ID查询调度信息
|
| | | * |
| | | * @param jobLogId 调度任务日志ID
|
| | | * @return 调度任务日志对象信息
|
| | | */
|
| | | @Override
|
| | | public SysJobLog selectJobLogById(Long jobLogId)
|
| | | {
|
| | | return jobLogMapper.selectJobLogById(jobLogId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 新增任务日志
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | */
|
| | | @Override
|
| | | public void addJobLog(SysJobLog jobLog)
|
| | | {
|
| | | jobLogMapper.insertJobLog(jobLog);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量删除调度日志信息
|
| | | * |
| | | * @param logIds 需要删除的数据ID
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | public int deleteJobLogByIds(Long[] logIds)
|
| | | {
|
| | | return jobLogMapper.deleteJobLogByIds(logIds);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除任务日志
|
| | | * |
| | | * @param jobId 调度日志ID
|
| | | */
|
| | | @Override
|
| | | public int deleteJobLogById(Long jobId)
|
| | | {
|
| | | return jobLogMapper.deleteJobLogById(jobId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 清空任务日志
|
| | | */
|
| | | @Override
|
| | | public void cleanJobLog()
|
| | | {
|
| | | jobLogMapper.cleanJobLog();
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/impl/SysJobServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service.impl; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.PostConstruct; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobKey; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.common.utils.job.CronUtils; |
| | | import com.ruoyi.common.utils.job.ScheduleUtils; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | import com.ruoyi.project.monitor.mapper.SysJobMapper; |
| | | import com.ruoyi.project.monitor.service.ISysJobService; |
| | | |
| | | /** |
| | | * 定时任务调度信息 服务层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysJobServiceImpl implements ISysJobService |
| | | { |
| | | @Autowired |
| | | private Scheduler scheduler; |
| | | |
| | | @Autowired |
| | | private SysJobMapper jobMapper; |
| | | |
| | | /** |
| | | * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) |
| | | */ |
| | | @PostConstruct |
| | | public void init() throws SchedulerException, TaskException |
| | | { |
| | | scheduler.clear(); |
| | | List<SysJob> jobList = jobMapper.selectJobAll(); |
| | | for (SysJob job : jobList) |
| | | { |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取quartz调度器的计划任务列表 |
| | | * |
| | | * @param job 调度信息 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SysJob> selectJobList(SysJob job) |
| | | { |
| | | return jobMapper.selectJobList(job); |
| | | } |
| | | |
| | | /** |
| | | * 通过调度任务ID查询调度信息 |
| | | * |
| | | * @param jobId 调度任务ID |
| | | * @return 调度任务对象信息 |
| | | */ |
| | | @Override |
| | | public SysJob selectJobById(Long jobId) |
| | | { |
| | | return jobMapper.selectJobById(jobId); |
| | | } |
| | | |
| | | /** |
| | | * 暂停任务 |
| | | * |
| | | * @param job 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int pauseJob(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| | | int rows = jobMapper.updateJob(job); |
| | | if (rows > 0) |
| | | { |
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 恢复任务 |
| | | * |
| | | * @param job 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int resumeJob(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); |
| | | int rows = jobMapper.updateJob(job); |
| | | if (rows > 0) |
| | | { |
| | | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 删除任务后,所对应的trigger也将被删除 |
| | | * |
| | | * @param job 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int deleteJob(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | int rows = jobMapper.deleteJobById(jobId); |
| | | if (rows > 0) |
| | | { |
| | | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 批量删除调度信息 |
| | | * |
| | | * @param jobIds 需要删除的任务ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException |
| | | { |
| | | for (Long jobId : jobIds) |
| | | { |
| | | SysJob job = jobMapper.selectJobById(jobId); |
| | | deleteJob(job); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 任务调度状态修改 |
| | | * |
| | | * @param job 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int changeStatus(SysJob job) throws SchedulerException |
| | | { |
| | | int rows = 0; |
| | | String status = job.getStatus(); |
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) |
| | | { |
| | | rows = resumeJob(job); |
| | | } |
| | | else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) |
| | | { |
| | | rows = pauseJob(job); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 立即运行任务 |
| | | * |
| | | * @param job 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void run(SysJob job) throws SchedulerException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | SysJob properties = selectJobById(job.getJobId()); |
| | | // 参数 |
| | | JobDataMap dataMap = new JobDataMap(); |
| | | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); |
| | | scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap); |
| | | } |
| | | |
| | | /** |
| | | * 新增任务 |
| | | * |
| | | * @param job 调度信息 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); |
| | | int rows = jobMapper.insertJob(job); |
| | | if (rows > 0) |
| | | { |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 更新任务的时间表达式 |
| | | * |
| | | * @param job 调度信息 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | SysJob properties = selectJobById(job.getJobId()); |
| | | int rows = jobMapper.updateJob(job); |
| | | if (rows > 0) |
| | | { |
| | | updateSchedulerJob(job, properties.getJobGroup()); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 更新任务 |
| | | * |
| | | * @param job 任务对象 |
| | | * @param jobGroup 任务组名 |
| | | */ |
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException |
| | | { |
| | | Long jobId = job.getJobId(); |
| | | // 判断是否存在 |
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
| | | if (scheduler.checkExists(jobKey)) |
| | | { |
| | | // 防止创建时存在数据问题 先移除,然后在执行创建操作 |
| | | scheduler.deleteJob(jobKey); |
| | | } |
| | | ScheduleUtils.createScheduleJob(scheduler, job); |
| | | } |
| | | |
| | | /** |
| | | * 校验cron表达式是否有效 |
| | | * |
| | | * @param cronExpression 表达式 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public boolean checkCronExpressionIsValid(String cronExpression) |
| | | { |
| | | return CronUtils.isValid(cronExpression); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import javax.annotation.PostConstruct;
|
| | | import org.quartz.JobDataMap;
|
| | | import org.quartz.JobKey;
|
| | | import org.quartz.Scheduler;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.mapper.SysJobMapper;
|
| | | import com.ruoyi.quartz.service.ISysJobService;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | | import com.ruoyi.quartz.util.ScheduleUtils;
|
| | |
|
| | | /**
|
| | | * 定时任务调度信息 服务层
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysJobServiceImpl implements ISysJobService
|
| | | {
|
| | | @Autowired
|
| | | private Scheduler scheduler;
|
| | |
|
| | | @Autowired
|
| | | private SysJobMapper jobMapper;
|
| | |
|
| | | /**
|
| | | * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
| | | */
|
| | | @PostConstruct
|
| | | public void init() throws SchedulerException, TaskException
|
| | | {
|
| | | scheduler.clear();
|
| | | List<SysJob> jobList = jobMapper.selectJobAll();
|
| | | for (SysJob job : jobList)
|
| | | {
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取quartz调度器的计划任务列表
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<SysJob> selectJobList(SysJob job)
|
| | | {
|
| | | return jobMapper.selectJobList(job);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过调度任务ID查询调度信息
|
| | | * |
| | | * @param jobId 调度任务ID
|
| | | * @return 调度任务对象信息
|
| | | */
|
| | | @Override
|
| | | public SysJob selectJobById(Long jobId)
|
| | | {
|
| | | return jobMapper.selectJobById(jobId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 暂停任务
|
| | | * |
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int pauseJob(SysJob job) throws SchedulerException
|
| | | {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
| | | int rows = jobMapper.updateJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 恢复任务
|
| | | * |
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int resumeJob(SysJob job) throws SchedulerException
|
| | | {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
|
| | | int rows = jobMapper.updateJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除任务后,所对应的trigger也将被删除
|
| | | * |
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteJob(SysJob job) throws SchedulerException
|
| | | {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | int rows = jobMapper.deleteJobById(jobId);
|
| | | if (rows > 0)
|
| | | {
|
| | | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量删除调度信息
|
| | | * |
| | | * @param jobIds 需要删除的任务ID
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException
|
| | | {
|
| | | for (Long jobId : jobIds)
|
| | | {
|
| | | SysJob job = jobMapper.selectJobById(jobId);
|
| | | deleteJob(job);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 任务调度状态修改
|
| | | * |
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int changeStatus(SysJob job) throws SchedulerException
|
| | | {
|
| | | int rows = 0;
|
| | | String status = job.getStatus();
|
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
|
| | | {
|
| | | rows = resumeJob(job);
|
| | | }
|
| | | else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
|
| | | {
|
| | | rows = pauseJob(job);
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 立即运行任务
|
| | | * |
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public void run(SysJob job) throws SchedulerException
|
| | | {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | SysJob properties = selectJobById(job.getJobId());
|
| | | // 参数
|
| | | JobDataMap dataMap = new JobDataMap();
|
| | | dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
|
| | | scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 新增任务
|
| | | * |
| | | * @param job 调度信息 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException
|
| | | {
|
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
| | | int rows = jobMapper.insertJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新任务的时间表达式
|
| | | * |
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException
|
| | | {
|
| | | SysJob properties = selectJobById(job.getJobId());
|
| | | int rows = jobMapper.updateJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | updateSchedulerJob(job, properties.getJobGroup());
|
| | | }
|
| | | return rows;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新任务
|
| | | * |
| | | * @param job 任务对象
|
| | | * @param jobGroup 任务组名
|
| | | */
|
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
|
| | | {
|
| | | Long jobId = job.getJobId();
|
| | | // 判断是否存在
|
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
| | | if (scheduler.checkExists(jobKey))
|
| | | {
|
| | | // 防止创建时存在数据问题 先移除,然后在执行创建操作
|
| | | scheduler.deleteJob(jobKey);
|
| | | }
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 校验cron表达式是否有效
|
| | | * |
| | | * @param cronExpression 表达式
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | public boolean checkCronExpressionIsValid(String cronExpression)
|
| | | {
|
| | | return CronUtils.isValid(cronExpression);
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/framework/task/RyTask.java 修改 |
| | |
| | | package com.ruoyi.framework.task; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * 定时任务调度测试 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component("ryTask") |
| | | public class RyTask |
| | | { |
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) |
| | | { |
| | | System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); |
| | | } |
| | | |
| | | public void ryParams(String params) |
| | | { |
| | | System.out.println("执行有参方法:" + params); |
| | | } |
| | | |
| | | public void ryNoParams() |
| | | { |
| | | System.out.println("执行无参方法"); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.task;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
|
| | | /**
|
| | | * 定时任务调度测试
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Component("ryTask")
|
| | | public class RyTask
|
| | | {
|
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
|
| | | {
|
| | | System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
|
| | | }
|
| | |
|
| | | public void ryParams(String params)
|
| | | {
|
| | | System.out.println("执行有参方法:" + params);
|
| | | }
|
| | |
|
| | | public void ryNoParams()
|
| | | {
|
| | | System.out.println("执行无参方法");
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/job/AbstractQuartzJob.java 修改 |
| | |
| | | package com.ruoyi.common.utils.job; |
| | | |
| | | import java.util.Date; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.utils.ExceptionUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | import com.ruoyi.project.monitor.domain.SysJobLog; |
| | | import com.ruoyi.project.monitor.service.ISysJobLogService; |
| | | |
| | | /** |
| | | * 抽象quartz调用 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public abstract class AbstractQuartzJob implements Job |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); |
| | | |
| | | /** |
| | | * 线程本地变量 |
| | | */ |
| | | private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | SysJob sysJob = new SysJob(); |
| | | BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); |
| | | try |
| | | { |
| | | before(context, sysJob); |
| | | if (sysJob != null) |
| | | { |
| | | doExecute(context, sysJob); |
| | | } |
| | | after(context, sysJob, null); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("任务执行异常 - :", e); |
| | | after(context, sysJob, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 执行前 |
| | | * |
| | | * @param context 工作执行上下文对象 |
| | | * @param sysJob 系统计划任务 |
| | | */ |
| | | protected void before(JobExecutionContext context, SysJob sysJob) |
| | | { |
| | | threadLocal.set(new Date()); |
| | | } |
| | | |
| | | /** |
| | | * 执行后 |
| | | * |
| | | * @param context 工作执行上下文对象 |
| | | * @param sysScheduleJob 系统计划任务 |
| | | */ |
| | | protected void after(JobExecutionContext context, SysJob sysJob, Exception e) |
| | | { |
| | | Date startTime = threadLocal.get(); |
| | | threadLocal.remove(); |
| | | |
| | | final SysJobLog sysJobLog = new SysJobLog(); |
| | | sysJobLog.setJobName(sysJob.getJobName()); |
| | | sysJobLog.setJobGroup(sysJob.getJobGroup()); |
| | | sysJobLog.setInvokeTarget(sysJob.getInvokeTarget()); |
| | | sysJobLog.setStartTime(startTime); |
| | | sysJobLog.setStopTime(new Date()); |
| | | long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); |
| | | sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); |
| | | if (e != null) |
| | | { |
| | | sysJobLog.setStatus(Constants.FAIL); |
| | | String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); |
| | | sysJobLog.setExceptionInfo(errorMsg); |
| | | } |
| | | else |
| | | { |
| | | sysJobLog.setStatus(Constants.SUCCESS); |
| | | } |
| | | |
| | | // 写入数据库当中 |
| | | SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); |
| | | } |
| | | |
| | | /** |
| | | * 执行方法,由子类重载 |
| | | * |
| | | * @param context 工作执行上下文对象 |
| | | * @param sysJob 系统计划任务 |
| | | * @throws Exception 执行过程中的异常 |
| | | */ |
| | | protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; |
| | | } |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import java.util.Date;
|
| | | import org.quartz.Job;
|
| | | import org.quartz.JobExecutionContext;
|
| | | import org.quartz.JobExecutionException;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.utils.ExceptionUtil;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.bean.BeanUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | |
|
| | | /**
|
| | | * 抽象quartz调用
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public abstract class AbstractQuartzJob implements Job
|
| | | {
|
| | | private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
|
| | |
|
| | | /**
|
| | | * 线程本地变量
|
| | | */
|
| | | private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
|
| | |
|
| | | @Override
|
| | | public void execute(JobExecutionContext context) throws JobExecutionException
|
| | | {
|
| | | SysJob sysJob = new SysJob();
|
| | | BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
| | | try
|
| | | {
|
| | | before(context, sysJob);
|
| | | if (sysJob != null)
|
| | | {
|
| | | doExecute(context, sysJob);
|
| | | }
|
| | | after(context, sysJob, null);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("任务执行异常 - :", e);
|
| | | after(context, sysJob, e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 执行前
|
| | | *
|
| | | * @param context 工作执行上下文对象
|
| | | * @param sysJob 系统计划任务
|
| | | */
|
| | | protected void before(JobExecutionContext context, SysJob sysJob)
|
| | | {
|
| | | threadLocal.set(new Date());
|
| | | }
|
| | |
|
| | | /**
|
| | | * 执行后
|
| | | *
|
| | | * @param context 工作执行上下文对象
|
| | | * @param sysScheduleJob 系统计划任务
|
| | | */
|
| | | protected void after(JobExecutionContext context, SysJob sysJob, Exception e)
|
| | | {
|
| | | Date startTime = threadLocal.get();
|
| | | threadLocal.remove();
|
| | |
|
| | | final SysJobLog sysJobLog = new SysJobLog();
|
| | | sysJobLog.setJobName(sysJob.getJobName());
|
| | | sysJobLog.setJobGroup(sysJob.getJobGroup());
|
| | | sysJobLog.setInvokeTarget(sysJob.getInvokeTarget());
|
| | | sysJobLog.setStartTime(startTime);
|
| | | sysJobLog.setStopTime(new Date());
|
| | | long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
|
| | | sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
|
| | | if (e != null)
|
| | | {
|
| | | sysJobLog.setStatus(Constants.FAIL);
|
| | | String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
|
| | | sysJobLog.setExceptionInfo(errorMsg);
|
| | | }
|
| | | else
|
| | | {
|
| | | sysJobLog.setStatus(Constants.SUCCESS);
|
| | | }
|
| | |
|
| | | // 写入数据库当中
|
| | | SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 执行方法,由子类重载
|
| | | *
|
| | | * @param context 工作执行上下文对象
|
| | | * @param sysJob 系统计划任务
|
| | | * @throws Exception 执行过程中的异常
|
| | | */
|
| | | protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/job/CronUtils.java 修改 |
| | |
| | | package com.ruoyi.common.utils.job; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.Date; |
| | | import org.quartz.CronExpression; |
| | | |
| | | /** |
| | | * cron表达式工具类 |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | */ |
| | | public class CronUtils |
| | | { |
| | | /** |
| | | * 返回一个布尔值代表一个给定的Cron表达式的有效性 |
| | | * |
| | | * @param cronExpression Cron表达式 |
| | | * @return boolean 表达式是否有效 |
| | | */ |
| | | public static boolean isValid(String cronExpression) |
| | | { |
| | | return CronExpression.isValidExpression(cronExpression); |
| | | } |
| | | |
| | | /** |
| | | * 返回一个字符串值,表示该消息无效Cron表达式给出有效性 |
| | | * |
| | | * @param cronExpression Cron表达式 |
| | | * @return String 无效时返回表达式错误描述,如果有效返回null |
| | | */ |
| | | public static String getInvalidMessage(String cronExpression) |
| | | { |
| | | try |
| | | { |
| | | new CronExpression(cronExpression); |
| | | return null; |
| | | } |
| | | catch (ParseException pe) |
| | | { |
| | | return pe.getMessage(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 返回下一个执行时间根据给定的Cron表达式 |
| | | * |
| | | * @param cronExpression Cron表达式 |
| | | * @return Date 下次Cron表达式执行时间 |
| | | */ |
| | | public static Date getNextExecution(String cronExpression) |
| | | { |
| | | try |
| | | { |
| | | CronExpression cron = new CronExpression(cronExpression); |
| | | return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); |
| | | } |
| | | catch (ParseException e) |
| | | { |
| | | throw new IllegalArgumentException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.util.Date;
|
| | | import org.quartz.CronExpression;
|
| | |
|
| | | /**
|
| | | * cron表达式工具类
|
| | | * |
| | | * @author ruoyi
|
| | | *
|
| | | */
|
| | | public class CronUtils
|
| | | {
|
| | | /**
|
| | | * 返回一个布尔值代表一个给定的Cron表达式的有效性
|
| | | *
|
| | | * @param cronExpression Cron表达式
|
| | | * @return boolean 表达式是否有效
|
| | | */
|
| | | public static boolean isValid(String cronExpression)
|
| | | {
|
| | | return CronExpression.isValidExpression(cronExpression);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 返回一个字符串值,表示该消息无效Cron表达式给出有效性
|
| | | *
|
| | | * @param cronExpression Cron表达式
|
| | | * @return String 无效时返回表达式错误描述,如果有效返回null
|
| | | */
|
| | | public static String getInvalidMessage(String cronExpression)
|
| | | {
|
| | | try
|
| | | {
|
| | | new CronExpression(cronExpression);
|
| | | return null;
|
| | | }
|
| | | catch (ParseException pe)
|
| | | {
|
| | | return pe.getMessage();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 返回下一个执行时间根据给定的Cron表达式
|
| | | *
|
| | | * @param cronExpression Cron表达式
|
| | | * @return Date 下次Cron表达式执行时间
|
| | | */
|
| | | public static Date getNextExecution(String cronExpression)
|
| | | {
|
| | | try
|
| | | {
|
| | | CronExpression cron = new CronExpression(cronExpression);
|
| | | return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
|
| | | }
|
| | | catch (ParseException e)
|
| | | {
|
| | | throw new IllegalArgumentException(e.getMessage());
|
| | | }
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/job/JobInvokeUtil.java 修改 |
| | |
| | | package com.ruoyi.common.utils.job; |
| | | |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | |
| | | /** |
| | | * 任务执行工具 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class JobInvokeUtil |
| | | { |
| | | /** |
| | | * 执行方法 |
| | | * |
| | | * @param sysJob 系统任务 |
| | | */ |
| | | public static void invokeMethod(SysJob sysJob) throws Exception |
| | | { |
| | | String invokeTarget = sysJob.getInvokeTarget(); |
| | | String beanName = getBeanName(invokeTarget); |
| | | String methodName = getMethodName(invokeTarget); |
| | | List<Object[]> methodParams = getMethodParams(invokeTarget); |
| | | |
| | | if (!isValidClassName(beanName)) |
| | | { |
| | | Object bean = SpringUtils.getBean(beanName); |
| | | invokeMethod(bean, methodName, methodParams); |
| | | } |
| | | else |
| | | { |
| | | Object bean = Class.forName(beanName).newInstance(); |
| | | invokeMethod(bean, methodName, methodParams); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 调用任务方法 |
| | | * |
| | | * @param bean 目标对象 |
| | | * @param methodName 方法名称 |
| | | * @param methodParams 方法参数 |
| | | */ |
| | | private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) |
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, |
| | | InvocationTargetException |
| | | { |
| | | if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) |
| | | { |
| | | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); |
| | | method.invoke(bean, getMethodParamsValue(methodParams)); |
| | | } |
| | | else |
| | | { |
| | | Method method = bean.getClass().getDeclaredMethod(methodName); |
| | | method.invoke(bean); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验是否为为class包名 |
| | | * |
| | | * @param str 名称 |
| | | * @return true是 false否 |
| | | */ |
| | | public static boolean isValidClassName(String invokeTarget) |
| | | { |
| | | return StringUtils.countMatches(invokeTarget, ".") > 1; |
| | | } |
| | | |
| | | /** |
| | | * 获取bean名称 |
| | | * |
| | | * @param invokeTarget 目标字符串 |
| | | * @return bean名称 |
| | | */ |
| | | public static String getBeanName(String invokeTarget) |
| | | { |
| | | String beanName = StringUtils.substringBefore(invokeTarget, "("); |
| | | return StringUtils.substringBeforeLast(beanName, "."); |
| | | } |
| | | |
| | | /** |
| | | * 获取bean方法 |
| | | * |
| | | * @param invokeTarget 目标字符串 |
| | | * @return method方法 |
| | | */ |
| | | public static String getMethodName(String invokeTarget) |
| | | { |
| | | String methodName = StringUtils.substringBefore(invokeTarget, "("); |
| | | return StringUtils.substringAfterLast(methodName, "."); |
| | | } |
| | | |
| | | /** |
| | | * 获取method方法参数相关列表 |
| | | * |
| | | * @param invokeTarget 目标字符串 |
| | | * @return method方法相关参数列表 |
| | | */ |
| | | public static List<Object[]> getMethodParams(String invokeTarget) |
| | | { |
| | | String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); |
| | | if (StringUtils.isEmpty(methodStr)) |
| | | { |
| | | return null; |
| | | } |
| | | String[] methodParams = methodStr.split(","); |
| | | List<Object[]> classs = new LinkedList<>(); |
| | | for (int i = 0; i < methodParams.length; i++) |
| | | { |
| | | String str = StringUtils.trimToEmpty(methodParams[i]); |
| | | // String字符串类型,包含' |
| | | if (StringUtils.contains(str, "'")) |
| | | { |
| | | classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class }); |
| | | } |
| | | // boolean布尔类型,等于true或者false |
| | | else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false")) |
| | | { |
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class }); |
| | | } |
| | | // long长整形,包含L |
| | | else if (StringUtils.containsIgnoreCase(str, "L")) |
| | | { |
| | | classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class }); |
| | | } |
| | | // double浮点类型,包含D |
| | | else if (StringUtils.containsIgnoreCase(str, "D")) |
| | | { |
| | | classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class }); |
| | | } |
| | | // 其他类型归类为整形 |
| | | else |
| | | { |
| | | classs.add(new Object[] { Integer.valueOf(str), Integer.class }); |
| | | } |
| | | } |
| | | return classs; |
| | | } |
| | | |
| | | /** |
| | | * 获取参数类型 |
| | | * |
| | | * @param methodParams 参数相关列表 |
| | | * @return 参数类型列表 |
| | | */ |
| | | public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) |
| | | { |
| | | Class<?>[] classs = new Class<?>[methodParams.size()]; |
| | | int index = 0; |
| | | for (Object[] os : methodParams) |
| | | { |
| | | classs[index] = (Class<?>) os[1]; |
| | | index++; |
| | | } |
| | | return classs; |
| | | } |
| | | |
| | | /** |
| | | * 获取参数值 |
| | | * |
| | | * @param methodParams 参数相关列表 |
| | | * @return 参数值列表 |
| | | */ |
| | | public static Object[] getMethodParamsValue(List<Object[]> methodParams) |
| | | { |
| | | Object[] classs = new Object[methodParams.size()]; |
| | | int index = 0; |
| | | for (Object[] os : methodParams) |
| | | { |
| | | classs[index] = (Object) os[0]; |
| | | index++; |
| | | } |
| | | return classs; |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import java.lang.reflect.InvocationTargetException;
|
| | | import java.lang.reflect.Method;
|
| | | import java.util.LinkedList;
|
| | | import java.util.List;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 任务执行工具
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public class JobInvokeUtil
|
| | | {
|
| | | /**
|
| | | * 执行方法
|
| | | *
|
| | | * @param sysJob 系统任务
|
| | | */
|
| | | public static void invokeMethod(SysJob sysJob) throws Exception
|
| | | {
|
| | | String invokeTarget = sysJob.getInvokeTarget();
|
| | | String beanName = getBeanName(invokeTarget);
|
| | | String methodName = getMethodName(invokeTarget);
|
| | | List<Object[]> methodParams = getMethodParams(invokeTarget);
|
| | |
|
| | | if (!isValidClassName(beanName))
|
| | | {
|
| | | Object bean = SpringUtils.getBean(beanName);
|
| | | invokeMethod(bean, methodName, methodParams);
|
| | | }
|
| | | else
|
| | | {
|
| | | Object bean = Class.forName(beanName).newInstance();
|
| | | invokeMethod(bean, methodName, methodParams);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 调用任务方法
|
| | | *
|
| | | * @param bean 目标对象
|
| | | * @param methodName 方法名称
|
| | | * @param methodParams 方法参数
|
| | | */
|
| | | private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
|
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
| | | InvocationTargetException
|
| | | {
|
| | | if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0)
|
| | | {
|
| | | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams));
|
| | | method.invoke(bean, getMethodParamsValue(methodParams));
|
| | | }
|
| | | else
|
| | | {
|
| | | Method method = bean.getClass().getDeclaredMethod(methodName);
|
| | | method.invoke(bean);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 校验是否为为class包名
|
| | | * |
| | | * @param str 名称
|
| | | * @return true是 false否
|
| | | */
|
| | | public static boolean isValidClassName(String invokeTarget)
|
| | | {
|
| | | return StringUtils.countMatches(invokeTarget, ".") > 1;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取bean名称
|
| | | * |
| | | * @param invokeTarget 目标字符串
|
| | | * @return bean名称
|
| | | */
|
| | | public static String getBeanName(String invokeTarget)
|
| | | {
|
| | | String beanName = StringUtils.substringBefore(invokeTarget, "(");
|
| | | return StringUtils.substringBeforeLast(beanName, ".");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取bean方法
|
| | | * |
| | | * @param invokeTarget 目标字符串
|
| | | * @return method方法
|
| | | */
|
| | | public static String getMethodName(String invokeTarget)
|
| | | {
|
| | | String methodName = StringUtils.substringBefore(invokeTarget, "(");
|
| | | return StringUtils.substringAfterLast(methodName, ".");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取method方法参数相关列表
|
| | | * |
| | | * @param invokeTarget 目标字符串
|
| | | * @return method方法相关参数列表
|
| | | */
|
| | | public static List<Object[]> getMethodParams(String invokeTarget)
|
| | | {
|
| | | String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
|
| | | if (StringUtils.isEmpty(methodStr))
|
| | | {
|
| | | return null;
|
| | | }
|
| | | String[] methodParams = methodStr.split(",");
|
| | | List<Object[]> classs = new LinkedList<>();
|
| | | for (int i = 0; i < methodParams.length; i++)
|
| | | {
|
| | | String str = StringUtils.trimToEmpty(methodParams[i]);
|
| | | // String字符串类型,包含'
|
| | | if (StringUtils.contains(str, "'"))
|
| | | {
|
| | | classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class });
|
| | | }
|
| | | // boolean布尔类型,等于true或者false
|
| | | else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false"))
|
| | | {
|
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
|
| | | }
|
| | | // long长整形,包含L
|
| | | else if (StringUtils.containsIgnoreCase(str, "L"))
|
| | | {
|
| | | classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class });
|
| | | }
|
| | | // double浮点类型,包含D
|
| | | else if (StringUtils.containsIgnoreCase(str, "D"))
|
| | | {
|
| | | classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class });
|
| | | }
|
| | | // 其他类型归类为整形
|
| | | else
|
| | | {
|
| | | classs.add(new Object[] { Integer.valueOf(str), Integer.class });
|
| | | }
|
| | | }
|
| | | return classs;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取参数类型
|
| | | * |
| | | * @param methodParams 参数相关列表
|
| | | * @return 参数类型列表
|
| | | */
|
| | | public static Class<?>[] getMethodParamsType(List<Object[]> methodParams)
|
| | | {
|
| | | Class<?>[] classs = new Class<?>[methodParams.size()];
|
| | | int index = 0;
|
| | | for (Object[] os : methodParams)
|
| | | {
|
| | | classs[index] = (Class<?>) os[1];
|
| | | index++;
|
| | | }
|
| | | return classs;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取参数值
|
| | | * |
| | | * @param methodParams 参数相关列表
|
| | | * @return 参数值列表
|
| | | */
|
| | | public static Object[] getMethodParamsValue(List<Object[]> methodParams)
|
| | | {
|
| | | Object[] classs = new Object[methodParams.size()];
|
| | | int index = 0;
|
| | | for (Object[] os : methodParams)
|
| | | {
|
| | | classs[index] = (Object) os[0];
|
| | | index++;
|
| | | }
|
| | | return classs;
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/job/QuartzDisallowConcurrentExecution.java 修改 |
| | |
| | | package com.ruoyi.common.utils.job; |
| | | |
| | | import org.quartz.DisallowConcurrentExecution; |
| | | import org.quartz.JobExecutionContext; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | |
| | | /** |
| | | * 定时任务处理(禁止并发执行) |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | */ |
| | | @DisallowConcurrentExecution |
| | | public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob |
| | | { |
| | | @Override |
| | | protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception |
| | | { |
| | | JobInvokeUtil.invokeMethod(sysJob); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import org.quartz.DisallowConcurrentExecution;
|
| | | import org.quartz.JobExecutionContext;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 定时任务处理(禁止并发执行)
|
| | | * |
| | | * @author ruoyi
|
| | | *
|
| | | */
|
| | | @DisallowConcurrentExecution
|
| | | public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob
|
| | | {
|
| | | @Override
|
| | | protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception
|
| | | {
|
| | | JobInvokeUtil.invokeMethod(sysJob);
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/job/QuartzJobExecution.java 修改 |
| | |
| | | package com.ruoyi.common.utils.job; |
| | | |
| | | import org.quartz.JobExecutionContext; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | |
| | | /** |
| | | * 定时任务处理(允许并发执行) |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | */ |
| | | public class QuartzJobExecution extends AbstractQuartzJob |
| | | { |
| | | @Override |
| | | protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception |
| | | { |
| | | JobInvokeUtil.invokeMethod(sysJob); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import org.quartz.JobExecutionContext;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 定时任务处理(允许并发执行)
|
| | | * |
| | | * @author ruoyi
|
| | | *
|
| | | */
|
| | | public class QuartzJobExecution extends AbstractQuartzJob
|
| | | {
|
| | | @Override
|
| | | protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception
|
| | | {
|
| | | JobInvokeUtil.invokeMethod(sysJob);
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/common/utils/job/ScheduleUtils.java 修改 |
| | |
| | | package com.ruoyi.common.utils.job; |
| | | |
| | | import org.quartz.CronScheduleBuilder; |
| | | import org.quartz.CronTrigger; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobBuilder; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobKey; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.quartz.TriggerBuilder; |
| | | import org.quartz.TriggerKey; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.exception.job.TaskException; |
| | | import com.ruoyi.common.exception.job.TaskException.Code; |
| | | import com.ruoyi.project.monitor.domain.SysJob; |
| | | |
| | | /** |
| | | * 定时任务工具类 |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | */ |
| | | public class ScheduleUtils |
| | | { |
| | | /** |
| | | * 得到quartz任务类 |
| | | * |
| | | * @param sysJob 执行计划 |
| | | * @return 具体执行任务类 |
| | | */ |
| | | private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) |
| | | { |
| | | boolean isConcurrent = "0".equals(sysJob.getConcurrent()); |
| | | return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; |
| | | } |
| | | |
| | | /** |
| | | * 构建任务触发对象 |
| | | */ |
| | | public static TriggerKey getTriggerKey(Long jobId, String jobGroup) |
| | | { |
| | | return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); |
| | | } |
| | | |
| | | /** |
| | | * 构建任务键对象 |
| | | */ |
| | | public static JobKey getJobKey(Long jobId, String jobGroup) |
| | | { |
| | | return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); |
| | | } |
| | | |
| | | /** |
| | | * 创建定时任务 |
| | | */ |
| | | public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException |
| | | { |
| | | Class<? extends Job> jobClass = getQuartzJobClass(job); |
| | | // 构建job信息 |
| | | Long jobId = job.getJobId(); |
| | | String jobGroup = job.getJobGroup(); |
| | | JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); |
| | | |
| | | // 表达式调度构建器 |
| | | CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); |
| | | cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); |
| | | |
| | | // 按新的cronExpression表达式构建一个新的trigger |
| | | CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) |
| | | .withSchedule(cronScheduleBuilder).build(); |
| | | |
| | | // 放入参数,运行时的方法可以获取 |
| | | jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); |
| | | |
| | | // 判断是否存在 |
| | | if (scheduler.checkExists(getJobKey(jobId, jobGroup))) |
| | | { |
| | | // 防止创建时存在数据问题 先移除,然后在执行创建操作 |
| | | scheduler.deleteJob(getJobKey(jobId, jobGroup)); |
| | | } |
| | | |
| | | scheduler.scheduleJob(jobDetail, trigger); |
| | | |
| | | // 暂停任务 |
| | | if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) |
| | | { |
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置定时任务策略 |
| | | */ |
| | | public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) |
| | | throws TaskException |
| | | { |
| | | switch (job.getMisfirePolicy()) |
| | | { |
| | | case ScheduleConstants.MISFIRE_DEFAULT: |
| | | return cb; |
| | | case ScheduleConstants.MISFIRE_IGNORE_MISFIRES: |
| | | return cb.withMisfireHandlingInstructionIgnoreMisfires(); |
| | | case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED: |
| | | return cb.withMisfireHandlingInstructionFireAndProceed(); |
| | | case ScheduleConstants.MISFIRE_DO_NOTHING: |
| | | return cb.withMisfireHandlingInstructionDoNothing(); |
| | | default: |
| | | throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() |
| | | + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR); |
| | | } |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import org.quartz.CronScheduleBuilder;
|
| | | import org.quartz.CronTrigger;
|
| | | import org.quartz.Job;
|
| | | import org.quartz.JobBuilder;
|
| | | import org.quartz.JobDetail;
|
| | | import org.quartz.JobKey;
|
| | | import org.quartz.Scheduler;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.quartz.TriggerBuilder;
|
| | | import org.quartz.TriggerKey;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.common.exception.job.TaskException.Code;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 定时任务工具类
|
| | | * |
| | | * @author ruoyi
|
| | | *
|
| | | */
|
| | | public class ScheduleUtils
|
| | | {
|
| | | /**
|
| | | * 得到quartz任务类
|
| | | *
|
| | | * @param sysJob 执行计划
|
| | | * @return 具体执行任务类
|
| | | */
|
| | | private static Class<? extends Job> getQuartzJobClass(SysJob sysJob)
|
| | | {
|
| | | boolean isConcurrent = "0".equals(sysJob.getConcurrent());
|
| | | return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 构建任务触发对象
|
| | | */
|
| | | public static TriggerKey getTriggerKey(Long jobId, String jobGroup)
|
| | | {
|
| | | return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 构建任务键对象
|
| | | */
|
| | | public static JobKey getJobKey(Long jobId, String jobGroup)
|
| | | {
|
| | | return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建定时任务
|
| | | */
|
| | | public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException
|
| | | {
|
| | | Class<? extends Job> jobClass = getQuartzJobClass(job);
|
| | | // 构建job信息
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();
|
| | |
|
| | | // 表达式调度构建器
|
| | | CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
|
| | | cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
|
| | |
|
| | | // 按新的cronExpression表达式构建一个新的trigger
|
| | | CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup))
|
| | | .withSchedule(cronScheduleBuilder).build();
|
| | |
|
| | | // 放入参数,运行时的方法可以获取
|
| | | jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
|
| | |
|
| | | // 判断是否存在
|
| | | if (scheduler.checkExists(getJobKey(jobId, jobGroup)))
|
| | | {
|
| | | // 防止创建时存在数据问题 先移除,然后在执行创建操作
|
| | | scheduler.deleteJob(getJobKey(jobId, jobGroup));
|
| | | }
|
| | |
|
| | | scheduler.scheduleJob(jobDetail, trigger);
|
| | |
|
| | | // 暂停任务
|
| | | if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
|
| | | {
|
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置定时任务策略
|
| | | */
|
| | | public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
|
| | | throws TaskException
|
| | | {
|
| | | switch (job.getMisfirePolicy())
|
| | | {
|
| | | case ScheduleConstants.MISFIRE_DEFAULT:
|
| | | return cb;
|
| | | case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
|
| | | return cb.withMisfireHandlingInstructionIgnoreMisfires();
|
| | | case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
|
| | | return cb.withMisfireHandlingInstructionFireAndProceed();
|
| | | case ScheduleConstants.MISFIRE_DO_NOTHING:
|
| | | return cb.withMisfireHandlingInstructionDoNothing();
|
| | | default:
|
| | | throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
|
| | | + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
|
| | | }
|
| | | }
|
| | | }
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysJobLogMapper.xml 修改 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ruoyi.project.monitor.mapper.SysJobLogMapper"> |
| | | |
| | | <resultMap type="SysJobLog" id="SysJobLogResult"> |
| | | <id property="jobLogId" column="job_log_id" /> |
| | | <result property="jobName" column="job_name" /> |
| | | <result property="jobGroup" column="job_group" /> |
| | | <result property="invokeTarget" column="invoke_target" /> |
| | | <result property="jobMessage" column="job_message" /> |
| | | <result property="status" column="status" /> |
| | | <result property="exceptionInfo" column="exception_info" /> |
| | | <result property="createTime" column="create_time" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectJobLogVo"> |
| | | select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time |
| | | from sys_job_log |
| | | </sql> |
| | | |
| | | <select id="selectJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult"> |
| | | <include refid="selectJobLogVo"/> |
| | | <where> |
| | | <if test="jobName != null and jobName != ''"> |
| | | AND job_name like concat('%', #{jobName}, '%') |
| | | </if> |
| | | <if test="jobGroup != null and jobGroup != ''"> |
| | | AND job_group = #{jobGroup} |
| | | </if> |
| | | <if test="status != null and status != ''"> |
| | | AND status = #{status} |
| | | </if> |
| | | <if test="invokeTarget != null and invokeTarget != ''"> |
| | | AND invoke_target like concat('%', #{invokeTarget}, '%') |
| | | </if> |
| | | <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| | | and date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') |
| | | </if> |
| | | <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| | | and date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectJobLogAll" resultMap="SysJobLogResult"> |
| | | <include refid="selectJobLogVo"/> |
| | | </select> |
| | | |
| | | <select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult"> |
| | | <include refid="selectJobLogVo"/> |
| | | where job_log_id = #{jobLogId} |
| | | </select> |
| | | |
| | | <delete id="deleteJobLogById" parameterType="Long"> |
| | | delete from sys_job_log where job_log_id = #{jobLogId} |
| | | </delete> |
| | | |
| | | <delete id="deleteJobLogByIds" parameterType="Long"> |
| | | delete from sys_job_log where job_log_id in |
| | | <foreach collection="array" item="jobLogId" open="(" separator="," close=")"> |
| | | #{jobLogId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <update id="cleanJobLog"> |
| | | truncate table sys_job_log |
| | | </update> |
| | | |
| | | <insert id="insertJobLog" parameterType="SysJobLog"> |
| | | insert into sys_job_log( |
| | | <if test="jobLogId != null and jobLogId != 0">job_log_id,</if> |
| | | <if test="jobName != null and jobName != ''">job_name,</if> |
| | | <if test="jobGroup != null and jobGroup != ''">job_group,</if> |
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if> |
| | | <if test="jobMessage != null and jobMessage != ''">job_message,</if> |
| | | <if test="status != null and status != ''">status,</if> |
| | | <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if> |
| | | create_time |
| | | )values( |
| | | <if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if> |
| | | <if test="jobName != null and jobName != ''">#{jobName},</if> |
| | | <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if> |
| | | <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if> |
| | | <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if> |
| | | <if test="status != null and status != ''">#{status},</if> |
| | | <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if> |
| | | sysdate() |
| | | ) |
| | | </insert> |
| | | |
| | | <?xml version="1.0" encoding="UTF-8" ?>
|
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.quartz.mapper.SysJobLogMapper">
|
| | |
|
| | | <resultMap type="SysJobLog" id="SysJobLogResult">
|
| | | <id property="jobLogId" column="job_log_id" />
|
| | | <result property="jobName" column="job_name" />
|
| | | <result property="jobGroup" column="job_group" />
|
| | | <result property="invokeTarget" column="invoke_target" />
|
| | | <result property="jobMessage" column="job_message" />
|
| | | <result property="status" column="status" />
|
| | | <result property="exceptionInfo" column="exception_info" />
|
| | | <result property="createTime" column="create_time" />
|
| | | </resultMap>
|
| | | |
| | | <sql id="selectJobLogVo">
|
| | | select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time |
| | | from sys_job_log
|
| | | </sql>
|
| | | |
| | | <select id="selectJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult">
|
| | | <include refid="selectJobLogVo"/>
|
| | | <where>
|
| | | <if test="jobName != null and jobName != ''">
|
| | | AND job_name like concat('%', #{jobName}, '%')
|
| | | </if>
|
| | | <if test="jobGroup != null and jobGroup != ''">
|
| | | AND job_group = #{jobGroup}
|
| | | </if>
|
| | | <if test="status != null and status != ''">
|
| | | AND status = #{status}
|
| | | </if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">
|
| | | AND invoke_target like concat('%', #{invokeTarget}, '%')
|
| | | </if>
|
| | | <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
|
| | | and date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
|
| | | </if>
|
| | | <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
|
| | | and date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
|
| | | </if>
|
| | | </where>
|
| | | </select>
|
| | | |
| | | <select id="selectJobLogAll" resultMap="SysJobLogResult">
|
| | | <include refid="selectJobLogVo"/>
|
| | | </select>
|
| | | |
| | | <select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult">
|
| | | <include refid="selectJobLogVo"/>
|
| | | where job_log_id = #{jobLogId}
|
| | | </select>
|
| | | |
| | | <delete id="deleteJobLogById" parameterType="Long">
|
| | | delete from sys_job_log where job_log_id = #{jobLogId}
|
| | | </delete>
|
| | | |
| | | <delete id="deleteJobLogByIds" parameterType="Long">
|
| | | delete from sys_job_log where job_log_id in
|
| | | <foreach collection="array" item="jobLogId" open="(" separator="," close=")">
|
| | | #{jobLogId}
|
| | | </foreach> |
| | | </delete>
|
| | | |
| | | <update id="cleanJobLog">
|
| | | truncate table sys_job_log
|
| | | </update>
|
| | | |
| | | <insert id="insertJobLog" parameterType="SysJobLog">
|
| | | insert into sys_job_log(
|
| | | <if test="jobLogId != null and jobLogId != 0">job_log_id,</if>
|
| | | <if test="jobName != null and jobName != ''">job_name,</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">job_group,</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
|
| | | <if test="jobMessage != null and jobMessage != ''">job_message,</if>
|
| | | <if test="status != null and status != ''">status,</if>
|
| | | <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if>
|
| | | create_time
|
| | | )values(
|
| | | <if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if>
|
| | | <if test="jobName != null and jobName != ''">#{jobName},</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
|
| | | <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if>
|
| | | <if test="status != null and status != ''">#{status},</if>
|
| | | <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if>
|
| | | sysdate()
|
| | | )
|
| | | </insert>
|
| | |
|
| | | </mapper> |
文件名从 ruoyi/src/main/resources/mybatis/system/SysJobMapper.xml 修改 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ruoyi.project.monitor.mapper.SysJobMapper"> |
| | | |
| | | <resultMap type="SysJob" id="SysJobResult"> |
| | | <id property="jobId" column="job_id" /> |
| | | <result property="jobName" column="job_name" /> |
| | | <result property="jobGroup" column="job_group" /> |
| | | <result property="invokeTarget" column="invoke_target" /> |
| | | <result property="cronExpression" column="cron_expression" /> |
| | | <result property="misfirePolicy" column="misfire_policy" /> |
| | | <result property="concurrent" column="concurrent" /> |
| | | <result property="status" column="status" /> |
| | | <result property="createBy" column="create_by" /> |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | <result property="remark" column="remark" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectJobVo"> |
| | | select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark |
| | | from sys_job |
| | | </sql> |
| | | |
| | | <select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult"> |
| | | <include refid="selectJobVo"/> |
| | | <where> |
| | | <if test="jobName != null and jobName != ''"> |
| | | AND job_name like concat('%', #{jobName}, '%') |
| | | </if> |
| | | <if test="jobGroup != null and jobGroup != ''"> |
| | | AND job_group = #{jobGroup} |
| | | </if> |
| | | <if test="status != null and status != ''"> |
| | | AND status = #{status} |
| | | </if> |
| | | <if test="invokeTarget != null and invokeTarget != ''"> |
| | | AND invoke_target like concat('%', #{invokeTarget}, '%') |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectJobAll" resultMap="SysJobResult"> |
| | | <include refid="selectJobVo"/> |
| | | </select> |
| | | |
| | | <select id="selectJobById" parameterType="Long" resultMap="SysJobResult"> |
| | | <include refid="selectJobVo"/> |
| | | where job_id = #{jobId} |
| | | </select> |
| | | |
| | | <delete id="deleteJobById" parameterType="Long"> |
| | | delete from sys_job where job_id = #{jobId} |
| | | </delete> |
| | | |
| | | <delete id="deleteJobByIds" parameterType="Long"> |
| | | delete from sys_job where job_id in |
| | | <foreach collection="array" item="jobId" open="(" separator="," close=")"> |
| | | #{jobId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <update id="updateJob" parameterType="SysJob"> |
| | | update sys_job |
| | | <set> |
| | | <if test="jobName != null and jobName != ''">job_name = #{jobName},</if> |
| | | <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if> |
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if> |
| | | <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if> |
| | | <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if> |
| | | <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if> |
| | | <if test="status !=null">status = #{status},</if> |
| | | <if test="remark != null and remark != ''">remark = #{remark},</if> |
| | | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| | | update_time = sysdate() |
| | | </set> |
| | | where job_id = #{jobId} |
| | | </update> |
| | | |
| | | <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId"> |
| | | insert into sys_job( |
| | | <if test="jobId != null and jobId != 0">job_id,</if> |
| | | <if test="jobName != null and jobName != ''">job_name,</if> |
| | | <if test="jobGroup != null and jobGroup != ''">job_group,</if> |
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if> |
| | | <if test="cronExpression != null and cronExpression != ''">cron_expression,</if> |
| | | <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if> |
| | | <if test="concurrent != null and concurrent != ''">concurrent,</if> |
| | | <if test="status != null and status != ''">status,</if> |
| | | <if test="remark != null and remark != ''">remark,</if> |
| | | <if test="createBy != null and createBy != ''">create_by,</if> |
| | | create_time |
| | | )values( |
| | | <if test="jobId != null and jobId != 0">#{jobId},</if> |
| | | <if test="jobName != null and jobName != ''">#{jobName},</if> |
| | | <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if> |
| | | <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if> |
| | | <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if> |
| | | <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if> |
| | | <if test="concurrent != null and concurrent != ''">#{concurrent},</if> |
| | | <if test="status != null and status != ''">#{status},</if> |
| | | <if test="remark != null and remark != ''">#{remark},</if> |
| | | <if test="createBy != null and createBy != ''">#{createBy},</if> |
| | | sysdate() |
| | | ) |
| | | </insert> |
| | | |
| | | <?xml version="1.0" encoding="UTF-8" ?>
|
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.quartz.mapper.SysJobMapper">
|
| | |
|
| | | <resultMap type="SysJob" id="SysJobResult">
|
| | | <id property="jobId" column="job_id" />
|
| | | <result property="jobName" column="job_name" />
|
| | | <result property="jobGroup" column="job_group" />
|
| | | <result property="invokeTarget" column="invoke_target" />
|
| | | <result property="cronExpression" column="cron_expression" />
|
| | | <result property="misfirePolicy" column="misfire_policy" />
|
| | | <result property="concurrent" column="concurrent" />
|
| | | <result property="status" column="status" />
|
| | | <result property="createBy" column="create_by" />
|
| | | <result property="createTime" column="create_time" />
|
| | | <result property="updateBy" column="update_by" />
|
| | | <result property="updateTime" column="update_time" />
|
| | | <result property="remark" column="remark" />
|
| | | </resultMap>
|
| | | |
| | | <sql id="selectJobVo">
|
| | | select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark |
| | | from sys_job
|
| | | </sql>
|
| | | |
| | | <select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult">
|
| | | <include refid="selectJobVo"/>
|
| | | <where>
|
| | | <if test="jobName != null and jobName != ''">
|
| | | AND job_name like concat('%', #{jobName}, '%')
|
| | | </if>
|
| | | <if test="jobGroup != null and jobGroup != ''">
|
| | | AND job_group = #{jobGroup}
|
| | | </if>
|
| | | <if test="status != null and status != ''">
|
| | | AND status = #{status}
|
| | | </if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">
|
| | | AND invoke_target like concat('%', #{invokeTarget}, '%')
|
| | | </if>
|
| | | </where>
|
| | | </select>
|
| | | |
| | | <select id="selectJobAll" resultMap="SysJobResult">
|
| | | <include refid="selectJobVo"/>
|
| | | </select>
|
| | | |
| | | <select id="selectJobById" parameterType="Long" resultMap="SysJobResult">
|
| | | <include refid="selectJobVo"/>
|
| | | where job_id = #{jobId}
|
| | | </select>
|
| | | |
| | | <delete id="deleteJobById" parameterType="Long">
|
| | | delete from sys_job where job_id = #{jobId}
|
| | | </delete>
|
| | | |
| | | <delete id="deleteJobByIds" parameterType="Long">
|
| | | delete from sys_job where job_id in
|
| | | <foreach collection="array" item="jobId" open="(" separator="," close=")">
|
| | | #{jobId}
|
| | | </foreach> |
| | | </delete>
|
| | | |
| | | <update id="updateJob" parameterType="SysJob">
|
| | | update sys_job
|
| | | <set>
|
| | | <if test="jobName != null and jobName != ''">job_name = #{jobName},</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if>
|
| | | <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
|
| | | <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if>
|
| | | <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if>
|
| | | <if test="status !=null">status = #{status},</if>
|
| | | <if test="remark != null and remark != ''">remark = #{remark},</if>
|
| | | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
| | | update_time = sysdate()
|
| | | </set>
|
| | | where job_id = #{jobId}
|
| | | </update>
|
| | | |
| | | <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId">
|
| | | insert into sys_job(
|
| | | <if test="jobId != null and jobId != 0">job_id,</if>
|
| | | <if test="jobName != null and jobName != ''">job_name,</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">job_group,</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
|
| | | <if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
|
| | | <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if>
|
| | | <if test="concurrent != null and concurrent != ''">concurrent,</if>
|
| | | <if test="status != null and status != ''">status,</if>
|
| | | <if test="remark != null and remark != ''">remark,</if>
|
| | | <if test="createBy != null and createBy != ''">create_by,</if>
|
| | | create_time
|
| | | )values(
|
| | | <if test="jobId != null and jobId != 0">#{jobId},</if>
|
| | | <if test="jobName != null and jobName != ''">#{jobName},</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
|
| | | <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
|
| | | <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if>
|
| | | <if test="concurrent != null and concurrent != ''">#{concurrent},</if>
|
| | | <if test="status != null and status != ''">#{status},</if>
|
| | | <if test="remark != null and remark != ''">#{remark},</if>
|
| | | <if test="createBy != null and createBy != ''">#{createBy},</if>
|
| | | sysdate()
|
| | | )
|
| | | </insert>
|
| | |
|
| | | </mapper> |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <project xmlns="http://maven.apache.org/POM/4.0.0"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| | | <parent>
|
| | | <artifactId>ruoyi</artifactId>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <version>3.0.0</version>
|
| | | </parent>
|
| | | <modelVersion>4.0.0</modelVersion>
|
| | |
|
| | | <artifactId>ruoyi-system</artifactId>
|
| | |
|
| | | <description>
|
| | | system系统模块
|
| | | </description>
|
| | |
|
| | | <dependencies>
|
| | |
|
| | | <!-- 通用工具-->
|
| | | <dependency>
|
| | | <groupId>com.ruoyi</groupId>
|
| | | <artifactId>ruoyi-common</artifactId>
|
| | | </dependency>
|
| | |
|
| | | </dependencies>
|
| | |
|
| | | </project> |
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysConfig.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 参数配置表 sys_config
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/domain/SysLogininfor.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import java.util.Date;
|
| | | import com.fasterxml.jackson.annotation.JsonFormat;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 系统访问记录表 sys_logininfor
|
| | |
| | | {
|
| | | this.loginTime = loginTime;
|
| | | }
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysNotice.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 通知公告表 sys_notice
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/domain/SysOperLog.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import java.util.Date;
|
| | | import com.fasterxml.jackson.annotation.JsonFormat;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 操作日志记录表 oper_log
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysPost.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import javax.validation.constraints.NotBlank;
|
| | | import javax.validation.constraints.Size;
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.framework.web.domain.BaseEntity;
|
| | | import com.ruoyi.common.annotation.Excel;
|
| | | import com.ruoyi.common.annotation.Excel.ColumnType;
|
| | | import com.ruoyi.common.core.domain.BaseEntity;
|
| | |
|
| | | /**
|
| | | * 岗位表 sys_post
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysRoleDept.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysRoleMenu.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/domain/SysUserOnline.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | /**
|
| | | * 当前在线会话
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysUserPost.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/SysUserRole.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain;
|
| | | package com.ruoyi.system.domain;
|
| | |
|
| | | import org.apache.commons.lang3.builder.ToStringBuilder;
|
| | | import org.apache.commons.lang3.builder.ToStringStyle;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/vo/MetaVo.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain.vo;
|
| | | package com.ruoyi.system.domain.vo;
|
| | |
|
| | | /**
|
| | | * 路由显示信息
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/domain/vo/RouterVo.java 修改 |
| | |
| | | package com.ruoyi.project.system.domain.vo;
|
| | | package com.ruoyi.system.domain.vo;
|
| | |
|
| | | import com.fasterxml.jackson.annotation.JsonInclude;
|
| | | import java.util.List;
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysConfigMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysConfig;
|
| | | import com.ruoyi.system.domain.SysConfig;
|
| | |
|
| | | /**
|
| | | * 参数配置 数据层
|
| | |
| | | * @return 结果
|
| | | */
|
| | | public int deleteConfigByIds(Long[] configIds);
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.common.core.domain.entity.SysDept;
|
| | |
|
| | | /**
|
| | | * 部门管理 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDictDataMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | |
|
| | | /**
|
| | | * 字典表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDictTypeMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | | import com.ruoyi.project.system.domain.SysDictType;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictType;
|
| | |
|
| | | /**
|
| | | * 字典表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/mapper/SysLogininforMapper.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.monitor.domain.SysLogininfor;
|
| | | import com.ruoyi.system.domain.SysLogininfor;
|
| | |
|
| | | /**
|
| | | * 系统访问日志情况信息 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysMenuMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | |
|
| | | /**
|
| | | * 菜单表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysNoticeMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysNotice;
|
| | | import com.ruoyi.system.domain.SysNotice;
|
| | |
|
| | | /**
|
| | | * 通知公告表 数据层
|
| | |
| | | * @return 结果
|
| | | */
|
| | | public int deleteNoticeByIds(Long[] noticeIds);
|
| | | } |
| | | }
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/mapper/SysOperLogMapper.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | | import com.ruoyi.system.domain.SysOperLog;
|
| | |
|
| | | /**
|
| | | * 操作日志 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysPostMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysPost;
|
| | | import com.ruoyi.system.domain.SysPost;
|
| | |
|
| | | /**
|
| | | * 岗位信息 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysRoleDeptMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysRoleDept;
|
| | | import com.ruoyi.system.domain.SysRoleDept;
|
| | |
|
| | | /**
|
| | | * 角色与部门关联表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysRoleMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | |
|
| | | /**
|
| | | * 角色表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysRoleMenuMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysRoleMenu;
|
| | | import com.ruoyi.system.domain.SysRoleMenu;
|
| | |
|
| | | /**
|
| | | * 角色与菜单关联表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysUserMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | |
|
| | | /**
|
| | | * 用户表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysUserPostMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysUserPost;
|
| | | import com.ruoyi.system.domain.SysUserPost;
|
| | |
|
| | | /**
|
| | | * 用户与岗位关联表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysUserRoleMapper.java 修改 |
| | |
| | | package com.ruoyi.project.system.mapper;
|
| | | package com.ruoyi.system.mapper;
|
| | |
|
| | | import java.util.List;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | | import com.ruoyi.project.system.domain.SysUserRole;
|
| | | import com.ruoyi.system.domain.SysUserRole;
|
| | |
|
| | | /**
|
| | | * 用户与角色关联表 数据层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysConfigService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysConfig;
|
| | | import com.ruoyi.system.domain.SysConfig;
|
| | |
|
| | | /**
|
| | | * 参数配置 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDeptService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.framework.web.domain.TreeSelect;
|
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.common.core.domain.TreeSelect;
|
| | | import com.ruoyi.common.core.domain.entity.SysDept;
|
| | |
|
| | | /**
|
| | | * 部门管理 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDictDataService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | |
|
| | | /**
|
| | | * 字典 业务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDictTypeService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | | import com.ruoyi.project.system.domain.SysDictType;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictType;
|
| | |
|
| | | /**
|
| | | * 字典 业务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/ISysLogininforService.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.monitor.domain.SysLogininfor;
|
| | | import com.ruoyi.system.domain.SysLogininfor;
|
| | |
|
| | | /**
|
| | | * 系统访问日志情况信息 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import com.ruoyi.framework.web.domain.TreeSelect;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.project.system.domain.vo.RouterVo;
|
| | | import com.ruoyi.common.core.domain.TreeSelect;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | | import com.ruoyi.system.domain.vo.RouterVo;
|
| | |
|
| | | /**
|
| | | * 菜单 业务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysNotice;
|
| | | import com.ruoyi.system.domain.SysNotice;
|
| | |
|
| | | /**
|
| | | * 公告 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/ISysOperLogService.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | | import com.ruoyi.system.domain.SysOperLog;
|
| | |
|
| | | /**
|
| | | * 操作日志 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysPostService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysPost;
|
| | | import com.ruoyi.system.domain.SysPost;
|
| | |
|
| | | /**
|
| | | * 岗位信息 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysRoleService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | |
|
| | | /**
|
| | | * 角色业务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysUserOnlineService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.project.monitor.domain.SysUserOnline;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.system.domain.SysUserOnline;
|
| | |
|
| | | /**
|
| | | * 在线用户 服务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/ISysUserService.java 修改 |
| | |
| | | package com.ruoyi.project.system.service;
|
| | | package com.ruoyi.system.service;
|
| | |
|
| | | import java.util.List;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | |
|
| | | /**
|
| | | * 用户 业务层
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.List;
|
| | | import javax.annotation.PostConstruct;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.annotation.DataSource;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.common.enums.DataSourceType;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.project.system.domain.SysConfig;
|
| | | import com.ruoyi.project.system.mapper.SysConfigMapper;
|
| | | import com.ruoyi.project.system.service.ISysConfigService;
|
| | | import com.ruoyi.system.domain.SysConfig;
|
| | | import com.ruoyi.system.mapper.SysConfigMapper;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | |
|
| | | /**
|
| | | * 参数配置 服务层实现
|
| | |
| | | * @return 参数配置信息
|
| | | */
|
| | | @Override
|
| | | @DataSource(DataSourceType.MASTER)
|
| | | public SysConfig selectConfigById(Long configId)
|
| | | {
|
| | | SysConfig config = new SysConfig();
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Iterator;
|
| | |
| | | import java.util.stream.Collectors;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.annotation.DataScope;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.TreeSelect;
|
| | | import com.ruoyi.common.core.domain.entity.SysDept;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
|
| | | import com.ruoyi.framework.web.domain.TreeSelect;
|
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.project.system.mapper.SysDeptMapper;
|
| | | import com.ruoyi.project.system.service.ISysDeptService;
|
| | | import com.ruoyi.system.mapper.SysDeptMapper;
|
| | | import com.ruoyi.system.service.ISysDeptService;
|
| | |
|
| | | /**
|
| | | * 部门管理 服务实现
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDictDataServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.utils.DictUtils;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | | import com.ruoyi.project.system.mapper.SysDictDataMapper;
|
| | | import com.ruoyi.project.system.service.ISysDictDataService;
|
| | | import com.ruoyi.system.mapper.SysDictDataMapper;
|
| | | import com.ruoyi.system.service.ISysDictDataService;
|
| | |
|
| | | /**
|
| | | * 字典 业务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDictTypeServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import javax.annotation.PostConstruct;
|
| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictType;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.DictUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.project.system.domain.SysDictData;
|
| | | import com.ruoyi.project.system.domain.SysDictType;
|
| | | import com.ruoyi.project.system.mapper.SysDictDataMapper;
|
| | | import com.ruoyi.project.system.mapper.SysDictTypeMapper;
|
| | | import com.ruoyi.project.system.service.ISysDictTypeService;
|
| | | import com.ruoyi.system.mapper.SysDictDataMapper;
|
| | | import com.ruoyi.system.mapper.SysDictTypeMapper;
|
| | | import com.ruoyi.system.service.ISysDictTypeService;
|
| | |
|
| | | /**
|
| | | * 字典 业务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/impl/SysLogininforServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.project.monitor.domain.SysLogininfor;
|
| | | import com.ruoyi.project.monitor.mapper.SysLogininforMapper;
|
| | | import com.ruoyi.project.monitor.service.ISysLogininforService;
|
| | | import com.ruoyi.system.domain.SysLogininfor;
|
| | | import com.ruoyi.system.mapper.SysLogininforMapper;
|
| | | import com.ruoyi.system.service.ISysLogininforService;
|
| | |
|
| | | /**
|
| | | * 系统访问日志情况信息 服务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | |
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.TreeSelect;
|
| | | import com.ruoyi.common.core.domain.entity.SysMenu;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.domain.TreeSelect;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.domain.vo.MetaVo;
|
| | | import com.ruoyi.project.system.domain.vo.RouterVo;
|
| | | import com.ruoyi.project.system.mapper.SysMenuMapper;
|
| | | import com.ruoyi.project.system.mapper.SysRoleMenuMapper;
|
| | | import com.ruoyi.project.system.service.ISysMenuService;
|
| | | import com.ruoyi.system.domain.vo.MetaVo;
|
| | | import com.ruoyi.system.domain.vo.RouterVo;
|
| | | import com.ruoyi.system.mapper.SysMenuMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
| | | import com.ruoyi.system.service.ISysMenuService;
|
| | |
|
| | | /**
|
| | | * 菜单 业务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.project.system.domain.SysNotice;
|
| | | import com.ruoyi.project.system.mapper.SysNoticeMapper;
|
| | | import com.ruoyi.project.system.service.ISysNoticeService;
|
| | | import com.ruoyi.system.domain.SysNotice;
|
| | | import com.ruoyi.system.mapper.SysNoticeMapper;
|
| | | import com.ruoyi.system.service.ISysNoticeService;
|
| | |
|
| | | /**
|
| | | * 公告 服务层实现
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/monitor/service/impl/SysOperLogServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.monitor.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | | import com.ruoyi.project.monitor.mapper.SysOperLogMapper;
|
| | | import com.ruoyi.project.monitor.service.ISysOperLogService;
|
| | | import com.ruoyi.system.domain.SysOperLog;
|
| | | import com.ruoyi.system.mapper.SysOperLogMapper;
|
| | | import com.ruoyi.system.service.ISysOperLogService;
|
| | |
|
| | | /**
|
| | | * 操作日志 服务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysPostServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.project.system.domain.SysPost;
|
| | | import com.ruoyi.project.system.mapper.SysPostMapper;
|
| | | import com.ruoyi.project.system.mapper.SysUserPostMapper;
|
| | | import com.ruoyi.project.system.service.ISysPostService;
|
| | | import com.ruoyi.system.domain.SysPost;
|
| | | import com.ruoyi.system.mapper.SysPostMapper;
|
| | | import com.ruoyi.system.mapper.SysUserPostMapper;
|
| | | import com.ruoyi.system.service.ISysPostService;
|
| | |
|
| | | /**
|
| | | * 岗位信息 服务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysRoleServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | |
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import com.ruoyi.common.annotation.DataScope;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.project.system.domain.SysRoleDept;
|
| | | import com.ruoyi.project.system.domain.SysRoleMenu;
|
| | | import com.ruoyi.project.system.mapper.SysRoleDeptMapper;
|
| | | import com.ruoyi.project.system.mapper.SysRoleMapper;
|
| | | import com.ruoyi.project.system.mapper.SysRoleMenuMapper;
|
| | | import com.ruoyi.project.system.mapper.SysUserRoleMapper;
|
| | | import com.ruoyi.project.system.service.ISysRoleService;
|
| | | import com.ruoyi.system.domain.SysRoleDept;
|
| | | import com.ruoyi.system.domain.SysRoleMenu;
|
| | | import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
| | | import com.ruoyi.system.mapper.SysUserRoleMapper;
|
| | | import com.ruoyi.system.service.ISysRoleService;
|
| | |
|
| | | /**
|
| | | * 角色 业务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysUserOnlineServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.common.core.domain.model.LoginUser;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.project.monitor.domain.SysUserOnline;
|
| | | import com.ruoyi.project.system.service.ISysUserOnlineService;
|
| | | import com.ruoyi.system.domain.SysUserOnline;
|
| | | import com.ruoyi.system.service.ISysUserOnlineService;
|
| | |
|
| | | /**
|
| | | * 在线用户 服务层处理
|
文件名从 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java 修改 |
| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | | package com.ruoyi.system.service.impl;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import com.ruoyi.common.annotation.DataScope;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.entity.SysRole;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.exception.CustomException;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
|
| | | import com.ruoyi.project.system.domain.SysPost;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.domain.SysUserPost;
|
| | | import com.ruoyi.project.system.domain.SysUserRole;
|
| | | import com.ruoyi.project.system.mapper.SysPostMapper;
|
| | | import com.ruoyi.project.system.mapper.SysRoleMapper;
|
| | | import com.ruoyi.project.system.mapper.SysUserMapper;
|
| | | import com.ruoyi.project.system.mapper.SysUserPostMapper;
|
| | | import com.ruoyi.project.system.mapper.SysUserRoleMapper;
|
| | | import com.ruoyi.project.system.service.ISysConfigService;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | | import com.ruoyi.system.domain.SysPost;
|
| | | import com.ruoyi.system.domain.SysUserPost;
|
| | | import com.ruoyi.system.domain.SysUserRole;
|
| | | import com.ruoyi.system.mapper.SysPostMapper;
|
| | | import com.ruoyi.system.mapper.SysRoleMapper;
|
| | | import com.ruoyi.system.mapper.SysUserMapper;
|
| | | import com.ruoyi.system.mapper.SysUserPostMapper;
|
| | | import com.ruoyi.system.mapper.SysUserRoleMapper;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | | import com.ruoyi.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | | * 用户 业务层处理
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysConfigMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysConfigMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysConfigMapper">
|
| | |
|
| | | <resultMap type="SysConfig" id="SysConfigResult">
|
| | | <id property="configId" column="config_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysDeptMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysDeptMapper">
|
| | |
|
| | | <resultMap type="SysDept" id="SysDeptResult">
|
| | | <id property="deptId" column="dept_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysDictDataMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysDictDataMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysDictDataMapper">
|
| | |
|
| | | <resultMap type="SysDictData" id="SysDictDataResult">
|
| | | <id property="dictCode" column="dict_code" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysDictTypeMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysDictTypeMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysDictTypeMapper">
|
| | |
|
| | | <resultMap type="SysDictType" id="SysDictTypeResult">
|
| | | <id property="dictId" column="dict_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/monitor/SysLogininforMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.monitor.mapper.SysLogininforMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysLogininforMapper">
|
| | |
|
| | | <resultMap type="SysLogininfor" id="SysLogininforResult">
|
| | | <id property="infoId" column="info_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysMenuMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysMenuMapper">
|
| | |
|
| | | <resultMap type="SysMenu" id="SysMenuResult">
|
| | | <id property="menuId" column="menu_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysNoticeMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysNoticeMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysNoticeMapper">
|
| | |
|
| | | <resultMap type="SysNotice" id="SysNoticeResult">
|
| | | <result property="noticeId" column="notice_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/monitor/SysOperLogMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.monitor.mapper.SysOperLogMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysOperLogMapper">
|
| | |
|
| | | <resultMap type="SysOperLog" id="SysOperLogResult">
|
| | | <id property="operId" column="oper_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysPostMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysPostMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysPostMapper">
|
| | |
|
| | | <resultMap type="SysPost" id="SysPostResult">
|
| | | <id property="postId" column="post_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysRoleDeptMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysRoleDeptMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysRoleDeptMapper">
|
| | |
|
| | | <resultMap type="SysRoleDept" id="SysRoleDeptResult">
|
| | | <result property="roleId" column="role_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysRoleMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysRoleMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysRoleMapper">
|
| | |
|
| | | <resultMap type="SysRole" id="SysRoleResult">
|
| | | <id property="roleId" column="role_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysRoleMenuMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysRoleMenuMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysRoleMenuMapper">
|
| | |
|
| | | <resultMap type="SysRoleMenu" id="SysRoleMenuResult">
|
| | | <result property="roleId" column="role_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysUserMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysUserMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysUserMapper">
|
| | |
|
| | | <resultMap type="SysUser" id="SysUserResult">
|
| | | <id property="userId" column="user_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysUserPostMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysUserPostMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysUserPostMapper">
|
| | |
|
| | | <resultMap type="SysUserPost" id="SysUserPostResult">
|
| | | <result property="userId" column="user_id" />
|
文件名从 ruoyi/src/main/resources/mybatis/system/SysUserRoleMapper.xml 修改 |
| | |
| | | <!DOCTYPE mapper
|
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.ruoyi.project.system.mapper.SysUserRoleMapper">
|
| | | <mapper namespace="com.ruoyi.system.mapper.SysUserRoleMapper">
|
| | |
|
| | | <resultMap type="SysUserRole" id="SysUserRoleResult">
|
| | | <result property="userId" column="user_id" />
|
| | |
| | | {
|
| | | "name": "ruoyi",
|
| | | "version": "2.3.0",
|
| | | "version": "3.0.0",
|
| | | "description": "若依管理系统",
|
| | | "author": "若依",
|
| | | "license": "MIT",
|
文件名从 ruoyi/ry.sh 修改 |
| | |
| | | #!/bin/bash
|
| | |
|
| | | AppName=ruoyi.jar
|
| | | AppName=ruoyi-admin.jar
|
| | |
|
| | | #JVM参数
|
| | | JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
|
文件名从 ruoyi/sql/quartz.sql 修改 |
| | |
| | | -- ---------------------------- |
| | | -- 1、存储每一个已配置的 jobDetail 的详细信息 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_JOB_DETAILS; |
| | | create table QRTZ_JOB_DETAILS ( |
| | | sched_name varchar(120) not null, |
| | | job_name varchar(200) not null, |
| | | job_group varchar(200) not null, |
| | | description varchar(250) null, |
| | | job_class_name varchar(250) not null, |
| | | is_durable varchar(1) not null, |
| | | is_nonconcurrent varchar(1) not null, |
| | | is_update_data varchar(1) not null, |
| | | requests_recovery varchar(1) not null, |
| | | job_data blob null, |
| | | primary key (sched_name,job_name,job_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 2、 存储已配置的 Trigger 的信息 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_TRIGGERS; |
| | | create table QRTZ_TRIGGERS ( |
| | | sched_name varchar(120) not null, |
| | | trigger_name varchar(200) not null, |
| | | trigger_group varchar(200) not null, |
| | | job_name varchar(200) not null, |
| | | job_group varchar(200) not null, |
| | | description varchar(250) null, |
| | | next_fire_time bigint(13) null, |
| | | prev_fire_time bigint(13) null, |
| | | priority integer null, |
| | | trigger_state varchar(16) not null, |
| | | trigger_type varchar(8) not null, |
| | | start_time bigint(13) not null, |
| | | end_time bigint(13) null, |
| | | calendar_name varchar(200) null, |
| | | misfire_instr smallint(2) null, |
| | | job_data blob null, |
| | | primary key (sched_name,trigger_name,trigger_group), |
| | | foreign key (sched_name,job_name,job_group) references QRTZ_JOB_DETAILS(sched_name,job_name,job_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 3、 存储简单的 Trigger,包括重复次数,间隔,以及已触发的次数 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_SIMPLE_TRIGGERS; |
| | | create table QRTZ_SIMPLE_TRIGGERS ( |
| | | sched_name varchar(120) not null, |
| | | trigger_name varchar(200) not null, |
| | | trigger_group varchar(200) not null, |
| | | repeat_count bigint(7) not null, |
| | | repeat_interval bigint(12) not null, |
| | | times_triggered bigint(10) not null, |
| | | primary key (sched_name,trigger_name,trigger_group), |
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 4、 存储 Cron Trigger,包括 Cron 表达式和时区信息 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_CRON_TRIGGERS; |
| | | create table QRTZ_CRON_TRIGGERS ( |
| | | sched_name varchar(120) not null, |
| | | trigger_name varchar(200) not null, |
| | | trigger_group varchar(200) not null, |
| | | cron_expression varchar(200) not null, |
| | | time_zone_id varchar(80), |
| | | primary key (sched_name,trigger_name,trigger_group), |
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 5、 Trigger 作为 Blob 类型存储(用于 Quartz 用户用 JDBC 创建他们自己定制的 Trigger 类型,JobStore 并不知道如何存储实例的时候) |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_BLOB_TRIGGERS; |
| | | create table QRTZ_BLOB_TRIGGERS ( |
| | | sched_name varchar(120) not null, |
| | | trigger_name varchar(200) not null, |
| | | trigger_group varchar(200) not null, |
| | | blob_data blob null, |
| | | primary key (sched_name,trigger_name,trigger_group), |
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 6、 以 Blob 类型存储存放日历信息, quartz可配置一个日历来指定一个时间范围 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_CALENDARS; |
| | | create table QRTZ_CALENDARS ( |
| | | sched_name varchar(120) not null, |
| | | calendar_name varchar(200) not null, |
| | | calendar blob not null, |
| | | primary key (sched_name,calendar_name) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 7、 存储已暂停的 Trigger 组的信息 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_PAUSED_TRIGGER_GRPS; |
| | | create table QRTZ_PAUSED_TRIGGER_GRPS ( |
| | | sched_name varchar(120) not null, |
| | | trigger_group varchar(200) not null, |
| | | primary key (sched_name,trigger_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 8、 存储与已触发的 Trigger 相关的状态信息,以及相联 Job 的执行信息 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_FIRED_TRIGGERS; |
| | | create table QRTZ_FIRED_TRIGGERS ( |
| | | sched_name varchar(120) not null, |
| | | entry_id varchar(95) not null, |
| | | trigger_name varchar(200) not null, |
| | | trigger_group varchar(200) not null, |
| | | instance_name varchar(200) not null, |
| | | fired_time bigint(13) not null, |
| | | sched_time bigint(13) not null, |
| | | priority integer not null, |
| | | state varchar(16) not null, |
| | | job_name varchar(200) null, |
| | | job_group varchar(200) null, |
| | | is_nonconcurrent varchar(1) null, |
| | | requests_recovery varchar(1) null, |
| | | primary key (sched_name,entry_id) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 9、 存储少量的有关 Scheduler 的状态信息,假如是用于集群中,可以看到其他的 Scheduler 实例 |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_SCHEDULER_STATE; |
| | | create table QRTZ_SCHEDULER_STATE ( |
| | | sched_name varchar(120) not null, |
| | | instance_name varchar(200) not null, |
| | | last_checkin_time bigint(13) not null, |
| | | checkin_interval bigint(13) not null, |
| | | primary key (sched_name,instance_name) |
| | | ) engine=innodb; |
| | | |
| | | -- ---------------------------- |
| | | -- 10、 存储程序的悲观锁的信息(假如使用了悲观锁) |
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_LOCKS; |
| | | create table QRTZ_LOCKS ( |
| | | sched_name varchar(120) not null, |
| | | lock_name varchar(40) not null, |
| | | primary key (sched_name,lock_name) |
| | | ) engine=innodb; |
| | | |
| | | drop table if exists QRTZ_SIMPROP_TRIGGERS; |
| | | create table QRTZ_SIMPROP_TRIGGERS ( |
| | | sched_name varchar(120) not null, |
| | | trigger_name varchar(200) not null, |
| | | trigger_group varchar(200) not null, |
| | | str_prop_1 varchar(512) null, |
| | | str_prop_2 varchar(512) null, |
| | | str_prop_3 varchar(512) null, |
| | | int_prop_1 int null, |
| | | int_prop_2 int null, |
| | | long_prop_1 bigint null, |
| | | long_prop_2 bigint null, |
| | | dec_prop_1 numeric(13,4) null, |
| | | dec_prop_2 numeric(13,4) null, |
| | | bool_prop_1 varchar(1) null, |
| | | bool_prop_2 varchar(1) null, |
| | | primary key (sched_name,trigger_name,trigger_group), |
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) |
| | | ) engine=innodb; |
| | | |
| | | -- ----------------------------
|
| | | -- 1、存储每一个已配置的 jobDetail 的详细信息
|
| | | -- ----------------------------
|
| | | drop table if exists QRTZ_JOB_DETAILS;
|
| | | create table QRTZ_JOB_DETAILS (
|
| | | sched_name varchar(120) not null,
|
| | | job_name varchar(200) not null,
|
| | | job_group varchar(200) not null,
|
| | | description varchar(250) null,
|
| | | job_class_name varchar(250) not null,
|
| | | is_durable varchar(1) not null,
|
| | | is_nonconcurrent varchar(1) not null,
|
| | | is_update_data varchar(1) not null,
|
| | | requests_recovery varchar(1) not null,
|
| | | job_data blob null,
|
| | | primary key (sched_name,job_name,job_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 2、 存储已配置的 Trigger 的信息
|
| | | -- ----------------------------
|
| | | drop table if exists QRTZ_TRIGGERS;
|
| | | create table QRTZ_TRIGGERS (
|
| | | sched_name varchar(120) not null,
|
| | | trigger_name varchar(200) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | job_name varchar(200) not null,
|
| | | job_group varchar(200) not null,
|
| | | description varchar(250) null,
|
| | | next_fire_time bigint(13) null,
|
| | | prev_fire_time bigint(13) null,
|
| | | priority integer null,
|
| | | trigger_state varchar(16) not null,
|
| | | trigger_type varchar(8) not null,
|
| | | start_time bigint(13) not null,
|
| | | end_time bigint(13) null,
|
| | | calendar_name varchar(200) null,
|
| | | misfire_instr smallint(2) null,
|
| | | job_data blob null,
|
| | | primary key (sched_name,trigger_name,trigger_group),
|
| | | foreign key (sched_name,job_name,job_group) references QRTZ_JOB_DETAILS(sched_name,job_name,job_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 3、 存储简单的 Trigger,包括重复次数,间隔,以及已触发的次数
|
| | | -- ----------------------------
|
| | | drop table if exists QRTZ_SIMPLE_TRIGGERS;
|
| | | create table QRTZ_SIMPLE_TRIGGERS (
|
| | | sched_name varchar(120) not null,
|
| | | trigger_name varchar(200) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | repeat_count bigint(7) not null,
|
| | | repeat_interval bigint(12) not null,
|
| | | times_triggered bigint(10) not null,
|
| | | primary key (sched_name,trigger_name,trigger_group),
|
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 4、 存储 Cron Trigger,包括 Cron 表达式和时区信息
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_CRON_TRIGGERS;
|
| | | create table QRTZ_CRON_TRIGGERS (
|
| | | sched_name varchar(120) not null,
|
| | | trigger_name varchar(200) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | cron_expression varchar(200) not null,
|
| | | time_zone_id varchar(80),
|
| | | primary key (sched_name,trigger_name,trigger_group),
|
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 5、 Trigger 作为 Blob 类型存储(用于 Quartz 用户用 JDBC 创建他们自己定制的 Trigger 类型,JobStore 并不知道如何存储实例的时候)
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_BLOB_TRIGGERS;
|
| | | create table QRTZ_BLOB_TRIGGERS (
|
| | | sched_name varchar(120) not null,
|
| | | trigger_name varchar(200) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | blob_data blob null,
|
| | | primary key (sched_name,trigger_name,trigger_group),
|
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 6、 以 Blob 类型存储存放日历信息, quartz可配置一个日历来指定一个时间范围
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_CALENDARS;
|
| | | create table QRTZ_CALENDARS (
|
| | | sched_name varchar(120) not null,
|
| | | calendar_name varchar(200) not null,
|
| | | calendar blob not null,
|
| | | primary key (sched_name,calendar_name)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 7、 存储已暂停的 Trigger 组的信息
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_PAUSED_TRIGGER_GRPS;
|
| | | create table QRTZ_PAUSED_TRIGGER_GRPS (
|
| | | sched_name varchar(120) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | primary key (sched_name,trigger_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 8、 存储与已触发的 Trigger 相关的状态信息,以及相联 Job 的执行信息
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_FIRED_TRIGGERS;
|
| | | create table QRTZ_FIRED_TRIGGERS (
|
| | | sched_name varchar(120) not null,
|
| | | entry_id varchar(95) not null,
|
| | | trigger_name varchar(200) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | instance_name varchar(200) not null,
|
| | | fired_time bigint(13) not null,
|
| | | sched_time bigint(13) not null,
|
| | | priority integer not null,
|
| | | state varchar(16) not null,
|
| | | job_name varchar(200) null,
|
| | | job_group varchar(200) null,
|
| | | is_nonconcurrent varchar(1) null,
|
| | | requests_recovery varchar(1) null,
|
| | | primary key (sched_name,entry_id)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 9、 存储少量的有关 Scheduler 的状态信息,假如是用于集群中,可以看到其他的 Scheduler 实例
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_SCHEDULER_STATE; |
| | | create table QRTZ_SCHEDULER_STATE (
|
| | | sched_name varchar(120) not null,
|
| | | instance_name varchar(200) not null,
|
| | | last_checkin_time bigint(13) not null,
|
| | | checkin_interval bigint(13) not null,
|
| | | primary key (sched_name,instance_name)
|
| | | ) engine=innodb;
|
| | |
|
| | | -- ----------------------------
|
| | | -- 10、 存储程序的悲观锁的信息(假如使用了悲观锁)
|
| | | -- ---------------------------- |
| | | drop table if exists QRTZ_LOCKS;
|
| | | create table QRTZ_LOCKS (
|
| | | sched_name varchar(120) not null,
|
| | | lock_name varchar(40) not null,
|
| | | primary key (sched_name,lock_name)
|
| | | ) engine=innodb;
|
| | |
|
| | | drop table if exists QRTZ_SIMPROP_TRIGGERS;
|
| | | create table QRTZ_SIMPROP_TRIGGERS (
|
| | | sched_name varchar(120) not null,
|
| | | trigger_name varchar(200) not null,
|
| | | trigger_group varchar(200) not null,
|
| | | str_prop_1 varchar(512) null,
|
| | | str_prop_2 varchar(512) null,
|
| | | str_prop_3 varchar(512) null,
|
| | | int_prop_1 int null,
|
| | | int_prop_2 int null,
|
| | | long_prop_1 bigint null,
|
| | | long_prop_2 bigint null,
|
| | | dec_prop_1 numeric(13,4) null,
|
| | | dec_prop_2 numeric(13,4) null,
|
| | | bool_prop_1 varchar(1) null,
|
| | | bool_prop_2 varchar(1) null,
|
| | | primary key (sched_name,trigger_name,trigger_group),
|
| | | foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group)
|
| | | ) engine=innodb;
|
| | |
|
| | | commit; |