删除test plus
This commit is contained in:
1 parent
6c08edf199
commit
a56f719066
155 files changed
-9848
No files matched your search
@@ -1,447 +0,0 @@
|
|||||||
<?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>4.0.0</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<artifactId>ruoyi-plus-api</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<utf8>UTF-8</utf8>
|
|
||||||
<project.build.sourceEncoding>${utf8}</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>${utf8}</project.reporting.outputEncoding>
|
|
||||||
<project-parent.version>${parent.version}</project-parent.version>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<spring-boot.version>2.1.8.RELEASE</spring-boot.version>
|
|
||||||
<mybatis-plus-boot-starter.version>3.2.0</mybatis-plus-boot-starter.version>
|
|
||||||
<fastjson.version>1.2.60</fastjson.version>
|
|
||||||
<swagger2.version>2.6.1</swagger2.version>
|
|
||||||
<commons-lang3.version>3.9</commons-lang3.version>
|
|
||||||
<commons-collections4.version>4.4</commons-collections4.version>
|
|
||||||
<velocity.version>1.7</velocity.version>
|
|
||||||
<mysql.version>5.1.47</mysql.version>
|
|
||||||
<druid.version>1.1.20</druid.version>
|
|
||||||
<commons-io.version>2.6</commons-io.version>
|
|
||||||
<reflections.version>0.9.11</reflections.version>
|
|
||||||
<commons-codec.version>1.13</commons-codec.version>
|
|
||||||
<commons-net.version>3.6</commons-net.version>
|
|
||||||
<jansi.version>1.18</jansi.version>
|
|
||||||
<lombok.version>1.18.8</lombok.version>
|
|
||||||
<commons-pool2.version>2.7.0</commons-pool2.version>
|
|
||||||
<jwt.version>0.9.1</jwt.version>
|
|
||||||
<spring-boot-admin.version>2.1.6</spring-boot-admin.version>
|
|
||||||
<hutool.version>4.6.4</hutool.version>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
|
|
||||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
|
||||||
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
|
|
||||||
<maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- spring-boot start -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-aop</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- spring-boot end -->
|
|
||||||
|
|
||||||
<!-- mybatis-plus begin -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
||||||
<version>${mybatis-plus-boot-starter.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-generator</artifactId>
|
|
||||||
<version>${mybatis-plus-boot-starter.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.velocity</groupId>
|
|
||||||
<artifactId>velocity</artifactId>
|
|
||||||
<version>${velocity.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>${mysql.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- mybatis-plus end -->
|
|
||||||
|
|
||||||
<!-- alibaba start -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>druid-spring-boot-starter</artifactId>
|
|
||||||
<version>${druid.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>fastjson</artifactId>
|
|
||||||
<version>${fastjson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- alibaba end -->
|
|
||||||
|
|
||||||
<!-- swagger start -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
|
||||||
<version>2.9.2</version>
|
|
||||||
</dependency>
|
|
||||||
<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>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger2.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- swagger end -->
|
|
||||||
|
|
||||||
<!-- apache commons start -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>${commons-lang3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-collections4</artifactId>
|
|
||||||
<version>${commons-collections4.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>${commons-io.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
<version>${commons-codec.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-net</groupId>
|
|
||||||
<artifactId>commons-net</artifactId>
|
|
||||||
<version>${commons-net.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-pool2</artifactId>
|
|
||||||
<version>${commons-pool2.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- apache commons end -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.reflections</groupId>
|
|
||||||
<artifactId>reflections</artifactId>
|
|
||||||
<version>${reflections.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.fusesource.jansi</groupId>
|
|
||||||
<artifactId>jansi</artifactId>
|
|
||||||
<version>${jansi.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.yaml</groupId>
|
|
||||||
<artifactId>snakeyaml</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
|
||||||
<artifactId>jjwt</artifactId>
|
|
||||||
<version>${jwt.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-all</artifactId>
|
|
||||||
<version>${hutool.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- spring boot admin start -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>de.codecentric</groupId>
|
|
||||||
<artifactId>spring-boot-admin-starter-server</artifactId>
|
|
||||||
<version>${spring-boot-admin.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>de.codecentric</groupId>
|
|
||||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
|
||||||
<version>${spring-boot-admin.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- spring boot admin end -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<finalName>spring-boot-plus</finalName>
|
|
||||||
|
|
||||||
<resources>
|
|
||||||
<!-- 资源文件配置 -->
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
<excludes>
|
|
||||||
<exclude>config/**</exclude>
|
|
||||||
</excludes>
|
|
||||||
</resource>
|
|
||||||
|
|
||||||
<!-- 过滤配置文件到config目录 -->
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources/config</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
<targetPath>config</targetPath>
|
|
||||||
<includes>
|
|
||||||
<include>application.yml</include>
|
|
||||||
<include>application-${profileActive}.yml</include>
|
|
||||||
<include>banner.txt</include>
|
|
||||||
<include>logback.xml</include>
|
|
||||||
<include>*.properties</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
|
|
||||||
</resources>
|
|
||||||
|
|
||||||
<plugins>
|
|
||||||
<!-- 由于没有直接继承spring-boot-starter-parent,此处修添加主类和设置repackage -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>io.geekidea.springbootplus.SpringBootPlusApplication</mainClass>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
|
||||||
<version>${maven-resources-plugin.version}</version>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- 打包时跳过测试 -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<skipTests>true</skipTests>
|
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- 打包插件 -->
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
<configuration>
|
|
||||||
<finalName>${project.build.finalName}-server</finalName>
|
|
||||||
<descriptors>
|
|
||||||
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
|
||||||
</descriptors>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>make-assembly</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>${maven-javadoc-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<additionalOptions>
|
|
||||||
<additionalOption>-Xdoclint:none</additionalOption>
|
|
||||||
</additionalOptions>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-javadocs</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
|
||||||
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
<!--MAVEN打包选择运行环境-->
|
|
||||||
<!-- 1:local(默认) 本地 2:dev:开发环境 3:test 4:uat 用户验收测试 5.prod:生产环境 -->
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>local</id>
|
|
||||||
<properties>
|
|
||||||
<profileActive>local</profileActive>
|
|
||||||
</properties>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>true</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>dev</id>
|
|
||||||
<properties>
|
|
||||||
<profileActive>dev</profileActive>
|
|
||||||
</properties>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>test</id>
|
|
||||||
<properties>
|
|
||||||
<profileActive>test</profileActive>
|
|
||||||
</properties>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>uat</id>
|
|
||||||
<properties>
|
|
||||||
<profileActive>uat</profileActive>
|
|
||||||
</properties>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>prod</id>
|
|
||||||
<properties>
|
|
||||||
<profileActive>prod</profileActive>
|
|
||||||
</properties>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<!--阿里云仓库-->
|
|
||||||
<repository>
|
|
||||||
<id>aliyun</id>
|
|
||||||
<name>aliyun-maven</name>
|
|
||||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>spring-milestones</id>
|
|
||||||
<name>Spring Milestones</name>
|
|
||||||
<url>https://maven.aliyun.com/repository/spring</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>central</id>
|
|
||||||
<name>maven-central</name>
|
|
||||||
<url>http://central.maven.org/maven2/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus;
|
|
||||||
|
|
||||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
|
||||||
import com.ruoyi.plus.util.PrintApplicationInfo;
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* spring-boot-plus 项目启动入口
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@EnableAsync
|
|
||||||
//@EnableScheduling
|
|
||||||
@EnableTransactionManagement
|
|
||||||
@EnableConfigurationProperties
|
|
||||||
//@EnableAdminServer
|
|
||||||
@MapperScan({"com.ruoyi.plus.**.mapper"})
|
|
||||||
@SpringBootApplication
|
|
||||||
public class SpringBootPlusApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// 启动spring-boot-plus
|
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusApplication.class, args);
|
|
||||||
// 打印项目信息
|
|
||||||
PrintApplicationInfo.print(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,292 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.aop;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.ruoyi.plus.common.api.ApiCode;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.util.AnsiUtil;
|
|
||||||
import com.ruoyi.plus.util.DateUtil;
|
|
||||||
import com.ruoyi.plus.util.IpUtil;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.Signature;
|
|
||||||
import org.aspectj.lang.annotation.Around;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
|
||||||
import org.fusesource.jansi.Ansi;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Controller Aop
|
|
||||||
* 获取响应结果信息
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Slf4j
|
|
||||||
@Aspect
|
|
||||||
public class LogAop {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 切点
|
|
||||||
*/
|
|
||||||
private static final String POINTCUT = "execution(public * io.geekidea.springbootplus.*.web.controller..*.*(..))";
|
|
||||||
/**
|
|
||||||
* 默认的请求内容类型,表单提交
|
|
||||||
**/
|
|
||||||
private static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
|
|
||||||
/**
|
|
||||||
* JSON请求内容类型
|
|
||||||
**/
|
|
||||||
private static final String APPLICATION_JSON = "application/json";
|
|
||||||
/**
|
|
||||||
* GET请求
|
|
||||||
**/
|
|
||||||
private static final String GET = "GET";
|
|
||||||
/**
|
|
||||||
* POST请求
|
|
||||||
**/
|
|
||||||
private static final String POST = "POST";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求日志是否格式化输出
|
|
||||||
*/
|
|
||||||
private boolean requestLogFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 响应日期是否格式化输出
|
|
||||||
*/
|
|
||||||
private boolean responseLogFormat;
|
|
||||||
|
|
||||||
@Around(POINTCUT)
|
|
||||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
||||||
|
|
||||||
// 获取请求相关信息
|
|
||||||
try {
|
|
||||||
// 获取当前的HttpServletRequest对象
|
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
||||||
HttpServletRequest request = attributes.getRequest();
|
|
||||||
|
|
||||||
|
|
||||||
Map<String,Object> map = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
// 获取请求类名和方法名称
|
|
||||||
Signature signature = joinPoint.getSignature();
|
|
||||||
|
|
||||||
// 获取真实的方法对象
|
|
||||||
MethodSignature methodSignature = (MethodSignature) signature;
|
|
||||||
Method method = methodSignature.getMethod();
|
|
||||||
|
|
||||||
// 请求全路径
|
|
||||||
String url = request.getRequestURI();
|
|
||||||
map.put("path",url);
|
|
||||||
// IP地址
|
|
||||||
String ip = IpUtil.getRequestIp();
|
|
||||||
map.put("ip",ip);
|
|
||||||
|
|
||||||
// 获取请求方式
|
|
||||||
String requestMethod = request.getMethod();
|
|
||||||
map.put("requestMethod",requestMethod);
|
|
||||||
|
|
||||||
// 获取请求内容类型
|
|
||||||
String contentType = request.getContentType();
|
|
||||||
map.put("contentType",contentType);
|
|
||||||
|
|
||||||
// 判断控制器方法参数中是否有RequestBody注解
|
|
||||||
Annotation[][] annotations = method.getParameterAnnotations();
|
|
||||||
boolean isRequestBody = isRequestBody(annotations);
|
|
||||||
map.put("isRequestBody",isRequestBody);
|
|
||||||
// 设置请求参数
|
|
||||||
Object requestParamJson = getRequestParamJsonString(joinPoint, request, requestMethod, contentType, isRequestBody);
|
|
||||||
map.put("param",requestParamJson);
|
|
||||||
map.put("time", DateUtil.getYYYYMMDDHHMMSS(new Date()));
|
|
||||||
|
|
||||||
// 获取请求头token
|
|
||||||
map.put("x-auth-token",request.getHeader("x-auth-token"));
|
|
||||||
|
|
||||||
String requestInfo = null;
|
|
||||||
try {
|
|
||||||
if (requestLogFormat){
|
|
||||||
requestInfo = "\n" + JSON.toJSONString(map,true);
|
|
||||||
}else{
|
|
||||||
requestInfo = JSON.toJSONString(map);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
log.info(AnsiUtil.getAnsi(Ansi.Color.GREEN,"requestInfo:" + requestInfo));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 执行目标方法,获得返回值
|
|
||||||
Object result = joinPoint.proceed();
|
|
||||||
try{
|
|
||||||
if (result != null && result instanceof ApiResult){
|
|
||||||
ApiResult apiResult = (ApiResult) result;
|
|
||||||
int code = apiResult.getCode();
|
|
||||||
String responseResultInfo = "responseResult:";
|
|
||||||
if (responseLogFormat){
|
|
||||||
responseResultInfo += "\n" + JSON.toJSONString(apiResult,true);
|
|
||||||
}else{
|
|
||||||
responseResultInfo += JSON.toJSONString(apiResult);
|
|
||||||
}
|
|
||||||
if (code == ApiCode.SUCCESS.getCode()){
|
|
||||||
log.info(AnsiUtil.getAnsi(Ansi.Color.BLUE,responseResultInfo));
|
|
||||||
}else{
|
|
||||||
log.error(AnsiUtil.getAnsi(Ansi.Color.RED,responseResultInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error("处理响应结果异常",e);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取请求参数JSON字符串
|
|
||||||
*
|
|
||||||
* @param joinPoint
|
|
||||||
* @param request
|
|
||||||
* @param requestMethod
|
|
||||||
* @param contentType
|
|
||||||
* @param isRequestBody
|
|
||||||
*/
|
|
||||||
private Object getRequestParamJsonString(ProceedingJoinPoint joinPoint, HttpServletRequest request, String requestMethod, String contentType, boolean isRequestBody) {
|
|
||||||
/**
|
|
||||||
* 判断请求内容类型
|
|
||||||
* 通常有3中请求内容类型
|
|
||||||
* 1.发送get请求时,contentType为null
|
|
||||||
* 2.发送post请求时,contentType为application/x-www-form-urlencoded
|
|
||||||
* 3.发送post json请求,contentType为application/json
|
|
||||||
* 4.发送post json请求并有RequestBody注解,contentType为application/json
|
|
||||||
*/
|
|
||||||
Object paramObject = null;
|
|
||||||
int requestType = 0;
|
|
||||||
if (GET.equals(requestMethod)) {
|
|
||||||
requestType = 1;
|
|
||||||
} else if (POST.equals(requestMethod)) {
|
|
||||||
if (contentType == null) {
|
|
||||||
requestType = 5;
|
|
||||||
} else if (contentType.startsWith(APPLICATION_X_WWW_FORM_URLENCODED)) {
|
|
||||||
requestType = 2;
|
|
||||||
} else if (contentType.startsWith(APPLICATION_JSON)) {
|
|
||||||
if (isRequestBody) {
|
|
||||||
requestType = 4;
|
|
||||||
} else {
|
|
||||||
requestType = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1,2,3中类型时,获取getParameterMap中所有的值,处理后序列化成JSON字符串
|
|
||||||
if (requestType == 1 || requestType == 2 || requestType == 3 || requestType == 5) {
|
|
||||||
Map<String, String[]> paramsMap = request.getParameterMap();
|
|
||||||
paramObject = getJsonForParamMap(paramsMap);
|
|
||||||
} else if (requestType == 4) { // POST,application/json,RequestBody的类型,简单判断,然后序列化成JSON字符串
|
|
||||||
Object[] args = joinPoint.getArgs();
|
|
||||||
paramObject = argsArrayToJsonString(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return paramObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断控制器方法参数中是否有RequestBody注解
|
|
||||||
*
|
|
||||||
* @param annotations
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean isRequestBody(Annotation[][] annotations) {
|
|
||||||
boolean isRequestBody = false;
|
|
||||||
for (Annotation[] annotationArray : annotations) {
|
|
||||||
for (Annotation annotation : annotationArray) {
|
|
||||||
if (annotation instanceof RequestBody) {
|
|
||||||
isRequestBody = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isRequestBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求参数拼装
|
|
||||||
*
|
|
||||||
* @param args
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Object argsArrayToJsonString(Object[] args) {
|
|
||||||
if (args == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (args.length == 1) {
|
|
||||||
return args[0];
|
|
||||||
} else {
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取参数Map的JSON字符串
|
|
||||||
*
|
|
||||||
* @param paramsMap
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public JSONObject getJsonForParamMap(Map<String, String[]> paramsMap) {
|
|
||||||
int paramSize = paramsMap.size();
|
|
||||||
if (paramsMap == null || paramSize == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
for (Map.Entry<String, String[]> kv : paramsMap.entrySet()) {
|
|
||||||
String key = kv.getKey();
|
|
||||||
String[] values = kv.getValue();
|
|
||||||
if (values == null) { // 没有值
|
|
||||||
jsonObject.put(key, null);
|
|
||||||
} else if (values.length == 1) { // 一个值
|
|
||||||
jsonObject.put(key, values[0]);
|
|
||||||
} else { // 多个值
|
|
||||||
jsonObject.put(key, values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* REST API 响应码
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
public enum ApiCode {
|
|
||||||
|
|
||||||
SUCCESS(200, "操作成功"),
|
|
||||||
|
|
||||||
UNAUTHORIZED(401, "非法访问"),
|
|
||||||
|
|
||||||
NOT_PERMISSION(403, "没有权限"),
|
|
||||||
|
|
||||||
NOT_FOUND(404, "你请求的路径不存在"),
|
|
||||||
|
|
||||||
FAIL(500, "操作失败"),
|
|
||||||
|
|
||||||
SYSTEM_EXCEPTION(5000,"系统异常!"),
|
|
||||||
|
|
||||||
PARAMETER_EXCEPTION(5001,"请求参数校验异常"),
|
|
||||||
|
|
||||||
PARAMETER_PARSE_EXCEPTION(5002,"请求参数解析异常"),
|
|
||||||
|
|
||||||
HTTP_MEDIA_TYPE_EXCEPTION(5003,"HTTP Media 类型异常"),
|
|
||||||
|
|
||||||
SYSTEM_LOGIN_EXCEPTION(5005,"系统登录异常")
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String msg;
|
|
||||||
|
|
||||||
ApiCode(final int code, final String msg) {
|
|
||||||
this.code = code;
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiCode getApiCode(int code) {
|
|
||||||
ApiCode[] ecs = ApiCode.values();
|
|
||||||
for (ApiCode ec : ecs) {
|
|
||||||
if (ec.getCode() == code) {
|
|
||||||
return ec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsg() {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.api;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* ApiResultEST API 公共控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class ApiController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 请求成功
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param data 数据内容
|
|
||||||
* @param <T> 对象泛型
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected <T> ApiResult<T> ok(T data) {
|
|
||||||
return ApiResult.ok(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 请求失败
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param msg 提示内容
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected ApiResult<Object> fail(String msg) {
|
|
||||||
return ApiResult.fail(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 请求失败
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param apiCode 请求错误码
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected ApiResult<Object> fail(ApiCode apiCode) {
|
|
||||||
return ApiResult.fail(apiCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.api;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* REST API 返回结果
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ApiResult<T> implements Serializable {
|
|
||||||
|
|
||||||
private int code;
|
|
||||||
|
|
||||||
private T data;
|
|
||||||
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
private Date time;
|
|
||||||
|
|
||||||
public ApiResult() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult result(boolean flag){
|
|
||||||
if (flag){
|
|
||||||
return ok();
|
|
||||||
}
|
|
||||||
return fail("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult result(ApiCode apiCode){
|
|
||||||
return result(apiCode,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult result(ApiCode apiCode,Object data){
|
|
||||||
return result(apiCode,null,data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult result(ApiCode apiCode,String msg,Object data){
|
|
||||||
String message = apiCode.getMsg();
|
|
||||||
if (StringUtils.isNotBlank(msg)){
|
|
||||||
message = msg;
|
|
||||||
}
|
|
||||||
return ApiResult.builder()
|
|
||||||
.code(apiCode.getCode())
|
|
||||||
.msg(message)
|
|
||||||
.data(data)
|
|
||||||
.time(new Date())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult ok(){
|
|
||||||
return ok(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult ok(Object data){
|
|
||||||
return result(ApiCode.SUCCESS,data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult ok(String key,Object value){
|
|
||||||
Map<String,Object> map = new HashMap<>();
|
|
||||||
map.put(key,value);
|
|
||||||
return ok(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult fail(ApiCode apiCode){
|
|
||||||
return result(apiCode,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult fail(String msg){
|
|
||||||
return result(ApiCode.FAIL,msg,null);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult fail(ApiCode apiCode,Object data){
|
|
||||||
if (ApiCode.SUCCESS == apiCode){
|
|
||||||
throw new RuntimeException("失败结果状态码不能为" + ApiCode.SUCCESS.getCode());
|
|
||||||
}
|
|
||||||
return result(apiCode,data);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult fail(String key,Object value){
|
|
||||||
Map<String,Object> map = new HashMap<>();
|
|
||||||
map.put(key,value);
|
|
||||||
return result(ApiCode.FAIL,map);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.api;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.baomidou.mybatisplus.extension.api.IErrorCode;
|
|
||||||
import com.baomidou.mybatisplus.extension.exceptions.ApiException;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* REST API 业务断言<br>
|
|
||||||
* 参考:org.junit.Assert
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
public class Assert {
|
|
||||||
|
|
||||||
protected Assert() {
|
|
||||||
// to do noting
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 大于O
|
|
||||||
*/
|
|
||||||
public static void gtZero(Integer num, IErrorCode errorCode) {
|
|
||||||
if (num == null || num <= 0) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 大于等于O
|
|
||||||
*/
|
|
||||||
public static void geZero(Integer num, IErrorCode errorCode) {
|
|
||||||
if (num == null || num < 0) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* num1大于num2
|
|
||||||
*/
|
|
||||||
public static void gt(Integer num1, Integer num2, IErrorCode errorCode) {
|
|
||||||
if (num1 <= num2) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* num1大于等于num2
|
|
||||||
*/
|
|
||||||
public static void ge(Integer num1, Integer num2, IErrorCode errorCode) {
|
|
||||||
if (num1 < num2) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* obj1 eq obj2
|
|
||||||
*/
|
|
||||||
public static void eq(Object obj1, Object obj2, IErrorCode errorCode) {
|
|
||||||
if (!obj1.equals(obj2)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void isTrue(boolean condition, IErrorCode errorCode) {
|
|
||||||
if (!condition) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void isFalse(boolean condition, IErrorCode errorCode) {
|
|
||||||
if (condition) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void isNull(IErrorCode errorCode, Object... conditions) {
|
|
||||||
if (ObjectUtils.isNotNull(conditions)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void notNull(IErrorCode errorCode, Object... conditions) {
|
|
||||||
if (ObjectUtils.isNull(conditions)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 失败结果
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param errorCode 异常错误码
|
|
||||||
*/
|
|
||||||
public static void fail(IErrorCode errorCode) {
|
|
||||||
throw new ApiException(errorCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fail(boolean condition, IErrorCode errorCode) {
|
|
||||||
if (condition) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fail(String message) {
|
|
||||||
throw new ApiException(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fail(boolean condition, String message) {
|
|
||||||
if (condition) {
|
|
||||||
Assert.fail(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void notEmpty(Object[] array, IErrorCode errorCode) {
|
|
||||||
if (ObjectUtils.isEmpty(array)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void noNullElements(Object[] array, IErrorCode errorCode) {
|
|
||||||
if (array != null) {
|
|
||||||
for (Object element : array) {
|
|
||||||
if (element == null) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void notEmpty(Collection<?> collection, IErrorCode errorCode) {
|
|
||||||
if (CollectionUtils.isNotEmpty(collection)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void notEmpty(Map<?, ?> map, IErrorCode errorCode) {
|
|
||||||
if (ObjectUtils.isEmpty(map)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void isInstanceOf(Class<?> type, Object obj, IErrorCode errorCode) {
|
|
||||||
Assert.notNull(errorCode, type);
|
|
||||||
if (!type.isInstance(obj)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void isAssignable(Class<?> superType, Class<?> subType, IErrorCode errorCode) {
|
|
||||||
Assert.notNull(errorCode, superType);
|
|
||||||
if (subType == null || !superType.isAssignableFrom(subType)) {
|
|
||||||
Assert.fail(errorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constant;
|
|
||||||
|
|
||||||
|
|
||||||
public interface CacheKey {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 常量
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public interface CommonConstant {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认页码为1
|
|
||||||
*/
|
|
||||||
Integer DEFAULT_PAGE_INDEX = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认页大小为10
|
|
||||||
*/
|
|
||||||
Integer DEFAULT_PAGE_SIZE = 10;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录用户
|
|
||||||
*/
|
|
||||||
String LOGIN_SYS_USER = "loginSysUser";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登陆token
|
|
||||||
*/
|
|
||||||
String TOKEN = "token";
|
|
||||||
/**
|
|
||||||
* 刷新token
|
|
||||||
*/
|
|
||||||
String REFRESH_TOKEN = "refresh_token";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始密码
|
|
||||||
*/
|
|
||||||
String INIT_PWD = "123456";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认头像
|
|
||||||
*/
|
|
||||||
String DEFAULT_HEAD_URL = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员角色名称
|
|
||||||
*/
|
|
||||||
String ADMIN_ROLE_NAME = "管理员";
|
|
||||||
|
|
||||||
String ADMIN_LOGIN = "adminLogin";
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* redis key 常量
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-23
|
|
||||||
**/
|
|
||||||
public interface CommonRedisKey {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统登录用户
|
|
||||||
*/
|
|
||||||
String LOGIN_SYS_USER = "login:sys:user:%s";
|
|
||||||
/**
|
|
||||||
* 系统登录token
|
|
||||||
*/
|
|
||||||
String LOGIN_TOKEN = "login:token";
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 日期格式常量
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public interface DatePattern {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 年-月-日
|
|
||||||
*/
|
|
||||||
String yyyy_MM_dd = "yyyy-MM-dd";
|
|
||||||
/**
|
|
||||||
* 年-月-日 时:分
|
|
||||||
*/
|
|
||||||
String yyyy_MM_dd_HH_mm = "yyyy-MM-dd HH:mm";
|
|
||||||
/**
|
|
||||||
* 年-月-日 时:分:秒
|
|
||||||
*/
|
|
||||||
String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss";
|
|
||||||
/**
|
|
||||||
* 年-月-日 时:分:秒:毫秒
|
|
||||||
*/
|
|
||||||
String yyyy_MM_dd_HH_mm_ss_S = "yyyy-MM-dd HH:mm:ss.S";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时:分
|
|
||||||
*/
|
|
||||||
String HH_mm = "HH:mm";
|
|
||||||
/**
|
|
||||||
* 时:分:秒
|
|
||||||
*/
|
|
||||||
String HH_mm_ss = "HH:mm:ss";
|
|
||||||
/**
|
|
||||||
* 时:分:秒:毫秒
|
|
||||||
*/
|
|
||||||
String HH_mm_ss_S = "HH:mm:ss:S";
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.*;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义系统内的枚举验证注解
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Documented
|
|
||||||
@Constraint(validatedBy = { EmailValidator.class })
|
|
||||||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
public @interface Email {
|
|
||||||
String message() default "请输入有效的邮箱";
|
|
||||||
|
|
||||||
Class<?>[] groups() default { };
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default { };
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义邮箱验证注解实现类
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class EmailValidator implements ConstraintValidator<Email, String> {
|
|
||||||
private static final String REG_EX = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$";
|
|
||||||
private static final Pattern PATTERN = Pattern.compile(REG_EX);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(Email parameters) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
|
||||||
if (value ==null){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return PATTERN.matcher(value).matches();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.enums.BaseTypeStateEnum;
|
|
||||||
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.*;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义邮箱正则验证注解
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Documented
|
|
||||||
@Constraint(validatedBy = { EnumTypeValidator.class })
|
|
||||||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
public @interface EnumType {
|
|
||||||
String message() default "请输入正确的类型值";
|
|
||||||
|
|
||||||
Class<? extends BaseTypeStateEnum> type();
|
|
||||||
|
|
||||||
Class<?>[] groups() default { };
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default { };
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.enums.BaseTypeStateEnum;
|
|
||||||
import com.ruoyi.plus.common.exception.BusinessException;
|
|
||||||
import com.ruoyi.plus.util.EnumUtil;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义系统内的枚举验证注解实现类
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class EnumTypeValidator implements ConstraintValidator<EnumType, Integer> {
|
|
||||||
|
|
||||||
private Class<? extends BaseTypeStateEnum> baseTypeStateEnum;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(EnumType parameters) {
|
|
||||||
baseTypeStateEnum = parameters.type();
|
|
||||||
if (baseTypeStateEnum == null){
|
|
||||||
throw new BusinessException("请传入枚举类型类");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
|
|
||||||
if (value ==null){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return EnumUtil.exists(baseTypeStateEnum,value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.*;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义身份证号码正则验证注解
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Documented
|
|
||||||
@Constraint(validatedBy = { IdCardValidator.class })
|
|
||||||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
public @interface IdCard {
|
|
||||||
String message() default "请输入有效的身份证号码";
|
|
||||||
|
|
||||||
Class<?>[] groups() default { };
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default { };
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义身份证号码验证注解实现类
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class IdCardValidator implements ConstraintValidator<IdCard, String> {
|
|
||||||
private static final String REG_EX = "(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{2}[0-9Xx]$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}[0-9Xx]$)";
|
|
||||||
private static final Pattern PATTERN = Pattern.compile(REG_EX);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(IdCard parameters) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
|
||||||
if (value ==null){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return PATTERN.matcher(value).matches();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.*;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义手机号码正则验证注解
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Documented
|
|
||||||
@Constraint(validatedBy = { PhoneValidator.class })
|
|
||||||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
public @interface Phone {
|
|
||||||
String message() default "请输入有效的手机号码";
|
|
||||||
|
|
||||||
Class<?>[] groups() default { };
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default { };
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.constraints;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义手机号码验证注解实现类
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class PhoneValidator implements ConstraintValidator<Phone, String> {
|
|
||||||
|
|
||||||
private static final String REG_EX = "^1[3,4,5,6,7,8,9]\\d{9}$";
|
|
||||||
private static final Pattern PATTERN = Pattern.compile(REG_EX);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(Phone parameters) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
|
||||||
if (value ==null){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return PATTERN.matcher(value).matches();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.entity;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@ApiModel("BaseEntity")
|
|
||||||
public abstract class BaseEntity implements Serializable{
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public interface BaseTypeStateEnum {
|
|
||||||
|
|
||||||
Integer getKey();
|
|
||||||
|
|
||||||
String getValue();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.exception;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务异常
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class BusinessException extends RuntimeException{
|
|
||||||
private Integer code;
|
|
||||||
public BusinessException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BusinessException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BusinessException(Integer code ,String message){
|
|
||||||
this(StringUtils.isBlank(message)?String.valueOf(code):message);
|
|
||||||
this.code=code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(Integer code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.exception;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiCode;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局Error/404处理
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@ApiIgnore
|
|
||||||
@RestController
|
|
||||||
@Slf4j
|
|
||||||
public class GlobalErrorController implements ErrorController {
|
|
||||||
|
|
||||||
private static final String ERROR_PATH = "/error";
|
|
||||||
|
|
||||||
@RequestMapping(ERROR_PATH)
|
|
||||||
public ApiResult handleError(){
|
|
||||||
log.error("404 NOT FOUND");
|
|
||||||
return ApiResult.fail(ApiCode.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getErrorPath() {
|
|
||||||
log.error("errorPath....");
|
|
||||||
return ERROR_PATH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-115
@@ -1,115 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.exception;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.ruoyi.plus.common.api.ApiCode;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
||||||
import org.springframework.validation.BindingResult;
|
|
||||||
import org.springframework.validation.FieldError;
|
|
||||||
import org.springframework.web.HttpMediaTypeException;
|
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@ControllerAdvice
|
|
||||||
@RestController
|
|
||||||
@Slf4j
|
|
||||||
public class GlobalExceptionHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 非法参数验证异常
|
|
||||||
* @param ex
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
||||||
@ResponseStatus(value = HttpStatus.OK)
|
|
||||||
public ApiResult handleMethodArgumentNotValidExceptionHandler(MethodArgumentNotValidException ex) {
|
|
||||||
BindingResult bindingResult = ex.getBindingResult();
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
|
|
||||||
for (FieldError fieldError : fieldErrors) {
|
|
||||||
list.add(fieldError.getDefaultMessage());
|
|
||||||
}
|
|
||||||
Collections.sort(list);
|
|
||||||
log.error("fieldErrors"+ JSON.toJSONString(list));
|
|
||||||
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION,list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统登录异常处理
|
|
||||||
* @param exception
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(value = SysLoginException.class)
|
|
||||||
@ResponseStatus(HttpStatus.OK)
|
|
||||||
public ApiResult sysLoginExceptionHandler(SysLoginException exception) {
|
|
||||||
log.warn("系统登录异常:" + exception.getMessage());
|
|
||||||
return ApiResult.fail(ApiCode.SYSTEM_LOGIN_EXCEPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP解析请求参数异常
|
|
||||||
* @param exception
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(value = HttpMessageNotReadableException.class)
|
|
||||||
@ResponseStatus(HttpStatus.OK)
|
|
||||||
public ApiResult httpMessageNotReadableException(HttpMessageNotReadableException exception) {
|
|
||||||
log.error("httpMessageNotReadableException:",exception);
|
|
||||||
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, ApiCode.PARAMETER_PARSE_EXCEPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP
|
|
||||||
* @param exception
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(value = HttpMediaTypeException.class)
|
|
||||||
@ResponseStatus(HttpStatus.OK)
|
|
||||||
public ApiResult httpMediaTypeException(HttpMediaTypeException exception) {
|
|
||||||
log.error("httpMediaTypeException:",exception);
|
|
||||||
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, ApiCode.HTTP_MEDIA_TYPE_EXCEPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认的异常处理
|
|
||||||
* @param exception
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
|
||||||
@ResponseStatus(HttpStatus.OK)
|
|
||||||
public ApiResult exceptionHandler(Exception exception) {
|
|
||||||
log.error("exception:",exception);
|
|
||||||
return ApiResult.fail(ApiCode.SYSTEM_EXCEPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.exception;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统登录异常
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-08-04
|
|
||||||
*/
|
|
||||||
public class SysLoginException extends RuntimeException{
|
|
||||||
private Integer code;
|
|
||||||
public SysLoginException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public SysLoginException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SysLoginException(Integer code , String message){
|
|
||||||
this(StringUtils.isBlank(message)?String.valueOf(code):message);
|
|
||||||
this.code=code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(Integer code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
* 公共部分
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public interface BaseService<T> extends IService<T> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.ruoyi.plus.common.service.BaseService;
|
|
||||||
import com.ruoyi.plus.common.web.param.OrderQueryParam;
|
|
||||||
import com.ruoyi.plus.common.web.param.QueryParam;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {
|
|
||||||
|
|
||||||
protected Page setPageParam(QueryParam queryParam) {
|
|
||||||
return setPageParam(queryParam,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Page setPageParam(QueryParam queryParam, OrderItem defaultOrder) {
|
|
||||||
Page page = new Page();
|
|
||||||
// 设置当前页码
|
|
||||||
page.setCurrent(queryParam.getCurrent());
|
|
||||||
// 设置页大小
|
|
||||||
page.setSize(queryParam.getSize());
|
|
||||||
/**
|
|
||||||
* 如果是queryParam是OrderQueryParam,并且不为空,则使用前端排序
|
|
||||||
* 否则使用默认排序
|
|
||||||
*/
|
|
||||||
if (queryParam instanceof OrderQueryParam){
|
|
||||||
OrderQueryParam orderQueryParam = (OrderQueryParam) queryParam;
|
|
||||||
List<OrderItem> orderItems = orderQueryParam.getOrders();
|
|
||||||
if (CollectionUtils.isEmpty(orderItems)){
|
|
||||||
page.setOrders(Arrays.asList(defaultOrder));
|
|
||||||
}else{
|
|
||||||
page.setOrders(orderItems);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
page.setOrders(Arrays.asList(defaultOrder));
|
|
||||||
}
|
|
||||||
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-45
@@ -1,45 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.controller;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Api文档
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/docs")
|
|
||||||
@ApiIgnore
|
|
||||||
public class ApiDocController extends BaseController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swaggerUI
|
|
||||||
*/
|
|
||||||
@GetMapping("")
|
|
||||||
public String swaggerUI(){
|
|
||||||
return "redirect:/swagger-ui.html";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.controller;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiController;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public abstract class BaseController extends ApiController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前请求
|
|
||||||
*
|
|
||||||
* @return request
|
|
||||||
*/
|
|
||||||
public HttpServletRequest getRequest() {
|
|
||||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 获取当前请求
|
|
||||||
*
|
|
||||||
* @return response
|
|
||||||
*/
|
|
||||||
public HttpServletResponse getResponse() {
|
|
||||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.controller;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 项目根路径提示信息
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018/11/12
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@ApiIgnore
|
|
||||||
@Slf4j
|
|
||||||
public class IndexController {
|
|
||||||
|
|
||||||
@RequestMapping("/index")
|
|
||||||
public ApiResult<String> index(){
|
|
||||||
log.debug("index...");
|
|
||||||
return ApiResult.ok("Welcome to Spring Boot Plus Project...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.filter;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import javax.servlet.*;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置允许跨域
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class CrossDomainFilter implements Filter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
|
||||||
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
|
|
||||||
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
|
|
||||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "*");
|
|
||||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "*");
|
|
||||||
httpServletResponse.setHeader("Access-Control-Request-Headers","*");
|
|
||||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "content-type,x-auth-token");
|
|
||||||
httpServletResponse.setHeader("Access-Control-Expose-Headers", "*");
|
|
||||||
|
|
||||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
||||||
String method = request.getMethod();
|
|
||||||
if ("OPTIONS".equals(method)){
|
|
||||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
PrintWriter w = response.getWriter();
|
|
||||||
ApiResult apiResult = new ApiResult();
|
|
||||||
apiResult.setCode(200);
|
|
||||||
apiResult.setMsg("ok...");
|
|
||||||
w.append(JSON.toJSONString(apiResult));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
filterChain.doFilter(servletRequest, httpServletResponse);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.filter;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import javax.servlet.*;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求路径过滤器
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class RequestPathFilter implements Filter {
|
|
||||||
|
|
||||||
private static List<String> excludes = new ArrayList<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
// 控制台日志忽略spring boot admin访问路径
|
|
||||||
excludes.add("/actuator");
|
|
||||||
excludes.add("/instances");
|
|
||||||
excludes.add("/logfile");
|
|
||||||
excludes.add("/sba-settings.js");
|
|
||||||
excludes.add("/assets/img/favicon.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
|
||||||
HttpServletRequest req = (HttpServletRequest) request;
|
|
||||||
String path = req.getServletPath();
|
|
||||||
String url = req.getRequestURL().toString();
|
|
||||||
|
|
||||||
boolean isOut = true;
|
|
||||||
for (String p : excludes){
|
|
||||||
if (path.startsWith(p)){
|
|
||||||
isOut = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isOut){
|
|
||||||
log.debug("requestURL:"+url);
|
|
||||||
}
|
|
||||||
chain.doFilter(req,response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.interceptor;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限拦截器
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
||||||
throws Exception {
|
|
||||||
log.info(request.getRequestURI());
|
|
||||||
log.info("\n\nPermissionInterceptor...\n\n");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-79
@@ -1,79 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.interceptor;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.constant.CommonConstant;
|
|
||||||
import com.ruoyi.plus.util.LoginUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Token超时拦截器
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class TokenTimeoutInterceptor extends HandlerInterceptorAdapter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate redisTemplate;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
||||||
throws Exception {
|
|
||||||
|
|
||||||
// 如果访问的不是控制器,则跳出,继续执行下一个拦截器
|
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取token
|
|
||||||
String token = request.getHeader(CommonConstant.TOKEN);
|
|
||||||
boolean hastoken = false;
|
|
||||||
if (StringUtils.isNotBlank(token)){
|
|
||||||
hastoken = true;
|
|
||||||
}
|
|
||||||
if (hastoken == false){
|
|
||||||
token = request.getParameter(CommonConstant.TOKEN);
|
|
||||||
if (StringUtils.isNotBlank(token)){
|
|
||||||
hastoken = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO 排除自动刷新的路径
|
|
||||||
if (hastoken == true){
|
|
||||||
// 如果有token,延长时间
|
|
||||||
redisTemplate.expire(token,LoginUtil.TOKEN_VALID_TIME_MINUTE, TimeUnit.MINUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.param;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@ApiModel("ID参数")
|
|
||||||
public class IdParam implements Serializable {
|
|
||||||
private static final long serialVersionUID = -5353973980674510450L;
|
|
||||||
|
|
||||||
@NotBlank(message="ID不能为空")
|
|
||||||
private String id;
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.param;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@ApiModel("主键状态VO")
|
|
||||||
public class IdStatusParam implements Serializable {
|
|
||||||
private static final long serialVersionUID = -7581307955242965701L;
|
|
||||||
|
|
||||||
@ApiModelProperty("主键ID")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@ApiModelProperty("状态,1:启用 0:禁用")
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(Integer status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "IdStatusVo{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", status=" + status +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.param;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 名称参数
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@ApiModel("名称参数")
|
|
||||||
public class NameParam implements Serializable {
|
|
||||||
private static final long serialVersionUID = -3710501706034574149L;
|
|
||||||
|
|
||||||
@ApiModelProperty("名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "NameParam{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.param;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 可排序查询参数对象
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@ApiModel("可排序查询参数对象")
|
|
||||||
public abstract class OrderQueryParam extends QueryParam{
|
|
||||||
private static final long serialVersionUID = 57714391204790143L;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "排序")
|
|
||||||
private List<OrderItem> orders;
|
|
||||||
|
|
||||||
public void defaultOrder(OrderItem orderItem){
|
|
||||||
this.defaultOrders(Arrays.asList(orderItem));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void defaultOrders(List<OrderItem> orderItems){
|
|
||||||
if (CollectionUtils.isEmpty(orderItems)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.orders = orderItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.param;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.constant.CommonConstant;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询参数
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@ApiModel("查询参数对象")
|
|
||||||
public abstract class QueryParam implements Serializable{
|
|
||||||
private static final long serialVersionUID = -3263921252635611410L;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "页码,默认为1")
|
|
||||||
private Integer current = CommonConstant.DEFAULT_PAGE_INDEX;
|
|
||||||
@ApiModelProperty(value = "页大小,默认为10")
|
|
||||||
private Integer size = CommonConstant.DEFAULT_PAGE_SIZE;
|
|
||||||
@ApiModelProperty(value = "搜索字符串")
|
|
||||||
private String keyword;
|
|
||||||
|
|
||||||
public void setCurrent(Integer current) {
|
|
||||||
if (current == null || current <= 0){
|
|
||||||
this.current = CommonConstant.DEFAULT_PAGE_INDEX;
|
|
||||||
}else{
|
|
||||||
this.current = current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(Integer size) {
|
|
||||||
if (size == null || size <= 0){
|
|
||||||
this.size = CommonConstant.DEFAULT_PAGE_SIZE;
|
|
||||||
}else{
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.vo;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 公共ID-NAME-VO对象
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@ApiModel("ID-NAME-VO")
|
|
||||||
public class CommonIdName {
|
|
||||||
|
|
||||||
@ApiModelProperty("id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@ApiModelProperty("名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public CommonIdName(String id, String name) {
|
|
||||||
super();
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public CommonIdName() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "CommonIdName [id=" + id + ", name=" + name + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.common.web.vo;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@ApiModel("分页")
|
|
||||||
public class Paging<T> implements Serializable {
|
|
||||||
private static final long serialVersionUID = -1683800405530086022L;
|
|
||||||
|
|
||||||
@ApiModelProperty("总行数")
|
|
||||||
@JSONField(name = "total")
|
|
||||||
@JsonProperty("total")
|
|
||||||
private long total = 0;
|
|
||||||
|
|
||||||
@ApiModelProperty("数据列表")
|
|
||||||
@JSONField(name = "records")
|
|
||||||
@JsonProperty("records")
|
|
||||||
private List<T> records = Collections.emptyList();
|
|
||||||
|
|
||||||
public Paging() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Paging(IPage page) {
|
|
||||||
this.total = page.getTotal();
|
|
||||||
this.records = page.getRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTotal() {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotal(long total) {
|
|
||||||
this.total = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> getRecords() {
|
|
||||||
return records;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRecords(List<T> records) {
|
|
||||||
this.records = records;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Paging{" +
|
|
||||||
"total=" + total +
|
|
||||||
", records=" + records +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.web.filter.CrossDomainFilter;
|
|
||||||
import com.ruoyi.plus.common.web.filter.RequestPathFilter;
|
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class FilterConfig {
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Filter crossDomainFilter(){
|
|
||||||
return new CrossDomainFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Filter requestPathFilter(){
|
|
||||||
return new RequestPathFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Order(1)
|
|
||||||
public FilterRegistrationBean requestPathFilterBean() {
|
|
||||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
|
||||||
registration.setFilter(requestPathFilter());
|
|
||||||
registration.addUrlPatterns("/*");
|
|
||||||
return registration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Order(2)
|
|
||||||
public FilterRegistrationBean crossDomainFilterBean() {
|
|
||||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
|
||||||
registration.setFilter(crossDomainFilter());
|
|
||||||
registration.addUrlPatterns("/*");
|
|
||||||
return registration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.util.unit.DataSize;
|
|
||||||
import org.springframework.util.unit.DataUnit;
|
|
||||||
|
|
||||||
import javax.servlet.MultipartConfigElement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件上传配置
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class MultipartConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件上传配置
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public MultipartConfigElement multipartConfigElement() {
|
|
||||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
|
||||||
//单个文件最大
|
|
||||||
//factory.setMaxFileSize("100MB"); //KB,MB
|
|
||||||
factory.setMaxFileSize(DataSize.of(100, DataUnit.MEGABYTES));
|
|
||||||
///设置总上传数据总大小
|
|
||||||
// factory.setMaxRequestSize("100MB");
|
|
||||||
factory.setMaxRequestSize(DataSize.of(100,DataUnit.MEGABYTES));
|
|
||||||
return factory.createMultipartConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* MybatisPlus配置
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class MybatisPlusConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mybatis-plus分页插件<br>
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public PaginationInterceptor paginationInterceptor() {
|
|
||||||
return new PaginationInterceptor();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
|
||||||
import org.springframework.cache.interceptor.KeyGenerator;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
|
||||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Redis Cache配置
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@EnableCaching
|
|
||||||
public class RedisCacheConfig extends CachingConfigurerSupport {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Override
|
|
||||||
public KeyGenerator keyGenerator() {
|
|
||||||
return (target, method, params) -> {
|
|
||||||
StringBuffer redisKey = new StringBuffer();
|
|
||||||
redisKey.append(target.getClass().getName()).append("-");
|
|
||||||
redisKey.append(method.getName());
|
|
||||||
if (params.length > 0) {
|
|
||||||
redisKey.append("-").append(Arrays.deepToString(params));
|
|
||||||
}
|
|
||||||
return redisKey.toString();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CacheManager cacheManager(RedisConnectionFactory factory) {
|
|
||||||
// 生成一个默认配置,通过config对象即可对缓存进行自定义配置
|
|
||||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
|
|
||||||
// 设置缓存的默认过期时间,也是使用Duration设置
|
|
||||||
config = config.entryTtl(Duration.ofMinutes(5)); // 过期时间5分钟
|
|
||||||
//.disableCachingNullValues(); // 不缓存空值
|
|
||||||
|
|
||||||
// 设置一个初始化的缓存空间set集合
|
|
||||||
Set<String> cacheNames = new HashSet<>();
|
|
||||||
cacheNames.add("my-redis-cache1");
|
|
||||||
cacheNames.add("my-redis-cache2");
|
|
||||||
|
|
||||||
// 对每个缓存空间应用不同的配置
|
|
||||||
Map<String, RedisCacheConfiguration> configMap = new HashMap<>();
|
|
||||||
configMap.put("my-redis-cache1", config);
|
|
||||||
configMap.put("my-redis-cache2", config.entryTtl(Duration.ofSeconds(120)));
|
|
||||||
|
|
||||||
// 使用自定义的缓存配置初始化一个cacheManager
|
|
||||||
RedisCacheManager cacheManager = RedisCacheManager.builder(factory)
|
|
||||||
.initialCacheNames(cacheNames) // 注意这两句的调用顺序,一定要先调用该方法设置初始化的缓存名,再初始化相关的配置
|
|
||||||
.withInitialCacheConfigurations(configMap)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return cacheManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Redis Template 配置
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RedisTemplateConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
|
||||||
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
|
|
||||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
|
||||||
|
|
||||||
// 自定义的string序列化器和fastjson序列化器
|
|
||||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
|
||||||
|
|
||||||
// jackson 序列化器
|
|
||||||
// GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
|
|
||||||
|
|
||||||
// fastjson 序列化器
|
|
||||||
GenericFastJsonRedisSerializer jsonRedisSerializer = new GenericFastJsonRedisSerializer();
|
|
||||||
|
|
||||||
// kv 序列化
|
|
||||||
redisTemplate.setKeySerializer(stringRedisSerializer);
|
|
||||||
redisTemplate.setValueSerializer(jsonRedisSerializer);
|
|
||||||
|
|
||||||
// hash 序列化
|
|
||||||
redisTemplate.setHashKeySerializer(stringRedisSerializer);
|
|
||||||
redisTemplate.setHashValueSerializer(jsonRedisSerializer);
|
|
||||||
|
|
||||||
redisTemplate.afterPropertiesSet();
|
|
||||||
|
|
||||||
return redisTemplate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RestTemplateConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
|
|
||||||
return new RestTemplate(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
|
|
||||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
|
||||||
factory.setReadTimeout(5000);//单位为ms
|
|
||||||
factory.setConnectTimeout(5000);//单位为ms
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.ParameterBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.schema.ModelRef;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.Contact;
|
|
||||||
import springfox.documentation.service.Parameter;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swagger2全局配置
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
public class Swagger2Config {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标题
|
|
||||||
*/
|
|
||||||
@Value("${swagger.title}")
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基本包
|
|
||||||
*/
|
|
||||||
@Value("${swagger.base.package}")
|
|
||||||
private String basePackage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 描述
|
|
||||||
*/
|
|
||||||
@Value("${swagger.description}")
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* URL
|
|
||||||
*/
|
|
||||||
@Value("${swagger.url}")
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 作者
|
|
||||||
*/
|
|
||||||
@Value("${swagger.contact.name}")
|
|
||||||
private String contactName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 作者网址
|
|
||||||
*/
|
|
||||||
@Value("${swagger.contact.url}")
|
|
||||||
private String contactUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 作者邮箱
|
|
||||||
*/
|
|
||||||
@Value("${swagger.contact.email}")
|
|
||||||
private String contactEmail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本
|
|
||||||
*/
|
|
||||||
@Value("${swagger.version}")
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage(basePackage))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build()
|
|
||||||
.globalOperationParameters(setHeaderToken());
|
|
||||||
}
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title(title)
|
|
||||||
.description(description)
|
|
||||||
.termsOfServiceUrl(url)
|
|
||||||
.contact(new Contact(contactName,contactUrl,contactEmail))
|
|
||||||
.version(version)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
private List<Parameter> setHeaderToken() {
|
|
||||||
List<Parameter> pars = new ArrayList<>();
|
|
||||||
|
|
||||||
// TODO 测试token值,上线关闭
|
|
||||||
String testTokenValue = "";
|
|
||||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
|
||||||
Parameter tokenParameter = tokenPar.name("token").description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).defaultValue(testTokenValue).build();
|
|
||||||
pars.add(tokenParameter);
|
|
||||||
return pars;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转换器配置
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class ConverterConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Converter<String, Date> stringToDateConverter() {
|
|
||||||
return new StringToDateConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Converter<String, Integer> stringToIntegerConverter() {
|
|
||||||
return new StringToIntegerConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Converter<String, Double> stringToDoubleConverter() {
|
|
||||||
return new StringToDoubleConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
* 日期转换器,将请求参数的日期字符串转换成java.util.Date类型
|
|
||||||
* </code>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class StringToDateConverter implements Converter<String, Date> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Date convert(String source) {
|
|
||||||
return StringToDateUtil.convert(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
* <pre>
|
|
||||||
* 日期转换器,将请求参数的日期字符串转换成java.util.Date类型
|
|
||||||
* 日期格式顺序:
|
|
||||||
* 1.yyyy-MM-dd HH:mm:ss:S
|
|
||||||
* 2.yyyy-MM-dd HH:mm:ss
|
|
||||||
* 3.yyyy-MM-dd HH:mm
|
|
||||||
* 4.yyyy-MM-dd HH
|
|
||||||
* 5.yyyy-MM-dd
|
|
||||||
* </pre>
|
|
||||||
* </code>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class StringToDateUtil{
|
|
||||||
/**
|
|
||||||
* 日期格式化数组
|
|
||||||
*/
|
|
||||||
private static DateFormat[] dateFormats = {
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:S"),
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm"),
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH"),
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd"),
|
|
||||||
new SimpleDateFormat("yyyy-MM")
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
* <pre>
|
|
||||||
* 1.如果日期字符串为空,则直接返回空
|
|
||||||
* 2.使用格式化组进行格式化,如果解析成功,则直接返回
|
|
||||||
* 4.否则,抛出非法参数异常
|
|
||||||
* @param source 请求的日期参数
|
|
||||||
* @return 解析后的日期类型:java.util.Date
|
|
||||||
* @exception IllegalArgumentException 非法参数异常
|
|
||||||
* </pre>
|
|
||||||
* </code>
|
|
||||||
*/
|
|
||||||
public static Date convert(String source) {
|
|
||||||
if (StringUtils.isBlank(source)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
source = source.trim();
|
|
||||||
|
|
||||||
try{
|
|
||||||
int timeLength = source.length();
|
|
||||||
Long time = Long.parseLong(source);
|
|
||||||
if (timeLength == 10){
|
|
||||||
time = time * 1000;
|
|
||||||
}
|
|
||||||
Date date = new Date(time);
|
|
||||||
return date;
|
|
||||||
}catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Date date = null;
|
|
||||||
boolean flag = false;
|
|
||||||
for (DateFormat dateFormat : dateFormats) {
|
|
||||||
try {
|
|
||||||
date = dateFormat.parse(source);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
} catch (ParseException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flag) {
|
|
||||||
return date;
|
|
||||||
}else{
|
|
||||||
throw new IllegalArgumentException("不能解析日期:" + source);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
*
|
|
||||||
* </code>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class StringToDoubleConverter implements Converter<String, Double> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Double convert(String source) {
|
|
||||||
return StringToDoubleUtil.convert(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
* <pre>
|
|
||||||
* 空字符串("")转换成Double的null
|
|
||||||
*
|
|
||||||
* </pre>
|
|
||||||
* </code>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class StringToDoubleUtil {
|
|
||||||
|
|
||||||
public static Double convert(String source) {
|
|
||||||
if (StringUtils.isBlank(source)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Double d = Double.parseDouble(source);
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
*
|
|
||||||
* </code>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class StringToIntegerConverter implements Converter<String, Integer> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer convert(String source) {
|
|
||||||
return StringToIntegerUtil.convert(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.converter;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>
|
|
||||||
* <pre>
|
|
||||||
* 空字符串("")转换成Integer的null
|
|
||||||
*
|
|
||||||
* </pre>
|
|
||||||
* </code>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class StringToIntegerUtil {
|
|
||||||
|
|
||||||
public static Integer convert(String source) {
|
|
||||||
if (StringUtils.isBlank(source)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Integer i = Integer.parseInt(source);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.fastjson;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
||||||
import com.alibaba.fastjson.serializer.ToStringSerializer;
|
|
||||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
||||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
//@Configuration
|
|
||||||
public class FastJsonMvcConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
private static final String DEFAULT_CHARSET = "UTF-8";
|
|
||||||
private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
||||||
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
|
|
||||||
|
|
||||||
List<MediaType> mediaTypes = new ArrayList<>();
|
|
||||||
mediaTypes.add(MediaType.APPLICATION_JSON);
|
|
||||||
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
|
|
||||||
mediaTypes.add(MediaType.TEXT_HTML);
|
|
||||||
mediaTypes.add(new MediaType("application", "xml"));
|
|
||||||
mediaTypes.add(new MediaType("text", "xml"));
|
|
||||||
mediaTypes.add(new MediaType("application", "*+xml"));
|
|
||||||
mediaTypes.add(MediaType.ALL);
|
|
||||||
fastJsonHttpMessageConverter.setSupportedMediaTypes(mediaTypes);
|
|
||||||
|
|
||||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
|
||||||
fastJsonConfig.setCharset(Charset.forName(DEFAULT_CHARSET));
|
|
||||||
fastJsonConfig.setDateFormat(DEFAULT_DATE_FORMAT);
|
|
||||||
SerializerFeature[] serializerFeatures = new SerializerFeature[]{
|
|
||||||
SerializerFeature.PrettyFormat, // 格式化
|
|
||||||
SerializerFeature.WriteMapNullValue, // 输出空值
|
|
||||||
SerializerFeature.WriteNullListAsEmpty, // 空集合输出[]
|
|
||||||
SerializerFeature.WriteDateUseDateFormat // 日期格式化
|
|
||||||
};
|
|
||||||
fastJsonConfig.setSerializerFeatures(serializerFeatures);
|
|
||||||
|
|
||||||
|
|
||||||
SerializeConfig serializeConfig = SerializeConfig.globalInstance;
|
|
||||||
serializeConfig.put(BigInteger.class, ToStringSerializer.instance);
|
|
||||||
serializeConfig.put(Long.class, ToStringSerializer.instance);
|
|
||||||
serializeConfig.put(Long.TYPE, ToStringSerializer.instance);
|
|
||||||
fastJsonConfig.setSerializeConfig(serializeConfig);
|
|
||||||
|
|
||||||
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
|
|
||||||
|
|
||||||
converters.add(0,fastJsonHttpMessageConverter);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
|
||||||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
|
||||||
import com.ruoyi.plus.common.constant.DatePattern;
|
|
||||||
import com.ruoyi.plus.config.json.jackson.deserializer.JacksonDateDeserializer;
|
|
||||||
import com.ruoyi.plus.config.json.jackson.deserializer.JacksonDoubleDeserializer;
|
|
||||||
import com.ruoyi.plus.config.json.jackson.serializer.JacksonDateSerializer;
|
|
||||||
import com.ruoyi.plus.config.json.jackson.serializer.JacksonIntegerDeserializer;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @author 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class JacksonConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
||||||
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
|
|
||||||
|
|
||||||
ObjectMapper objectMapper = jackson2HttpMessageConverter.getObjectMapper();
|
|
||||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
|
||||||
objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
|
|
||||||
|
|
||||||
SimpleModule simpleModule = new SimpleModule();
|
|
||||||
// Long类型序列化成字符串,避免Long精度丢失
|
|
||||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
|
||||||
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
|
||||||
|
|
||||||
// Date
|
|
||||||
simpleModule.addSerializer(Date.class,new JacksonDateSerializer());
|
|
||||||
simpleModule.addDeserializer(Date.class,new JacksonDateDeserializer());
|
|
||||||
|
|
||||||
simpleModule.addDeserializer(Integer.class,new JacksonIntegerDeserializer());
|
|
||||||
simpleModule.addDeserializer(Double.class,new JacksonDoubleDeserializer());
|
|
||||||
|
|
||||||
// jdk8日期序列化和反序列化设置
|
|
||||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
||||||
javaTimeModule.addSerializer(LocalDateTime.class,new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss)));
|
|
||||||
javaTimeModule.addDeserializer(LocalDateTime.class,new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss)));
|
|
||||||
|
|
||||||
javaTimeModule.addSerializer(LocalDate.class,new LocalDateSerializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd)));
|
|
||||||
javaTimeModule.addDeserializer(LocalDate.class,new LocalDateDeserializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd)));
|
|
||||||
|
|
||||||
javaTimeModule.addSerializer(LocalTime.class,new LocalTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.HH_mm_ss)));
|
|
||||||
javaTimeModule.addDeserializer(LocalTime.class,new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.HH_mm_ss)));
|
|
||||||
|
|
||||||
objectMapper.registerModule(simpleModule).registerModule(javaTimeModule).registerModule(new ParameterNamesModule());
|
|
||||||
|
|
||||||
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
|
|
||||||
|
|
||||||
//放到第一个
|
|
||||||
converters.add(0,jackson2HttpMessageConverter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson.deserializer;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.ruoyi.plus.config.converter.StringToDateUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Jackson Date序列化器
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class JacksonDateDeserializer extends JsonDeserializer<Date> {
|
|
||||||
@Override
|
|
||||||
public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
|
||||||
String date = jp.getText();
|
|
||||||
return StringToDateUtil.convert(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson.deserializer;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.ruoyi.plus.config.converter.StringToDoubleUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class JacksonDoubleDeserializer extends JsonDeserializer<Double> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Double deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
|
||||||
String string = jsonParser.getText();
|
|
||||||
return StringToDoubleUtil.convert(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson.deserializer;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.ruoyi.plus.common.constant.DatePattern;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Jackson LocaDateTime反序列化器
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class JacksonLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
|
|
||||||
String string = jp.getText();
|
|
||||||
if (StringUtils.isBlank(string)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return LocalDateTime.parse(string, DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson.serializer;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
||||||
import com.ruoyi.plus.util.DateUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Jackson Date反序列化器
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class JacksonDateSerializer extends JsonSerializer<Date> {
|
|
||||||
@Override
|
|
||||||
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
|
||||||
if (date != null){
|
|
||||||
String dateString = DateUtil.getYYYYMMDDHHMMSS(date);
|
|
||||||
jsonGenerator.writeString(dateString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson.serializer;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.ruoyi.plus.config.converter.StringToIntegerUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
public class JacksonIntegerDeserializer extends JsonDeserializer<Integer> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
|
||||||
String string = jsonParser.getText();
|
|
||||||
return StringToIntegerUtil.convert(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config.json.jackson.serializer;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
||||||
import com.ruoyi.plus.common.constant.DatePattern;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Jackson LocalDateTime 自定义序列化器
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018/11/8
|
|
||||||
*/
|
|
||||||
public class JacksonLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serialize(LocalDateTime localDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
|
||||||
if (localDateTime != null){
|
|
||||||
String string = localDateTime.format(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss));
|
|
||||||
jsonGenerator.writeString(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
* 公共配置
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.config;
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.ruoyi.plus.core;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.aop.LogAop;
|
|
||||||
import com.ruoyi.plus.common.web.interceptor.*;
|
|
||||||
import com.ruoyi.plus.resource.web.interceptor.DownloadInterceptor;
|
|
||||||
import com.ruoyi.plus.resource.web.interceptor.ResourceInterceptor;
|
|
||||||
import com.ruoyi.plus.resource.web.interceptor.UploadInterceptor;
|
|
||||||
import com.ruoyi.plus.security.interceptor.JwtInterceptor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* spring-boot-plus配置
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/4
|
|
||||||
* @since 1.2.0-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
@EnableConfigurationProperties({SpringBootPlusProperties.class})
|
|
||||||
public class SpringBootPlusConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置日志AOP
|
|
||||||
* @param springBootPlusProperties
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public LogAop logAop(SpringBootPlusProperties springBootPlusProperties){
|
|
||||||
LogAop logAop = new LogAop();
|
|
||||||
logAop.setRequestLogFormat(springBootPlusProperties.isRequestLogFormat());
|
|
||||||
logAop.setResponseLogFormat(springBootPlusProperties.isResponseLogFormat());
|
|
||||||
log.info("init LogAop success");
|
|
||||||
return logAop;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JWT TOKEN验证拦截器
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public JwtInterceptor jwtInterceptor(){
|
|
||||||
JwtInterceptor jwtInterceptor = new JwtInterceptor();
|
|
||||||
return jwtInterceptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限拦截器
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public PermissionInterceptor permissionInterceptor(){
|
|
||||||
PermissionInterceptor permissionInterceptor = new PermissionInterceptor();
|
|
||||||
return permissionInterceptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TOKEN超时拦截器
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public TokenTimeoutInterceptor tokenTimeoutInterceptor(){
|
|
||||||
TokenTimeoutInterceptor tokenTimeoutInterceptor = new TokenTimeoutInterceptor();
|
|
||||||
return tokenTimeoutInterceptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传拦截器
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public UploadInterceptor uploadInterceptor(){
|
|
||||||
UploadInterceptor uploadInterceptor = new UploadInterceptor();
|
|
||||||
return uploadInterceptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源拦截器
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public ResourceInterceptor resourceInterceptor(){
|
|
||||||
ResourceInterceptor resourceInterceptor = new ResourceInterceptor();
|
|
||||||
return resourceInterceptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载拦截器
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public DownloadInterceptor downloadInterceptor(){
|
|
||||||
DownloadInterceptor downloadInterceptor = new DownloadInterceptor();
|
|
||||||
return downloadInterceptor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.core;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author liujixiang
|
|
||||||
* @date 2019/8/5
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class SpringBootPlusInterceptorConfig implements Serializable {
|
|
||||||
private static final long serialVersionUID = -2738042100246082469L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JWT拦截器排除路径
|
|
||||||
*/
|
|
||||||
private InterceptorConfig jwtConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TOKEN超时拦截器排除路径
|
|
||||||
*/
|
|
||||||
private InterceptorConfig tokenTimeoutConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限拦截器排除路径
|
|
||||||
*/
|
|
||||||
private InterceptorConfig permissionConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源拦截器
|
|
||||||
*/
|
|
||||||
private InterceptorConfig resourceConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传拦截器
|
|
||||||
*/
|
|
||||||
private InterceptorConfig uploadConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载拦截器
|
|
||||||
*/
|
|
||||||
private InterceptorConfig downloadConfig;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class InterceptorConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否启用
|
|
||||||
*/
|
|
||||||
private boolean enabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排除路径
|
|
||||||
*/
|
|
||||||
private String[] excludePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 包含的路径
|
|
||||||
*/
|
|
||||||
private String[] includePath;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.core;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* spring-boot-plus属性配置信息
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-08-04
|
|
||||||
* @since 1.2.0-RELEASE
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@ConfigurationProperties(prefix = "spring-boot-plus")
|
|
||||||
public class SpringBootPlusProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否启用ansi控制台输出有颜色的字体,local环境建议开启,服务器环境设置为false
|
|
||||||
*/
|
|
||||||
private boolean enableAnsi;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求日志在控制台是否格式化输出,local环境建议开启,服务器环境设置为false
|
|
||||||
*/
|
|
||||||
private boolean requestLogFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 响应日志在控制台是否格式化输出,local环境建议开启,服务器环境设置为false
|
|
||||||
*/
|
|
||||||
private boolean responseLogFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录token失效时间,单位分钟,默认60分钟失效
|
|
||||||
*/
|
|
||||||
private Integer tokenValidTime = 60;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拦截器配置
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private SpringBootPlusInterceptorConfig interceptorConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传目录
|
|
||||||
*/
|
|
||||||
private String uploadPath;
|
|
||||||
/**
|
|
||||||
* 资源访问路径,前端访问
|
|
||||||
*/
|
|
||||||
private String resourceAccessPath;
|
|
||||||
/**
|
|
||||||
* 资源访问路径,后段配置,资源映射/拦截器使用
|
|
||||||
*/
|
|
||||||
private String resourceAccessPatterns;
|
|
||||||
/**
|
|
||||||
* 资源访问全路径
|
|
||||||
*/
|
|
||||||
private String resourceAccessUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 允许上传的文件后缀集合
|
|
||||||
*/
|
|
||||||
private List<String> allowUploadFileExtensions;
|
|
||||||
/**
|
|
||||||
* 允许下载的文件后缀集合
|
|
||||||
*/
|
|
||||||
private List<String> allowDownloadFileExtensions;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.core;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.ruoyi.plus.common.web.interceptor.PermissionInterceptor;
|
|
||||||
import com.ruoyi.plus.common.web.interceptor.TokenTimeoutInterceptor;
|
|
||||||
import com.ruoyi.plus.resource.web.interceptor.DownloadInterceptor;
|
|
||||||
import com.ruoyi.plus.resource.web.interceptor.ResourceInterceptor;
|
|
||||||
import com.ruoyi.plus.resource.web.interceptor.UploadInterceptor;
|
|
||||||
import com.ruoyi.plus.security.interceptor.JwtInterceptor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
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 javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* WebMvc配置
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2018-11-08
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@Slf4j
|
|
||||||
public class SpringBootPlusWebMvcConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JwtInterceptor jwtInterceptor;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PermissionInterceptor permissionInterceptor;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TokenTimeoutInterceptor tokenTimeoutInterceptor;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ResourceInterceptor resourceInterceptor;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UploadInterceptor uploadInterceptor;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DownloadInterceptor downloadInterceptor;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init(){
|
|
||||||
// 打印SpringBootPlusProperties配置信息
|
|
||||||
log.info("SpringBootPlusProperties:{}", JSON.toJSONString(springBootPlusProperties));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
|
||||||
SpringBootPlusInterceptorConfig interceptorConfig = springBootPlusProperties.getInterceptorConfig();
|
|
||||||
|
|
||||||
// 上传拦截器
|
|
||||||
registry.addInterceptor(uploadInterceptor)
|
|
||||||
.addPathPatterns(interceptorConfig.getUploadConfig().getIncludePath());
|
|
||||||
|
|
||||||
// 资源拦截器注册
|
|
||||||
registry.addInterceptor(resourceInterceptor)
|
|
||||||
.addPathPatterns(interceptorConfig.getResourceConfig().getIncludePath());
|
|
||||||
|
|
||||||
// 下载拦截器注册
|
|
||||||
registry.addInterceptor(downloadInterceptor)
|
|
||||||
.addPathPatterns(interceptorConfig.getDownloadConfig().getIncludePath());
|
|
||||||
|
|
||||||
if (interceptorConfig.getJwtConfig().isEnabled()){
|
|
||||||
// JWT拦截器注册
|
|
||||||
registry.addInterceptor(jwtInterceptor)
|
|
||||||
.addPathPatterns(interceptorConfig.getJwtConfig().getIncludePath())
|
|
||||||
.excludePathPatterns(interceptorConfig.getJwtConfig().getExcludePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (interceptorConfig.getTokenTimeoutConfig().isEnabled()){
|
|
||||||
// TOKEN超时拦截器注册
|
|
||||||
registry.addInterceptor(tokenTimeoutInterceptor)
|
|
||||||
.addPathPatterns(interceptorConfig.getTokenTimeoutConfig().getIncludePath())
|
|
||||||
.excludePathPatterns(interceptorConfig.getTokenTimeoutConfig().getExcludePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (interceptorConfig.getPermissionConfig().isEnabled()){
|
|
||||||
// 权限拦截器注册
|
|
||||||
registry.addInterceptor(permissionInterceptor)
|
|
||||||
.addPathPatterns(interceptorConfig.getPermissionConfig().getIncludePath())
|
|
||||||
.excludePathPatterns(interceptorConfig.getPermissionConfig().getExcludePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
// 设置项目静态资源访问
|
|
||||||
registry.addResourceHandler("/static/**")
|
|
||||||
.addResourceLocations("classpath:/static/");
|
|
||||||
registry.addResourceHandler("/templates/**")
|
|
||||||
.addResourceLocations("classpath:/templates/");
|
|
||||||
// 设置swagger静态资源访问
|
|
||||||
registry.addResourceHandler("swagger-ui.html")
|
|
||||||
.addResourceLocations("classpath:/META-INF/resources/");
|
|
||||||
registry.addResourceHandler("/webjars/**")
|
|
||||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
||||||
// 设置上传文件访问路径
|
|
||||||
registry.addResourceHandler(springBootPlusProperties.getResourceAccessPatterns())
|
|
||||||
.addResourceLocations("file:" + springBootPlusProperties.getUploadPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
package com.ruoyi.plus.resource;
|
|
||||||
-71
@@ -1,71 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.resource.web.controller;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.core.SpringBootPlusProperties;
|
|
||||||
import com.ruoyi.plus.util.DownloadUtil;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载控制器
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/20
|
|
||||||
* @since 1.2.1-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/download")
|
|
||||||
public class DownloadController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载文件
|
|
||||||
*/
|
|
||||||
@RequestMapping("/{downloadFileName}")
|
|
||||||
@ApiOperation(value = "下载文件",notes = "下载文件",response = ApiResult.class)
|
|
||||||
public void download(@PathVariable(required = true) String downloadFileName, HttpServletResponse response) throws Exception{
|
|
||||||
// 下载目录,既是上传目录
|
|
||||||
String downloadDir = springBootPlusProperties.getUploadPath();
|
|
||||||
// 允许下载的文件后缀
|
|
||||||
List<String> allowFileExtensions = springBootPlusProperties.getAllowDownloadFileExtensions();
|
|
||||||
// 文件下载,使用默认下载处理器
|
|
||||||
// DownloadUtil.download(downloadDir,downloadFileName,allowFileExtensions,response);
|
|
||||||
// 文件下载,使用自定义下载处理器
|
|
||||||
DownloadUtil.download(downloadDir,downloadFileName,allowFileExtensions,response, (dir, fileName, file, fileExtension, contentType, length) -> {
|
|
||||||
// 下载自定义处理,返回true:执行下载,false:取消下载
|
|
||||||
log.info("dir = " + dir);
|
|
||||||
log.info("fileName = " + fileName);
|
|
||||||
log.info("file = " + file);
|
|
||||||
log.info("fileExtension = " + fileExtension);
|
|
||||||
log.info("contentType = " + contentType);
|
|
||||||
log.info("length = " + length);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.resource.web.controller;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.core.SpringBootPlusProperties;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片等文件资源访问控制器
|
|
||||||
* /api/resource 访问路径 用于区分 文件访问虚拟目录映射 /resource
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/20
|
|
||||||
* @since 1.2.1-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/api/resource")
|
|
||||||
public class ResourceController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 访问图片
|
|
||||||
*/
|
|
||||||
@GetMapping("/image/{imageFileName}")
|
|
||||||
@ApiOperation(value = "访问图片",notes = "访问图片",response = ApiResult.class)
|
|
||||||
public void getImage(@PathVariable(required = true) String imageFileName, HttpServletResponse response) throws Exception{
|
|
||||||
log.info("imageFileName:{}",imageFileName);
|
|
||||||
// 重定向到图片访问路径
|
|
||||||
response.sendRedirect(springBootPlusProperties.getResourceAccessPath() + imageFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
package com.ruoyi.plus.resource.web.controller;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.common.web.param.IdParam;
|
|
||||||
import com.ruoyi.plus.core.SpringBootPlusProperties;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysLogQueryVo;
|
|
||||||
import com.ruoyi.plus.util.UploadUtil;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传控制器
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/20
|
|
||||||
* @since 1.2.1-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/upload")
|
|
||||||
public class UploadController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
@GetMapping("/hello")
|
|
||||||
public ApiResult hello(){
|
|
||||||
log.info("hello...");
|
|
||||||
return ApiResult.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取系统日志
|
|
||||||
*/
|
|
||||||
@PostMapping("/info")
|
|
||||||
@ApiOperation(value = "获取SysLog对象详情",notes = "查看系统日志",response = SysLogQueryVo.class)
|
|
||||||
public ApiResult<SysLogQueryVo> getSysUser(@Valid @RequestBody IdParam idParam) throws Exception{
|
|
||||||
log.info("idParam = " + idParam);
|
|
||||||
return ApiResult.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传单个文件
|
|
||||||
*/
|
|
||||||
@PostMapping("/")
|
|
||||||
@ApiOperation(value = "上传单个文件",notes = "上传单个文件",response = ApiResult.class)
|
|
||||||
public ApiResult<Boolean> upload(@RequestParam("img") MultipartFile multipartFile) throws Exception{
|
|
||||||
log.info("multipartFile = " + multipartFile);
|
|
||||||
log.info("ContentType = " + multipartFile.getContentType());
|
|
||||||
log.info("OriginalFilename = " + multipartFile.getOriginalFilename());
|
|
||||||
log.info("Name = " + multipartFile.getName());
|
|
||||||
log.info("Size = " + multipartFile.getSize());
|
|
||||||
|
|
||||||
// 上传文件,返回保存的文件名称
|
|
||||||
String saveFileName = UploadUtil.upload(springBootPlusProperties.getUploadPath(), multipartFile, originalFilename -> {
|
|
||||||
// 文件后缀
|
|
||||||
String fileExtension= FilenameUtils.getExtension(originalFilename);
|
|
||||||
// 这里可自定义文件名称,比如按照业务类型/文件格式/日期
|
|
||||||
String dateString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssS"));
|
|
||||||
String fileName = dateString + "." +fileExtension;
|
|
||||||
return fileName;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 上传成功之后,返回访问路径,请根据实际情况设置
|
|
||||||
|
|
||||||
String fileAccessPath = springBootPlusProperties.getResourceAccessUrl() + saveFileName;
|
|
||||||
log.info("fileAccessPath:{}",fileAccessPath);
|
|
||||||
|
|
||||||
return ApiResult.ok(fileAccessPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-78
@@ -1,78 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.resource.web.interceptor;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.core.SpringBootPlusProperties;
|
|
||||||
import com.ruoyi.plus.util.HttpServletResponseUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载拦截器
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/21
|
|
||||||
* @since 1.2.2-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class DownloadInterceptor extends HandlerInterceptorAdapter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
// 如果访问的不是控制器,则跳出,继续执行下一个拦截器
|
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 访问路径
|
|
||||||
String url = request.getRequestURI();
|
|
||||||
// 访问全路径
|
|
||||||
String fullUrl = request.getRequestURL().toString();
|
|
||||||
|
|
||||||
// 未启用资源访问时,返回错误消息
|
|
||||||
if (!springBootPlusProperties.getInterceptorConfig().getDownloadConfig().isEnabled()){
|
|
||||||
log.error("下载已关闭,非法下载:{}",fullUrl);
|
|
||||||
HttpServletResponseUtil.printJSON(response, ApiResult.fail("非法下载"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载拦截器,业务处理代码
|
|
||||||
log.info("DownloadInterceptor...");
|
|
||||||
|
|
||||||
// 访问token,如果需要,可以设置参数,进行鉴权
|
|
||||||
String token = request.getParameter("token");
|
|
||||||
|
|
||||||
log.info("url:{}",url);
|
|
||||||
log.info("fullUrl:{}",fullUrl);
|
|
||||||
log.info("token:{}",token);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
||||||
// 记录实际下载日志...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-78
@@ -1,78 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.resource.web.interceptor;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.core.SpringBootPlusProperties;
|
|
||||||
import com.ruoyi.plus.util.HttpServletResponseUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源拦截器
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/20
|
|
||||||
* @since 1.2.1-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class ResourceInterceptor extends HandlerInterceptorAdapter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
// 如果访问的控制器,则跳出,继续执行下一个拦截器
|
|
||||||
if (handler instanceof HandlerMethod) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 访问路径
|
|
||||||
String url = request.getRequestURI();
|
|
||||||
// 访问全路径
|
|
||||||
String fullUrl = request.getRequestURL().toString();
|
|
||||||
|
|
||||||
// 未启用资源访问时,返回错误消息
|
|
||||||
if (!springBootPlusProperties.getInterceptorConfig().getResourceConfig().isEnabled()){
|
|
||||||
log.error("资源访问已关闭,非法访问:{}",fullUrl);
|
|
||||||
HttpServletResponseUtil.printJSON(response,ApiResult.fail("非法访问"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 资源拦截器,业务处理代码
|
|
||||||
log.info("ResourceInterceptor...");
|
|
||||||
|
|
||||||
// 访问token,如果需要,可以设置参数,进行鉴权
|
|
||||||
String token = request.getParameter("token");
|
|
||||||
|
|
||||||
log.info("url:{}",url);
|
|
||||||
log.info("fullUrl:{}",fullUrl);
|
|
||||||
log.info("token:{}",token);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
||||||
// 记录实际访问图片日志...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.resource.web.interceptor;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.core.SpringBootPlusProperties;
|
|
||||||
import com.ruoyi.plus.util.HttpServletResponseUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传拦截器
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019/8/22
|
|
||||||
* @since 1.2.2-RELEASE
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class UploadInterceptor extends HandlerInterceptorAdapter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SpringBootPlusProperties springBootPlusProperties;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
// 如果访问的不是控制器,则跳出,继续执行下一个拦截器
|
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 访问路径
|
|
||||||
String url = request.getRequestURI();
|
|
||||||
// 访问全路径
|
|
||||||
String fullUrl = request.getRequestURL().toString();
|
|
||||||
if (!springBootPlusProperties.getInterceptorConfig().getUploadConfig().isEnabled()){
|
|
||||||
log.error("上传功能已关闭,非法上传:{}",fullUrl);
|
|
||||||
HttpServletResponseUtil.printJSON(response, ApiResult.fail("非法上传"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传拦截器,业务处理代码
|
|
||||||
log.info("UploadInterceptor...");
|
|
||||||
// 访问token,如果需要,可以设置参数,进行鉴权
|
|
||||||
String token = request.getParameter("token");
|
|
||||||
|
|
||||||
log.info("url:{}",url);
|
|
||||||
log.info("fullUrl:{}",fullUrl);
|
|
||||||
log.info("token:{}",token);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
||||||
// 记录实际上传日志...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Jwt配置属性
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-22
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "spring-boot-plus.jwt")
|
|
||||||
public class JwtProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 密码
|
|
||||||
*/
|
|
||||||
// @Value("spring-boot-plus.jwt.secret:spring-boot-plus")
|
|
||||||
private String secret;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 签发人
|
|
||||||
*/
|
|
||||||
// @Value("spring-boot-plus.jwt.issuer:spring-boot-plus")
|
|
||||||
private String issuer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主题
|
|
||||||
*/
|
|
||||||
// @Value("spring-boot-plus.jwt.subject:spring-boot-plus-jwt")
|
|
||||||
private String subject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 签发的目标
|
|
||||||
*/
|
|
||||||
// @Value("spring-boot-plus.jwt.audience:web")
|
|
||||||
private String audience;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* token失效时间,默认30分钟
|
|
||||||
*/
|
|
||||||
// @Value("spring-boot-plus.jwt.default.expire.minutes:30")
|
|
||||||
private Integer expireMinutes;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.controller;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiCode;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.common.web.controller.BaseController;
|
|
||||||
import com.ruoyi.plus.security.param.LoginParam;
|
|
||||||
import com.ruoyi.plus.security.service.LoginService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-15
|
|
||||||
**/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/login")
|
|
||||||
public class LoginController extends BaseController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LoginService loginService;
|
|
||||||
|
|
||||||
@PostMapping("")
|
|
||||||
public ApiResult login(@Validated @RequestBody LoginParam loginParam) throws Exception{
|
|
||||||
return loginService.login(loginParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/non")
|
|
||||||
public ApiResult nonLogin() throws Exception{
|
|
||||||
log.info("nonLogin....");
|
|
||||||
return ApiResult.fail(ApiCode.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.interceptor;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiCode;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.security.service.LoginService;
|
|
||||||
import com.ruoyi.plus.security.util.JwtUtil;
|
|
||||||
import com.ruoyi.plus.util.HttpServletResponseUtil;
|
|
||||||
import com.ruoyi.plus.util.LoginUtil;
|
|
||||||
import io.jsonwebtoken.Claims;
|
|
||||||
import io.jsonwebtoken.Jws;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 判断jwt token是否有效
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-22
|
|
||||||
**/
|
|
||||||
@Slf4j
|
|
||||||
public class JwtInterceptor extends HandlerInterceptorAdapter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LoginService loginService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
// 如果访问的不是控制器,则跳出,继续执行下一个拦截器
|
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取token
|
|
||||||
String token = LoginUtil.getToken(request);
|
|
||||||
|
|
||||||
// 如果token为空,则s输出提示并返回
|
|
||||||
if (StringUtils.isBlank(token)){
|
|
||||||
ApiResult apiResult = ApiResult.result(ApiCode.UNAUTHORIZED);
|
|
||||||
log.error("token is empty");
|
|
||||||
HttpServletResponseUtil.printJSON(response,apiResult);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("token:{}",token);
|
|
||||||
|
|
||||||
// 验证token是否有效
|
|
||||||
Jws<Claims> jws = JwtUtil.verify(token);
|
|
||||||
log.debug("token verify:{}",jws);
|
|
||||||
if (jws == null){
|
|
||||||
ApiResult apiResult = ApiResult.result(ApiCode.UNAUTHORIZED);
|
|
||||||
log.error("token verify failed");
|
|
||||||
HttpServletResponseUtil.printJSON(response,apiResult);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 刷新token
|
|
||||||
loginService.refreshToken(response, jws);
|
|
||||||
|
|
||||||
// 存储jws对象到request对象中
|
|
||||||
request.setAttribute("jws",jws);
|
|
||||||
|
|
||||||
log.debug("token verify success");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.param;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 登录参数
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-15
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
@ApiModel("登录参数")
|
|
||||||
public class LoginParam {
|
|
||||||
|
|
||||||
@NotBlank(message = "请输入账号")
|
|
||||||
@ApiModelProperty("账号")
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
@NotBlank(message = "请输入密码")
|
|
||||||
@ApiModelProperty("密码")
|
|
||||||
private String pwd;
|
|
||||||
|
|
||||||
@ApiModelProperty("验证码")
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.service;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.security.param.LoginParam;
|
|
||||||
import io.jsonwebtoken.Claims;
|
|
||||||
import io.jsonwebtoken.Jws;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 登录服务接口
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-23
|
|
||||||
**/
|
|
||||||
public interface LoginService {
|
|
||||||
|
|
||||||
ApiResult login(LoginParam loginParam);
|
|
||||||
|
|
||||||
void refreshToken(HttpServletResponse response, Jws<Claims> jws);
|
|
||||||
|
|
||||||
}
|
|
||||||
-186
@@ -1,186 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.service.impl;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.ruoyi.plus.common.api.ApiResult;
|
|
||||||
import com.ruoyi.plus.common.constant.CommonConstant;
|
|
||||||
import com.ruoyi.plus.common.constant.CommonRedisKey;
|
|
||||||
import com.ruoyi.plus.security.param.LoginParam;
|
|
||||||
import com.ruoyi.plus.security.service.LoginService;
|
|
||||||
import com.ruoyi.plus.security.util.JwtUtil;
|
|
||||||
import com.ruoyi.plus.security.vo.ClientInfo;
|
|
||||||
import com.ruoyi.plus.security.vo.JwtTokenRedisVo;
|
|
||||||
import com.ruoyi.plus.security.vo.LoginSysUserRedisVo;
|
|
||||||
import com.ruoyi.plus.security.vo.LoginSysUserVo;
|
|
||||||
import com.ruoyi.plus.util.ClientInfoUtil;
|
|
||||||
import com.ruoyi.plus.util.HttpServletRequestUtil;
|
|
||||||
import com.ruoyi.plus.util.MapUtil;
|
|
||||||
import io.jsonwebtoken.Claims;
|
|
||||||
import io.jsonwebtoken.Jws;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 登录服务实现类
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-23
|
|
||||||
**/
|
|
||||||
@Api
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class LoginServiceImpl implements LoginService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate redisTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApiResult login(LoginParam loginParam) {
|
|
||||||
log.info("loginParam = " + loginParam);
|
|
||||||
|
|
||||||
// 数据库校验账号密码
|
|
||||||
|
|
||||||
Long userId = 1L;
|
|
||||||
String userName = "admin";
|
|
||||||
|
|
||||||
LoginSysUserVo loginSysUserVo = new LoginSysUserVo();
|
|
||||||
loginSysUserVo.setId(userId);
|
|
||||||
loginSysUserVo.setUserName(userName);
|
|
||||||
|
|
||||||
// token过期时间
|
|
||||||
Date expireDate = DateUtils.addMinutes(new Date(), 30);
|
|
||||||
// 创建token
|
|
||||||
String token = JwtUtil.create(expireDate,null,null);
|
|
||||||
// token md5,方便使用
|
|
||||||
String tokenMd5 = DigestUtils.md5Hex(token);
|
|
||||||
// login redis处理
|
|
||||||
loginRedis(userId, loginSysUserVo, expireDate, token, tokenMd5);
|
|
||||||
// 响应数据
|
|
||||||
Map<String,Object> map = MapUtil.builder()
|
|
||||||
.put("token",token)
|
|
||||||
.put("loginSysUser",loginSysUserVo)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return ApiResult.ok(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* jwt生成的token携带用户id和账号,uuid唯一标识,返回token
|
|
||||||
* redis存储当前登录对象的详细信息 hash
|
|
||||||
* key: login.sys.user.token的md5值
|
|
||||||
* value : LoginSysUserRedisVo
|
|
||||||
* redis hash
|
|
||||||
* key: login.sys.user.用户ID
|
|
||||||
* value: token md5值
|
|
||||||
* @param userId
|
|
||||||
* @param loginSysUserVo
|
|
||||||
* @param expireDate
|
|
||||||
* @param token
|
|
||||||
* @param tokenMd5
|
|
||||||
*/
|
|
||||||
private void loginRedis(Long userId, LoginSysUserVo loginSysUserVo, Date expireDate, String token, String tokenMd5) {
|
|
||||||
String loginTokenRedisKey = CommonRedisKey.LOGIN_TOKEN;
|
|
||||||
|
|
||||||
// 获取用户客户端信息
|
|
||||||
HttpServletRequest request = HttpServletRequestUtil.getRequest();
|
|
||||||
String userAgent = request.getHeader("User-Agent");
|
|
||||||
ClientInfo clientInfo = ClientInfoUtil.get(userAgent);
|
|
||||||
log.info("clientInfo = " + JSON.toJSONString(clientInfo,true));
|
|
||||||
|
|
||||||
// jwt token对象
|
|
||||||
JwtTokenRedisVo jwtTokenRedisVo = new JwtTokenRedisVo();
|
|
||||||
jwtTokenRedisVo.setToken(token);
|
|
||||||
jwtTokenRedisVo.setTokenMd5(tokenMd5);
|
|
||||||
jwtTokenRedisVo.setCreateDate(new Date());
|
|
||||||
jwtTokenRedisVo.setExpiredDate(expireDate);
|
|
||||||
|
|
||||||
// loginUser redis缓存信息
|
|
||||||
LoginSysUserRedisVo loginSysUserRedisVo = new LoginSysUserRedisVo();
|
|
||||||
loginSysUserRedisVo.setClientInfo(clientInfo); // 设置用户客户端信息
|
|
||||||
loginSysUserRedisVo.setLoginSysUserVo(loginSysUserVo); // 设置系统登录用户对象
|
|
||||||
loginSysUserRedisVo.setJwtTokenRedisVo(jwtTokenRedisVo); // 设置系统登录用户token对象
|
|
||||||
|
|
||||||
// token hash cache
|
|
||||||
redisTemplate.opsForHash().put(loginTokenRedisKey,tokenMd5,loginSysUserRedisVo);
|
|
||||||
|
|
||||||
// user hash cache
|
|
||||||
String loginUserRedisKey = String.format(CommonRedisKey.LOGIN_SYS_USER,userId);
|
|
||||||
|
|
||||||
// 支持一个账号多次登录
|
|
||||||
redisTemplate.opsForHash().put(loginUserRedisKey,tokenMd5,jwtTokenRedisVo);
|
|
||||||
|
|
||||||
// 单个登录,始终以最后一个有效
|
|
||||||
// String oneLoginUserRedisKey = "login:sys:user";
|
|
||||||
// redisTemplate.opsForHash().put(oneLoginUserRedisKey,String.valueOf(userId),jwtTokenRedisVo);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新token
|
|
||||||
* @param response
|
|
||||||
* @param jws
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void refreshToken(HttpServletResponse response, Jws<Claims> jws) {
|
|
||||||
Date expiredDate = jws.getBody().getExpiration();
|
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
String string = dateFormat.format(expiredDate);
|
|
||||||
log.info("expiredDate = " + string);
|
|
||||||
|
|
||||||
// 如果token还有1分钟要过期,则重新生成token,并响应到response头中
|
|
||||||
Date beforeExpiredDate = DateUtils.addMinutes(expiredDate,-1);
|
|
||||||
long beforeExpiredTime = beforeExpiredDate.getTime();
|
|
||||||
|
|
||||||
Date currentDate = new Date(System.currentTimeMillis());
|
|
||||||
long currentTime = currentDate.getTime();
|
|
||||||
|
|
||||||
log.info("beforeExpiredTime = " + beforeExpiredTime);
|
|
||||||
log.info("currentTime = " + currentTime);
|
|
||||||
|
|
||||||
log.info("beforeExpiredDate = " + dateFormat.format(beforeExpiredDate));
|
|
||||||
log.info("currentDate = " + dateFormat.format(currentDate));
|
|
||||||
|
|
||||||
log.info((beforeExpiredTime <= currentTime)+"");
|
|
||||||
log.info((beforeExpiredTime - currentTime)+"");
|
|
||||||
|
|
||||||
|
|
||||||
if (beforeExpiredTime <= currentTime){
|
|
||||||
log.info("====>>>>>");
|
|
||||||
response.setHeader(CommonConstant.REFRESH_TOKEN,"123456");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.util;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.ruoyi.plus.security.config.JwtProperties;
|
|
||||||
import com.ruoyi.plus.util.UUIDUtil;
|
|
||||||
import io.jsonwebtoken.*;
|
|
||||||
import io.jsonwebtoken.impl.DefaultJwsHeader;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.MapUtils;
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* jwt工具类
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-15
|
|
||||||
**/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class JwtUtil {
|
|
||||||
|
|
||||||
private static final String UTF8 = "UTF-8";
|
|
||||||
|
|
||||||
private static JwtProperties jwtProperties;
|
|
||||||
|
|
||||||
public JwtUtil(JwtProperties jwtProperties){
|
|
||||||
JwtUtil.jwtProperties = jwtProperties;
|
|
||||||
log.info(JSON.toJSONString(JwtUtil.jwtProperties));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String create() {
|
|
||||||
return create(null,null,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成jwt token
|
|
||||||
* @param expireDate token过期时间
|
|
||||||
* @param headerClaims header数据
|
|
||||||
* @param payloadClaims body数据
|
|
||||||
* @return jwt token
|
|
||||||
*/
|
|
||||||
public static String create(Date expireDate,Map<String,Object> headerClaims, Map<String, Object> payloadClaims) {
|
|
||||||
try {
|
|
||||||
// 默认过期时间为1小时
|
|
||||||
if (expireDate == null) {
|
|
||||||
expireDate = DateUtils.addMinutes(new Date(), jwtProperties.getExpireMinutes());
|
|
||||||
}
|
|
||||||
log.debug("expireDate:{}", expireDate);
|
|
||||||
|
|
||||||
if (MapUtils.isEmpty(headerClaims)) {
|
|
||||||
headerClaims = new HashMap<>();
|
|
||||||
}
|
|
||||||
log.debug("headerClaims:{}", headerClaims);
|
|
||||||
|
|
||||||
if (MapUtils.isEmpty(payloadClaims)) {
|
|
||||||
payloadClaims = new HashMap<>();
|
|
||||||
}
|
|
||||||
log.debug("payloadClaims:{}", payloadClaims);
|
|
||||||
|
|
||||||
Header header = new DefaultJwsHeader();
|
|
||||||
header.setContentType(Header.CONTENT_TYPE);
|
|
||||||
header.setType(Header.JWT_TYPE);
|
|
||||||
headerClaims.putAll(header);
|
|
||||||
|
|
||||||
// 构建token
|
|
||||||
String token = Jwts.builder()
|
|
||||||
.setHeader(headerClaims)
|
|
||||||
.setClaims(payloadClaims)
|
|
||||||
.setId(UUIDUtil.getUUID()) // jwt唯一id
|
|
||||||
.setIssuer(jwtProperties.getIssuer()) // 签发人
|
|
||||||
.setSubject(jwtProperties.getSubject()) // 主题
|
|
||||||
.setAudience(jwtProperties.getAudience()) // 签发的目标
|
|
||||||
.setIssuedAt(new Date()) // 签名时间
|
|
||||||
.setExpiration(expireDate) // token过期时间
|
|
||||||
// 签名
|
|
||||||
.signWith(SignatureAlgorithm.HS256, jwtProperties.getSecret().getBytes(UTF8))
|
|
||||||
.compact();
|
|
||||||
return token;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("create token exception",e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证jwt token
|
|
||||||
* @param token jwt token
|
|
||||||
* @return Jws对象
|
|
||||||
*/
|
|
||||||
public static Jws<Claims> verify(String token) {
|
|
||||||
try {
|
|
||||||
Jws<Claims> jws = Jwts.parser()
|
|
||||||
.setSigningKey(jwtProperties.getSecret().getBytes(UTF8))
|
|
||||||
.parseClaimsJws(token);
|
|
||||||
return jws;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("verify token exception",e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 用户客户端信息对象
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-23
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
public class ClientInfo implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -5549531244606897514L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ip
|
|
||||||
*/
|
|
||||||
private String ip;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ip对应的地址
|
|
||||||
*/
|
|
||||||
private String addree;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 浏览器名称
|
|
||||||
*/
|
|
||||||
private String browserName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 浏览器版本
|
|
||||||
*/
|
|
||||||
private String browserversion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 浏览器引擎名称
|
|
||||||
*/
|
|
||||||
private String engineName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 浏览器引擎版本
|
|
||||||
*/
|
|
||||||
private String engineVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统名称
|
|
||||||
*/
|
|
||||||
private String osName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 平台名称
|
|
||||||
*/
|
|
||||||
private String platformName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否是手机
|
|
||||||
*/
|
|
||||||
private boolean mobile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 移动端设备型号
|
|
||||||
*/
|
|
||||||
private String deviceName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 移动端设备型号
|
|
||||||
*/
|
|
||||||
private String deviceModel;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 设备信息
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-24
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
public class DeviceInfo implements Serializable {
|
|
||||||
private static final long serialVersionUID = -5912785220335057555L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备名称
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备型号
|
|
||||||
*/
|
|
||||||
private String model;
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-23
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
public class JwtTokenRedisVo implements Serializable {
|
|
||||||
private static final long serialVersionUID = 5631646796482815114L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录token
|
|
||||||
*/
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录token md5
|
|
||||||
*/
|
|
||||||
private String tokenMd5;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private Date createDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 过期时间
|
|
||||||
*/
|
|
||||||
private Date expiredDate;
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.vo;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 登录用户redis对象,后台使用
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-15
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
@ApiModel("系统用户登录值对象")
|
|
||||||
public class LoginSysUserRedisVo implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -4497185071769175695L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录对象vo
|
|
||||||
*/
|
|
||||||
private LoginSysUserVo loginSysUserVo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* jwt token对象
|
|
||||||
*/
|
|
||||||
private JwtTokenRedisVo jwtTokenRedisVo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 唯一标识
|
|
||||||
*/
|
|
||||||
private String uuid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录ip
|
|
||||||
*/
|
|
||||||
private ClientInfo clientInfo;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.ruoyi.plus.security.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 登录用户对象,响应给前端
|
|
||||||
* </p>
|
|
||||||
* @author geekidea
|
|
||||||
* @date 2019-05-15
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
public class LoginSysUserVo implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -1758338570596088158L;
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.ruoyi.plus.common.entity.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* IP地址
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@ApiModel(value="Ip对象", description="IP地址")
|
|
||||||
public class Ip extends BaseEntity {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ip开始地址")
|
|
||||||
private String ipStart;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ip结束地址")
|
|
||||||
private String ipEnd;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "区域")
|
|
||||||
private String area;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "运营商")
|
|
||||||
private String operator;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "主键")
|
|
||||||
@TableId(value = "id", type = IdType.ID_WORKER)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ip开始地址数字")
|
|
||||||
private Long ipStartNum;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ip结束地址数字")
|
|
||||||
private Long ipEndNum;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.ruoyi.plus.common.entity.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 系统日志
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@ApiModel(value="SysLog对象", description="系统日志")
|
|
||||||
public class SysLog extends BaseEntity {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "主键")
|
|
||||||
@TableId(value = "log_id", type = IdType.ID_WORKER)
|
|
||||||
private Long logId;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "类型")
|
|
||||||
private Boolean type;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "内容")
|
|
||||||
private String content;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建人ID")
|
|
||||||
private Long createId;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建时间")
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import java.util.Date;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.ruoyi.plus.common.entity.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* SystemUser
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-26
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@ApiModel(value="SysUser对象", description="SystemUser")
|
|
||||||
public class SysUser extends BaseEntity {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "id")
|
|
||||||
@TableId(value = "id", type = IdType.ID_WORKER)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "account")
|
|
||||||
private String account;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "password")
|
|
||||||
private String pwd;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "remark")
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "create time")
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "update time")
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.ruoyi.plus.system.entity.Ip;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* IP地址 Mapper 接口
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public interface IpMapper extends BaseMapper<Ip> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.ruoyi.plus.system.entity.SysLog;
|
|
||||||
import com.ruoyi.plus.system.web.param.SysLogQueryParam;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysLogQueryVo;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 系统日志 Mapper 接口
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public interface SysLogMapper extends BaseMapper<SysLog> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID获取查询对象
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
SysLogQueryVo getSysLogById(Serializable id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分页对象
|
|
||||||
* @param page
|
|
||||||
* @param sysLogQueryParam
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
IPage<SysLogQueryVo> getSysLogPageList(@Param("page") Page page, @Param("param") SysLogQueryParam sysLogQueryParam);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.ruoyi.plus.system.entity.SysUser;
|
|
||||||
import com.ruoyi.plus.system.web.param.SysUserQueryParam;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysUserQueryVo;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* SystemUser Mapper 接口
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-26
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID获取查询对象
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
SysUserQueryVo getSysUserById(Serializable id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分页对象
|
|
||||||
* @param page
|
|
||||||
* @param sysUserQueryParam
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
IPage<SysUserQueryVo> getSysUserPageList(@Param("page") Page page, @Param("param") SysUserQueryParam sysUserQueryParam);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.service;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.service.BaseService;
|
|
||||||
import com.ruoyi.plus.system.entity.Ip;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* IP地址 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
public interface IpService extends BaseService<Ip> {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.service;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.system.entity.SysLog;
|
|
||||||
import com.ruoyi.plus.common.service.BaseService;
|
|
||||||
import com.ruoyi.plus.system.web.param.SysLogQueryParam;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysLogQueryVo;
|
|
||||||
import com.ruoyi.plus.common.web.vo.Paging;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 系统日志 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
public interface SysLogService extends BaseService<SysLog> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID获取查询对象
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
SysLogQueryVo getSysLogById(Serializable id) throws Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分页对象
|
|
||||||
* @param sysLogQueryParam
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Paging<SysLogQueryVo> getSysLogPageList(SysLogQueryParam sysLogQueryParam) throws Exception;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.service;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.system.entity.SysUser;
|
|
||||||
import com.ruoyi.plus.common.service.BaseService;
|
|
||||||
import com.ruoyi.plus.system.web.param.SysUserQueryParam;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysUserQueryVo;
|
|
||||||
import com.ruoyi.plus.common.web.vo.Paging;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* SystemUser 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-26
|
|
||||||
*/
|
|
||||||
public interface SysUserService extends BaseService<SysUser> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID获取查询对象
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
SysUserQueryVo getSysUserById(Serializable id) throws Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分页对象
|
|
||||||
* @param sysUserQueryParam
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Paging<SysUserQueryVo> getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.service.impl;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.common.service.impl.BaseServiceImpl;
|
|
||||||
import com.ruoyi.plus.system.entity.Ip;
|
|
||||||
import com.ruoyi.plus.system.mapper.IpMapper;
|
|
||||||
import com.ruoyi.plus.system.service.IpService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* IP地址 服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Slf4j
|
|
||||||
public class IpServiceImpl extends BaseServiceImpl<IpMapper, Ip> implements IpService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IpMapper ipMapper;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.service.impl;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.system.entity.SysLog;
|
|
||||||
import com.ruoyi.plus.system.mapper.SysLogMapper;
|
|
||||||
import com.ruoyi.plus.system.service.SysLogService;
|
|
||||||
import com.ruoyi.plus.system.web.param.SysLogQueryParam;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysLogQueryVo;
|
|
||||||
import com.ruoyi.plus.common.service.impl.BaseServiceImpl;
|
|
||||||
import com.ruoyi.plus.common.web.vo.Paging;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 系统日志 服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-04
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public class SysLogServiceImpl extends BaseServiceImpl<SysLogMapper, SysLog> implements SysLogService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SysLogMapper sysLogMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SysLogQueryVo getSysLogById(Serializable id) throws Exception{
|
|
||||||
return sysLogMapper.getSysLogById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Paging<SysLogQueryVo> getSysLogPageList(SysLogQueryParam sysLogQueryParam) throws Exception{
|
|
||||||
Page page = setPageParam(sysLogQueryParam,OrderItem.desc("create_time"));
|
|
||||||
IPage<SysLogQueryVo> iPage = sysLogMapper.getSysLogPageList(page,sysLogQueryParam);
|
|
||||||
return new Paging(iPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package com.ruoyi.plus.system.service.impl;
|
|
||||||
|
|
||||||
import com.ruoyi.plus.system.entity.SysUser;
|
|
||||||
import com.ruoyi.plus.system.mapper.SysUserMapper;
|
|
||||||
import com.ruoyi.plus.system.service.SysUserService;
|
|
||||||
import com.ruoyi.plus.system.web.param.SysUserQueryParam;
|
|
||||||
import com.ruoyi.plus.system.web.vo.SysUserQueryVo;
|
|
||||||
import com.ruoyi.plus.common.service.impl.BaseServiceImpl;
|
|
||||||
import com.ruoyi.plus.common.web.vo.Paging;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* SystemUser 服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author geekidea
|
|
||||||
* @since 2019-08-26
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SysUserMapper sysUserMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SysUserQueryVo getSysUserById(Serializable id) throws Exception{
|
|
||||||
return sysUserMapper.getSysUserById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Paging<SysUserQueryVo> getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception{
|
|
||||||
Page page = setPageParam(sysUserQueryParam,OrderItem.desc("create_time"));
|
|
||||||
IPage<SysUserQueryVo> iPage = sysUserMapper.getSysUserPageList(page,sysUserQueryParam);
|
|
||||||
return new Paging(iPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loaded 100 of 155 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user