若依开源1.1.1发布
commit
262ee25d8e
@ -0,0 +1 @@
|
||||
/target/
|
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2018 RuoYi All rights reserved.
|
||||
|
||||
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.
|
@ -0,0 +1,225 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>RuoYi</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>RuoYi</name>
|
||||
<description>若依管理系统</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.10.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<shiro.version>1.3.2</shiro.version>
|
||||
<thymeleaf-extras-shiro.version>1.2.1</thymeleaf-extras-shiro.version>
|
||||
<mybatis-spring-boot-starter.version>1.1.1</mybatis-spring-boot-starter.version>
|
||||
<fastjson.version>1.2.31</fastjson.version>
|
||||
<druid.version>1.0.28</druid.version>
|
||||
<commons.lang3.version>3.6</commons.lang3.version>
|
||||
<bitwalker.version>1.19</bitwalker.version>
|
||||
<lombok.version>1.16.18</lombok.version>
|
||||
<mybatisplus-spring-boot-starter.version>1.0.4</mybatisplus-spring-boot-starter.version>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
<quartz.version>2.3.0</quartz.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringBoot 核心包 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot 测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot 拦截器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Web容器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot集成thymeleaf模板 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- thymeleaf网页解析 -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.nekohtml</groupId>
|
||||
<artifactId>nekohtml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql驱动包 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot集成mybatis框架 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pagehelper 分页插件 -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--阿里数据库连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--常用工具类 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons.lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--io常用工具类 -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
<!--Shiro核心框架 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Shiro使用Srping框架 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Shiro使用EhCache缓存框架 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-ehcache</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- thymeleaf模板引擎和shiro框架的整合 -->
|
||||
<dependency>
|
||||
<groupId>com.github.theborakompanioni</groupId>
|
||||
<artifactId>thymeleaf-extras-shiro</artifactId>
|
||||
<version>${thymeleaf-extras-shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 阿里JSON解析器 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 解析客户端操作系统、浏览器等 -->
|
||||
<dependency>
|
||||
<groupId>eu.bitwalker</groupId>
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
<version>${bitwalker.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Spring框架基本的核心工具-->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 定时任务 -->
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>${quartz.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.mchange</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--velocity代码生成使用模板 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>${velocity.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<executable>true</executable>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
</project>
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
|
||||
@MapperScan("com.ruoyi.project.*.*.dao")
|
||||
public class RuoYiApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(RuoYiApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
" .-------. ____ __ \n" +
|
||||
" | _ _ \\ \\ \\ / / \n" +
|
||||
" | ( ' ) | \\ _. / ' \n" +
|
||||
" |(_ o _) / _( )_ .' \n" +
|
||||
" | (_,_).' __ ___(_ o _)' \n" +
|
||||
" | |\\ \\ | || |(_,_)' \n" +
|
||||
" | | \\ `' /| `-' / \n" +
|
||||
" | | \\ / \\ / \n" +
|
||||
" ''-' `'-' `-..-' ");
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CommonConstant
|
||||
{
|
||||
|
||||
/**
|
||||
* 通用成功标识
|
||||
*/
|
||||
public static final String SUCCESS = "0";
|
||||
|
||||
/**
|
||||
* 通用失败标识
|
||||
*/
|
||||
public static final String FAIL = "1";
|
||||
|
||||
/**
|
||||
* 登录成功
|
||||
*/
|
||||
public static final String LOGIN_SUCCESS = "Success";
|
||||
|
||||
/**
|
||||
* 注销
|
||||
*/
|
||||
public static final String LOGOUT = "Logout";
|
||||
|
||||
/**
|
||||
* 登录失败
|
||||
*/
|
||||
public static final String LOGIN_FAIL = "Error";
|
||||
|
||||
/**
|
||||
* 自动去除表前缀
|
||||
*/
|
||||
public static String AUTO_REOMVE_PRE = "true";
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 通用Map数据
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CommonMap
|
||||
{
|
||||
/** 状态编码转换 */
|
||||
public static Map<String, String> javaTypeMap = new HashMap<String, String>();
|
||||
|
||||
static
|
||||
{
|
||||
initJavaTypeMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回状态映射
|
||||
*/
|
||||
public static void initJavaTypeMap()
|
||||
{
|
||||
javaTypeMap.put("tinyint", "Integer");
|
||||
javaTypeMap.put("smallint", "Integer");
|
||||
javaTypeMap.put("mediumint", "Integer");
|
||||
javaTypeMap.put("int", "Integer");
|
||||
javaTypeMap.put("integer", "integer");
|
||||
javaTypeMap.put("bigint", "Long");
|
||||
javaTypeMap.put("float", "Float");
|
||||
javaTypeMap.put("double", "Double");
|
||||
javaTypeMap.put("decimal", "BigDecimal");
|
||||
javaTypeMap.put("bit", "Boolean");
|
||||
javaTypeMap.put("char", "String");
|
||||
javaTypeMap.put("varchar", "String");
|
||||
javaTypeMap.put("tinytext", "String");
|
||||
javaTypeMap.put("text", "String");
|
||||
javaTypeMap.put("mediumtext", "String");
|
||||
javaTypeMap.put("longtext", "String");
|
||||
javaTypeMap.put("date", "String");
|
||||
javaTypeMap.put("datetime", "String");
|
||||
javaTypeMap.put("timestamp", "String");
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 任务调度通用常量
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ScheduleConstants
|
||||
{
|
||||
/**
|
||||
* 任务调度参数key
|
||||
*/
|
||||
public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY";
|
||||
|
||||
public enum Status
|
||||
{
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL(0),
|
||||
/**
|
||||
* 暂停
|
||||
*/
|
||||
PAUSE(1);
|
||||
|
||||
private int value;
|
||||
|
||||
private Status(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* Shiro通用常量
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ShiroConstants
|
||||
{
|
||||
/**
|
||||
* 当前登录的用户
|
||||
*/
|
||||
public static final String CURRENT_USER = "currentUser";
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
public static final String CURRENT_USERNAME = "username";
|
||||
|
||||
/**
|
||||
* 消息key
|
||||
*/
|
||||
public static String MESSAGE = "message";
|
||||
|
||||
/**
|
||||
* 错误key
|
||||
*/
|
||||
public static String ERROR = "errorMsg";
|
||||
|
||||
/**
|
||||
* 编码格式
|
||||
*/
|
||||
public static String ENCODING = "UTF-8";
|
||||
|
||||
/**
|
||||
* 当前在线会话
|
||||
*/
|
||||
public String ONLINE_SESSION = "online_session";
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 用户常量信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserConstants
|
||||
{
|
||||
|
||||
/** 正常状态 */
|
||||
public static final int NORMAL = 0;
|
||||
|
||||
/** 异常状态 */
|
||||
public static final int EXCEPTION = 1;
|
||||
|
||||
/** 用户封禁状态 */
|
||||
public static final int USER_BLOCKED = 1;
|
||||
|
||||
/** 角色封禁状态 */
|
||||
public static final int ROLE_BLOCKED = 1;
|
||||
|
||||
/**
|
||||
* 用户名长度限制
|
||||
*/
|
||||
public static final int USERNAME_MIN_LENGTH = 2;
|
||||
public static final int USERNAME_MAX_LENGTH = 10;
|
||||
|
||||
/** 名称是否唯一的返回结果码 */
|
||||
public final static String NAME_UNIQUE = "0";
|
||||
public final static String NAME_NOT_UNIQUE = "1";
|
||||
|
||||
/**
|
||||
* 密码长度限制
|
||||
*/
|
||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.ruoyi.common.exception.base;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
|
||||
/**
|
||||
* 基础异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class BaseException extends RuntimeException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 所属模块
|
||||
*/
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 错误码对应的参数
|
||||
*/
|
||||
private Object[] args;
|
||||
|
||||
/**
|
||||
* 错误消息
|
||||
*/
|
||||
private String defaultMessage;
|
||||
|
||||
public BaseException(String module, String code, Object[] args, String defaultMessage)
|
||||
{
|
||||
this.module = module;
|
||||
this.code = code;
|
||||
this.args = args;
|
||||
this.defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
public BaseException(String module, String code, Object[] args)
|
||||
{
|
||||
this(module, code, args, null);
|
||||
}
|
||||
|
||||
public BaseException(String module, String defaultMessage)
|
||||
{
|
||||
this(module, null, null, defaultMessage);
|
||||
}
|
||||
|
||||
public BaseException(String code, Object[] args)
|
||||
{
|
||||
this(null, code, args, null);
|
||||
}
|
||||
|
||||
public BaseException(String defaultMessage)
|
||||
{
|
||||
this(null, null, null, defaultMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
String message = null;
|
||||
if (!StringUtils.isEmpty(code))
|
||||
{
|
||||
message = MessageUtils.message(code, args);
|
||||
}
|
||||
if (message == null)
|
||||
{
|
||||
message = defaultMessage;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getModule()
|
||||
{
|
||||
return module;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public Object[] getArgs()
|
||||
{
|
||||
return args;
|
||||
}
|
||||
|
||||
public String getDefaultMessage()
|
||||
{
|
||||
return defaultMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getClass() + "{" + "module='" + module + '\'' + ", message='" + getMessage() + '\'' + '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.common.exception.base;
|
||||
|
||||
/**
|
||||
* Dao异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DaoException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误消息
|
||||
*/
|
||||
private String defaultMessage;
|
||||
|
||||
public DaoException(String defaultMessage)
|
||||
{
|
||||
this.defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
public String getDefaultMessage()
|
||||
{
|
||||
return defaultMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getClass() + "{" + "message='" + getMessage() + '\'' + '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
/**
|
||||
* 角色锁定异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class RoleBlockedException extends UserException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public RoleBlockedException(String reason)
|
||||
{
|
||||
super("role.blocked", new Object[] { reason });
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
/**
|
||||
* 用户锁定异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserBlockedException extends UserException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserBlockedException(String reason)
|
||||
{
|
||||
super("user.blocked", new Object[] { reason });
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
import com.ruoyi.common.exception.base.BaseException;
|
||||
|
||||
/**
|
||||
* 用户信息异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserException extends BaseException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserException(String code, Object[] args)
|
||||
{
|
||||
super("user", code, args, null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
/**
|
||||
* 用户不存在异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserNotExistsException extends UserException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserNotExistsException()
|
||||
{
|
||||
super("user.not.exists", null);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
/**
|
||||
* 用户密码不正确或不符合规范异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserPasswordNotMatchException extends UserException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserPasswordNotMatchException()
|
||||
{
|
||||
super("user.password.not.match", null);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
/**
|
||||
* 用户错误记数异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserPasswordRetryLimitCountException extends UserException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserPasswordRetryLimitCountException(int retryLimitCount, String password)
|
||||
{
|
||||
super("user.password.retry.limit.count", new Object[] { retryLimitCount, password });
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.common.exception.user;
|
||||
|
||||
/**
|
||||
* 用户错误最大次数异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserPasswordRetryLimitExceedException extends UserException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserPasswordRetryLimitExceedException(int retryLimitCount)
|
||||
{
|
||||
super("user.password.retry.limit.exceed", new Object[] { retryLimitCount });
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 时间工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DateUtils
|
||||
{
|
||||
public static final String DEFAULT_YYYYMMDD = "yyyyMMddHHmmss";
|
||||
|
||||
public static final String DEFAULT_YYYY_MM_DD = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
/**
|
||||
* 获取当前日期, 默认格式为yyyy-MM-dd
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getDate()
|
||||
{
|
||||
return dateTimeNow("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
public static final String dateTimeStr()
|
||||
{
|
||||
return dateTimeNow(DEFAULT_YYYY_MM_DD);
|
||||
}
|
||||
|
||||
public static final String dateTimeNow()
|
||||
{
|
||||
return dateTimeNow(DEFAULT_YYYYMMDD);
|
||||
}
|
||||
|
||||
public static final String dateTimeNow(final String format)
|
||||
{
|
||||
return dateTime(format, new Date());
|
||||
}
|
||||
|
||||
public static final String dateTime(final Date date)
|
||||
{
|
||||
return dateTime(DEFAULT_YYYYMMDD, date);
|
||||
}
|
||||
|
||||
public static final String dateTime(final String format, final Date date)
|
||||
{
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
public static final Date dateTime(final String format, final String ts)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new SimpleDateFormat(format).parse(ts);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 获取IP方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class IpUtils
|
||||
{
|
||||
public static String getIpAddr(HttpServletRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||
{
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||
{
|
||||
ip = request.getHeader("X-Forwarded-For");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||
{
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||
{
|
||||
ip = request.getHeader("X-Real-IP");
|
||||
}
|
||||
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||
{
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 处理并记录日志文件
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class LogUtils
|
||||
{
|
||||
|
||||
public static final Logger ERROR_LOG = LoggerFactory.getLogger("sys-error");
|
||||
public static final Logger ACCESS_LOG = LoggerFactory.getLogger("sys-access");
|
||||
|
||||
/**
|
||||
* 记录访问日志 [username][jsessionid][ip][accept][UserAgent][url][params][Referer]
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
public static void logAccess(HttpServletRequest request)
|
||||
{
|
||||
String username = getUsername();
|
||||
String jsessionId = request.getRequestedSessionId();
|
||||
String ip = IpUtils.getIpAddr(request);
|
||||
String accept = request.getHeader("accept");
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
String url = request.getRequestURI();
|
||||
String params = getParams(request);
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(getBlock(username));
|
||||
s.append(getBlock(jsessionId));
|
||||
s.append(getBlock(ip));
|
||||
s.append(getBlock(accept));
|
||||
s.append(getBlock(userAgent));
|
||||
s.append(getBlock(url));
|
||||
s.append(getBlock(params));
|
||||
s.append(getBlock(request.getHeader("Referer")));
|
||||
getAccessLog().info(s.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录异常错误 格式 [exception]
|
||||
*
|
||||
* @param message
|
||||
* @param e
|
||||
*/
|
||||
public static void logError(String message, Throwable e)
|
||||
{
|
||||
String username = getUsername();
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(getBlock("exception"));
|
||||
s.append(getBlock(username));
|
||||
s.append(getBlock(message));
|
||||
ERROR_LOG.error(s.toString(), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录页面错误 错误日志记录 [page/eception][username][statusCode][errorMessage][servletName][uri][exceptionName][ip][exception]
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
public static void logPageError(HttpServletRequest request)
|
||||
{
|
||||
String username = getUsername();
|
||||
|
||||
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||
String message = (String) request.getAttribute("javax.servlet.error.message");
|
||||
String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
|
||||
Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception");
|
||||
|
||||
if (statusCode == null)
|
||||
{
|
||||
statusCode = 0;
|
||||
}
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(getBlock(t == null ? "page" : "exception"));
|
||||
s.append(getBlock(username));
|
||||
s.append(getBlock(statusCode));
|
||||
s.append(getBlock(message));
|
||||
s.append(getBlock(IpUtils.getIpAddr(request)));
|
||||
|
||||
s.append(getBlock(uri));
|
||||
s.append(getBlock(request.getHeader("Referer")));
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
while (t != null)
|
||||
{
|
||||
t.printStackTrace(new PrintWriter(sw));
|
||||
t = t.getCause();
|
||||
}
|
||||
s.append(getBlock(sw.toString()));
|
||||
getErrorLog().error(s.toString());
|
||||
|
||||
}
|
||||
|
||||
public static String getBlock(Object msg)
|
||||
{
|
||||
if (msg == null)
|
||||
{
|
||||
msg = "";
|
||||
}
|
||||
return "[" + msg.toString() + "]";
|
||||
}
|
||||
|
||||
protected static String getParams(HttpServletRequest request)
|
||||
{
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
return JSON.toJSONString(params);
|
||||
}
|
||||
|
||||
protected static String getUsername()
|
||||
{
|
||||
return (String) SecurityUtils.getSubject().getPrincipal();
|
||||
}
|
||||
|
||||
public static Logger getAccessLog()
|
||||
{
|
||||
return ACCESS_LOG;
|
||||
}
|
||||
|
||||
public static Logger getErrorLog()
|
||||
{
|
||||
return ERROR_LOG;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Map通用处理方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class MapDataUtil
|
||||
{
|
||||
public static Map<String, Object> convertDataMap(HttpServletRequest request)
|
||||
{
|
||||
Map<String, String[]> properties = request.getParameterMap();
|
||||
Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
Iterator<?> entries = properties.entrySet().iterator();
|
||||
Map.Entry<?, ?> entry;
|
||||
String name = "";
|
||||
String value = "";
|
||||
while (entries.hasNext())
|
||||
{
|
||||
entry = (Entry<?, ?>) entries.next();
|
||||
name = (String) entry.getKey();
|
||||
Object valueObj = entry.getValue();
|
||||
if (null == valueObj)
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
else if (valueObj instanceof String[])
|
||||
{
|
||||
String[] values = (String[]) valueObj;
|
||||
for (int i = 0; i < values.length; i++)
|
||||
{
|
||||
value = values[i] + ",";
|
||||
}
|
||||
value = value.substring(0, value.length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = valueObj.toString();
|
||||
}
|
||||
returnMap.put(name, value);
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
|
||||
/**
|
||||
* 获取i18n资源文件
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class MessageUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* 根据消息键和参数 获取消息 委托给spring messageSource
|
||||
*
|
||||
* @param code 消息键
|
||||
* @param args 参数
|
||||
* @return
|
||||
*/
|
||||
public static String message(String code, Object... args)
|
||||
{
|
||||
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
|
||||
return messageSource.getMessage(code, args, null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ServletUtils
|
||||
{
|
||||
/**
|
||||
* 获取request对象
|
||||
*/
|
||||
public static HttpServletRequest getHttpServletRequest()
|
||||
{
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是Ajax异步请求
|
||||
*/
|
||||
public static boolean isAjaxRequest(HttpServletRequest request)
|
||||
{
|
||||
|
||||
String accept = request.getHeader("accept");
|
||||
if (accept != null && accept.indexOf("application/json") != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ajax = request.getParameter("__ajax");
|
||||
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.project.system.menu.domain.Menu;
|
||||
|
||||
/**
|
||||
* 权限数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TreeUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* 根据父节点的ID获取所有子节点
|
||||
*
|
||||
* @param list 分类表
|
||||
* @param typeId 传入的父节点ID
|
||||
* @return String
|
||||
*/
|
||||
public static List<Menu> getChildPerms(List<Menu> list, int praentId)
|
||||
{
|
||||
List<Menu> returnList = new ArrayList<Menu>();
|
||||
for (Iterator<Menu> iterator = list.iterator(); iterator.hasNext();)
|
||||
{
|
||||
Menu t = (Menu) iterator.next();
|
||||
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||
if (t.getParentId() == praentId)
|
||||
{
|
||||
recursionFn(list, t);
|
||||
returnList.add(t);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*
|
||||
* @param list
|
||||
* @param Menu
|
||||
*/
|
||||
private static void recursionFn(List<Menu> list, Menu t)
|
||||
{
|
||||
// 得到子节点列表
|
||||
List<Menu> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (Menu tChild : childList)
|
||||
{
|
||||
if (hasChild(list, tChild))
|
||||
{
|
||||
// 判断是否有子节点
|
||||
Iterator<Menu> it = childList.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Menu n = (Menu) it.next();
|
||||
recursionFn(list, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private static List<Menu> getChildList(List<Menu> list, Menu t)
|
||||
{
|
||||
|
||||
List<Menu> tlist = new ArrayList<Menu>();
|
||||
Iterator<Menu> it = list.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Menu n = (Menu) it.next();
|
||||
if (n.getParentId().longValue() == t.getMenuId().longValue())
|
||||
{
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
List<Menu> returnList = new ArrayList<Menu>();
|
||||
|
||||
/**
|
||||
* 根据父节点的ID获取所有子节点
|
||||
*
|
||||
* @param list 分类表
|
||||
* @param typeId 传入的父节点ID
|
||||
* @param prefix 子节点前缀
|
||||
*/
|
||||
public List<Menu> getChildPerms(List<Menu> list, int typeId, String prefix)
|
||||
{
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (Iterator<Menu> iterator = list.iterator(); iterator.hasNext();)
|
||||
{
|
||||
Menu node = (Menu) iterator.next();
|
||||
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||
if (node.getParentId() == typeId)
|
||||
{
|
||||
recursionFn(list, node, prefix);
|
||||
}
|
||||
// 二、遍历所有的父节点下的所有子节点
|
||||
/*
|
||||
* if (node.getParentId()==0) { recursionFn(list, node); }
|
||||
*/
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
private void recursionFn(List<Menu> list, Menu node, String p)
|
||||
{
|
||||
// 得到子节点列表
|
||||
List<Menu> childList = getChildList(list, node);
|
||||
if (hasChild(list, node))
|
||||
{
|
||||
// 判断是否有子节点
|
||||
returnList.add(node);
|
||||
Iterator<Menu> it = childList.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Menu n = (Menu) it.next();
|
||||
n.setMenuName(p + n.getMenuName());
|
||||
recursionFn(list, n, p + p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnList.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private static boolean hasChild(List<Menu> list, Menu t)
|
||||
{
|
||||
return getChildList(list, t).size() > 0 ? true : false;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.ruoyi.common.utils.security;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
* shiro 工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ShiroUtils
|
||||
{
|
||||
|
||||
public static Subject getSubjct()
|
||||
{
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
|
||||
public static void logout()
|
||||
{
|
||||
getSubjct().logout();
|
||||
}
|
||||
|
||||
public static User getUser()
|
||||
{
|
||||
return (User) getSubjct().getPrincipal();
|
||||
}
|
||||
|
||||
public static Long getUserId()
|
||||
{
|
||||
return getUser().getUserId().longValue();
|
||||
}
|
||||
|
||||
public static String getLoginName()
|
||||
{
|
||||
return getUser().getLoginName();
|
||||
}
|
||||
|
||||
public static String getIp()
|
||||
{
|
||||
return getSubjct().getSession().getHost();
|
||||
}
|
||||
|
||||
public static String getSessionId()
|
||||
{
|
||||
return String.valueOf(getSubjct().getSession().getId());
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.framework.aspectj.lang.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义操作日志记录注解
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Log
|
||||
{
|
||||
/** 模块 */
|
||||
String title() default "";
|
||||
|
||||
/** 功能 */
|
||||
String action() default "";
|
||||
|
||||
/** 渠道 */
|
||||
String channel() default "web";
|
||||
|
||||
/** 是否保存请求的参数 */
|
||||
boolean isSaveRequestData() default true;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
/**
|
||||
* 资源文件配置加载
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
@Component
|
||||
public class I18nConfig extends WebMvcConfigurerAdapter
|
||||
{
|
||||
|
||||
@Bean
|
||||
public LocaleResolver localeResolver()
|
||||
{
|
||||
SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||
// 默认语言
|
||||
slr.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
|
||||
return slr;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocaleChangeInterceptor localeChangeInterceptor()
|
||||
{
|
||||
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
||||
// 参数名
|
||||
lci.setParamName("lang");
|
||||
return lci;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry)
|
||||
{
|
||||
registry.addInterceptor(localeChangeInterceptor());
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 读取项目相关配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "ruoyi")
|
||||
public class RuoYiConfig
|
||||
{
|
||||
/** 项目名称 */
|
||||
private String name;
|
||||
/** 版本 */
|
||||
private String version;
|
||||
/** 版权年份 */
|
||||
private String copyrightYear;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getCopyrightYear()
|
||||
{
|
||||
return copyrightYear;
|
||||
}
|
||||
|
||||
public void setCopyrightYear(String copyrightYear)
|
||||
{
|
||||
this.copyrightYear = copyrightYear;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.ruoyi.framework.mybatis;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 拦截需要分页SQL 反射工具
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ReflectHelper
|
||||
{
|
||||
/**
|
||||
* 获取obj对象fieldName的Field
|
||||
*
|
||||
* @param obj
|
||||
* @param fieldName
|
||||
* @return
|
||||
*/
|
||||
public static Field getFieldByFieldName(Object obj, String fieldName)
|
||||
{
|
||||
for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass())
|
||||
{
|
||||
try
|
||||
{
|
||||
return superClass.getDeclaredField(fieldName);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取obj对象fieldName的属性值
|
||||
*
|
||||
* @param obj
|
||||
* @param fieldName
|
||||
* @return
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchFieldException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static Object getValueByFieldName(Object obj, String fieldName)
|
||||
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
Field field = getFieldByFieldName(obj, fieldName);
|
||||
Object value = null;
|
||||
if (field != null)
|
||||
{
|
||||
if (field.isAccessible())
|
||||
{
|
||||
value = field.get(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
field.setAccessible(true);
|
||||
value = field.get(obj);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置obj对象fieldName的属性值
|
||||
*
|
||||
* @param obj
|
||||
* @param fieldName
|
||||
* @param value
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchFieldException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static void setValueByFieldName(Object obj, String fieldName, Object value)
|
||||
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
Field field = obj.getClass().getDeclaredField(fieldName);
|
||||
if (field.isAccessible())
|
||||
{
|
||||
field.set(obj, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
field.setAccessible(true);
|
||||
field.set(obj, value);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package com.ruoyi.framework.shiro.realm;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.ExcessiveAttemptsException;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.ruoyi.common.exception.user.RoleBlockedException;
|
||||
import com.ruoyi.common.exception.user.UserBlockedException;
|
||||
import com.ruoyi.common.exception.user.UserNotExistsException;
|
||||
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
||||
import com.ruoyi.common.exception.user.UserPasswordRetryLimitExceedException;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.framework.shiro.service.LoginService;
|
||||
import com.ruoyi.project.system.menu.service.IMenuService;
|
||||
import com.ruoyi.project.system.role.service.IRoleService;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
* 自定义Realm 处理登录 权限
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserRealm extends AuthorizingRealm
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(UserRealm.class);
|
||||
|
||||
@Autowired
|
||||
private IMenuService menuService;
|
||||
|
||||
@Autowired
|
||||
private IRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private LoginService loginService;
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0)
|
||||
{
|
||||
Long userId = ShiroUtils.getUserId();
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
// 角色加入AuthorizationInfo认证对象
|
||||
info.setRoles(roleService.selectRoleKeys(userId));
|
||||
// 权限加入AuthorizationInfo认证对象
|
||||
info.setStringPermissions(menuService.selectPermsByUserId(userId));
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录认证
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException
|
||||
{
|
||||
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
|
||||
String username = upToken.getUsername();
|
||||
String password = "";
|
||||
if (upToken.getPassword() != null)
|
||||
{
|
||||
password = new String(upToken.getPassword());
|
||||
}
|
||||
|
||||
User user = null;
|
||||
try
|
||||
{
|
||||
user = loginService.login(username, password);
|
||||
}
|
||||
catch (UserNotExistsException e)
|
||||
{
|
||||
throw new UnknownAccountException(e.getMessage(), e);
|
||||
}
|
||||
catch (UserPasswordNotMatchException e)
|
||||
{
|
||||
throw new IncorrectCredentialsException(e.getMessage(), e);
|
||||
}
|
||||
catch (UserPasswordRetryLimitExceedException e)
|
||||
{
|
||||
throw new ExcessiveAttemptsException(e.getMessage(), e);
|
||||
}
|
||||
catch (UserBlockedException e)
|
||||
{
|
||||
throw new LockedAccountException(e.getMessage(), e);
|
||||
}
|
||||
catch (RoleBlockedException e)
|
||||
{
|
||||
throw new LockedAccountException(e.getMessage(), e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.info("对用户[" + username + "]进行登录验证..验证未通过{}", e.getMessage());
|
||||
throw new AuthenticationException(e.getMessage(), e);
|
||||
}
|
||||
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password, getName());
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.ruoyi.framework.shiro.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import com.ruoyi.common.constant.CommonConstant;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.exception.user.UserBlockedException;
|
||||
import com.ruoyi.common.exception.user.UserNotExistsException;
|
||||
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.SystemLogUtils;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
import com.ruoyi.project.system.user.service.IUserService;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class LoginService
|
||||
{
|
||||
@Autowired
|
||||
private PasswordService passwordService;
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public User login(String username, String password)
|
||||
{
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("not.null"));
|
||||
throw new UserNotExistsException();
|
||||
}
|
||||
// 密码如果不在指定范围内 错误
|
||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.password.not.match"));
|
||||
throw new UserPasswordNotMatchException();
|
||||
}
|
||||
|
||||
// 用户名不在指定范围内 错误
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.password.not.match"));
|
||||
throw new UserPasswordNotMatchException();
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
User user = userService.selectUserByName(username);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.not.exists"));
|
||||
throw new UserNotExistsException();
|
||||
}
|
||||
|
||||
passwordService.validate(user, password);
|
||||
|
||||
if (UserConstants.USER_BLOCKED == user.getStatus())
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRefuseDes()));
|
||||
throw new UserBlockedException(user.getRefuseDes());
|
||||
}
|
||||
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.ruoyi.framework.shiro.service;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.apache.shiro.crypto.hash.Md5Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ruoyi.common.constant.CommonConstant;
|
||||
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
||||
import com.ruoyi.common.exception.user.UserPasswordRetryLimitExceedException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.SystemLogUtils;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
* 登录密码方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class PasswordService
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
private Cache<String, AtomicInteger> loginRecordCache;
|
||||
|
||||
@Value(value = "${user.password.maxRetryCount}")
|
||||
private String maxRetryCount;
|
||||
|
||||
@PostConstruct
|
||||
public void init()
|
||||
{
|
||||
loginRecordCache = cacheManager.getCache("loginRecordCache");
|
||||
}
|
||||
|
||||
public void validate(User user, String password)
|
||||
{
|
||||
String loginName = user.getLoginName();
|
||||
|
||||
AtomicInteger retryCount = loginRecordCache.get(loginName);
|
||||
|
||||
if (retryCount == null)
|
||||
{
|
||||
retryCount = new AtomicInteger(0);
|
||||
loginRecordCache.put(loginName, retryCount);
|
||||
}
|
||||
if (retryCount.incrementAndGet() > Integer.valueOf(maxRetryCount).intValue())
|
||||
{
|
||||
SystemLogUtils.log(loginName, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount));
|
||||
throw new UserPasswordRetryLimitExceedException(Integer.valueOf(maxRetryCount).intValue());
|
||||
}
|
||||
|
||||
if (!matches(user, password))
|
||||
{
|
||||
SystemLogUtils.log(loginName, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.count", retryCount, password));
|
||||
loginRecordCache.put(loginName, retryCount);
|
||||
throw new UserPasswordNotMatchException();
|
||||
}
|
||||
else
|
||||
{
|
||||
clearLoginRecordCache(loginName);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(User user, String newPassword)
|
||||
{
|
||||
return user.getPassword().equals(encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
|
||||
}
|
||||
|
||||
public void clearLoginRecordCache(String username)
|
||||
{
|
||||
loginRecordCache.remove(username);
|
||||
}
|
||||
|
||||
public String encryptPassword(String username, String password, String salt)
|
||||
{
|
||||
return new Md5Hash(username + password + salt).toHex().toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(new PasswordService().encryptPassword("admin", "admin123", "111111"));
|
||||
System.out.println(new PasswordService().encryptPassword("ry", "admin123", "222222"));
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.ruoyi.framework.shiro.service;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* RuoYi首创 js调用 thymeleaf 实现按钮权限可见性
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class PermissionService
|
||||
{
|
||||
public String hasPermi(String permission)
|
||||
{
|
||||
return isPermittedOperator(permission) ? "" : "hidden";
|
||||
}
|
||||
|
||||
private boolean isPermittedOperator(String permission)
|
||||
{
|
||||
if (SecurityUtils.getSubject().isPermitted(permission))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.ruoyi.framework.shiro.session;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.SessionContext;
|
||||
import org.apache.shiro.session.mgt.SessionFactory;
|
||||
import org.apache.shiro.web.session.mgt.WebSessionContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.IpUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.project.monitor.online.domain.OnlineSession;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
|
||||
import eu.bitwalker.useragentutils.UserAgent;
|
||||
|
||||
/**
|
||||
* 自定义sessionFactory会话
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class OnlineSessionFactory implements SessionFactory
|
||||
{
|
||||
public Session createSession(UserOnline userOnline)
|
||||
{
|
||||
OnlineSession onlineSession = userOnline.getSession();
|
||||
if (StringUtils.isNotNull(onlineSession) && onlineSession.getId() == null)
|
||||
{
|
||||
onlineSession.setId(userOnline.getSessionId());
|
||||
}
|
||||
return userOnline.getSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session createSession(SessionContext initData)
|
||||
{
|
||||
OnlineSession session = new OnlineSession();
|
||||
if (initData != null && initData instanceof WebSessionContext)
|
||||
{
|
||||
WebSessionContext sessionContext = (WebSessionContext) initData;
|
||||
HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
|
||||
if (request != null)
|
||||
{
|
||||
UserAgent userAgent = UserAgent
|
||||
.parseUserAgentString(ServletUtils.getHttpServletRequest().getHeader("User-Agent"));
|
||||
// 获取客户端操作系统
|
||||
String os = userAgent.getOperatingSystem().getName();
|
||||
// 获取客户端浏览器
|
||||
String browser = userAgent.getBrowser().getName();
|
||||
session.setHost(IpUtils.getIpAddr(request));
|
||||
session.setBrowser(browser);
|
||||
session.setOs(os);
|
||||
}
|
||||
}
|
||||
return session;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.ruoyi.framework.shiro.web.filter;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import org.apache.shiro.session.SessionException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.constant.CommonConstant;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.SystemLogUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
* 退出过滤器
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(LogoutFilter.class);
|
||||
|
||||
/**
|
||||
* 退出后重定向的地址
|
||||
*/
|
||||
private String loginUrl;
|
||||
|
||||
public String getLoginUrl()
|
||||
{
|
||||
return loginUrl;
|
||||
}
|
||||
|
||||
public void setLoginUrl(String loginUrl)
|
||||
{
|
||||
this.loginUrl = loginUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
Subject subject = getSubject(request, response);
|
||||
String redirectUrl = getRedirectUrl(request, response, subject);
|
||||
try
|
||||
{
|
||||
User user = (User) ShiroUtils.getSubjct().getPrincipal();
|
||||
if (StringUtils.isNotNull(user))
|
||||
{
|
||||
String loginName = user.getLoginName();
|
||||
// 记录用户退出日志
|
||||
SystemLogUtils.log(loginName, CommonConstant.LOGOUT, MessageUtils.message("user.logout.success"));
|
||||
}
|
||||
// 退出登录
|
||||
subject.logout();
|
||||
}
|
||||
catch (SessionException ise)
|
||||
{
|
||||
log.error("logout fail.", ise);
|
||||
}
|
||||
issueRedirect(request, response, redirectUrl);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.debug("Encountered session exception during logout. This can generally safely be ignored.", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出跳转URL
|
||||
*/
|
||||
@Override
|
||||
protected String getRedirectUrl(ServletRequest request, ServletResponse response, Subject subject)
|
||||
{
|
||||
String url = getLoginUrl();
|
||||
if (StringUtils.isNotEmpty(url))
|
||||
{
|
||||
return url;
|
||||
}
|
||||
return super.getRedirectUrl(request, response, subject);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
package com.ruoyi.framework.shiro.web.session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.apache.shiro.session.ExpiredSessionException;
|
||||
import org.apache.shiro.session.InvalidSessionException;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.DefaultSessionKey;
|
||||
import org.apache.shiro.session.mgt.SessionKey;
|
||||
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.constant.ShiroConstants;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.project.monitor.online.domain.OnlineSession;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
import com.ruoyi.project.monitor.online.service.UserOnlineServiceImpl;
|
||||
|
||||
/**
|
||||
* 主要是在此如果会话的属性修改了 就标识下其修改了 然后方便 OnlineSessionDao同步
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class OnlineWebSessionManager extends DefaultWebSessionManager
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(OnlineWebSessionManager.class);
|
||||
|
||||
@Override
|
||||
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
|
||||
{
|
||||
super.setAttribute(sessionKey, attributeKey, value);
|
||||
if (value != null && needMarkAttributeChanged(attributeKey))
|
||||
{
|
||||
OnlineSession s = (OnlineSession) doGetSession(sessionKey);
|
||||
s.markAttributeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needMarkAttributeChanged(Object attributeKey)
|
||||
{
|
||||
if (attributeKey == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String attributeKeyStr = attributeKey.toString();
|
||||
// 优化 flash属性没必要持久化
|
||||
if (attributeKeyStr.startsWith("org.springframework"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (attributeKeyStr.startsWith("javax.servlet"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (attributeKeyStr.equals(ShiroConstants.CURRENT_USERNAME))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
|
||||
{
|
||||
Object removed = super.removeAttribute(sessionKey, attributeKey);
|
||||
if (removed != null)
|
||||
{
|
||||
OnlineSession s = (OnlineSession) doGetSession(sessionKey);
|
||||
s.markAttributeChanged();
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证session是否有效 用于删除过期session
|
||||
*/
|
||||
@Override
|
||||
public void validateSessions()
|
||||
{
|
||||
if (log.isInfoEnabled())
|
||||
{
|
||||
log.info("invalidation sessions...");
|
||||
}
|
||||
|
||||
int invalidCount = 0;
|
||||
|
||||
int timeout = (int) this.getGlobalSessionTimeout();
|
||||
Date expiredDate = DateUtils.addMilliseconds(new Date(), 0 - timeout);
|
||||
UserOnlineServiceImpl userOnlineService = SpringUtils.getBean(UserOnlineServiceImpl.class);
|
||||
List<UserOnline> userOnlineList = userOnlineService.selectOnlineByExpired(expiredDate);
|
||||
// 批量过期删除
|
||||
List<String> needOfflineIdList = new ArrayList<String>();
|
||||
for (UserOnline userOnline : userOnlineList)
|
||||
{
|
||||
try
|
||||
{
|
||||
SessionKey key = new DefaultSessionKey(userOnline.getSessionId());
|
||||
Session session = retrieveSession(key);
|
||||
if (session != null)
|
||||
{
|
||||
throw new InvalidSessionException();
|
||||
}
|
||||
}
|
||||
catch (InvalidSessionException e)
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
boolean expired = (e instanceof ExpiredSessionException);
|
||||
String msg = "Invalidated session with id [" + userOnline.getSessionId() + "]"
|
||||
+ (expired ? " (expired)" : " (stopped)");
|
||||
log.debug(msg);
|
||||
}
|
||||
invalidCount++;
|
||||
needOfflineIdList.add(userOnline.getSessionId());
|
||||
}
|
||||
|
||||
}
|
||||
if (needOfflineIdList.size() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
userOnlineService.batchDeleteOnline(needOfflineIdList);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("batch delete db session error.", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isInfoEnabled())
|
||||
{
|
||||
String msg = "Finished invalidation session.";
|
||||
if (invalidCount > 0)
|
||||
{
|
||||
msg += " [" + invalidCount + "] sessions were stopped.";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg += " No sessions were stopped.";
|
||||
}
|
||||
log.info(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Session> getActiveSessions()
|
||||
{
|
||||
throw new UnsupportedOperationException("getActiveSessions method not supported");
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.ruoyi.framework.web.controller;
|
||||
|
||||
import java.util.List;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.framework.web.page.PageDomain;
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.framework.web.support.TableSupport;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
* web层通用数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class BaseController
|
||||
{
|
||||
/**
|
||||
* 获取请求分页数据
|
||||
*/
|
||||
public PageUtilEntity getPageUtilEntity()
|
||||
{
|
||||
PageUtilEntity pageUtilEntity = TableSupport.buildPageRequest();
|
||||
return pageUtilEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求分页数据
|
||||
*/
|
||||
protected void setPageInfo(Object obj)
|
||||
{
|
||||
PageDomain page = (PageDomain) obj;
|
||||
if (StringUtils.isNotEmpty(page.getPageNum()) && StringUtils.isNotEmpty(page.getPageSize()))
|
||||
{
|
||||
int pageNum = Integer.valueOf(page.getPageNum());
|
||||
int pageSize = Integer.valueOf(page.getPageSize());
|
||||
String orderBy = page.getOrderBy();
|
||||
PageHelper.startPage(pageNum, pageSize, orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应请求分页数据
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected TableDataInfo getDataTable(List<?> list)
|
||||
{
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setRows(list);
|
||||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
public User getUser()
|
||||
{
|
||||
return ShiroUtils.getUser();
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return getUser().getUserId();
|
||||
}
|
||||
|
||||
public String getLoginName()
|
||||
{
|
||||
return getUser().getLoginName();
|
||||
}
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
package com.ruoyi.framework.web.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 数据DAO层通用数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DynamicObjectBaseDao
|
||||
{
|
||||
@Resource(name = "sqlSessionTemplate")
|
||||
private SqlSessionTemplate sqlSessionTemplate;
|
||||
|
||||
/**
|
||||
* 保存对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int save(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.insert(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int batchSave(String str, List<?> objs)
|
||||
{
|
||||
return sqlSessionTemplate.insert(str, objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int update(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.update(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public void batchUpdate(String str, List<?> objs) throws Exception
|
||||
{
|
||||
SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
|
||||
// 批量执行器
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
try
|
||||
{
|
||||
if (objs != null)
|
||||
{
|
||||
for (int i = 0, size = objs.size(); i < size; i++)
|
||||
{
|
||||
sqlSession.update(str, objs.get(i));
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
sqlSession.commit();
|
||||
sqlSession.clearCache();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除 根据对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int batchDelete(String str, List<?> objs) throws Exception
|
||||
{
|
||||
return sqlSessionTemplate.delete(str, objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除 根据数组
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int batchDelete(String str, Long[] objs)
|
||||
{
|
||||
return sqlSessionTemplate.delete(str, objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int delete(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.delete(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找单条对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public <T> T findForObject(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.selectOne(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找总数
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int count(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.selectOne(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找对象 - 无条件
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public <E> List<E> findForList(String str)
|
||||
{
|
||||
return sqlSessionTemplate.selectList(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找对象 - 有条件
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public <E> List<E> findForList(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.selectList(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义分页方法
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public TableDataInfo findForList(String str, PageUtilEntity pageUtilEntity)
|
||||
{
|
||||
List<?> pageList = sqlSessionTemplate.selectList(str, pageUtilEntity);
|
||||
TableDataInfo tableDataInfo = new TableDataInfo(pageList, pageUtilEntity.getTotalResult());
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
public Object findForMap(String str, Object obj, String key, String value) throws Exception
|
||||
{
|
||||
return sqlSessionTemplate.selectMap(str, obj, key);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.ruoyi.framework.web.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 返回数据通用处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class JSON extends HashMap<String, Object>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JSON()
|
||||
{
|
||||
put("code", 0);
|
||||
put("msg", "操作成功");
|
||||
}
|
||||
|
||||
public static JSON error()
|
||||
{
|
||||
return error(1, "操作失败");
|
||||
}
|
||||
|
||||
public static JSON error(String msg)
|
||||
{
|
||||
return error(500, msg);
|
||||
}
|
||||
|
||||
public static JSON error(int code, String msg)
|
||||
{
|
||||
JSON json = new JSON();
|
||||
json.put("code", code);
|
||||
json.put("msg", msg);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSON ok(String msg)
|
||||
{
|
||||
JSON json = new JSON();
|
||||
json.put("msg", msg);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSON ok(Map<String, Object> map)
|
||||
{
|
||||
JSON json = new JSON();
|
||||
json.putAll(map);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSON ok()
|
||||
{
|
||||
return new JSON();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSON put(String key, Object value)
|
||||
{
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.ruoyi.framework.web.exception;
|
||||
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
|
||||
/**
|
||||
* 自定义异常处理器
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class DefaultExceptionHandler
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultExceptionHandler.class);
|
||||
|
||||
/**
|
||||
* 权限校验失败
|
||||
*/
|
||||
@ExceptionHandler(AuthorizationException.class)
|
||||
public JSON handleAuthorizationException(AuthorizationException e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
return JSON.error("您没有数据的权限,请联系管理员添加");
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求方式不支持
|
||||
*/
|
||||
@ExceptionHandler({ HttpRequestMethodNotSupportedException.class })
|
||||
public JSON handleException(HttpRequestMethodNotSupportedException e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
return JSON.error("不支持' " + e.getMethod() + "'请求");
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截未知的运行时异常
|
||||
*/
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public JSON notFount(RuntimeException e)
|
||||
{
|
||||
log.error("运行时异常:", e);
|
||||
return JSON.error("运行时异常:" + e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public JSON handleException(Exception e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
return JSON.error("服务器错误,请联系管理员");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package com.ruoyi.framework.web.page;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 分页数据
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class PageDomain
|
||||
{
|
||||
/** 当前记录起始索引 */
|
||||
private String pageNum;
|
||||
/** 每页显示记录数 */
|
||||
private String pageSize;
|
||||
/** 排序列 */
|
||||
private String orderByColumn;
|
||||
/** 排序的方向 "desc" 或者 "asc". */
|
||||
private String isAsc;
|
||||
/** 搜索值 */
|
||||
private String searchValue;
|
||||
|
||||
public String getOrderBy()
|
||||
{
|
||||
if (StringUtils.isEmpty(orderByColumn))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return orderByColumn + " " + isAsc;
|
||||
}
|
||||
|
||||
public String getPageNum()
|
||||
{
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(String pageNum)
|
||||
{
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public String getPageSize()
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(String pageSize)
|
||||
{
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getOrderByColumn()
|
||||
{
|
||||
return orderByColumn;
|
||||
}
|
||||
|
||||
public void setOrderByColumn(String orderByColumn)
|
||||
{
|
||||
this.orderByColumn = orderByColumn;
|
||||
}
|
||||
|
||||
public String getIsAsc()
|
||||
{
|
||||
return isAsc;
|
||||
}
|
||||
|
||||
public void setIsAsc(String isAsc)
|
||||
{
|
||||
this.isAsc = isAsc;
|
||||
}
|
||||
|
||||
public String getSearchValue()
|
||||
{
|
||||
return searchValue;
|
||||
}
|
||||
|
||||
public void setSearchValue(String searchValue)
|
||||
{
|
||||
this.searchValue = searchValue;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.ruoyi.framework.web.page;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表格分页数据对象
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TableDataInfo implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** 总记录数 */
|
||||
private long total;
|
||||
/** 列表数据 */
|
||||
private List<?> rows;
|
||||
|
||||
/**
|
||||
* 表格数据对象
|
||||
*/
|
||||
public TableDataInfo()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public TableDataInfo(List<?> list, int total)
|
||||
{
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public long getTotal()
|
||||
{
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total)
|
||||
{
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<?> getRows()
|
||||
{
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<?> rows)
|
||||
{
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.ruoyi.framework.web.support;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.MapDataUtil;
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
|
||||
/**
|
||||
* 表格数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TableSupport
|
||||
{
|
||||
/**
|
||||
* 封装分页对象
|
||||
*/
|
||||
public static PageUtilEntity getPageUtilEntity()
|
||||
{
|
||||
HttpServletRequest request = ServletUtils.getHttpServletRequest();
|
||||
PageUtilEntity pageUtilEntity = new PageUtilEntity();
|
||||
pageUtilEntity.setPage(Integer.valueOf(request.getParameter("offset")));
|
||||
pageUtilEntity.setSize(Integer.valueOf(request.getParameter("limit")));
|
||||
pageUtilEntity.setOrderByColumn(request.getParameter("sort"));
|
||||
pageUtilEntity.setIsAsc(request.getParameter("order"));
|
||||
pageUtilEntity.setSearchValue(request.getParameter("search"));
|
||||
pageUtilEntity.setReqMap(MapDataUtil.convertDataMap(request));
|
||||
return pageUtilEntity;
|
||||
}
|
||||
|
||||
public static PageUtilEntity buildPageRequest()
|
||||
{
|
||||
return getPageUtilEntity();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.ruoyi.project.monitor.druid;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
|
||||
/**
|
||||
* druid 监控
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/monitor/data")
|
||||
public class DruidController extends BaseController
|
||||
{
|
||||
private String prefix = "/monitor/druid";
|
||||
|
||||
@RequiresPermissions("monitor:data:view")
|
||||
@GetMapping()
|
||||
public String index()
|
||||
{
|
||||
return "redirect:" + prefix + "/index";
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
package com.ruoyi.project.monitor.job.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.monitor.job.domain.Job;
|
||||
import com.ruoyi.project.monitor.job.service.IJobService;
|
||||
|
||||
/**
|
||||
* 调度任务信息操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/monitor/job")
|
||||
public class JobController extends BaseController
|
||||
{
|
||||
private String prefix = "monitor/job";
|
||||
|
||||
@Autowired
|
||||
private IJobService jobService;
|
||||
|
||||
@RequiresPermissions("monitor:job:view")
|
||||
@GetMapping()
|
||||
public String job()
|
||||
{
|
||||
return prefix + "/job";
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:job:list")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(Job job)
|
||||
{
|
||||
setPageInfo(job);
|
||||
List<Job> list = jobService.selectJobList(job);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@Log(title = "监控管理", action = "定时任务-删除调度")
|
||||
@RequiresPermissions("monitor:job:remove")
|
||||
@RequestMapping("/remove/{jobId}")
|
||||
@ResponseBody
|
||||
public JSON remove(@PathVariable("jobId") Long jobId)
|
||||
{
|
||||
Job job = jobService.selectJobById(jobId);
|
||||
if (job == null)
|
||||
{
|
||||
return JSON.error("调度任务不存在");
|
||||
}
|
||||
if (jobService.deleteJob(job) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
@Log(title = "监控管理", action = "定时任务-批量删除")
|
||||
@RequiresPermissions("monitor:job:batchRemove")
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
jobService.batchDeleteJob(ids);
|
||||
return JSON.ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return JSON.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务调度状态修改
|
||||
*/
|
||||
@Log(title = "监控管理", action = "定时任务-状态修改")
|
||||
@RequiresPermissions("monitor:job:changeStatus")
|
||||
@PostMapping("/changeStatus")
|
||||
@ResponseBody
|
||||
public JSON changeStatus(Job job)
|
||||
{
|
||||
if (jobService.changeStatus(job) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增调度
|
||||
*/
|
||||
@Log(title = "监控管理", action = "定时任务-新增调度")
|
||||
@RequiresPermissions("monitor:job:add")
|
||||
@GetMapping("/add")
|
||||
public String add(Model model)
|
||||
{
|
||||
return prefix + "/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改调度
|
||||
*/
|
||||
@Log(title = "监控管理", action = "定时任务-修改调度")
|
||||
@RequiresPermissions("monitor:job:edit")
|
||||
@GetMapping("/edit/{jobId}")
|
||||
public String edit(@PathVariable("jobId") Long jobId, Model model)
|
||||
{
|
||||
Job job = jobService.selectJobById(jobId);
|
||||
model.addAttribute("job", job);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存调度
|
||||
*/
|
||||
@Log(title = "监控管理", action = "定时任务-保存调度")
|
||||
@RequiresPermissions("monitor:job:save")
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public JSON save(Job job)
|
||||
{
|
||||
if (jobService.saveJobCron(job) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.ruoyi.project.monitor.job.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.monitor.job.domain.JobLog;
|
||||
import com.ruoyi.project.monitor.job.service.IJobLogService;
|
||||
|
||||
/**
|
||||
* 调度日志操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/monitor/jobLog")
|
||||
public class JobLogController extends BaseController
|
||||
{
|
||||
private String prefix = "monitor/job";
|
||||
|
||||
@Autowired
|
||||
private IJobLogService jobLogService;
|
||||
|
||||
@RequiresPermissions("monitor:job:view")
|
||||
@GetMapping()
|
||||
public String jobLog()
|
||||
{
|
||||
return prefix + "/jobLog";
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:job:list")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(JobLog jobLog)
|
||||
{
|
||||
setPageInfo(jobLog);
|
||||
List<JobLog> list = jobLogService.selectJobLogList(jobLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调度日志删除
|
||||
*/
|
||||
@Log(title = "监控管理", action = "定时任务-删除调度日志")
|
||||
@RequiresPermissions("monitor:job:remove")
|
||||
@RequestMapping("/remove/{jobLogId}")
|
||||
@ResponseBody
|
||||
public JSON remove(@PathVariable("jobLogId") Long jobLogId)
|
||||
{
|
||||
JobLog jobLog = jobLogService.selectJobLogById(jobLogId);
|
||||
if (jobLog == null)
|
||||
{
|
||||
return JSON.error("调度任务不存在");
|
||||
}
|
||||
if (jobLogService.deleteJobLogById(jobLogId) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
@Log(title = "监控管理", action = "定时任务-批量删除日志")
|
||||
@RequiresPermissions("monitor:job:batchRemove")
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
jobLogService.batchDeleteJoblog(ids);
|
||||
return JSON.ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return JSON.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.ruoyi.project.monitor.job.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.job.domain.Job;
|
||||
|
||||
/**
|
||||
* 调度任务信息 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IJobDao
|
||||
{
|
||||
|
||||
/**
|
||||
* 查询调度任务日志集合
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 操作日志集合
|
||||
*/
|
||||
public List<Job> selectJobList(Job job);
|
||||
|
||||
/**
|
||||
* 查询所有调度任务
|
||||
*
|
||||
* @return 调度任务列表
|
||||
*/
|
||||
public List<Job> selectJobAll();
|
||||
|
||||
/**
|
||||
* 通过调度ID查询调度任务信息
|
||||
*
|
||||
* @param jobId 调度ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
public Job selectJobById(Long jobId);
|
||||
|
||||
/**
|
||||
* 通过调度ID删除调度任务信息
|
||||
*
|
||||
* @param jobId 调度ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobById(Job job);
|
||||
|
||||
/**
|
||||
* 批量删除调度任务信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchDeleteJob(Long[] ids);
|
||||
|
||||
/**
|
||||
* 修改调度任务信息
|
||||
*
|
||||
* @param job 调度任务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateJob(Job job);
|
||||
|
||||
/**
|
||||
* 新增调度任务信息
|
||||
*
|
||||
* @param job 调度任务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertJob(Job job);
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.ruoyi.project.monitor.job.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.job.domain.JobLog;
|
||||
|
||||
/**
|
||||
* 调度任务日志信息 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IJobLogDao
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取quartz调度器日志的计划任务
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 调度任务日志集合
|
||||
*/
|
||||
public List<JobLog> selectJobLogList(JobLog jobLog);
|
||||
|
||||
/**
|
||||
* 通过调度任务日志ID查询调度信息
|
||||
*
|
||||
* @param jobLogId 调度任务日志ID
|
||||
* @return 调度任务日志对象信息
|
||||
*/
|
||||
public JobLog selectJobLogById(Long jobLogId);
|
||||
|
||||
/**
|
||||
* 新增任务日志
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertJobLog(JobLog jobLog);
|
||||
|
||||
/**
|
||||
* 批量删除调度日志信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchDeleteJobLog(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除任务日志
|
||||
*
|
||||
* @param jobId 调度日志ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobLogById(Long jobId);
|
||||
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package com.ruoyi.project.monitor.job.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.ruoyi.framework.web.page.PageDomain;
|
||||
|
||||
/**
|
||||
* 定时任务调度日志信息 sys_job_log
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class JobLog extends PageDomain
|
||||
{
|
||||
/** ID */
|
||||
private Integer jobLogId;
|
||||
/** 任务名称 */
|
||||
private String jobName;
|
||||
/** 任务组名 */
|
||||
private String jobGroup;
|
||||
/** 任务方法 */
|
||||
private String methodName;
|
||||
/** 方法参数 */
|
||||
private String params;
|
||||
/** 日志信息 */
|
||||
private String jobMessage;
|
||||
/** 是否异常 */
|
||||
private int isException;
|
||||
/** 异常信息 */
|
||||
private String exceptionInfo;
|
||||
/** 创建时间 */
|
||||
private Date createTime;
|
||||
|
||||
public Integer getJobLogId()
|
||||
{
|
||||
return jobLogId;
|
||||
}
|
||||
|
||||
public void setJobLogId(Integer jobLogId)
|
||||
{
|
||||
this.jobLogId = jobLogId;
|
||||
}
|
||||
|
||||
public String getJobName()
|
||||
{
|
||||
return jobName;
|
||||
}
|
||||
|
||||
public void setJobName(String jobName)
|
||||
{
|
||||
this.jobName = jobName;
|
||||
}
|
||||
|
||||
public String getJobGroup()
|
||||
{
|
||||
return jobGroup;
|
||||
}
|
||||
|
||||
public void setJobGroup(String jobGroup)
|
||||
{
|
||||
this.jobGroup = jobGroup;
|
||||
}
|
||||
|
||||
public String getMethodName()
|
||||
{
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName)
|
||||
{
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public String getParams()
|
||||
{
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(String params)
|
||||
{
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public String getJobMessage()
|
||||
{
|
||||
return jobMessage;
|
||||
}
|
||||
|
||||
public void setJobMessage(String jobMessage)
|
||||
{
|
||||
this.jobMessage = jobMessage;
|
||||
}
|
||||
|
||||
public int getIsException()
|
||||
{
|
||||
return isException;
|
||||
}
|
||||
|
||||
public void setIsException(int isException)
|
||||
{
|
||||
this.isException = isException;
|
||||
}
|
||||
|
||||
public String getExceptionInfo()
|
||||
{
|
||||
return exceptionInfo;
|
||||
}
|
||||
|
||||
public void setExceptionInfo(String exceptionInfo)
|
||||
{
|
||||
this.exceptionInfo = exceptionInfo;
|
||||
}
|
||||
|
||||
public Date getCreateTime()
|
||||
{
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime)
|
||||
{
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "JobLog [jobLogId=" + jobLogId + ", jobName=" + jobName + ", jobGroup=" + jobGroup + ", methodName="
|
||||
+ methodName + ", params=" + params + ", jobMessage=" + jobMessage + ", isException=" + isException
|
||||
+ ", exceptionInfo=" + exceptionInfo + ", createTime=" + createTime + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.ruoyi.project.monitor.job.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.job.domain.JobLog;
|
||||
|
||||
/**
|
||||
* 定时任务调度日志信息信息 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IJobLogService
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取quartz调度器日志的计划任务
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 调度任务日志集合
|
||||
*/
|
||||
public List<JobLog> selectJobLogList(JobLog jobLog);
|
||||
|
||||
/**
|
||||
* 通过调度任务日志ID查询调度信息
|
||||
*
|
||||
* @param jobLogId 调度任务日志ID
|
||||
* @return 调度任务日志对象信息
|
||||
*/
|
||||
public JobLog selectJobLogById(Long jobLogId);
|
||||
|
||||
/**
|
||||
* 新增任务日志
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
*/
|
||||
public void addJobLog(JobLog jobLog);
|
||||
|
||||
/**
|
||||
* 批量删除调度日志信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchDeleteJoblog(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除任务日志
|
||||
*
|
||||
* @param jobId 调度日志ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobLogById(Long jobId);
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.ruoyi.project.monitor.job.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.project.monitor.job.dao.IJobLogDao;
|
||||
import com.ruoyi.project.monitor.job.domain.JobLog;
|
||||
|
||||
/**
|
||||
* 定时任务调度日志信息 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service("jobLogService")
|
||||
public class JobLogServiceImpl implements IJobLogService
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private IJobLogDao jobLogDao;
|
||||
|
||||
/**
|
||||
* 获取quartz调度器日志的计划任务
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 调度任务日志集合
|
||||
*/
|
||||
@Override
|
||||
public List<JobLog> selectJobLogList(JobLog jobLog)
|
||||
{
|
||||
return jobLogDao.selectJobLogList(jobLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过调度任务日志ID查询调度信息
|
||||
*
|
||||
* @param jobId 调度任务日志ID
|
||||
* @return 调度任务日志对象信息
|
||||
*/
|
||||
@Override
|
||||
public JobLog selectJobLogById(Long jobLogId)
|
||||
{
|
||||
return jobLogDao.selectJobLogById(jobLogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增任务日志
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
*/
|
||||
@Override
|
||||
public void addJobLog(JobLog jobLog)
|
||||
{
|
||||
jobLogDao.insertJobLog(jobLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除调度日志信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int batchDeleteJoblog(Long[] ids)
|
||||
{
|
||||
return jobLogDao.batchDeleteJobLog(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务日志
|
||||
*
|
||||
* @param jobId 调度日志ID
|
||||
*/
|
||||
@Override
|
||||
public int deleteJobLogById(Long jobId)
|
||||
{
|
||||
return jobLogDao.deleteJobLogById(jobId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.ruoyi.project.monitor.job.task;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 定时任务调度测试
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component("ryTask")
|
||||
public class RyTask
|
||||
{
|
||||
|
||||
public void ryParams(String params)
|
||||
{
|
||||
System.out.println("执行有参方法:" + params);
|
||||
}
|
||||
|
||||
public void ryNoParams()
|
||||
{
|
||||
System.out.println("执行无参方法");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.ruoyi.project.monitor.job.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
|
||||
/**
|
||||
* 执行定时任务
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
public class ScheduleRunnable implements Runnable
|
||||
{
|
||||
private Object target;
|
||||
private Method method;
|
||||
private String params;
|
||||
|
||||
public ScheduleRunnable(String beanName, String methodName, String params)
|
||||
throws NoSuchMethodException, SecurityException
|
||||
{
|
||||
this.target = SpringUtils.getBean(beanName);
|
||||
this.params = params;
|
||||
|
||||
if (StringUtils.isNotEmpty(params))
|
||||
{
|
||||
this.method = target.getClass().getDeclaredMethod(methodName, String.class);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.method = target.getClass().getDeclaredMethod(methodName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
if (StringUtils.isNotEmpty(params))
|
||||
{
|
||||
method.invoke(target, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
method.invoke(target);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
package com.ruoyi.project.monitor.job.util;
|
||||
|
||||
import org.quartz.CronScheduleBuilder;
|
||||
import org.quartz.CronTrigger;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobDetail;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.quartz.TriggerBuilder;
|
||||
import org.quartz.TriggerKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.constant.ScheduleConstants;
|
||||
import com.ruoyi.project.monitor.job.domain.Job;
|
||||
|
||||
/**
|
||||
* 定时任务工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
public class ScheduleUtils
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(ScheduleUtils.class);
|
||||
|
||||
private final static String JOB_NAME = "TASK_";
|
||||
|
||||
/**
|
||||
* 获取触发器key
|
||||
*/
|
||||
public static TriggerKey getTriggerKey(Long jobId)
|
||||
{
|
||||
return TriggerKey.triggerKey(JOB_NAME + jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jobKey
|
||||
*/
|
||||
public static JobKey getJobKey(Long jobId)
|
||||
{
|
||||
return JobKey.jobKey(JOB_NAME + jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表达式触发器
|
||||
*/
|
||||
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建定时任务
|
||||
*/
|
||||
public static void createScheduleJob(Scheduler scheduler, Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(job.getJobId())).build();
|
||||
|
||||
// 表达式调度构建器
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
|
||||
|
||||
// 按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(job.getJobId())).withSchedule(scheduleBuilder).build();
|
||||
|
||||
// 放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(ScheduleConstants.JOB_PARAM_KEY, job);
|
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
|
||||
// 暂停任务
|
||||
if (job.getStatus() == ScheduleConstants.Status.PAUSE.getValue())
|
||||
{
|
||||
pauseJob(scheduler, job.getJobId());
|
||||
}
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*/
|
||||
public static void updateScheduleJob(Scheduler scheduler, Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
TriggerKey triggerKey = getTriggerKey(job.getJobId());
|
||||
|
||||
// 表达式调度构建器
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
|
||||
|
||||
CronTrigger trigger = getCronTrigger(scheduler, job.getJobId());
|
||||
|
||||
// 按新的cronExpression表达式重新构建trigger
|
||||
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
||||
|
||||
// 参数
|
||||
trigger.getJobDataMap().put(ScheduleConstants.JOB_PARAM_KEY, job);
|
||||
|
||||
scheduler.rescheduleJob(triggerKey, trigger);
|
||||
|
||||
// 暂停任务
|
||||
if (job.getStatus() == ScheduleConstants.Status.PAUSE.getValue())
|
||||
{
|
||||
pauseJob(scheduler, job.getJobId());
|
||||
}
|
||||
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即执行任务
|
||||
*/
|
||||
public static void run(Scheduler scheduler, Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 参数
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put(ScheduleConstants.JOB_PARAM_KEY, job);
|
||||
|
||||
scheduler.triggerJob(getJobKey(job.getJobId()), dataMap);
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*/
|
||||
public static void pauseJob(Scheduler scheduler, Long jobId)
|
||||
{
|
||||
try
|
||||
{
|
||||
scheduler.pauseJob(getJobKey(jobId));
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复任务
|
||||
*/
|
||||
public static void resumeJob(Scheduler scheduler, Long jobId)
|
||||
{
|
||||
try
|
||||
{
|
||||
scheduler.resumeJob(getJobKey(jobId));
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*/
|
||||
public static void deleteScheduleJob(Scheduler scheduler, Long jobId)
|
||||
{
|
||||
try
|
||||
{
|
||||
scheduler.deleteJob(getJobKey(jobId));
|
||||
}
|
||||
catch (SchedulerException e)
|
||||
{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.ruoyi.project.monitor.logininfor.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.monitor.logininfor.domain.Logininfor;
|
||||
import com.ruoyi.project.monitor.logininfor.service.ILogininforService;
|
||||
|
||||
/**
|
||||
* 系统访问记录
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/monitor/logininfor")
|
||||
public class LogininforController extends BaseController
|
||||
{
|
||||
private String prefix = "monitor/logininfor";
|
||||
|
||||
@Autowired
|
||||
private ILogininforService logininforService;
|
||||
|
||||
@RequiresPermissions("monitor:logininfor:view")
|
||||
@GetMapping()
|
||||
public String logininfor()
|
||||
{
|
||||
return prefix + "/logininfor";
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:logininfor:list")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(Logininfor logininfor)
|
||||
{
|
||||
setPageInfo(logininfor);
|
||||
List<Logininfor> list = logininforService.selectLogininforList(logininfor);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:logininfor:batchRemove")
|
||||
@Log(title = "监控管理", action = "登录日志-批量删除")
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
|
||||
{
|
||||
int rows = logininforService.batchDeleteLogininfor(ids);
|
||||
if (rows > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.ruoyi.project.monitor.logininfor.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.logininfor.domain.Logininfor;
|
||||
|
||||
/**
|
||||
* 系统访问日志情况信息 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ILogininforDao
|
||||
{
|
||||
/**
|
||||
* 新增系统登录日志
|
||||
*
|
||||
* @param logininfor 访问日志对象
|
||||
*/
|
||||
public void insertLogininfor(Logininfor logininfor);
|
||||
|
||||
/**
|
||||
* 查询系统登录日志集合
|
||||
*
|
||||
* @param logininfor 访问日志对象
|
||||
* @return 登录记录集合
|
||||
*/
|
||||
public List<Logininfor> selectLogininforList(Logininfor logininfor);
|
||||
|
||||
/**
|
||||
* 批量删除系统登录日志
|
||||
*
|
||||
* @param ids 需要删除的数据
|
||||
* @return
|
||||
*/
|
||||
public int batchDeleteLogininfor(Long[] ids);
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.ruoyi.project.monitor.logininfor.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.ruoyi.framework.web.page.PageDomain;
|
||||
|
||||
/**
|
||||
* 系统访问日志情况信息 sys_logininfor
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class Logininfor extends PageDomain
|
||||
{
|
||||
/** ID */
|
||||
private Integer infoId;
|
||||
/** 用户账号 */
|
||||
private String loginName;
|
||||
/** 登录状态 0成功 1失败 */
|
||||
private String status;
|
||||
/** 登录IP地址 */
|
||||
private String ipaddr;
|
||||
/** 浏览器类型 */
|
||||
private String browser;
|
||||
/** 操作系统 */
|
||||
private String os;
|
||||
/** 提示消息 */
|
||||
private String msg;
|
||||
/** 访问时间 */
|
||||
private Date loginTime;
|
||||
|
||||
public Integer getInfoId()
|
||||
{
|
||||
return infoId;
|
||||
}
|
||||
|
||||
public void setInfoId(Integer infoId)
|
||||
{
|
||||
this.infoId = infoId;
|
||||
}
|
||||
|
||||
public String getLoginName()
|
||||
{
|
||||
return loginName;
|
||||
}
|
||||
|
||||
public void setLoginName(String loginName)
|
||||
{
|
||||
this.loginName = loginName;
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getIpaddr()
|
||||
{
|
||||
return ipaddr;
|
||||
}
|
||||
|
||||
public void setIpaddr(String ipaddr)
|
||||
{
|
||||
this.ipaddr = ipaddr;
|
||||
}
|
||||
|
||||
public String getBrowser()
|
||||
{
|
||||
return browser;
|
||||
}
|
||||
|
||||
public void setBrowser(String browser)
|
||||
{
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public String getOs()
|
||||
{
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setOs(String os)
|
||||
{
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public String getMsg()
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg)
|
||||
{
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Date getLoginTime()
|
||||
{
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime(Date loginTime)
|
||||
{
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Logininfor [infoId=" + infoId + ", loginName=" + loginName + ", status=" + status + ", ipaddr=" + ipaddr
|
||||
+ ", browser=" + browser + ", os=" + os + ", msg=" + msg + ", loginTime=" + loginTime + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.ruoyi.project.monitor.logininfor.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.logininfor.domain.Logininfor;
|
||||
|
||||
/**
|
||||
* 系统访问日志情况信息 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ILogininforService
|
||||
{
|
||||
|
||||
/**
|
||||
* 新增系统登录日志
|
||||
*
|
||||
* @param logininfor 访问日志对象
|
||||
*/
|
||||
public void insertLogininfor(Logininfor logininfor);
|
||||
|
||||
/**
|
||||
* 查询系统登录日志集合
|
||||
*
|
||||
* @param logininfor 访问日志对象
|
||||
* @return 登录记录集合
|
||||
*/
|
||||
public List<Logininfor> selectLogininforList(Logininfor logininfor);
|
||||
|
||||
/**
|
||||
* 批量删除系统登录日志
|
||||
*
|
||||
* @param ids 需要删除的数据
|
||||
* @return
|
||||
*/
|
||||
public int batchDeleteLogininfor(Long[] ids);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.ruoyi.project.monitor.logininfor.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.project.monitor.logininfor.dao.ILogininforDao;
|
||||
import com.ruoyi.project.monitor.logininfor.domain.Logininfor;
|
||||
|
||||
/**
|
||||
* 系统访问日志情况信息 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service("logininforService")
|
||||
public class LogininforServiceImpl implements ILogininforService
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private ILogininforDao logininforDao;
|
||||
|
||||
/**
|
||||
* 新增系统登录日志
|
||||
*
|
||||
* @param logininfor 访问日志对象
|
||||
*/
|
||||
@Override
|
||||
public void insertLogininfor(Logininfor logininfor)
|
||||
{
|
||||
logininforDao.insertLogininfor(logininfor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统登录日志集合
|
||||
*
|
||||
* @param logininfor 访问日志对象
|
||||
* @return 登录记录集合
|
||||
*/
|
||||
@Override
|
||||
public List<Logininfor> selectLogininforList(Logininfor logininfor)
|
||||
{
|
||||
return logininforDao.selectLogininforList(logininfor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除系统登录日志
|
||||
*
|
||||
* @param ids 需要删除的数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int batchDeleteLogininfor(Long[] ids)
|
||||
{
|
||||
return logininforDao.batchDeleteLogininfor(ids);
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.ruoyi.project.monitor.online.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.monitor.online.domain.OnlineSession;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
import com.ruoyi.project.monitor.online.service.IUserOnlineService;
|
||||
|
||||
/**
|
||||
* 在线用户监控
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/monitor/online")
|
||||
public class UserOnlineController extends BaseController
|
||||
{
|
||||
private String prefix = "monitor/online";
|
||||
|
||||
@Autowired
|
||||
private IUserOnlineService userOnlineService;
|
||||
|
||||
@Autowired
|
||||
private OnlineSessionDAO onlineSessionDAO;
|
||||
|
||||
@RequiresPermissions("monitor:online:view")
|
||||
@GetMapping()
|
||||
public String online()
|
||||
{
|
||||
return prefix + "/online";
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:online:list")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(UserOnline userOnline)
|
||||
{
|
||||
setPageInfo(userOnline);
|
||||
List<UserOnline> list = userOnlineService.selectUserOnlineList(userOnline);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:online:batchForceLogout")
|
||||
@Log(title = "监控管理", action = "在线用户-批量强退用户")
|
||||
@PostMapping("/batchForceLogout")
|
||||
@ResponseBody
|
||||
public JSON batchForceLogout(@RequestParam("ids[]") String[] ids)
|
||||
{
|
||||
for (String sessionId : ids)
|
||||
{
|
||||
UserOnline online = userOnlineService.selectOnlineById(sessionId);
|
||||
if (online == null)
|
||||
{
|
||||
return JSON.error("用户已下线");
|
||||
}
|
||||
OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
|
||||
if (onlineSession == null)
|
||||
{
|
||||
return JSON.error("用户已下线");
|
||||
}
|
||||
onlineSession.setStatus(OnlineSession.OnlineStatus.off_line);
|
||||
online.setStatus(OnlineSession.OnlineStatus.off_line);
|
||||
userOnlineService.saveOnline(online);
|
||||
}
|
||||
return JSON.ok();
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:online:forceLogout")
|
||||
@Log(title = "监控管理", action = "在线用户-强退用户")
|
||||
@RequestMapping("/forceLogout/{sessionId}")
|
||||
@ResponseBody
|
||||
public JSON forceLogout(@PathVariable("sessionId") String sessionId)
|
||||
{
|
||||
UserOnline online = userOnlineService.selectOnlineById(sessionId);
|
||||
if (online == null)
|
||||
{
|
||||
return JSON.error("用户已下线");
|
||||
}
|
||||
OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
|
||||
if (onlineSession == null)
|
||||
{
|
||||
return JSON.error("用户已下线");
|
||||
}
|
||||
onlineSession.setStatus(OnlineSession.OnlineStatus.off_line);
|
||||
online.setStatus(OnlineSession.OnlineStatus.off_line);
|
||||
userOnlineService.saveOnline(online);
|
||||
return JSON.ok();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.ruoyi.project.monitor.online.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
|
||||
/**
|
||||
* 在线用户 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IUserOnlineDao
|
||||
{
|
||||
/**
|
||||
* 通过会话序号查询信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public UserOnline selectOnlineById(String sessionId);
|
||||
|
||||
/**
|
||||
* 通过会话序号删除信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public int deleteOnlineById(String sessionId);
|
||||
|
||||
/**
|
||||
* 保存会话信息
|
||||
*
|
||||
* @param online 会话信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int saveOnline(UserOnline online);
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param userOnline 会话参数
|
||||
* @return 会话集合
|
||||
*/
|
||||
public List<UserOnline> selectUserOnlineList(UserOnline userOnline);
|
||||
|
||||
/**
|
||||
* 查询过期会话集合
|
||||
*
|
||||
* @param lastAccessTime 过期时间
|
||||
* @return 会话集合
|
||||
*/
|
||||
public List<UserOnline> selectOnlineByExpired(String lastAccessTime);
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
package com.ruoyi.project.monitor.online.domain;
|
||||
|
||||
import org.apache.shiro.session.mgt.SimpleSession;
|
||||
|
||||
/**
|
||||
* 在线用户会话属性
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class OnlineSession extends SimpleSession
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 用户ID */
|
||||
private Long userId;
|
||||
|
||||
/** 用户名称 */
|
||||
private String loginName;
|
||||
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
|
||||
/** 登录IP地址 */
|
||||
private String host;
|
||||
|
||||
/** 浏览器类型 */
|
||||
private String browser;
|
||||
|
||||
/** 操作系统 */
|
||||
private String os;
|
||||
|
||||
/** 在线状态 */
|
||||
private OnlineStatus status = OnlineStatus.on_line;
|
||||
|
||||
/** 属性是否改变 优化session数据同步 */
|
||||
private transient boolean attributeChanged = false;
|
||||
|
||||
@Override
|
||||
public String getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHost(String host)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getBrowser()
|
||||
{
|
||||
return browser;
|
||||
}
|
||||
|
||||
public void setBrowser(String browser)
|
||||
{
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public String getOs()
|
||||
{
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setOs(String os)
|
||||
{
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getLoginName()
|
||||
{
|
||||
return loginName;
|
||||
}
|
||||
|
||||
public void setLoginName(String loginName)
|
||||
{
|
||||
this.loginName = loginName;
|
||||
}
|
||||
|
||||
public String getDeptName()
|
||||
{
|
||||
return deptName;
|
||||
}
|
||||
|
||||
public void setDeptName(String deptName)
|
||||
{
|
||||
this.deptName = deptName;
|
||||
}
|
||||
|
||||
public OnlineStatus getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(OnlineStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void markAttributeChanged()
|
||||
{
|
||||
this.attributeChanged = true;
|
||||
}
|
||||
|
||||
public void resetAttributeChanged()
|
||||
{
|
||||
this.attributeChanged = false;
|
||||
}
|
||||
|
||||
public boolean isAttributeChanged()
|
||||
{
|
||||
return attributeChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(Object key, Object value)
|
||||
{
|
||||
super.setAttribute(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object removeAttribute(Object key)
|
||||
{
|
||||
return super.removeAttribute(key);
|
||||
}
|
||||
|
||||
public static enum OnlineStatus
|
||||
{
|
||||
/** 用户状态 */
|
||||
on_line("在线"), off_line("离线");
|
||||
private final String info;
|
||||
|
||||
private OnlineStatus(String info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
package com.ruoyi.project.monitor.online.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.ruoyi.framework.web.page.PageDomain;
|
||||
import com.ruoyi.project.monitor.online.domain.OnlineSession.OnlineStatus;
|
||||
|
||||
/**
|
||||
* 当前在线会话 sys_user_online
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserOnline extends PageDomain
|
||||
{
|
||||
/** 用户会话id */
|
||||
private String sessionId;
|
||||
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
|
||||
/** 登录名称 */
|
||||
private String loginName;
|
||||
|
||||
/** 登录IP地址 */
|
||||
private String ipaddr;
|
||||
|
||||
/** 浏览器类型 */
|
||||
private String browser;
|
||||
|
||||
/** 操作系统 */
|
||||
private String os;
|
||||
|
||||
/** session创建时间 */
|
||||
private Date startTimestamp;
|
||||
|
||||
/** session最后访问时间 */
|
||||
private Date lastAccessTime;
|
||||
|
||||
/** 超时时间,单位为分钟 */
|
||||
private Long expireTime;
|
||||
|
||||
/** 在线状态 */
|
||||
private OnlineStatus status = OnlineStatus.on_line;
|
||||
|
||||
/** 备份的当前用户会话 */
|
||||
private OnlineSession session;
|
||||
|
||||
/**
|
||||
* 设置session对象
|
||||
*/
|
||||
public static final UserOnline fromOnlineSession(OnlineSession session)
|
||||
{
|
||||
UserOnline online = new UserOnline();
|
||||
online.setSessionId(String.valueOf(session.getId()));
|
||||
online.setDeptName(session.getDeptName());
|
||||
online.setLoginName(session.getLoginName());
|
||||
online.setStartTimestamp(session.getStartTimestamp());
|
||||
online.setLastAccessTime(session.getLastAccessTime());
|
||||
online.setExpireTime(session.getTimeout());
|
||||
online.setIpaddr(session.getHost());
|
||||
online.setBrowser(session.getBrowser());
|
||||
online.setOs(session.getOs());
|
||||
online.setStatus(session.getStatus());
|
||||
online.setSession(session);
|
||||
return online;
|
||||
}
|
||||
|
||||
public String getSessionId()
|
||||
{
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(String sessionId)
|
||||
{
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public String getDeptName()
|
||||
{
|
||||
return deptName;
|
||||
}
|
||||
|
||||
public void setDeptName(String deptName)
|
||||
{
|
||||
this.deptName = deptName;
|
||||
}
|
||||
|
||||
public String getLoginName()
|
||||
{
|
||||
return loginName;
|
||||
}
|
||||
|
||||
public void setLoginName(String loginName)
|
||||
{
|
||||
this.loginName = loginName;
|
||||
}
|
||||
|
||||
public String getIpaddr()
|
||||
{
|
||||
return ipaddr;
|
||||
}
|
||||
|
||||
public void setIpaddr(String ipaddr)
|
||||
{
|
||||
this.ipaddr = ipaddr;
|
||||
}
|
||||
|
||||
public String getBrowser()
|
||||
{
|
||||
return browser;
|
||||
}
|
||||
|
||||
public void setBrowser(String browser)
|
||||
{
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public String getOs()
|
||||
{
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setOs(String os)
|
||||
{
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public Date getStartTimestamp()
|
||||
{
|
||||
return startTimestamp;
|
||||
}
|
||||
|
||||
public void setStartTimestamp(Date startTimestamp)
|
||||
{
|
||||
this.startTimestamp = startTimestamp;
|
||||
}
|
||||
|
||||
public Date getLastAccessTime()
|
||||
{
|
||||
return lastAccessTime;
|
||||
}
|
||||
|
||||
public void setLastAccessTime(Date lastAccessTime)
|
||||
{
|
||||
this.lastAccessTime = lastAccessTime;
|
||||
}
|
||||
|
||||
public Long getExpireTime()
|
||||
{
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime(Long expireTime)
|
||||
{
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public OnlineStatus getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(OnlineStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public OnlineSession getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(OnlineSession session)
|
||||
{
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "UserOnline [sessionId=" + sessionId + ", deptName=" + deptName + ", loginName=" + loginName
|
||||
+ ", ipaddr=" + ipaddr + ", browser=" + browser + ", os=" + os + ", startTimestamp=" + startTimestamp
|
||||
+ ", lastAccessTime=" + lastAccessTime + ", expireTime=" + expireTime + ", status=" + status
|
||||
+ ", session=" + session + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.ruoyi.project.monitor.online.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
|
||||
/**
|
||||
* 在线用户 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IUserOnlineService
|
||||
{
|
||||
/**
|
||||
* 通过会话序号查询信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public UserOnline selectOnlineById(String sessionId);
|
||||
|
||||
/**
|
||||
* 通过会话序号删除信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public void deleteOnlineById(String sessionId);
|
||||
|
||||
/**
|
||||
* 通过会话序号删除信息
|
||||
*
|
||||
* @param sessions 会话ID集合
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public void batchDeleteOnline(List<String> sessions);
|
||||
|
||||
/**
|
||||
* 保存会话信息
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
public void saveOnline(UserOnline online);
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param userOnline 分页参数
|
||||
* @return 会话集合
|
||||
*/
|
||||
public List<UserOnline> selectUserOnlineList(UserOnline userOnline);
|
||||
|
||||
/**
|
||||
* 强退用户
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
public void forceLogout(String sessionId);
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param expiredDate 有效期
|
||||
* @return 会话集合
|
||||
*/
|
||||
public List<UserOnline> selectOnlineByExpired(Date expiredDate);
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package com.ruoyi.project.monitor.online.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
||||
import com.ruoyi.project.monitor.online.dao.IUserOnlineDao;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
|
||||
/**
|
||||
* 在线用户 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service("userOnlineService")
|
||||
public class UserOnlineServiceImpl implements IUserOnlineService
|
||||
{
|
||||
@Autowired
|
||||
private IUserOnlineDao userOnlineDao;
|
||||
|
||||
@Autowired
|
||||
private OnlineSessionDAO onlineSessionDAO;
|
||||
|
||||
/**
|
||||
* 通过会话序号查询信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public UserOnline selectOnlineById(String sessionId)
|
||||
{
|
||||
return userOnlineDao.selectOnlineById(sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过会话序号删除信息
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public void deleteOnlineById(String sessionId)
|
||||
{
|
||||
UserOnline userOnline = selectOnlineById(sessionId);
|
||||
if (userOnline != null)
|
||||
{
|
||||
userOnlineDao.deleteOnlineById(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过会话序号删除信息
|
||||
*
|
||||
* @param sessions 会话ID集合
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public void batchDeleteOnline(List<String> sessions)
|
||||
{
|
||||
for (String sessionId : sessions)
|
||||
{
|
||||
UserOnline userOnline = selectOnlineById(sessionId);
|
||||
if (userOnline != null)
|
||||
{
|
||||
userOnlineDao.deleteOnlineById(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存会话信息
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
@Override
|
||||
public void saveOnline(UserOnline online)
|
||||
{
|
||||
userOnlineDao.saveOnline(online);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param pageUtilEntity 分页参数
|
||||
*/
|
||||
@Override
|
||||
public List<UserOnline> selectUserOnlineList(UserOnline userOnline)
|
||||
{
|
||||
return userOnlineDao.selectUserOnlineList(userOnline);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强退用户
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
@Override
|
||||
public void forceLogout(String sessionId)
|
||||
{
|
||||
Session session = onlineSessionDAO.readSession(sessionId);
|
||||
if (session == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
session.setTimeout(1000);
|
||||
userOnlineDao.deleteOnlineById(sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会话集合
|
||||
*
|
||||
* @param online 会话信息
|
||||
*/
|
||||
@Override
|
||||
public List<UserOnline> selectOnlineByExpired(Date expiredDate)
|
||||
{
|
||||
String lastAccessTime = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", expiredDate);
|
||||
return userOnlineDao.selectOnlineByExpired(lastAccessTime);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.ruoyi.project.monitor.operlog.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.monitor.operlog.domain.OperLog;
|
||||
import com.ruoyi.project.monitor.operlog.service.IOperLogService;
|
||||
|
||||
/**
|
||||
* 操作日志记录
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/monitor/operlog")
|
||||
public class OperlogController extends BaseController
|
||||
{
|
||||
private String prefix = "monitor/operlog";
|
||||
|
||||
@Autowired
|
||||
private IOperLogService operLogService;
|
||||
|
||||
@RequiresPermissions("monitor:operlog:view")
|
||||
@GetMapping()
|
||||
public String operlog()
|
||||
{
|
||||
return prefix + "/operlog";
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:operlog:list")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(OperLog operLog)
|
||||
{
|
||||
setPageInfo(operLog);
|
||||
List<OperLog> list = operLogService.selectOperLogList(operLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:operlog:batchRemove")
|
||||
@Log(title = "监控管理", action = "操作日志-批量删除")
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
|
||||
{
|
||||
int rows = operLogService.batchDeleteOperLog(ids);
|
||||
if (rows > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
@RequiresPermissions("monitor:operlog:detail")
|
||||
@GetMapping("/detail/{operId}")
|
||||
public String detail(@PathVariable("operId") Long deptId, Model model)
|
||||
{
|
||||
OperLog operLog = operLogService.selectOperLogById(deptId);
|
||||
model.addAttribute("operLog", operLog);
|
||||
return prefix + "/detail";
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.ruoyi.project.monitor.operlog.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.operlog.domain.OperLog;
|
||||
|
||||
/**
|
||||
* 操作日志 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IOperLogDao
|
||||
{
|
||||
/**
|
||||
* 新增操作日志
|
||||
*
|
||||
* @param operLog 操作日志对象
|
||||
*/
|
||||
public void insertOperlog(OperLog operLog);
|
||||
|
||||
/**
|
||||
* 查询系统操作日志集合
|
||||
*
|
||||
* @param operLog 操作日志对象
|
||||
* @return 操作日志集合
|
||||
*/
|
||||
public List<OperLog> selectOperLogList(OperLog operLog);
|
||||
|
||||
/**
|
||||
* 批量删除系统操作日志
|
||||
*
|
||||
* @param ids 需要删除的数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchDeleteOperLog(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询操作日志详细
|
||||
*
|
||||
* @param operId 操作ID
|
||||
* @return 操作日志对象
|
||||
*/
|
||||
public OperLog selectOperLogById(Long operId);
|
||||
}
|
@ -0,0 +1,179 @@
|
||||
package com.ruoyi.project.monitor.operlog.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import com.ruoyi.framework.web.page.PageDomain;
|
||||
|
||||
/**
|
||||
* 操作日志记录 oper_log
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class OperLog extends PageDomain
|
||||
{
|
||||
/** 日志主键 */
|
||||
private Integer operId;
|
||||
/** 模块标题 */
|
||||
private String title;
|
||||
/** 功能请求 */
|
||||
private String action;
|
||||
/** 请求方法 */
|
||||
private String method;
|
||||
/** 来源渠道 */
|
||||
private String channel;
|
||||
/** 操作员名称 */
|
||||
private String loginName;
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
/** 请求url */
|
||||
private String operUrl;
|
||||
/** 操作地址 */
|
||||
private String operIp;
|
||||
/** 请求参数 */
|
||||
private String operParam;
|
||||
/** 状态0正常 1异常 */
|
||||
private int status;
|
||||
/** 错误消息 */
|
||||
private String errorMsg;
|
||||
/** 操作时间 */
|
||||
private Date operTime;
|
||||
|
||||
public Integer getOperId()
|
||||
{
|
||||
return operId;
|
||||
}
|
||||
|
||||
public void setOperId(Integer operId)
|
||||
{
|
||||
this.operId = operId;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAction()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action)
|
||||
{
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method)
|
||||
{
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getChannel()
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(String channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public String getLoginName()
|
||||
{
|
||||
return loginName;
|
||||
}
|
||||
|
||||
public void setLoginName(String loginName)
|
||||
{
|
||||
this.loginName = loginName;
|
||||
}
|
||||
|
||||
public String getDeptName()
|
||||
{
|
||||
return deptName;
|
||||
}
|
||||
|
||||
public void setDeptName(String deptName)
|
||||
{
|
||||
this.deptName = deptName;
|
||||
}
|
||||
|
||||
public String getOperUrl()
|
||||
{
|
||||
return operUrl;
|
||||
}
|
||||
|
||||
public void setOperUrl(String operUrl)
|
||||
{
|
||||
this.operUrl = operUrl;
|
||||
}
|
||||
|
||||
public String getOperIp()
|
||||
{
|
||||
return operIp;
|
||||
}
|
||||
|
||||
public void setOperIp(String operIp)
|
||||
{
|
||||
this.operIp = operIp;
|
||||
}
|
||||
|
||||
public String getOperParam()
|
||||
{
|
||||
return operParam;
|
||||
}
|
||||
|
||||
public void setOperParam(String operParam)
|
||||
{
|
||||
this.operParam = operParam;
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getErrorMsg()
|
||||
{
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg)
|
||||
{
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public Date getOperTime()
|
||||
{
|
||||
return operTime;
|
||||
}
|
||||
|
||||
public void setOperTime(Date operTime)
|
||||
{
|
||||
this.operTime = operTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "OperLog [operId=" + operId + ", title=" + title + ", action=" + action + ", method=" + method
|
||||
+ ", channel=" + channel + ", loginName=" + loginName + ", deptName=" + deptName + ", operUrl="
|
||||
+ operUrl + ", operIp=" + operIp + ", operParam=" + operParam + ", status=" + status + ", errorMsg="
|
||||
+ errorMsg + ", operTime=" + operTime + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.ruoyi.project.monitor.operlog.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.monitor.operlog.domain.OperLog;
|
||||
|
||||
/**
|
||||
* 操作日志 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IOperLogService
|
||||
{
|
||||
/**
|
||||
* 新增操作日志
|
||||
*
|
||||
* @param operLog 操作日志对象
|
||||
*/
|
||||
public void insertOperlog(OperLog operLog);
|
||||
|
||||
/**
|
||||
* 查询系统操作日志集合
|
||||
*
|
||||
* @param operLog 操作日志对象
|
||||
* @return 操作日志集合
|
||||
*/
|
||||
public List<OperLog> selectOperLogList(OperLog operLog);
|
||||
|
||||
/**
|
||||
* 批量删除系统操作日志
|
||||
*
|
||||
* @param ids 需要删除的数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchDeleteOperLog(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询操作日志详细
|
||||
*
|
||||
* @param operId 操作ID
|
||||
* @return 操作日志对象
|
||||
*/
|
||||
public OperLog selectOperLogById(Long operId);
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.ruoyi.project.monitor.operlog.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.project.monitor.operlog.dao.IOperLogDao;
|
||||
import com.ruoyi.project.monitor.operlog.domain.OperLog;
|
||||
|
||||
/**
|
||||
* 操作日志 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service("operLogService")
|
||||
public class OperLogServiceImpl implements IOperLogService
|
||||
{
|
||||
@Autowired
|
||||
private IOperLogDao operLogDao;
|
||||
|
||||
/**
|
||||
* 新增操作日志
|
||||
*
|
||||
* @param operLog 操作日志对象
|
||||
*/
|
||||
@Override
|
||||
public void insertOperlog(OperLog operLog)
|
||||
{
|
||||
operLogDao.insertOperlog(operLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统操作日志集合
|
||||
*
|
||||
* @param operLog 操作日志对象
|
||||
* @return 操作日志集合
|
||||
*/
|
||||
@Override
|
||||
public List<OperLog> selectOperLogList(OperLog operLog)
|
||||
{
|
||||
return operLogDao.selectOperLogList(operLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除系统操作日志
|
||||
*
|
||||
* @param ids 需要删除的数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int batchDeleteOperLog(Long[] ids)
|
||||
{
|
||||
return operLogDao.batchDeleteOperLog(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询操作日志详细
|
||||
*
|
||||
* @param operId 操作ID
|
||||
* @return 操作日志对象
|
||||
*/
|
||||
@Override
|
||||
public OperLog selectOperLogById(Long operId)
|
||||
{
|
||||
return operLogDao.selectOperLogById(operId);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package com.ruoyi.project.system.dept.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.project.system.dept.domain.Dept;
|
||||
import com.ruoyi.project.system.dept.service.IDeptService;
|
||||
|
||||
/**
|
||||
* 部门信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/system/dept")
|
||||
public class DeptController
|
||||
{
|
||||
private String prefix = "system/dept";
|
||||
|
||||
@Autowired
|
||||
private IDeptService deptService;
|
||||
|
||||
@RequiresPermissions("system:dept:view")
|
||||
@GetMapping()
|
||||
public String dept()
|
||||
{
|
||||
return prefix + "/dept";
|
||||
}
|
||||
|
||||
@RequiresPermissions("system:dept:list")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public List<Dept> list()
|
||||
{
|
||||
List<Dept> deptList = deptService.selectDeptAll();
|
||||
return deptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@Log(title = "系统管理", action = "部门管理-修改部门")
|
||||
@RequiresPermissions("system:dept:edit")
|
||||
@GetMapping("/edit/{deptId}")
|
||||
public String edit(@PathVariable("deptId") Long deptId, Model model)
|
||||
{
|
||||
Dept dept = deptService.selectDeptById(deptId);
|
||||
model.addAttribute("dept", dept);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@Log(title = "系统管理", action = "部门管理-新增部门")
|
||||
@RequiresPermissions("system:dept:add")
|
||||
@GetMapping("/add/{parentId}")
|
||||
public String add(@PathVariable("parentId") Long parentId, Model model)
|
||||
{
|
||||
Dept dept = deptService.selectDeptById(parentId);
|
||||
model.addAttribute("dept", dept);
|
||||
return prefix + "/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@Log(title = "系统管理", action = "部门管理-保存部门")
|
||||
@RequiresPermissions("system:dept:save")
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public JSON save(Dept dept)
|
||||
{
|
||||
if (deptService.saveDept(dept) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@Log(title = "系统管理", action = "部门管理-删除部门")
|
||||
@RequiresPermissions("system:dept:remove")
|
||||
@GetMapping("/remove/{deptId}")
|
||||
@ResponseBody
|
||||
public JSON remove(@PathVariable("deptId") Long deptId)
|
||||
{
|
||||
if (deptService.selectDeptCount(deptId) > 0)
|
||||
{
|
||||
return JSON.error(1, "存在下级部门,不允许删除");
|
||||
}
|
||||
|
||||
if (deptService.checkDeptExistUser(deptId))
|
||||
{
|
||||
return JSON.error(1, "部门存在用户,不允许删除");
|
||||
}
|
||||
if (deptService.deleteDeptById(deptId) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验部门名称
|
||||
*/
|
||||
@PostMapping("/checkDeptNameUnique")
|
||||
@ResponseBody
|
||||
public String checkDeptNameUnique(Dept dept)
|
||||
{
|
||||
String uniqueFlag = "0";
|
||||
if (dept != null)
|
||||
{
|
||||
uniqueFlag = deptService.checkDeptNameUnique(dept);
|
||||
}
|
||||
return uniqueFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择部门树
|
||||
*/
|
||||
@GetMapping("/selectDeptTree/{deptId}")
|
||||
public String selectDeptTree(@PathVariable("deptId") Long deptId, Model model)
|
||||
{
|
||||
model.addAttribute("treeName", deptService.selectDeptById(deptId).getDeptName());
|
||||
return prefix + "/tree";
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载部门列表树
|
||||
*/
|
||||
@GetMapping("/treeData")
|
||||
@ResponseBody
|
||||
public List<Map<String, Object>> treeData()
|
||||
{
|
||||
List<Map<String, Object>> tree = deptService.selectDeptTree();
|
||||
return tree;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.ruoyi.project.system.dept.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.project.system.dept.domain.Dept;
|
||||
|
||||
/**
|
||||
* 部门管理 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IDeptDao
|
||||
{
|
||||
/**
|
||||
* 查询部门人数
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int selectDeptCount(Dept dept);
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int checkDeptExistUser(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询部门管理集合
|
||||
*
|
||||
* @return 所有部门信息
|
||||
*/
|
||||
public List<Dept> selectDeptAll();
|
||||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 新增部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDept(Dept dept);
|
||||
|
||||
/**
|
||||
* 修改部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDept(Dept dept);
|
||||
|
||||
/**
|
||||
* 根据部门ID查询信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
public Dept selectDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @return 结果
|
||||
*/
|
||||
public Dept checkDeptNameUnique(String deptName);
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
package com.ruoyi.project.system.dept.domain;
|
||||
|
||||
/**
|
||||
* 部门对象 sys_dept
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class Dept
|
||||
{
|
||||
/** 部门ID */
|
||||
private Long deptId;
|
||||
/** 父部门ID */
|
||||
private Long parentId;
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
/** 显示顺序 */
|
||||
private String orderNum;
|
||||
/** 负责人 */
|
||||
private String leader;
|
||||
/** 联系电话 */
|
||||
private String phone;
|
||||
/** 邮箱 */
|
||||
private String email;
|
||||
/** 部门状态:0正常,1停用 */
|
||||
private int status;
|
||||
/** 父部门名称 */
|
||||
private String parentName;
|
||||
/** 创建者 */
|
||||
private String createBy;
|
||||
/** 创建时间 */
|
||||
private String createTime;
|
||||
/** 更新者 */
|
||||
private String updateBy;
|
||||
/** 更新时间 */
|
||||
private String updateTime;
|
||||
|
||||
public Long getDeptId()
|
||||
{
|
||||
return deptId;
|
||||
}
|
||||
|
||||
public void setDeptId(Long deptId)
|
||||
{
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
public Long getParentId()
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(Long parentId)
|
||||
{
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getDeptName()
|
||||
{
|
||||
return deptName;
|
||||
}
|
||||
|
||||
public void setDeptName(String deptName)
|
||||
{
|
||||
this.deptName = deptName;
|
||||
}
|
||||
|
||||
public String getOrderNum()
|
||||
{
|
||||
return orderNum;
|
||||
}
|
||||
|
||||
public void setOrderNum(String orderNum)
|
||||
{
|
||||
this.orderNum = orderNum;
|
||||
}
|
||||
|
||||
public String getLeader()
|
||||
{
|
||||
return leader;
|
||||
}
|
||||
|
||||
public void setLeader(String leader)
|
||||
{
|
||||
this.leader = leader;
|
||||
}
|
||||
|
||||
public String getPhone()
|
||||
{
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone)
|
||||
{
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email)
|
||||
{
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getParentName()
|
||||
{
|
||||
return parentName;
|
||||
}
|
||||
|
||||
public void setParentName(String parentName)
|
||||
{
|
||||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
public String getCreateBy()
|
||||
{
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(String createBy)
|
||||
{
|
||||
this.createBy = createBy;
|
||||
}
|
||||
|
||||
public String getCreateTime()
|
||||
{
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime)
|
||||
{
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getUpdateBy()
|
||||
{
|
||||
return updateBy;
|
||||
}
|
||||
|
||||
public void setUpdateBy(String updateBy)
|
||||
{
|
||||
this.updateBy = updateBy;
|
||||
}
|
||||
|
||||
public String getUpdateTime()
|
||||
{
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime)
|
||||
{
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Dept [deptId=" + deptId + ", parentId=" + parentId + ", deptName=" + deptName + ", orderNum=" + orderNum
|
||||
+ ", leader=" + leader + ", phone=" + phone + ", email=" + email + ", status=" + status
|
||||
+ ", parentName=" + parentName + ", createBy=" + createBy + ", createTime=" + createTime + ", updateBy="
|
||||
+ updateBy + ", updateTime=" + updateTime + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package com.ruoyi.project.system.dept.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.project.system.dept.dao.IDeptDao;
|
||||
import com.ruoyi.project.system.dept.domain.Dept;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Repository("deptService")
|
||||
public class DeptServiceImpl implements IDeptService
|
||||
{
|
||||
@Autowired
|
||||
private IDeptDao deptDao;
|
||||
|
||||
/**
|
||||
* 查询部门管理集合
|
||||
*
|
||||
* @return 所有部门信息
|
||||
*/
|
||||
@Override
|
||||
public List<Dept> selectDeptAll()
|
||||
{
|
||||
return deptDao.selectDeptAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门管理树
|
||||
*
|
||||
* @return 所有部门信息
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> selectDeptTree()
|
||||
{
|
||||
List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
|
||||
List<Dept> deptList = deptDao.selectDeptAll();
|
||||
|
||||
for (Dept dept : deptList)
|
||||
{
|
||||
Map<String, Object> deptMap = new HashMap<String, Object>();
|
||||
deptMap.put("id", dept.getDeptId());
|
||||
deptMap.put("pId", dept.getParentId());
|
||||
deptMap.put("name", dept.getDeptName());
|
||||
trees.add(deptMap);
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门人数
|
||||
*
|
||||
* @param parentId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int selectDeptCount(Long parentId)
|
||||
{
|
||||
Dept dept = new Dept();
|
||||
dept.setParentId(parentId);
|
||||
return deptDao.selectDeptCount(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
@Override
|
||||
public boolean checkDeptExistUser(Long deptId)
|
||||
{
|
||||
int result = deptDao.checkDeptExistUser(deptId);
|
||||
return result > 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeptById(Long deptId)
|
||||
{
|
||||
return deptDao.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int saveDept(Dept dept)
|
||||
{
|
||||
if (StringUtils.isNotNull(dept.getDeptId()))
|
||||
{
|
||||
dept.setUpdateBy(ShiroUtils.getLoginName());
|
||||
return deptDao.updateDept(dept);
|
||||
}
|
||||
else
|
||||
{
|
||||
dept.setCreateBy(ShiroUtils.getLoginName());
|
||||
return deptDao.insertDept(dept);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门ID查询信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
@Override
|
||||
public Dept selectDeptById(Long deptId)
|
||||
{
|
||||
return deptDao.selectDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkDeptNameUnique(Dept dept)
|
||||
{
|
||||
Long deptId = dept.getDeptId();
|
||||
Dept info = deptDao.checkDeptNameUnique(dept.getDeptName());
|
||||
if (StringUtils.isNotNull(info) && StringUtils.isNotNull(info.getDeptId())
|
||||
&& info.getDeptId().longValue() != deptId.longValue())
|
||||
{
|
||||
return UserConstants.NAME_NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.NAME_UNIQUE;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.ruoyi.project.system.dept.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.project.system.dept.domain.Dept;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IDeptService
|
||||
{
|
||||
/**
|
||||
* 查询部门管理集合
|
||||
*
|
||||
* @return 所有部门信息
|
||||
*/
|
||||
public List<Dept> selectDeptAll();
|
||||
|
||||
/**
|
||||
* 查询部门管理树
|
||||
*
|
||||
* @return 所有部门信息
|
||||
*/
|
||||
public List<Map<String, Object>> selectDeptTree();
|
||||
|
||||
|
||||
/**
|
||||
* 查询部门人数
|
||||
*
|
||||
* @param parentId 父部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int selectDeptCount(Long parentId);
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
public boolean checkDeptExistUser(Long deptId);
|
||||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 保存部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int saveDept(Dept dept);
|
||||
|
||||
/**
|
||||
* 根据部门ID查询信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
public Dept selectDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkDeptNameUnique(Dept dept);
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package com.ruoyi.project.system.dict.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.system.dict.domain.DictData;
|
||||
import com.ruoyi.project.system.dict.service.IDictDataService;
|
||||
|
||||
/**
|
||||
* 数据字典信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/system/dict/data")
|
||||
public class DictDataController extends BaseController
|
||||
{
|
||||
private String prefix = "system/dict/data";
|
||||
|
||||
@Autowired
|
||||
private IDictDataService dictDataService;
|
||||
|
||||
@RequiresPermissions("system:dict:view")
|
||||
@GetMapping()
|
||||
public String dictData()
|
||||
{
|
||||
return prefix + "/data";
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("system:dict:list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(DictData dictData)
|
||||
{
|
||||
setPageInfo(dictData);
|
||||
List<DictData> list = dictDataService.selectDictDataList(dictData);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改字典类型
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-修改字典数据")
|
||||
@RequiresPermissions("system:dict:edit")
|
||||
@GetMapping("/edit/{dictCode}")
|
||||
public String edit(@PathVariable("dictCode") Long dictCode, Model model)
|
||||
{
|
||||
DictData dict = dictDataService.selectDictDataById(dictCode);
|
||||
model.addAttribute("dict", dict);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-新增字典数据")
|
||||
@RequiresPermissions("system:dict:add")
|
||||
@GetMapping("/add/{dictType}")
|
||||
public String add(@PathVariable("dictType") String dictType, Model model)
|
||||
{
|
||||
model.addAttribute("dictType", dictType);
|
||||
return prefix + "/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存字典类型
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-保存字典数据")
|
||||
@RequiresPermissions("system:dict:save")
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public JSON save(DictData dict)
|
||||
{
|
||||
if (dictDataService.saveDictData(dict) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-删除字典数据")
|
||||
@RequiresPermissions("system:dict:remove")
|
||||
@RequestMapping("/remove/{dictCode}")
|
||||
@ResponseBody
|
||||
public JSON remove(@PathVariable("dictCode") Long dictCode)
|
||||
{
|
||||
DictData dictData = dictDataService.selectDictDataById(dictCode);
|
||||
if (dictData == null)
|
||||
{
|
||||
return JSON.error("字典数据不存在");
|
||||
}
|
||||
if (dictDataService.deleteDictDataById(dictCode) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
@Log(title = "系统管理", action = "字典类型-批量删除")
|
||||
@RequiresPermissions("system:dict:batchRemove")
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
|
||||
{
|
||||
int rows = dictDataService.batchDeleteDictData(ids);
|
||||
if (rows > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
package com.ruoyi.project.system.dict.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.JSON;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.system.dict.domain.DictType;
|
||||
import com.ruoyi.project.system.dict.service.IDictTypeService;
|
||||
|
||||
/**
|
||||
* 数据字典信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/system/dict")
|
||||
public class DictTypeController extends BaseController
|
||||
{
|
||||
private String prefix = "system/dict/type";
|
||||
|
||||
@Autowired
|
||||
private IDictTypeService dictTypeService;
|
||||
|
||||
@RequiresPermissions("system:dict:view")
|
||||
@GetMapping()
|
||||
public String dictType()
|
||||
{
|
||||
return prefix + "/type";
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("system:dict:list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(DictType dictType)
|
||||
{
|
||||
setPageInfo(dictType);
|
||||
List<DictType> list = dictTypeService.selectDictTypeList(dictType);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改字典类型
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-修改字典类型")
|
||||
@RequiresPermissions("system:dict:edit")
|
||||
@GetMapping("/edit/{dictId}")
|
||||
public String edit(@PathVariable("dictId") Long dictId, Model model)
|
||||
{
|
||||
DictType dict = dictTypeService.selectDictTypeById(dictId);
|
||||
model.addAttribute("dict", dict);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-新增字典类型")
|
||||
@RequiresPermissions("system:dict:add")
|
||||
@GetMapping("/add")
|
||||
public String add()
|
||||
{
|
||||
return prefix + "/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存字典类型
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-保存字典类型")
|
||||
@RequiresPermissions("system:dict:save")
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public JSON save(DictType dict)
|
||||
{
|
||||
if (dictTypeService.saveDictType(dict) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-删除字典类型")
|
||||
@RequiresPermissions("system:dict:remove")
|
||||
@RequestMapping("/remove/{dictId}")
|
||||
@ResponseBody
|
||||
public JSON remove(@PathVariable("dictId") Long dictId)
|
||||
{
|
||||
DictType dictType = dictTypeService.selectDictTypeById(dictId);
|
||||
if (dictType == null)
|
||||
{
|
||||
return JSON.error("字典不存在");
|
||||
}
|
||||
if (dictTypeService.deleteDictTypeById(dictId) > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
@Log(title = "系统管理", action = "字典类型-批量删除")
|
||||
@RequiresPermissions("system:dict:batchRemove")
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
|
||||
{
|
||||
int rows = dictTypeService.batchDeleteDictType(ids);
|
||||
if (rows > 0)
|
||||
{
|
||||
return JSON.ok();
|
||||
}
|
||||
return JSON.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询字典详细
|
||||
*/
|
||||
@Log(title = "系统管理", action = "字典管理-查询字典数据")
|
||||
@RequiresPermissions("system:dict:list")
|
||||
@GetMapping("/detail/{dictId}")
|
||||
public String detail(@PathVariable("dictId") Long dictId, Model model)
|
||||
{
|
||||
DictType dict = dictTypeService.selectDictTypeById(dictId);
|
||||
model.addAttribute("dict", dict);
|
||||
return "system/dict/data/data";
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验字典类型
|
||||
*/
|
||||
@PostMapping("/checkDictTypeUnique")
|
||||
@ResponseBody
|
||||
public String checkDictTypeUnique(DictType dictType)
|
||||
{
|
||||
String uniqueFlag = "0";
|
||||
if (dictType != null)
|
||||
{
|
||||
uniqueFlag = dictTypeService.checkDictTypeUnique(dictType);
|
||||
}
|
||||
return uniqueFlag;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue