修改了一些代码的注释,方便后期对代码进行维护,修改,以及新功能模块的开发
This commit is contained in:
parent
465952560f
commit
479957fbc1
File diff suppressed because it is too large
Load Diff
|
|
@ -14,6 +14,14 @@ import org.apache.shiro.subject.Subject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shiro 工具类
|
* shiro 工具类
|
||||||
|
* Subject:主体.每个用户登录后都会对应一个Subject对象,所有用户信息都存储到Subject中
|
||||||
|
* Security Manager:Shiro最大的容器.Shiro所有功能都封装在Security Manager中 1:编写代码时,想要使用Shiro第一个步骤获取到Security Manager 2:在整个程序中保证Security Manager有且只有一个
|
||||||
|
* Authenticator: 认证器.执行认证过程调用的组件.
|
||||||
|
* Authorizer:授权器.执行授权时调用的组件.
|
||||||
|
* Session Manager: Session管理器.
|
||||||
|
* Cache Manager: 缓存管理器.Shiro支持很多第三方缓存工具.例如Ehcache等.
|
||||||
|
* SessionDao: 操作Session内容的组件
|
||||||
|
* Realm:该组件的作用负责获取到数据库中数据并根据用户自定义逻辑进行授权和认证等操作. 1:Shiro 框架和数据库没有关系.没有对数据库设计有认证强制要求 2:如果Shiro想要访问数据库都是通过Realm组件. 3:如果Shiro数据不是来源于数据库,可以使用.ini文件设置静态数据.
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
|
@ -52,7 +60,7 @@ public class ShiroUtils {
|
||||||
*/
|
*/
|
||||||
public static void setSysUser(SysUser user) {
|
public static void setSysUser(SysUser user) {
|
||||||
Subject subject = getSubject();
|
Subject subject = getSubject();
|
||||||
//获取当事人的信息
|
//获取当事人的信息,身份.代表用户名,邮箱,手机等能够唯一确认身份的信息
|
||||||
PrincipalCollection principalCollection = subject.getPrincipals();
|
PrincipalCollection principalCollection = subject.getPrincipals();
|
||||||
String realmName = principalCollection.getRealmNames().iterator().next();
|
String realmName = principalCollection.getRealmNames().iterator().next();
|
||||||
PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
|
PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,18 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spring工具类 方便在非spring管理环境中获取bean
|
* spring工具类 方便在非spring管理环境中获取bean
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public final class SpringUtils implements BeanFactoryPostProcessor
|
public final class SpringUtils implements BeanFactoryPostProcessor {
|
||||||
{
|
/**
|
||||||
/** Spring应用上下文环境 */
|
* Spring应用上下文环境
|
||||||
|
*/
|
||||||
private static ConfigurableListableBeanFactory beanFactory;
|
private static ConfigurableListableBeanFactory beanFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||||
{
|
|
||||||
SpringUtils.beanFactory = beanFactory;
|
SpringUtils.beanFactory = beanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,11 +29,9 @@ public final class SpringUtils implements BeanFactoryPostProcessor
|
||||||
* @param name
|
* @param name
|
||||||
* @return Object 一个以所给名字注册的bean的实例
|
* @return Object 一个以所给名字注册的bean的实例
|
||||||
* @throws org.springframework.beans.BeansException
|
* @throws org.springframework.beans.BeansException
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T getBean(String name) throws BeansException
|
public static <T> T getBean(String name) throws BeansException {
|
||||||
{
|
|
||||||
return (T) beanFactory.getBean(name);
|
return (T) beanFactory.getBean(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,10 +41,8 @@ public final class SpringUtils implements BeanFactoryPostProcessor
|
||||||
* @param clz
|
* @param clz
|
||||||
* @return
|
* @return
|
||||||
* @throws org.springframework.beans.BeansException
|
* @throws org.springframework.beans.BeansException
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static <T> T getBean(Class<T> clz) throws BeansException
|
public static <T> T getBean(Class<T> clz) throws BeansException {
|
||||||
{
|
|
||||||
T result = (T) beanFactory.getBean(clz);
|
T result = (T) beanFactory.getBean(clz);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -57,8 +53,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor
|
||||||
* @param name
|
* @param name
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean containsBean(String name)
|
public static boolean containsBean(String name) {
|
||||||
{
|
|
||||||
return beanFactory.containsBean(name);
|
return beanFactory.containsBean(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,10 +63,8 @@ public final class SpringUtils implements BeanFactoryPostProcessor
|
||||||
* @param name
|
* @param name
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException
|
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
|
||||||
{
|
|
||||||
return beanFactory.isSingleton(name);
|
return beanFactory.isSingleton(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,10 +72,8 @@ public final class SpringUtils implements BeanFactoryPostProcessor
|
||||||
* @param name
|
* @param name
|
||||||
* @return Class 注册对象的类型
|
* @return Class 注册对象的类型
|
||||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException
|
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException {
|
||||||
{
|
|
||||||
return beanFactory.getType(name);
|
return beanFactory.getType(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,10 +83,8 @@ public final class SpringUtils implements BeanFactoryPostProcessor
|
||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException
|
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException {
|
||||||
{
|
|
||||||
return beanFactory.getAliases(name);
|
return beanFactory.getAliases(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
package com.ruoyi.framework.web.base;
|
package com.ruoyi.framework.web.base;
|
||||||
|
|
||||||
import java.beans.PropertyEditorSupport;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.ruoyi.common.base.AjaxResult;
|
import com.ruoyi.common.base.AjaxResult;
|
||||||
|
|
@ -15,41 +10,41 @@ import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.util.ShiroUtils;
|
import com.ruoyi.framework.util.ShiroUtils;
|
||||||
import com.ruoyi.framework.web.page.TableSupport;
|
import com.ruoyi.framework.web.page.TableSupport;
|
||||||
import com.ruoyi.system.domain.SysUser;
|
import com.ruoyi.system.domain.SysUser;
|
||||||
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
|
|
||||||
|
import java.beans.PropertyEditorSupport;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* web层通用数据处理
|
* web层通用数据处理
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class BaseController
|
public class BaseController {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 将前台传递过来的日期格式的字符串,自动转化为Date类型
|
* 将前台传递过来的日期格式的字符串,自动转化为Date类型
|
||||||
*/
|
*/
|
||||||
@InitBinder
|
@InitBinder
|
||||||
public void initBinder(WebDataBinder binder)
|
public void initBinder(WebDataBinder binder) {
|
||||||
{
|
|
||||||
// Date 类型转换
|
// Date 类型转换
|
||||||
binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
|
binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void setAsText(String text)
|
public void setAsText(String text) {
|
||||||
{
|
|
||||||
setValue(DateUtils.parseDate(text));
|
setValue(DateUtils.parseDate(text));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置请求分页数据
|
* 设置请求分页数据,查询的时候调用分页查询
|
||||||
*/
|
*/
|
||||||
protected void startPage()
|
protected void startPage() {
|
||||||
{
|
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||||
Integer pageNum = pageDomain.getPageNum();
|
Integer pageNum = pageDomain.getPageNum();
|
||||||
Integer pageSize = pageDomain.getPageSize();
|
Integer pageSize = pageDomain.getPageSize();
|
||||||
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
|
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
|
||||||
{
|
|
||||||
String orderBy = pageDomain.getOrderBy();
|
String orderBy = pageDomain.getOrderBy();
|
||||||
PageHelper.startPage(pageNum, pageSize, orderBy);
|
PageHelper.startPage(pageNum, pageSize, orderBy);
|
||||||
}
|
}
|
||||||
|
|
@ -57,10 +52,10 @@ public class BaseController
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应请求分页数据
|
* 响应请求分页数据
|
||||||
|
* 分页返回的数据
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
protected TableDataInfo getDataTable(List<?> list)
|
protected TableDataInfo getDataTable(List<?> list) {
|
||||||
{
|
|
||||||
TableDataInfo rspData = new TableDataInfo();
|
TableDataInfo rspData = new TableDataInfo();
|
||||||
rspData.setCode(0);
|
rspData.setCode(0);
|
||||||
rspData.setRows(list);
|
rspData.setRows(list);
|
||||||
|
|
@ -69,92 +64,80 @@ public class BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应返回结果
|
* 响应返回结果,如果查询出的行数 > 0的话,就返回成功,否则返回错误
|
||||||
*
|
*
|
||||||
* @param rows 影响行数
|
* @param rows 影响行数
|
||||||
* @return 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
protected AjaxResult toAjax(int rows)
|
protected AjaxResult toAjax(int rows) {
|
||||||
{
|
|
||||||
return rows > 0 ? success() : error();
|
return rows > 0 ? success() : error();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应返回结果
|
* 响应返回结果
|
||||||
*
|
*
|
||||||
* @param result 结果
|
* @param result 结果
|
||||||
* @return 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
protected AjaxResult toAjax(boolean result)
|
protected AjaxResult toAjax(boolean result) {
|
||||||
{
|
|
||||||
return result ? success() : error();
|
return result ? success() : error();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回成功
|
* 返回成功
|
||||||
*/
|
*/
|
||||||
public AjaxResult success()
|
public AjaxResult success() {
|
||||||
{
|
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回失败消息
|
* 返回失败消息
|
||||||
*/
|
*/
|
||||||
public AjaxResult error()
|
public AjaxResult error() {
|
||||||
{
|
|
||||||
return AjaxResult.error();
|
return AjaxResult.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回成功消息
|
* 返回成功消息
|
||||||
*/
|
*/
|
||||||
public AjaxResult success(String message)
|
public AjaxResult success(String message) {
|
||||||
{
|
|
||||||
return AjaxResult.success(message);
|
return AjaxResult.success(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回失败消息
|
* 返回失败消息
|
||||||
*/
|
*/
|
||||||
public AjaxResult error(String message)
|
public AjaxResult error(String message) {
|
||||||
{
|
|
||||||
return AjaxResult.error(message);
|
return AjaxResult.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回错误码消息
|
* 返回错误码消息
|
||||||
*/
|
*/
|
||||||
public AjaxResult error(int code, String message)
|
public AjaxResult error(int code, String message) {
|
||||||
{
|
|
||||||
return AjaxResult.error(code, message);
|
return AjaxResult.error(code, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面跳转
|
* 页面跳转
|
||||||
*/
|
*/
|
||||||
public String redirect(String url)
|
public String redirect(String url) {
|
||||||
{
|
|
||||||
return StringUtils.format("redirect:{}", url);
|
return StringUtils.format("redirect:{}", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SysUser getSysUser()
|
public SysUser getSysUser() {
|
||||||
{
|
|
||||||
return ShiroUtils.getSysUser();
|
return ShiroUtils.getSysUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSysUser(SysUser user)
|
public void setSysUser(SysUser user) {
|
||||||
{
|
|
||||||
ShiroUtils.setSysUser(user);
|
ShiroUtils.setSysUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getUserId()
|
public Long getUserId() {
|
||||||
{
|
|
||||||
return getSysUser().getUserId();
|
return getSysUser().getUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLoginName()
|
public String getLoginName() {
|
||||||
{
|
|
||||||
return getSysUser().getLoginName();
|
return getSysUser().getLoginName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,8 @@
|
||||||
package com.ruoyi.framework.web.domain;
|
package com.ruoyi.framework.web.domain;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
import com.ruoyi.common.utils.Arith;
|
import com.ruoyi.common.utils.Arith;
|
||||||
import com.ruoyi.common.utils.IpUtils;
|
import com.ruoyi.common.utils.IpUtils;
|
||||||
import com.ruoyi.framework.web.domain.server.Cpu;
|
import com.ruoyi.framework.web.domain.server.*;
|
||||||
import com.ruoyi.framework.web.domain.server.Jvm;
|
|
||||||
import com.ruoyi.framework.web.domain.server.Mem;
|
|
||||||
import com.ruoyi.framework.web.domain.server.Sys;
|
|
||||||
import com.ruoyi.framework.web.domain.server.SysFile;
|
|
||||||
import oshi.SystemInfo;
|
import oshi.SystemInfo;
|
||||||
import oshi.hardware.CentralProcessor;
|
import oshi.hardware.CentralProcessor;
|
||||||
import oshi.hardware.CentralProcessor.TickType;
|
import oshi.hardware.CentralProcessor.TickType;
|
||||||
|
|
@ -21,16 +13,20 @@ import oshi.software.os.OSFileStore;
|
||||||
import oshi.software.os.OperatingSystem;
|
import oshi.software.os.OperatingSystem;
|
||||||
import oshi.util.Util;
|
import oshi.util.Util;
|
||||||
|
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器相关信息
|
* 服务器相关信息:包含CPU、JVM、内存、磁盘、服务器相关信息
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class Server
|
public class Server {
|
||||||
{
|
|
||||||
|
|
||||||
private static final int OSHI_WAIT_SECOND = 1000;
|
private static final int OSHI_WAIT_SECOND = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CPU相关信息
|
* CPU相关信息
|
||||||
*/
|
*/
|
||||||
|
|
@ -56,58 +52,47 @@ public class Server
|
||||||
*/
|
*/
|
||||||
private List<SysFile> sysFiles = new LinkedList<SysFile>();
|
private List<SysFile> sysFiles = new LinkedList<SysFile>();
|
||||||
|
|
||||||
public Cpu getCpu()
|
public Cpu getCpu() {
|
||||||
{
|
|
||||||
return cpu;
|
return cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCpu(Cpu cpu)
|
public void setCpu(Cpu cpu) {
|
||||||
{
|
|
||||||
this.cpu = cpu;
|
this.cpu = cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mem getMem()
|
public Mem getMem() {
|
||||||
{
|
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMem(Mem mem)
|
public void setMem(Mem mem) {
|
||||||
{
|
|
||||||
this.mem = mem;
|
this.mem = mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jvm getJvm()
|
public Jvm getJvm() {
|
||||||
{
|
|
||||||
return jvm;
|
return jvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJvm(Jvm jvm)
|
public void setJvm(Jvm jvm) {
|
||||||
{
|
|
||||||
this.jvm = jvm;
|
this.jvm = jvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sys getSys()
|
public Sys getSys() {
|
||||||
{
|
|
||||||
return sys;
|
return sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSys(Sys sys)
|
public void setSys(Sys sys) {
|
||||||
{
|
|
||||||
this.sys = sys;
|
this.sys = sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SysFile> getSysFiles()
|
public List<SysFile> getSysFiles() {
|
||||||
{
|
|
||||||
return sysFiles;
|
return sysFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSysFiles(List<SysFile> sysFiles)
|
public void setSysFiles(List<SysFile> sysFiles) {
|
||||||
{
|
|
||||||
this.sysFiles = sysFiles;
|
this.sysFiles = sysFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo() throws Exception
|
public void copyTo() throws Exception {
|
||||||
{
|
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
HardwareAbstractionLayer hal = si.getHardware();
|
HardwareAbstractionLayer hal = si.getHardware();
|
||||||
|
|
||||||
|
|
@ -125,8 +110,7 @@ public class Server
|
||||||
/**
|
/**
|
||||||
* 设置CPU信息
|
* 设置CPU信息
|
||||||
*/
|
*/
|
||||||
private void setCpuInfo(CentralProcessor processor)
|
private void setCpuInfo(CentralProcessor processor) {
|
||||||
{
|
|
||||||
// CPU信息
|
// CPU信息
|
||||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||||
Util.sleep(OSHI_WAIT_SECOND);
|
Util.sleep(OSHI_WAIT_SECOND);
|
||||||
|
|
@ -151,8 +135,7 @@ public class Server
|
||||||
/**
|
/**
|
||||||
* 设置内存信息
|
* 设置内存信息
|
||||||
*/
|
*/
|
||||||
private void setMemInfo(GlobalMemory memory)
|
private void setMemInfo(GlobalMemory memory) {
|
||||||
{
|
|
||||||
mem.setTotal(memory.getTotal());
|
mem.setTotal(memory.getTotal());
|
||||||
mem.setUsed(memory.getTotal() - memory.getAvailable());
|
mem.setUsed(memory.getTotal() - memory.getAvailable());
|
||||||
mem.setFree(memory.getAvailable());
|
mem.setFree(memory.getAvailable());
|
||||||
|
|
@ -161,8 +144,7 @@ public class Server
|
||||||
/**
|
/**
|
||||||
* 设置服务器信息
|
* 设置服务器信息
|
||||||
*/
|
*/
|
||||||
private void setSysInfo()
|
private void setSysInfo() {
|
||||||
{
|
|
||||||
Properties props = System.getProperties();
|
Properties props = System.getProperties();
|
||||||
sys.setComputerName(IpUtils.getHostName());
|
sys.setComputerName(IpUtils.getHostName());
|
||||||
sys.setComputerIp(IpUtils.getHostIp());
|
sys.setComputerIp(IpUtils.getHostIp());
|
||||||
|
|
@ -174,8 +156,7 @@ public class Server
|
||||||
/**
|
/**
|
||||||
* 设置Java虚拟机
|
* 设置Java虚拟机
|
||||||
*/
|
*/
|
||||||
private void setJvmInfo() throws UnknownHostException
|
private void setJvmInfo() throws UnknownHostException {
|
||||||
{
|
|
||||||
Properties props = System.getProperties();
|
Properties props = System.getProperties();
|
||||||
jvm.setTotal(Runtime.getRuntime().totalMemory());
|
jvm.setTotal(Runtime.getRuntime().totalMemory());
|
||||||
jvm.setMax(Runtime.getRuntime().maxMemory());
|
jvm.setMax(Runtime.getRuntime().maxMemory());
|
||||||
|
|
@ -187,12 +168,10 @@ public class Server
|
||||||
/**
|
/**
|
||||||
* 设置磁盘信息
|
* 设置磁盘信息
|
||||||
*/
|
*/
|
||||||
private void setSysFiles(OperatingSystem os)
|
private void setSysFiles(OperatingSystem os) {
|
||||||
{
|
|
||||||
FileSystem fileSystem = os.getFileSystem();
|
FileSystem fileSystem = os.getFileSystem();
|
||||||
OSFileStore[] fsArray = fileSystem.getFileStores();
|
OSFileStore[] fsArray = fileSystem.getFileStores();
|
||||||
for (OSFileStore fs : fsArray)
|
for (OSFileStore fs : fsArray) {
|
||||||
{
|
|
||||||
long free = fs.getUsableSpace();
|
long free = fs.getUsableSpace();
|
||||||
long total = fs.getTotalSpace();
|
long total = fs.getTotalSpace();
|
||||||
long used = total - free;
|
long used = total - free;
|
||||||
|
|
@ -210,31 +189,23 @@ public class Server
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字节转换
|
* 字节转换
|
||||||
*
|
*
|
||||||
* @param size 字节大小
|
* @param size 字节大小
|
||||||
* @return 转换后值
|
* @return 转换后值
|
||||||
*/
|
*/
|
||||||
public String convertFileSize(long size)
|
public String convertFileSize(long size) {
|
||||||
{
|
|
||||||
long kb = 1024;
|
long kb = 1024;
|
||||||
long mb = kb * 1024;
|
long mb = kb * 1024;
|
||||||
long gb = mb * 1024;
|
long gb = mb * 1024;
|
||||||
if (size >= gb)
|
if (size >= gb) {
|
||||||
{
|
|
||||||
return String.format("%.1f GB", (float) size / gb);
|
return String.format("%.1f GB", (float) size / gb);
|
||||||
}
|
} else if (size >= mb) {
|
||||||
else if (size >= mb)
|
|
||||||
{
|
|
||||||
float f = (float) size / mb;
|
float f = (float) size / mb;
|
||||||
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
||||||
}
|
} else if (size >= kb) {
|
||||||
else if (size >= kb)
|
|
||||||
{
|
|
||||||
float f = (float) size / kb;
|
float f = (float) size / kb;
|
||||||
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return String.format("%d B", size);
|
return String.format("%d B", size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,11 @@ package com.ruoyi.framework.web.domain.server;
|
||||||
import com.ruoyi.common.utils.Arith;
|
import com.ruoyi.common.utils.Arith;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CPU相关信息
|
* CPU实体类:CPU相关信息
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class Cpu
|
public class Cpu {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 核心数
|
* 核心数
|
||||||
*/
|
*/
|
||||||
|
|
@ -39,63 +38,51 @@ public class Cpu
|
||||||
*/
|
*/
|
||||||
private double free;
|
private double free;
|
||||||
|
|
||||||
public int getCpuNum()
|
public int getCpuNum() {
|
||||||
{
|
|
||||||
return cpuNum;
|
return cpuNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCpuNum(int cpuNum)
|
public void setCpuNum(int cpuNum) {
|
||||||
{
|
|
||||||
this.cpuNum = cpuNum;
|
this.cpuNum = cpuNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTotal()
|
public double getTotal() {
|
||||||
{
|
|
||||||
return Arith.round(Arith.mul(total, 100), 2);
|
return Arith.round(Arith.mul(total, 100), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotal(double total)
|
public void setTotal(double total) {
|
||||||
{
|
|
||||||
this.total = total;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSys()
|
public double getSys() {
|
||||||
{
|
|
||||||
return Arith.round(Arith.mul(sys / total, 100), 2);
|
return Arith.round(Arith.mul(sys / total, 100), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSys(double sys)
|
public void setSys(double sys) {
|
||||||
{
|
|
||||||
this.sys = sys;
|
this.sys = sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUsed()
|
public double getUsed() {
|
||||||
{
|
|
||||||
return Arith.round(Arith.mul(used / total, 100), 2);
|
return Arith.round(Arith.mul(used / total, 100), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsed(double used)
|
public void setUsed(double used) {
|
||||||
{
|
|
||||||
this.used = used;
|
this.used = used;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getWait()
|
public double getWait() {
|
||||||
{
|
|
||||||
return Arith.round(Arith.mul(wait / total, 100), 2);
|
return Arith.round(Arith.mul(wait / total, 100), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWait(double wait)
|
public void setWait(double wait) {
|
||||||
{
|
|
||||||
this.wait = wait;
|
this.wait = wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getFree()
|
public double getFree() {
|
||||||
{
|
|
||||||
return Arith.round(Arith.mul(free / total, 100), 2);
|
return Arith.round(Arith.mul(free / total, 100), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFree(double free)
|
public void setFree(double free) {
|
||||||
{
|
|
||||||
this.free = free;
|
this.free = free;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
package com.ruoyi.framework.web.domain.server;
|
package com.ruoyi.framework.web.domain.server;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import com.ruoyi.common.utils.Arith;
|
import com.ruoyi.common.utils.Arith;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JVM相关信息
|
* JVM实体类:JVM相关信息
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class Jvm
|
public class Jvm {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 当前JVM占用的内存总数(M)
|
* 当前JVM占用的内存总数(M)
|
||||||
*/
|
*/
|
||||||
|
|
@ -36,87 +36,72 @@ public class Jvm
|
||||||
*/
|
*/
|
||||||
private String home;
|
private String home;
|
||||||
|
|
||||||
public double getTotal()
|
public double getTotal() {
|
||||||
{
|
|
||||||
return Arith.div(total, (1024 * 1024), 2);
|
return Arith.div(total, (1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotal(double total)
|
public void setTotal(double total) {
|
||||||
{
|
|
||||||
this.total = total;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMax()
|
public double getMax() {
|
||||||
{
|
|
||||||
return Arith.div(max, (1024 * 1024), 2);
|
return Arith.div(max, (1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMax(double max)
|
public void setMax(double max) {
|
||||||
{
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getFree()
|
public double getFree() {
|
||||||
{
|
|
||||||
return Arith.div(free, (1024 * 1024), 2);
|
return Arith.div(free, (1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFree(double free)
|
public void setFree(double free) {
|
||||||
{
|
|
||||||
this.free = free;
|
this.free = free;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUsed()
|
public double getUsed() {
|
||||||
{
|
|
||||||
return Arith.div(total - free, (1024 * 1024), 2);
|
return Arith.div(total - free, (1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUsage()
|
public double getUsage() {
|
||||||
{
|
|
||||||
return Arith.mul(Arith.div(total - free, total, 4), 100);
|
return Arith.mul(Arith.div(total - free, total, 4), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取JDK名称
|
* 获取JDK名称
|
||||||
*/
|
*/
|
||||||
public String getName()
|
public String getName() {
|
||||||
{
|
|
||||||
return ManagementFactory.getRuntimeMXBean().getVmName();
|
return ManagementFactory.getRuntimeMXBean().getVmName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion()
|
public String getVersion() {
|
||||||
{
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(String version)
|
public void setVersion(String version) {
|
||||||
{
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHome()
|
public String getHome() {
|
||||||
{
|
|
||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHome(String home)
|
public void setHome(String home) {
|
||||||
{
|
|
||||||
this.home = home;
|
this.home = home;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDK启动时间
|
* JDK启动时间
|
||||||
*/
|
*/
|
||||||
public String getStartTime()
|
public String getStartTime() {
|
||||||
{
|
|
||||||
return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate());
|
return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDK运行时间
|
* JDK运行时间
|
||||||
*/
|
*/
|
||||||
public String getRunTime()
|
public String getRunTime() {
|
||||||
{
|
|
||||||
return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate());
|
return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,11 @@ package com.ruoyi.framework.web.domain.server;
|
||||||
import com.ruoyi.common.utils.Arith;
|
import com.ruoyi.common.utils.Arith;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 內存相关信息
|
* 内存实体类:內存相关信息
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class Mem
|
public class Mem {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 内存总量
|
* 内存总量
|
||||||
*/
|
*/
|
||||||
|
|
@ -24,38 +23,31 @@ public class Mem
|
||||||
*/
|
*/
|
||||||
private double free;
|
private double free;
|
||||||
|
|
||||||
public double getTotal()
|
public double getTotal() {
|
||||||
{
|
|
||||||
return Arith.div(total, (1024 * 1024 * 1024), 2);
|
return Arith.div(total, (1024 * 1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotal(long total)
|
public void setTotal(long total) {
|
||||||
{
|
|
||||||
this.total = total;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUsed()
|
public double getUsed() {
|
||||||
{
|
|
||||||
return Arith.div(used, (1024 * 1024 * 1024), 2);
|
return Arith.div(used, (1024 * 1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsed(long used)
|
public void setUsed(long used) {
|
||||||
{
|
|
||||||
this.used = used;
|
this.used = used;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getFree()
|
public double getFree() {
|
||||||
{
|
|
||||||
return Arith.div(free, (1024 * 1024 * 1024), 2);
|
return Arith.div(free, (1024 * 1024 * 1024), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFree(long free)
|
public void setFree(long free) {
|
||||||
{
|
|
||||||
this.free = free;
|
this.free = free;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUsage()
|
public double getUsage() {
|
||||||
{
|
|
||||||
return Arith.mul(Arith.div(used, total, 4), 100);
|
return Arith.mul(Arith.div(used, total, 4), 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package com.ruoyi.framework.web.domain.server;
|
package com.ruoyi.framework.web.domain.server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统相关信息
|
* 系统实体类:系统相关信息
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class Sys
|
public class Sys {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 服务器名称
|
* 服务器名称
|
||||||
*/
|
*/
|
||||||
|
|
@ -32,53 +31,43 @@ public class Sys
|
||||||
*/
|
*/
|
||||||
private String osArch;
|
private String osArch;
|
||||||
|
|
||||||
public String getComputerName()
|
public String getComputerName() {
|
||||||
{
|
|
||||||
return computerName;
|
return computerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComputerName(String computerName)
|
public void setComputerName(String computerName) {
|
||||||
{
|
|
||||||
this.computerName = computerName;
|
this.computerName = computerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComputerIp()
|
public String getComputerIp() {
|
||||||
{
|
|
||||||
return computerIp;
|
return computerIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComputerIp(String computerIp)
|
public void setComputerIp(String computerIp) {
|
||||||
{
|
|
||||||
this.computerIp = computerIp;
|
this.computerIp = computerIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserDir()
|
public String getUserDir() {
|
||||||
{
|
|
||||||
return userDir;
|
return userDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserDir(String userDir)
|
public void setUserDir(String userDir) {
|
||||||
{
|
|
||||||
this.userDir = userDir;
|
this.userDir = userDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOsName()
|
public String getOsName() {
|
||||||
{
|
|
||||||
return osName;
|
return osName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOsName(String osName)
|
public void setOsName(String osName) {
|
||||||
{
|
|
||||||
this.osName = osName;
|
this.osName = osName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOsArch()
|
public String getOsArch() {
|
||||||
{
|
|
||||||
return osArch;
|
return osArch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOsArch(String osArch)
|
public void setOsArch(String osArch) {
|
||||||
{
|
|
||||||
this.osArch = osArch;
|
this.osArch = osArch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package com.ruoyi.framework.web.domain.server;
|
package com.ruoyi.framework.web.domain.server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统文件相关信息
|
* 系统文件:系统文件相关信息
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SysFile
|
public class SysFile {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 盘符路径
|
* 盘符路径
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,73 +41,59 @@ public class SysFile
|
||||||
*/
|
*/
|
||||||
private double usage;
|
private double usage;
|
||||||
|
|
||||||
public String getDirName()
|
public String getDirName() {
|
||||||
{
|
|
||||||
return dirName;
|
return dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDirName(String dirName)
|
public void setDirName(String dirName) {
|
||||||
{
|
|
||||||
this.dirName = dirName;
|
this.dirName = dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSysTypeName()
|
public String getSysTypeName() {
|
||||||
{
|
|
||||||
return sysTypeName;
|
return sysTypeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSysTypeName(String sysTypeName)
|
public void setSysTypeName(String sysTypeName) {
|
||||||
{
|
|
||||||
this.sysTypeName = sysTypeName;
|
this.sysTypeName = sysTypeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeName()
|
public String getTypeName() {
|
||||||
{
|
|
||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTypeName(String typeName)
|
public void setTypeName(String typeName) {
|
||||||
{
|
|
||||||
this.typeName = typeName;
|
this.typeName = typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTotal()
|
public String getTotal() {
|
||||||
{
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotal(String total)
|
public void setTotal(String total) {
|
||||||
{
|
|
||||||
this.total = total;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFree()
|
public String getFree() {
|
||||||
{
|
|
||||||
return free;
|
return free;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFree(String free)
|
public void setFree(String free) {
|
||||||
{
|
|
||||||
this.free = free;
|
this.free = free;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsed()
|
public String getUsed() {
|
||||||
{
|
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsed(String used)
|
public void setUsed(String used) {
|
||||||
{
|
|
||||||
this.used = used;
|
this.used = used;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUsage()
|
public double getUsage() {
|
||||||
{
|
|
||||||
return usage;
|
return usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsage(double usage)
|
public void setUsage(double usage) {
|
||||||
{
|
|
||||||
this.usage = usage;
|
this.usage = usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,30 @@
|
||||||
package com.ruoyi.framework.web.exception;
|
package com.ruoyi.framework.web.exception;
|
||||||
|
|
||||||
|
import com.ruoyi.common.base.AjaxResult;
|
||||||
|
import com.ruoyi.common.exception.BusinessException;
|
||||||
|
import com.ruoyi.common.exception.DemoModeException;
|
||||||
|
import com.ruoyi.framework.util.PermissionUtils;
|
||||||
import org.apache.shiro.authz.AuthorizationException;
|
import org.apache.shiro.authz.AuthorizationException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import com.ruoyi.common.base.AjaxResult;
|
|
||||||
import com.ruoyi.common.exception.BusinessException;
|
|
||||||
import com.ruoyi.common.exception.DemoModeException;
|
|
||||||
import com.ruoyi.framework.util.PermissionUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义异常处理器
|
* 自定义异常处理器
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class DefaultExceptionHandler
|
public class DefaultExceptionHandler {
|
||||||
{
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(DefaultExceptionHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(DefaultExceptionHandler.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限校验失败
|
* 权限校验失败
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(AuthorizationException.class)
|
@ExceptionHandler(AuthorizationException.class)
|
||||||
public AjaxResult handleAuthorizationException(AuthorizationException e)
|
public AjaxResult handleAuthorizationException(AuthorizationException e) {
|
||||||
{
|
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return AjaxResult.error(PermissionUtils.getMsg(e.getMessage()));
|
return AjaxResult.error(PermissionUtils.getMsg(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
@ -34,9 +32,8 @@ public class DefaultExceptionHandler
|
||||||
/**
|
/**
|
||||||
* 请求方式不支持
|
* 请求方式不支持
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler({ HttpRequestMethodNotSupportedException.class })
|
@ExceptionHandler({HttpRequestMethodNotSupportedException.class})
|
||||||
public AjaxResult handleException(HttpRequestMethodNotSupportedException e)
|
public AjaxResult handleException(HttpRequestMethodNotSupportedException e) {
|
||||||
{
|
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return AjaxResult.error("不支持' " + e.getMethod() + "'请求");
|
return AjaxResult.error("不支持' " + e.getMethod() + "'请求");
|
||||||
}
|
}
|
||||||
|
|
@ -45,8 +42,7 @@ public class DefaultExceptionHandler
|
||||||
* 拦截未知的运行时异常
|
* 拦截未知的运行时异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(RuntimeException.class)
|
@ExceptionHandler(RuntimeException.class)
|
||||||
public AjaxResult notFount(RuntimeException e)
|
public AjaxResult notFount(RuntimeException e) {
|
||||||
{
|
|
||||||
log.error("运行时异常:", e);
|
log.error("运行时异常:", e);
|
||||||
return AjaxResult.error("运行时异常:" + e.getMessage());
|
return AjaxResult.error("运行时异常:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -55,8 +51,7 @@ public class DefaultExceptionHandler
|
||||||
* 系统异常
|
* 系统异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public AjaxResult handleException(Exception e)
|
public AjaxResult handleException(Exception e) {
|
||||||
{
|
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return AjaxResult.error("服务器错误,请联系管理员");
|
return AjaxResult.error("服务器错误,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
@ -65,8 +60,7 @@ public class DefaultExceptionHandler
|
||||||
* 业务异常
|
* 业务异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(BusinessException.class)
|
@ExceptionHandler(BusinessException.class)
|
||||||
public AjaxResult businessException(BusinessException e)
|
public AjaxResult businessException(BusinessException e) {
|
||||||
{
|
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return AjaxResult.error(e.getMessage());
|
return AjaxResult.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -75,8 +69,7 @@ public class DefaultExceptionHandler
|
||||||
* 演示模式异常
|
* 演示模式异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(DemoModeException.class)
|
@ExceptionHandler(DemoModeException.class)
|
||||||
public AjaxResult demoModeException(DemoModeException e)
|
public AjaxResult demoModeException(DemoModeException e) {
|
||||||
{
|
|
||||||
return AjaxResult.error("演示模式,不允许操作");
|
return AjaxResult.error("演示模式,不允许操作");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,11 @@ import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.util.MessageUtils;
|
import com.ruoyi.framework.util.MessageUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础异常
|
* 基础异常,把平常容易出错且多次出现的异常封装在一起,方便管理和调用
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class BaseException extends RuntimeException
|
public class BaseException extends RuntimeException {
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,66 +31,54 @@ public class BaseException extends RuntimeException
|
||||||
*/
|
*/
|
||||||
private String defaultMessage;
|
private String defaultMessage;
|
||||||
|
|
||||||
public BaseException(String module, String code, Object[] args, String defaultMessage)
|
public BaseException(String module, String code, Object[] args, String defaultMessage) {
|
||||||
{
|
|
||||||
this.module = module;
|
this.module = module;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.defaultMessage = defaultMessage;
|
this.defaultMessage = defaultMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String module, String code, Object[] args)
|
public BaseException(String module, String code, Object[] args) {
|
||||||
{
|
|
||||||
this(module, code, args, null);
|
this(module, code, args, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String module, String defaultMessage)
|
public BaseException(String module, String defaultMessage) {
|
||||||
{
|
|
||||||
this(module, null, null, defaultMessage);
|
this(module, null, null, defaultMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String code, Object[] args)
|
public BaseException(String code, Object[] args) {
|
||||||
{
|
|
||||||
this(null, code, args, null);
|
this(null, code, args, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String defaultMessage)
|
public BaseException(String defaultMessage) {
|
||||||
{
|
|
||||||
this(null, null, null, defaultMessage);
|
this(null, null, null, defaultMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage()
|
public String getMessage() {
|
||||||
{
|
|
||||||
String message = null;
|
String message = null;
|
||||||
if (!StringUtils.isEmpty(code))
|
if (!StringUtils.isEmpty(code)) {
|
||||||
{
|
|
||||||
message = MessageUtils.message(code, args);
|
message = MessageUtils.message(code, args);
|
||||||
}
|
}
|
||||||
if (message == null)
|
if (message == null) {
|
||||||
{
|
|
||||||
message = defaultMessage;
|
message = defaultMessage;
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModule()
|
public String getModule() {
|
||||||
{
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCode()
|
public String getCode() {
|
||||||
{
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getArgs()
|
public Object[] getArgs() {
|
||||||
{
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultMessage()
|
public String getDefaultMessage() {
|
||||||
{
|
|
||||||
return defaultMessage;
|
return defaultMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,26 @@
|
||||||
package com.ruoyi.framework.web.service;
|
package com.ruoyi.framework.web.service;
|
||||||
|
|
||||||
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RuoYi首创 html调用 thymeleaf 实现参数管理
|
* 首创 html调用 thymeleaf 实现参数管理
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service("config")
|
@Service("config")
|
||||||
public class ConfigService
|
public class ConfigService {
|
||||||
{
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysConfigService configService;
|
private ISysConfigService configService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据键名查询参数配置信息
|
* 根据键名查询参数配置信息
|
||||||
*
|
*
|
||||||
* @param configName 参数名称
|
* @param configKey 参数名称
|
||||||
* @return 参数键值
|
* @return 参数键值
|
||||||
*/
|
*/
|
||||||
public String getKey(String configKey)
|
public String getKey(String configKey) {
|
||||||
{
|
|
||||||
return configService.selectConfigByKey(configKey);
|
return configService.selectConfigByKey(configKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,40 @@
|
||||||
package com.ruoyi.framework.web.service;
|
package com.ruoyi.framework.web.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.ruoyi.system.domain.SysDictData;
|
import com.ruoyi.system.domain.SysDictData;
|
||||||
import com.ruoyi.system.service.ISysDictDataService;
|
import com.ruoyi.system.service.ISysDictDataService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RuoYi首创 html调用 thymeleaf 实现字典读取
|
* 首创 html调用 thymeleaf 实现字典读取
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service("dict")
|
@Service("dict")
|
||||||
public class DictService
|
public class DictService {
|
||||||
{
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDictDataService dictDataService;
|
private ISysDictDataService dictDataService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字典类型查询字典数据信息
|
* 根据字典类型查询字典数据信息
|
||||||
*
|
*
|
||||||
* @param dictType 字典类型
|
* @param dictType 字典类型
|
||||||
* @return 参数键值
|
* @return 参数键值
|
||||||
*/
|
*/
|
||||||
public List<SysDictData> getType(String dictType)
|
public List<SysDictData> getType(String dictType) {
|
||||||
{
|
|
||||||
return dictDataService.selectDictDataByType(dictType);
|
return dictDataService.selectDictDataByType(dictType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字典类型和字典键值查询字典数据信息
|
* 根据字典类型和字典键值查询字典数据信息
|
||||||
*
|
*
|
||||||
* @param dictType 字典类型
|
* @param dictType 字典类型
|
||||||
* @param dictValue 字典键值
|
* @param dictValue 字典键值
|
||||||
* @return 字典标签
|
* @return 字典标签
|
||||||
*/
|
*/
|
||||||
public String getLabel(String dictType, String dictValue)
|
public String getLabel(String dictType, String dictValue) {
|
||||||
{
|
|
||||||
return dictDataService.selectDictLabel(dictType, dictValue);
|
return dictDataService.selectDictLabel(dictType, dictValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,17 @@ import org.apache.shiro.SecurityUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RuoYi首创 js调用 thymeleaf 实现按钮权限可见性
|
* 首创 js调用 thymeleaf 实现按钮权限可见性
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service("permission")
|
@Service("permission")
|
||||||
public class PermissionService
|
public class PermissionService {
|
||||||
{
|
public String hasPermi(String permission) {
|
||||||
public String hasPermi(String permission)
|
|
||||||
{
|
|
||||||
return isPermittedOperator(permission) ? "" : "hidden";
|
return isPermittedOperator(permission) ? "" : "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPermittedOperator(String permission)
|
private boolean isPermittedOperator(String permission) {
|
||||||
{
|
|
||||||
return SecurityUtils.getSubject().isPermitted(permission);
|
return SecurityUtils.getSubject().isPermitted(permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue