From 403c12eb9c5df93b2159de82edf0484fbae87294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Sat, 15 May 2021 14:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=20v2.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 2 +- ruoyi-ui/src/views/index.vue | 10 +- ruoyi-ui/src/views/monitor/server/index.vue | 210 ------------------ ruoyi/pom.xml | 37 ++- .../ruoyi/common/core/page/IServicePlus.java | 114 +++++++++- .../com/ruoyi/common/core/page/PagePlus.java | 93 ++++---- .../com/ruoyi/common/utils/PageUtils.java | 29 ++- .../ruoyi/framework/web/domain/Server.java | 157 ------------- .../framework/web/domain/server/Cpu.java | 88 -------- .../framework/web/domain/server/Jvm.java | 112 ---------- .../framework/web/domain/server/Mem.java | 61 ----- .../framework/web/domain/server/Sys.java | 84 ------- .../framework/web/domain/server/SysFile.java | 114 ---------- .../controller/monitor/ServerController.java | 27 --- .../web/controller/tool/TestController.java | 166 -------------- .../ruoyi/web/core/config/SwaggerConfig.java | 23 +- 16 files changed, 222 insertions(+), 1105 deletions(-) delete mode 100644 ruoyi-ui/src/views/monitor/server/index.vue delete mode 100644 ruoyi/src/main/java/com/ruoyi/framework/web/domain/Server.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Sys.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/SysFile.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java delete mode 100644 ruoyi/src/main/java/com/ruoyi/web/controller/tool/TestController.java diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 313d72117..0ac7e1556 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -1,6 +1,6 @@ { "name": "ruoyi-vue-plus", - "version": "2.0.0", + "version": "2.1.0", "description": "RuoYi-Vue-Plus后台管理系统", "author": "LionLi", "license": "MIT", diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue index 84921bcea..9cee59a13 100644 --- a/ruoyi-ui/src/views/index.vue +++ b/ruoyi-ui/src/views/index.vue @@ -80,6 +80,14 @@ 更新日志 + +
    +
  1. update swagger升级3.0.2
  2. +
  3. update 增强分页工具兼容性
  4. +
  5. update 通用Service接口 增加自定义vo转换函数
  6. +
  7. remove 移除ruoyi自带服务监控(Admin已全部包含)
  8. +
+
  1. springboot 升级 2.3.10 依赖全面升级适配
  2. @@ -140,7 +148,7 @@ export default { data() { return { // 版本号 - version: "2.0.0", + version: "2.1.0", }; }, methods: { diff --git a/ruoyi-ui/src/views/monitor/server/index.vue b/ruoyi-ui/src/views/monitor/server/index.vue deleted file mode 100644 index 8ba30823d..000000000 --- a/ruoyi-ui/src/views/monitor/server/index.vue +++ /dev/null @@ -1,210 +0,0 @@ - - - \ No newline at end of file diff --git a/ruoyi/pom.xml b/ruoyi/pom.xml index 39b9fab2b..444bc7159 100644 --- a/ruoyi/pom.xml +++ b/ruoyi/pom.xml @@ -20,11 +20,9 @@ 1.8 3.1.1 1.2.4 - 2.0.8 - 1.3.0 + 3.0.2 + 1.5.22 1.2.75 - 5.6.0 - 5.7.0 4.1.2 1.7 0.9.1 @@ -91,25 +89,6 @@ ${druid.version} - - - com.github.oshi - oshi-core - ${oshi.version} - - - - net.java.dev.jna - jna - ${jna.version} - - - - net.java.dev.jna - jna-platform - ${jna.version} - - org.apache.velocity @@ -140,6 +119,18 @@ com.github.xiaoymin knife4j-spring-boot-starter ${knife4j.version} + + + swagger-annotations + io.swagger + + + + + + io.swagger + swagger-annotations + ${swagger-annotations.version} diff --git a/ruoyi/src/main/java/com/ruoyi/common/core/page/IServicePlus.java b/ruoyi/src/main/java/com/ruoyi/common/core/page/IServicePlus.java index 864a38e83..aeaee0b58 100644 --- a/ruoyi/src/main/java/com/ruoyi/common/core/page/IServicePlus.java +++ b/ruoyi/src/main/java/com/ruoyi/common/core/page/IServicePlus.java @@ -9,6 +9,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -30,6 +31,18 @@ public interface IServicePlus extends IService { return BeanUtil.toBean(t, kClass); } + /** + * 根据 ID 查询 + * + * @param id 主键ID + * @param convertor 转换函数 + * @param vo类型 + */ + default K getVoById(Serializable id, Function convertor) { + T t = getBaseMapper().selectById(id); + return convertor.apply(t); + } + /** * 查询(根据ID 批量查询) * @@ -46,6 +59,21 @@ public interface IServicePlus extends IService { .collect(Collectors.toList()); } + /** + * 查询(根据ID 批量查询) + * + * @param convertor 转换函数 + * @param idList 主键ID列表 + */ + default List listVoByIds(Collection idList, + Function, List> convertor) { + List list = getBaseMapper().selectBatchIds(idList); + if (list == null) { + return null; + } + return convertor.apply(list); + } + /** * 查询(根据 columnMap 条件) * @@ -62,6 +90,21 @@ public interface IServicePlus extends IService { .collect(Collectors.toList()); } + /** + * 查询(根据 columnMap 条件) + * + * @param convertor 转换函数 + * @param columnMap 表字段 map 对象 + */ + default List listVoByMap(Map columnMap, + Function, List> convertor) { + List list = getBaseMapper().selectByMap(columnMap); + if (list == null) { + return null; + } + return convertor.apply(list); + } + /** * 根据 Wrapper,查询一条记录
    *

    结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")

    @@ -73,6 +116,17 @@ public interface IServicePlus extends IService { return BeanUtil.toBean(getOne(queryWrapper, true), kClass); } + /** + * 根据 Wrapper,查询一条记录
    + *

    结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")

    + * + * @param convertor 转换函数 + * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper} + */ + default K getVoOne(Wrapper queryWrapper, Function convertor) { + return convertor.apply(getOne(queryWrapper, true)); + } + /** * 查询列表 * @@ -89,6 +143,20 @@ public interface IServicePlus extends IService { .collect(Collectors.toList()); } + /** + * 查询列表 + * + * @param convertor 转换函数 + * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper} + */ + default List listVo(Wrapper queryWrapper, Function, List> convertor) { + List list = getBaseMapper().selectList(queryWrapper); + if (list == null) { + return null; + } + return convertor.apply(list); + } + /** * 查询所有 * @@ -99,28 +167,64 @@ public interface IServicePlus extends IService { return listVo(Wrappers.emptyWrapper(), kClass); } + /** + * 查询所有 + * + * @param convertor 转换函数 + * @see Wrappers#emptyWrapper() + */ + default List listVo(Function, List> convertor) { + return listVo(Wrappers.emptyWrapper(), convertor); + } + /** * 翻页查询 * * @param page 翻页对象 * @param queryWrapper 实体对象封装操作类 - * @param kClass vo类型 + * @param kClass vo类型 */ default PagePlus pageVo(PagePlus page, Wrapper queryWrapper, Class kClass) { - PagePlus e = getBaseMapper().selectPage(page, queryWrapper); - page.recordsToVo(kClass); - return page; + PagePlus result = getBaseMapper().selectPage(page, queryWrapper); + List volist = result.getRecords().stream() + .map(any -> BeanUtil.toBean(any, kClass)) + .collect(Collectors.toList()); + result.setRecordsVo(volist); + return result; + } + + /** + * 翻页查询 + * + * @param page 翻页对象 + * @param queryWrapper 实体对象封装操作类 + * @param convertor 转换函数 + */ + default PagePlus pageVo(PagePlus page, Wrapper queryWrapper, + Function, List> convertor) { + PagePlus result = getBaseMapper().selectPage(page, queryWrapper); + return result.setRecordsVo(convertor.apply(result.getRecords())); } /** * 无条件翻页查询 * - * @param page 翻页对象 + * @param page 翻页对象 * @param kClass vo类型 */ default PagePlus pageVo(PagePlus page, Class kClass) { return pageVo(page, Wrappers.emptyWrapper(), kClass); } + /** + * 无条件翻页查询 + * + * @param page 翻页对象 + * @param convertor 转换函数 + */ + default PagePlus pageVo(PagePlus page, Function, List> convertor) { + return pageVo(page, Wrappers.emptyWrapper(), convertor); + } + } diff --git a/ruoyi/src/main/java/com/ruoyi/common/core/page/PagePlus.java b/ruoyi/src/main/java/com/ruoyi/common/core/page/PagePlus.java index 7200fc515..889d549f5 100644 --- a/ruoyi/src/main/java/com/ruoyi/common/core/page/PagePlus.java +++ b/ruoyi/src/main/java/com/ruoyi/common/core/page/PagePlus.java @@ -1,6 +1,5 @@ package com.ruoyi.common.core.page; -import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.OrderItem; import lombok.Data; @@ -10,34 +9,67 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; @Data @Accessors(chain = true) public class PagePlus implements IPage { - protected List records; - protected List recordsVo; - protected long total; - protected long size; - protected long current; - protected List orders; - protected boolean optimizeCountSql; - protected boolean isSearchCount; - protected boolean hitCount; - protected String countId; - protected Long maxLimit; + /** + * domain实体列表 + */ + private List records = Collections.emptyList(); + + /** + * vo实体列表 + */ + private List recordsVo = Collections.emptyList(); + + /** + * 总数 + */ + private long total = 0L; + + /** + * 页长度 + */ + private long size = 10L; + + /** + * 当前页 + */ + private long current = 1L; + + /** + * 排序字段信息 + */ + private List orders = new ArrayList<>(); + + /** + * 自动优化 COUNT SQL + */ + private boolean optimizeCountSql = true; + + /** + * 是否进行 count 查询 + */ + private boolean isSearchCount = true; + + /** + * 是否命中count缓存 + */ + private boolean hitCount = false; + + /** + * countId + */ + private String countId; + + /** + * 最大limit + */ + private Long maxLimit; public PagePlus() { - this.records = Collections.emptyList(); - this.recordsVo = Collections.emptyList(); - this.total = 0L; - this.size = 10L; - this.current = 1L; - this.orders = new ArrayList(); - this.optimizeCountSql = true; - this.isSearchCount = true; - this.hitCount = false; } public PagePlus(long current, long size) { @@ -53,18 +85,9 @@ public class PagePlus implements IPage { } public PagePlus(long current, long size, long total, boolean isSearchCount) { - this.records = Collections.emptyList(); - this.total = 0L; - this.size = 10L; - this.current = 1L; - this.orders = new ArrayList(); - this.optimizeCountSql = true; - this.isSearchCount = true; - this.hitCount = false; if (current > 1L) { this.current = current; } - this.size = size; this.total = total; this.isSearchCount = isSearchCount; @@ -78,12 +101,6 @@ public class PagePlus implements IPage { return this.current < this.getPages(); } - public void recordsToVo(Class kClass) { - this.recordsVo = this.records.stream() - .map(any -> BeanUtil.toBean(any, kClass)) - .collect(Collectors.toList()); - } - @Override public String countId() { return this.getCountId(); @@ -116,7 +133,7 @@ public class PagePlus implements IPage { @Override public boolean isSearchCount() { - return this.total < 0L ? false : this.isSearchCount; + return this.total >= 0L && this.isSearchCount; } public PagePlus setSearchCount(boolean isSearchCount) { diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/PageUtils.java b/ruoyi/src/main/java/com/ruoyi/common/utils/PageUtils.java index e484f6dd5..cf3f886d7 100644 --- a/ruoyi/src/main/java/com/ruoyi/common/utils/PageUtils.java +++ b/ruoyi/src/main/java/com/ruoyi/common/utils/PageUtils.java @@ -37,9 +37,25 @@ public class PageUtils { */ public static final String IS_ASC = "isAsc"; + /** + * 当前记录起始索引 默认值 + */ + public static final int DEFAULT_PAGE_NUM = 1; + + /** + * 每页显示记录数 默认值 + */ + public static final int DEFAULT_PAGE_SIZE = 10; + + /** + * 构建 plus 分页对象 + * @param domain 实体 + * @param vo 实体 + * @return 分页对象 + */ public static PagePlus buildPagePlus() { - Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM); - Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE); + Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM, DEFAULT_PAGE_NUM); + Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, DEFAULT_PAGE_SIZE); String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN); String isAsc = ServletUtils.getParameter(IS_ASC); PagePlus page = new PagePlus<>(pageNum, pageSize); @@ -54,9 +70,14 @@ public class PageUtils { return page; } + /** + * 构建 MP 普通分页对象 + * @param domain 实体 + * @return 分页对象 + */ public static Page buildPage() { - Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM); - Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE); + Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM, DEFAULT_PAGE_NUM); + Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, DEFAULT_PAGE_SIZE); String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN); String isAsc = ServletUtils.getParameter(IS_ASC); Page page = new Page<>(pageNum, pageSize); diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/Server.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/Server.java deleted file mode 100644 index 341d0b36e..000000000 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/Server.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.ruoyi.framework.web.domain; - -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.system.*; -import cn.hutool.system.oshi.CpuInfo; -import cn.hutool.system.oshi.OshiUtil; -import com.ruoyi.framework.web.domain.server.*; -import lombok.Data; -import oshi.hardware.GlobalMemory; -import oshi.software.os.FileSystem; -import oshi.software.os.OSFileStore; -import oshi.software.os.OperatingSystem; - -import java.util.LinkedList; -import java.util.List; - -/** - * 服务器相关信息 - * - * @author ruoyi - */ -@Data -public class Server { - private static final int OSHI_WAIT_SECOND = 1000; - - /** - * CPU相关信息 - */ - private Cpu cpu = new Cpu(); - - /** - * 內存相关信息 - */ - private Mem mem = new Mem(); - - /** - * JVM相关信息 - */ - private Jvm jvm = new Jvm(); - - /** - * 服务器相关信息 - */ - private Sys sys = new Sys(); - - /** - * 磁盘相关信息 - */ - private List sysFiles = new LinkedList(); - - - public void copyTo() { - setCpuInfo(); - setMemInfo(); - setSysInfo(); - setJvmInfo(); - setSysFiles(); - } - - /** - * 设置CPU信息 - */ - private void setCpuInfo() { - CpuInfo cpuInfo = OshiUtil.getCpuInfo(OSHI_WAIT_SECOND); - cpu.setCpuNum(cpuInfo.getCpuNum()); - cpu.setTotal(cpuInfo.getToTal()); - cpu.setSys(cpuInfo.getSys()); - cpu.setUsed(cpuInfo.getUsed()); - cpu.setWait(cpuInfo.getWait()); - cpu.setFree(cpuInfo.getFree()); - } - - /** - * 设置内存信息 - */ - private void setMemInfo() { - GlobalMemory memory = OshiUtil.getMemory(); - mem.setTotal(memory.getTotal()); - mem.setUsed(memory.getTotal() - memory.getAvailable()); - mem.setFree(memory.getAvailable()); - } - - /** - * 设置服务器信息 - */ - private void setSysInfo() { - HostInfo hostInfo = SystemUtil.getHostInfo(); - OsInfo osInfo = SystemUtil.getOsInfo(); - UserInfo userInfo = SystemUtil.getUserInfo(); - sys.setComputerName(hostInfo.getName()); - sys.setComputerIp(hostInfo.getAddress()); - sys.setOsName(osInfo.getName()); - sys.setOsArch(osInfo.getArch()); - sys.setUserDir(userInfo.getCurrentDir()); - } - - /** - * 设置Java虚拟机 - */ - private void setJvmInfo() { - JavaInfo javaInfo = SystemUtil.getJavaInfo(); - RuntimeInfo runtimeInfo = SystemUtil.getRuntimeInfo(); - JavaRuntimeInfo javaRuntimeInfo = SystemUtil.getJavaRuntimeInfo(); - jvm.setTotal(runtimeInfo.getTotalMemory()); - jvm.setMax(runtimeInfo.getMaxMemory()); - jvm.setFree(runtimeInfo.getFreeMemory()); - jvm.setVersion(javaInfo.getVersion()); - jvm.setHome(javaRuntimeInfo.getHomeDir()); - } - - /** - * 设置磁盘信息 - */ - private void setSysFiles() { - OperatingSystem os = OshiUtil.getOs(); - FileSystem fileSystem = os.getFileSystem(); - List fsArray = fileSystem.getFileStores(); - for (OSFileStore fs : fsArray) { - long free = fs.getUsableSpace(); - long total = fs.getTotalSpace(); - long used = total - free; - SysFile sysFile = new SysFile(); - sysFile.setDirName(fs.getMount()); - sysFile.setSysTypeName(fs.getType()); - sysFile.setTypeName(fs.getName()); - sysFile.setTotal(convertFileSize(total)); - sysFile.setFree(convertFileSize(free)); - sysFile.setUsed(convertFileSize(used)); - sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100)); - sysFiles.add(sysFile); - } - } - - /** - * 字节转换 - * - * @param size 字节大小 - * @return 转换后值 - */ - public String convertFileSize(long size) { - long kb = 1024; - long mb = kb * 1024; - long gb = mb * 1024; - if (size >= gb) { - return String.format("%.1f GB", (float) size / gb); - } else if (size >= mb) { - float f = (float) size / mb; - return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f); - } else if (size >= kb) { - float f = (float) size / kb; - return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f); - } else { - return String.format("%d B", size); - } - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java deleted file mode 100644 index 4295f6eec..000000000 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.ruoyi.framework.web.domain.server; - -import cn.hutool.core.util.NumberUtil; - -/** - * CPU相关信息 - * - * @author ruoyi - */ -public class Cpu { - /** - * 核心数 - */ - private int cpuNum; - - /** - * CPU总的使用率 - */ - private double total; - - /** - * CPU系统使用率 - */ - private double sys; - - /** - * CPU用户使用率 - */ - private double used; - - /** - * CPU当前等待率 - */ - private double wait; - - /** - * CPU当前空闲率 - */ - private double free; - - public int getCpuNum() { - return cpuNum; - } - - public void setCpuNum(int cpuNum) { - this.cpuNum = cpuNum; - } - - public double getTotal() { - return NumberUtil.round(NumberUtil.mul(total, 100), 2).doubleValue(); - } - - public void setTotal(double total) { - this.total = total; - } - - public double getSys() { - return NumberUtil.round(NumberUtil.mul(sys / total, 100), 2).doubleValue(); - } - - public void setSys(double sys) { - this.sys = sys; - } - - public double getUsed() { - return NumberUtil.round(NumberUtil.mul(used / total, 100), 2).doubleValue(); - } - - public void setUsed(double used) { - this.used = used; - } - - public double getWait() { - return NumberUtil.round(NumberUtil.mul(wait / total, 100), 2).doubleValue(); - } - - public void setWait(double wait) { - this.wait = wait; - } - - public double getFree() { - return NumberUtil.round(NumberUtil.mul(free / total, 100), 2).doubleValue(); - } - - public void setFree(double free) { - this.free = free; - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java deleted file mode 100644 index 4b70cbb84..000000000 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.ruoyi.framework.web.domain.server; - -import java.lang.management.ManagementFactory; -import java.util.Date; - -import cn.hutool.core.date.BetweenFormatter; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.NumberUtil; -import com.ruoyi.common.utils.DateUtils; - -/** - * JVM相关信息 - * - * @author ruoyi - */ -public class Jvm { - /** - * 当前JVM占用的内存总数(M) - */ - private double total; - - /** - * JVM最大可用内存总数(M) - */ - private double max; - - /** - * JVM空闲内存(M) - */ - private double free; - - /** - * JDK版本 - */ - private String version; - - /** - * JDK路径 - */ - private String home; - - public double getTotal() { - return NumberUtil.div(total, (1024 * 1024), 2); - } - - public void setTotal(double total) { - this.total = total; - } - - public double getMax() { - return NumberUtil.div(max, (1024 * 1024), 2); - } - - public void setMax(double max) { - this.max = max; - } - - public double getFree() { - return NumberUtil.div(free, (1024 * 1024), 2); - } - - public void setFree(double free) { - this.free = free; - } - - public double getUsed() { - return NumberUtil.div(total - free, (1024 * 1024), 2); - } - - public double getUsage() { - return NumberUtil.mul(NumberUtil.div(total - free, total, 4), 100); - } - - /** - * 获取JDK名称 - */ - public String getName() { - return ManagementFactory.getRuntimeMXBean().getVmName(); - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getHome() { - return home; - } - - public void setHome(String home) { - this.home = home; - } - - /** - * JDK启动时间 - */ - public String getStartTime() - { - return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate()); - } - - /** - * JDK运行时间 - */ - public String getRunTime() - { - return DateUtils.getDatePoor(DateUtils.getNowDate(), DateUtils.getServerStartDate()); - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java deleted file mode 100644 index 757ff5712..000000000 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.ruoyi.framework.web.domain.server; - -import cn.hutool.core.util.NumberUtil; - -/** - * 內存相关信息 - * - * @author ruoyi - */ -public class Mem -{ - /** - * 内存总量 - */ - private double total; - - /** - * 已用内存 - */ - private double used; - - /** - * 剩余内存 - */ - private double free; - - public double getTotal() - { - return NumberUtil.div(total, (1024 * 1024 * 1024), 2); - } - - public void setTotal(long total) - { - this.total = total; - } - - public double getUsed() - { - return NumberUtil.div(used, (1024 * 1024 * 1024), 2); - } - - public void setUsed(long used) - { - this.used = used; - } - - public double getFree() - { - return NumberUtil.div(free, (1024 * 1024 * 1024), 2); - } - - public void setFree(long free) - { - this.free = free; - } - - public double getUsage() - { - return NumberUtil.mul(NumberUtil.div(used, total, 4), 100); - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Sys.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Sys.java deleted file mode 100644 index 45d64d9cd..000000000 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/Sys.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.ruoyi.framework.web.domain.server; - -/** - * 系统相关信息 - * - * @author ruoyi - */ -public class Sys -{ - /** - * 服务器名称 - */ - private String computerName; - - /** - * 服务器Ip - */ - private String computerIp; - - /** - * 项目路径 - */ - private String userDir; - - /** - * 操作系统 - */ - private String osName; - - /** - * 系统架构 - */ - private String osArch; - - public String getComputerName() - { - return computerName; - } - - public void setComputerName(String computerName) - { - this.computerName = computerName; - } - - public String getComputerIp() - { - return computerIp; - } - - public void setComputerIp(String computerIp) - { - this.computerIp = computerIp; - } - - public String getUserDir() - { - return userDir; - } - - public void setUserDir(String userDir) - { - this.userDir = userDir; - } - - public String getOsName() - { - return osName; - } - - public void setOsName(String osName) - { - this.osName = osName; - } - - public String getOsArch() - { - return osArch; - } - - public void setOsArch(String osArch) - { - this.osArch = osArch; - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/SysFile.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/SysFile.java deleted file mode 100644 index 1320cde6e..000000000 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/server/SysFile.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.ruoyi.framework.web.domain.server; - -/** - * 系统文件相关信息 - * - * @author ruoyi - */ -public class SysFile -{ - /** - * 盘符路径 - */ - private String dirName; - - /** - * 盘符类型 - */ - private String sysTypeName; - - /** - * 文件类型 - */ - private String typeName; - - /** - * 总大小 - */ - private String total; - - /** - * 剩余大小 - */ - private String free; - - /** - * 已经使用量 - */ - private String used; - - /** - * 资源的使用率 - */ - private double usage; - - public String getDirName() - { - return dirName; - } - - public void setDirName(String dirName) - { - this.dirName = dirName; - } - - public String getSysTypeName() - { - return sysTypeName; - } - - public void setSysTypeName(String sysTypeName) - { - this.sysTypeName = sysTypeName; - } - - public String getTypeName() - { - return typeName; - } - - public void setTypeName(String typeName) - { - this.typeName = typeName; - } - - public String getTotal() - { - return total; - } - - public void setTotal(String total) - { - this.total = total; - } - - public String getFree() - { - return free; - } - - public void setFree(String free) - { - this.free = free; - } - - public String getUsed() - { - return used; - } - - public void setUsed(String used) - { - this.used = used; - } - - public double getUsage() - { - return usage; - } - - public void setUsage(double usage) - { - this.usage = usage; - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java b/ruoyi/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java deleted file mode 100644 index cc805ad89..000000000 --- a/ruoyi/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.ruoyi.web.controller.monitor; - -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.framework.web.domain.Server; - -/** - * 服务器监控 - * - * @author ruoyi - */ -@RestController -@RequestMapping("/monitor/server") -public class ServerController -{ - @PreAuthorize("@ss.hasPermi('monitor:server:list')") - @GetMapping() - public AjaxResult getInfo() throws Exception - { - Server server = new Server(); - server.copyTo(); - return AjaxResult.success(server); - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/web/controller/tool/TestController.java b/ruoyi/src/main/java/com/ruoyi/web/controller/tool/TestController.java deleted file mode 100644 index 3c5bf7c01..000000000 --- a/ruoyi/src/main/java/com/ruoyi/web/controller/tool/TestController.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.ruoyi.web.controller.tool; - -import cn.hutool.core.lang.Validator; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import io.swagger.annotations.*; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * swagger 用户测试方法 - * - * @author ruoyi - */ -@Api("用户信息管理") -@RestController -@RequestMapping("/test/user") -public class TestController extends BaseController -{ - private final static Map users = new LinkedHashMap(); - { - users.put(1, new UserEntity(1, "admin", "admin123", "15888888888")); - users.put(2, new UserEntity(2, "ry", "admin123", "15666666666")); - } - - @ApiOperation("获取用户列表") - @GetMapping("/list") - public AjaxResult userList() - { - List userList = new ArrayList(users.values()); - return AjaxResult.success(userList); - } - - @ApiOperation("获取用户详细") - @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path") - @GetMapping("/{userId}") - public AjaxResult getUser(@PathVariable Integer userId) - { - if (!users.isEmpty() && users.containsKey(userId)) - { - return AjaxResult.success(users.get(userId)); - } - else - { - return AjaxResult.error("用户不存在"); - } - } - - @ApiOperation("新增用户") - @ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity") - @PostMapping("/save") - public AjaxResult save(UserEntity user) - { - if (Validator.isNull(user) || Validator.isNull(user.getUserId())) - { - return AjaxResult.error("用户ID不能为空"); - } - return AjaxResult.success(users.put(user.getUserId(), user)); - } - - @ApiOperation("更新用户") - @ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity") - @PutMapping("/update") - public AjaxResult update(UserEntity user) - { - if (Validator.isNull(user) || Validator.isNull(user.getUserId())) - { - return AjaxResult.error("用户ID不能为空"); - } - if (users.isEmpty() || !users.containsKey(user.getUserId())) - { - return AjaxResult.error("用户不存在"); - } - users.remove(user.getUserId()); - return AjaxResult.success(users.put(user.getUserId(), user)); - } - - @ApiOperation("删除用户信息") - @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path") - @DeleteMapping("/{userId}") - public AjaxResult delete(@PathVariable Integer userId) - { - if (!users.isEmpty() && users.containsKey(userId)) - { - users.remove(userId); - return AjaxResult.success(); - } - else - { - return AjaxResult.error("用户不存在"); - } - } -} - -@ApiModel("用户实体") -class UserEntity -{ - @ApiModelProperty("用户ID") - private Integer userId; - - @ApiModelProperty("用户名称") - private String username; - - @ApiModelProperty("用户密码") - private String password; - - @ApiModelProperty("用户手机") - private String mobile; - - public UserEntity() - { - - } - - public UserEntity(Integer userId, String username, String password, String mobile) - { - this.userId = userId; - this.username = username; - this.password = password; - this.mobile = mobile; - } - - public Integer getUserId() - { - return userId; - } - - public void setUserId(Integer userId) - { - this.userId = userId; - } - - public String getUsername() - { - return username; - } - - public void setUsername(String username) - { - this.username = username; - } - - public String getPassword() - { - return password; - } - - public void setPassword(String password) - { - this.password = password; - } - - public String getMobile() - { - return mobile; - } - - public void setMobile(String mobile) - { - this.mobile = mobile; - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java b/ruoyi/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java index 8a1b74be3..39c7786ea 100644 --- a/ruoyi/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java +++ b/ruoyi/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java @@ -5,6 +5,8 @@ import com.ruoyi.common.config.RuoYiConfig; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; @@ -14,7 +16,7 @@ import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; +import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList; import java.util.List; @@ -25,8 +27,10 @@ import java.util.List; * @author Lion Li */ @Configuration -@EnableSwagger2WebMvc +@EnableSwagger2 @EnableKnife4j +@ConditionalOnClass({Docket.class, ApiInfoBuilder.class}) +@ConditionalOnProperty(prefix = "swagger", value = "enable", matchIfMissing = true) public class SwaggerConfig { /** * 系统基础配置 @@ -34,12 +38,6 @@ public class SwaggerConfig { @Autowired private RuoYiConfig ruoyiConfig; - /** - * 是否开启swagger - */ - @Value("${swagger.enabled}") - private boolean enabled; - /** * 设置请求的统一前缀 */ @@ -70,8 +68,6 @@ public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) - // 是否启用Swagger - .enable(enabled) // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) .apiInfo(apiInfo()) // 设置哪些接口暴露给Swagger展示 @@ -85,15 +81,14 @@ public class SwaggerConfig { .build() /* 设置安全模式,swagger可以设置访问token */ .securitySchemes(securitySchemes()) - .securityContexts(securityContexts()) - .pathMapping(pathMapping); + .securityContexts(securityContexts()); } /** * 安全模式,这里指定token通过Authorization头请求头传递 */ - private List securitySchemes() { - List apiKeyList = new ArrayList(); + private List securitySchemes() { + List apiKeyList = new ArrayList(); apiKeyList.add(new ApiKey("Authorization", "Authorization", "header")); return apiKeyList; }