From 339b932a3dea57068f20c40af384641c399c375e Mon Sep 17 00:00:00 2001 From: Josway Date: Mon, 22 Feb 2021 17:49:17 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81=E5=8F=AA=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/components/Editor/index.vue | 395 ++++++++++++----------- 1 file changed, 200 insertions(+), 195 deletions(-) diff --git a/ruoyi-ui/src/components/Editor/index.vue b/ruoyi-ui/src/components/Editor/index.vue index 905499536..ba2ea736d 100644 --- a/ruoyi-ui/src/components/Editor/index.vue +++ b/ruoyi-ui/src/components/Editor/index.vue @@ -1,195 +1,200 @@ - - - - - \ No newline at end of file + + + + + From 9a384a2fc27cdd05465f21ee446d02aaaa12de02 Mon Sep 17 00:00:00 2001 From: tzg Date: Tue, 23 Feb 2021 16:28:55 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20Byte[]=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=20to=20string=20=E6=AD=BB=E5=BE=AA=E7=8E=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/core/text/Convert.java | 113 +++++++++--------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java index 9dd076d04..8108c0ca4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java @@ -7,10 +7,11 @@ import java.nio.charset.Charset; import java.text.NumberFormat; import java.util.Set; import com.ruoyi.common.utils.StringUtils; +import org.apache.commons.lang3.ArrayUtils; /** * 类型转换器 - * + * * @author ruoyi */ public class Convert @@ -19,7 +20,7 @@ public class Convert * 转换为字符串
* 如果给定的值为null,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -41,7 +42,7 @@ public class Convert * 转换为字符串
* 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -54,7 +55,7 @@ public class Convert * 转换为字符
* 如果给定的值为null,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -78,7 +79,7 @@ public class Convert * 转换为字符
* 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -91,7 +92,7 @@ public class Convert * 转换为byte
* 如果给定的值为null,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -129,7 +130,7 @@ public class Convert * 转换为byte
* 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -142,7 +143,7 @@ public class Convert * 转换为Short
* 如果给定的值为null,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -180,7 +181,7 @@ public class Convert * 转换为Short
* 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -193,7 +194,7 @@ public class Convert * 转换为Number
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -227,7 +228,7 @@ public class Convert * 转换为Number
* 如果给定的值为空,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -240,7 +241,7 @@ public class Convert * 转换为int
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -278,7 +279,7 @@ public class Convert * 转换为int
* 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -289,7 +290,7 @@ public class Convert /** * 转换为Integer数组
- * + * * @param str 被转换的值 * @return 结果 */ @@ -300,7 +301,7 @@ public class Convert /** * 转换为Long数组
- * + * * @param str 被转换的值 * @return 结果 */ @@ -311,7 +312,7 @@ public class Convert /** * 转换为Integer数组
- * + * * @param split 分隔符 * @param split 被转换的值 * @return 结果 @@ -334,7 +335,7 @@ public class Convert /** * 转换为Long数组
- * + * * @param split 分隔符 * @param str 被转换的值 * @return 结果 @@ -357,7 +358,7 @@ public class Convert /** * 转换为String数组
- * + * * @param str 被转换的值 * @return 结果 */ @@ -368,7 +369,7 @@ public class Convert /** * 转换为String数组
- * + * * @param split 分隔符 * @param split 被转换的值 * @return 结果 @@ -382,7 +383,7 @@ public class Convert * 转换为long
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -421,7 +422,7 @@ public class Convert * 转换为long
* 如果给定的值为null,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -434,7 +435,7 @@ public class Convert * 转换为double
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -473,7 +474,7 @@ public class Convert * 转换为double
* 如果给定的值为空,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -486,7 +487,7 @@ public class Convert * 转换为Float
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -524,7 +525,7 @@ public class Convert * 转换为Float
* 如果给定的值为空,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -537,7 +538,7 @@ public class Convert * 转换为boolean
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -583,7 +584,7 @@ public class Convert * 转换为boolean
* 如果给定的值为空,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -595,7 +596,7 @@ public class Convert /** * 转换为Enum对象
* 如果给定的值为空,或者转换失败,返回默认值
- * + * * @param clazz Enum的Class * @param value 值 * @param defaultValue 默认值 @@ -631,7 +632,7 @@ public class Convert /** * 转换为Enum对象
* 如果给定的值为空,或者转换失败,返回默认值null
- * + * * @param clazz Enum的Class * @param value 值 * @return Enum @@ -645,7 +646,7 @@ public class Convert * 转换为BigInteger
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -683,7 +684,7 @@ public class Convert * 转换为BigInteger
* 如果给定的值为空,或者转换失败,返回默认值null
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -696,7 +697,7 @@ public class Convert * 转换为BigDecimal
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @param defaultValue 转换错误时的默认值 * @return 结果 @@ -742,7 +743,7 @@ public class Convert * 转换为BigDecimal
* 如果给定的值为空,或者转换失败,返回默认值
* 转换失败不会报错 - * + * * @param value 被转换的值 * @return 结果 */ @@ -754,7 +755,7 @@ public class Convert /** * 将对象转为字符串
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 - * + * * @param obj 对象 * @return 字符串 */ @@ -766,7 +767,7 @@ public class Convert /** * 将对象转为字符串
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 - * + * * @param obj 对象 * @param charsetName 字符集 * @return 字符串 @@ -779,28 +780,24 @@ public class Convert /** * 将对象转为字符串
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 - * + * * @param obj 对象 * @param charset 字符集 * @return 字符串 */ - public static String str(Object obj, Charset charset) - { - if (null == obj) - { + public static String str(Object obj, Charset charset) { + if (null == obj) { return null; } - if (obj instanceof String) - { + if (obj instanceof String) { return (String) obj; - } - else if (obj instanceof byte[] || obj instanceof Byte[]) - { - return str((Byte[]) obj, charset); - } - else if (obj instanceof ByteBuffer) - { + } else if (obj instanceof byte[]) { + return str((byte[]) obj, charset); + } else if (obj instanceof Byte[]) { + byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); + return str(bytes, charset); + } else if (obj instanceof ByteBuffer) { return str((ByteBuffer) obj, charset); } return obj.toString(); @@ -808,7 +805,7 @@ public class Convert /** * 将byte数组转为字符串 - * + * * @param bytes byte数组 * @param charset 字符集 * @return 字符串 @@ -820,7 +817,7 @@ public class Convert /** * 解码字节码 - * + * * @param data 字符串 * @param charset 字符集,如果此字段为空,则解码的结果取决于平台 * @return 解码后的字符串 @@ -841,7 +838,7 @@ public class Convert /** * 将编码的byteBuffer数据转换为字符串 - * + * * @param data 数据 * @param charset 字符集,如果为空使用当前系统字符集 * @return 字符串 @@ -858,7 +855,7 @@ public class Convert /** * 将编码的byteBuffer数据转换为字符串 - * + * * @param data 数据 * @param charset 字符集,如果为空使用当前系统字符集 * @return 字符串 @@ -875,7 +872,7 @@ public class Convert // ----------------------------------------------------------------------- 全角半角转换 /** * 半角转全角 - * + * * @param input String. * @return 全角字符串. */ @@ -886,7 +883,7 @@ public class Convert /** * 半角转全角 - * + * * @param input String * @param notConvertSet 不替换的字符集合 * @return 全角字符串. @@ -917,7 +914,7 @@ public class Convert /** * 全角转半角 - * + * * @param input String. * @return 半角字符串 */ @@ -928,7 +925,7 @@ public class Convert /** * 替换全角为半角 - * + * * @param text 文本 * @param notConvertSet 不替换的字符集合 * @return 替换后的字符 @@ -960,7 +957,7 @@ public class Convert /** * 数字金额大写转换 先写个完整的然后将如零拾替换成零 - * + * * @param n 数字 * @return 中文大写数字 */ From 64e807f27bc7f4d9770e5f1b856573719e9d3d8b Mon Sep 17 00:00:00 2001 From: RuoYi Date: Wed, 24 Feb 2021 13:45:24 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=BE=A4?= =?UTF-8?q?=E5=8F=B7=EF=BC=9A186866453?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- ruoyi-ui/src/views/index.vue | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 646c213cd..51a93691b 100644 --- a/README.md +++ b/README.md @@ -82,4 +82,4 @@ ## 若依前后端分离交流群 -QQ群: [![加入QQ群](https://img.shields.io/badge/已满-937441-blue.svg)](https://jq.qq.com/?_wv=1027&k=5bVB1og) [![加入QQ群](https://img.shields.io/badge/已满-887144332-blue.svg)](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [![加入QQ群](https://img.shields.io/badge/已满-180251782-blue.svg)](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [![加入QQ群](https://img.shields.io/badge/104180207-blue.svg)](https://jq.qq.com/?_wv=1027&k=51G72yr) 点击按钮入群。 \ No newline at end of file +QQ群: [![加入QQ群](https://img.shields.io/badge/已满-937441-blue.svg)](https://jq.qq.com/?_wv=1027&k=5bVB1og) [![加入QQ群](https://img.shields.io/badge/已满-887144332-blue.svg)](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [![加入QQ群](https://img.shields.io/badge/已满-180251782-blue.svg)](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [![加入QQ群](https://img.shields.io/badge/已满-104180207-blue.svg)](https://jq.qq.com/?_wv=1027&k=51G72yr) [![加入QQ群](https://img.shields.io/badge/186866453-blue.svg)](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) 点击按钮入群。 \ No newline at end of file diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue index 2aef93171..f3cf00f46 100644 --- a/ruoyi-ui/src/views/index.vue +++ b/ruoyi-ui/src/views/index.vue @@ -119,9 +119,9 @@

QQ群:满937441 - 满887144332 满180251782 - 104180207满887144332 满180251782 满104180207 + 186866453

From 0d8c3b4940cf9f0db2f8bf4069fc61742c3ddcd5 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Wed, 3 Mar 2021 13:53:03 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7oshi=E5=88=B0=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=ACv5.6.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a4309d89b..c9377ce48 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ 2.3.2 1.3.0 1.2.75 - 5.3.6 - 5.6.0 + 5.6.0 + 5.7.0 2.5 1.3.3 4.1.2 From 45fa686a64fd89a78e1516929592fd90e869e541 Mon Sep 17 00:00:00 2001 From: asher <285252577@qq.com> Date: Thu, 4 Mar 2021 16:58:18 +0800 Subject: [PATCH 05/10] update ruoyi-ui/src/views/monitor/operlog/index.vue. --- ruoyi-ui/src/views/monitor/operlog/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/monitor/operlog/index.vue b/ruoyi-ui/src/views/monitor/operlog/index.vue index 2f5262d24..28f1877b4 100644 --- a/ruoyi-ui/src/views/monitor/operlog/index.vue +++ b/ruoyi-ui/src/views/monitor/operlog/index.vue @@ -100,7 +100,7 @@ icon="el-icon-download" size="mini" @click="handleExport" - v-hasPermi="['system:config:export']" + v-hasPermi="['monitor:operlog:export']" >导出 From f938a24df00809418ff83859aa4041c4fc83a505 Mon Sep 17 00:00:00 2001 From: asher <285252577@qq.com> Date: Thu, 4 Mar 2021 17:00:07 +0800 Subject: [PATCH 06/10] update ruoyi-ui/src/views/monitor/logininfor/index.vue. --- ruoyi-ui/src/views/monitor/logininfor/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/monitor/logininfor/index.vue b/ruoyi-ui/src/views/monitor/logininfor/index.vue index b83d138b1..c9ffcea52 100644 --- a/ruoyi-ui/src/views/monitor/logininfor/index.vue +++ b/ruoyi-ui/src/views/monitor/logininfor/index.vue @@ -84,7 +84,7 @@ icon="el-icon-download" size="mini" @click="handleExport" - v-hasPermi="['system:logininfor:export']" + v-hasPermi="['monitor:logininfor:export']" >导出 From 61432480c8866ce0af8313dea367b2777e30b644 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 7 Mar 2021 11:06:47 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/core/text/Convert.java | 21 +++++++++++++------ ruoyi-ui/src/permission.js | 6 ++---- ruoyi-ui/src/store/modules/user.js | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java index 8108c0ca4..515cf0bc8 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java @@ -785,19 +785,28 @@ public class Convert * @param charset 字符集 * @return 字符串 */ - public static String str(Object obj, Charset charset) { - if (null == obj) { + public static String str(Object obj, Charset charset) + { + if (null == obj) + { return null; } - if (obj instanceof String) { + if (obj instanceof String) + { return (String) obj; - } else if (obj instanceof byte[]) { + } + else if (obj instanceof byte[]) + { return str((byte[]) obj, charset); - } else if (obj instanceof Byte[]) { + } + else if (obj instanceof Byte[]) + { byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); return str(bytes, charset); - } else if (obj instanceof ByteBuffer) { + } + else if (obj instanceof ByteBuffer) + { return str((ByteBuffer) obj, charset); } return obj.toString(); diff --git a/ruoyi-ui/src/permission.js b/ruoyi-ui/src/permission.js index 2c0b1cfb8..ae0bda25f 100644 --- a/ruoyi-ui/src/permission.js +++ b/ruoyi-ui/src/permission.js @@ -19,10 +19,8 @@ router.beforeEach((to, from, next) => { } else { if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息 - store.dispatch('GetInfo').then(res => { - // 拉取user_info - const roles = res.roles - store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => { + store.dispatch('GetInfo').then(() => { + store.dispatch('GenerateRoutes').then(accessRoutes => { // 根据roles权限生成可访问的路由表 router.addRoutes(accessRoutes) // 动态添加可访问路由表 next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 diff --git a/ruoyi-ui/src/store/modules/user.js b/ruoyi-ui/src/store/modules/user.js index 91f825307..92bd8f76a 100644 --- a/ruoyi-ui/src/store/modules/user.js +++ b/ruoyi-ui/src/store/modules/user.js @@ -49,7 +49,7 @@ const user = { // 获取用户信息 GetInfo({ commit, state }) { return new Promise((resolve, reject) => { - getInfo(state.token).then(res => { + getInfo().then(res => { const user = res.user const avatar = user.avatar == "" ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar; if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 From 51d942f14ced457feb49e8d22c8566c6ccf3683b Mon Sep 17 00:00:00 2001 From: hechieh <361020878@qq.com> Date: Wed, 10 Mar 2021 13:27:10 +0800 Subject: [PATCH 08/10] update ruoyi-admin/src/main/resources/application.yml. --- ruoyi-admin/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 35919facf..2255d690e 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -153,7 +153,7 @@ mybatis-plus: # 全局的entity的逻辑删除字段属性名 logicDeleteField: null # 逻辑已删除值 - logicDeleteValue: 1 + logicDeleteValue: 2 # 逻辑未删除值 logicNotDeleteValue: 0 # 字段验证策略之 insert,在 insert 的时候的字段验证策略 From 57cfad671fb6450c12e4f0dede7b248c5b9e799d 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: Fri, 12 Mar 2021 16:52:55 +0800 Subject: [PATCH 09/10] =?UTF-8?q?update=20=E4=BD=BF=E7=94=A8hutool?= =?UTF-8?q?=E9=87=8D=E5=86=99=E9=AA=8C=E8=AF=81=E7=A0=81=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + pom.xml | 10 +- .../controller/common/CaptchaController.java | 126 +++-- .../src/main/resources/application.yml | 8 + .../ruoyi/common/utils/VerifyCodeUtils.java | 228 --------- .../common/utils/file/FileUploadUtils.java | 5 +- .../com/ruoyi/common/utils/uuid/IdUtils.java | 51 -- .../com/ruoyi/common/utils/uuid/UUID.java | 484 ------------------ ruoyi-framework/pom.xml | 12 - .../ruoyi/framework/config/CaptchaConfig.java | 112 ++-- .../framework/config/KaptchaTextCreator.java | 75 --- .../framework/web/service/TokenService.java | 5 +- 12 files changed, 138 insertions(+), 979 deletions(-) delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/VerifyCodeUtils.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/IdUtils.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java delete mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/config/KaptchaTextCreator.java diff --git a/README.md b/README.md index c30be9ab7..c8d2829ef 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ * 容器改动 Tomcat 改为 并发性能更好的 undertow * 代码生成模板 改为适配 Mybatis-Plus 的代码 * 项目修改为 maven多环境配置 +* 集成 Hutool 5.X 并重写RuoYi部分功能 * 集成 Feign 接口化管理 Http 请求(如三方请求 支付,短信,推送等) * 升级MybatisPlus 3.4.2 * 增加demo模块示例(给不会增加模块的小伙伴做参考) diff --git a/pom.xml b/pom.xml index c648de5cc..328bad019 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,6 @@ 1.2.4 1.21 2.9.2 - 2.3.2 1.3.0 1.2.75 5.6.0 @@ -32,7 +31,7 @@ 1.7 0.9.1 3.4.2 - 5.4.0 + 5.5.8 2.2.6.RELEASE 11.0 @@ -162,13 +161,6 @@ ${jwt.version} - - - com.github.penggle - kaptcha - ${kaptcha.version} - - com.baomidou mybatis-plus-boot-starter diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java index 8cafcef1c..b170b1d4f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java @@ -1,86 +1,120 @@ package com.ruoyi.web.controller.common; -import java.awt.image.BufferedImage; -import java.io.IOException; import java.util.concurrent.TimeUnit; -import javax.annotation.Resource; -import javax.imageio.ImageIO; -import javax.servlet.http.HttpServletResponse; + +import cn.hutool.captcha.CircleCaptcha; +import cn.hutool.captcha.ICaptcha; +import cn.hutool.captcha.LineCaptcha; +import cn.hutool.captcha.ShearCaptcha; +import cn.hutool.captcha.generator.CodeGenerator; +import cn.hutool.captcha.generator.MathGenerator; +import cn.hutool.captcha.generator.RandomGenerator; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.ruoyi.common.core.text.Convert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.util.FastByteArrayOutputStream; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import com.google.code.kaptcha.Producer; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisCache; -import com.ruoyi.common.utils.sign.Base64; -import com.ruoyi.common.utils.uuid.IdUtils; + +import javax.annotation.Resource; /** * 验证码操作处理 - * - * @author ruoyi + * + * @author Lion Li */ @RestController -public class CaptchaController -{ - @Resource(name = "captchaProducer") - private Producer captchaProducer; +public class CaptchaController { - @Resource(name = "captchaProducerMath") - private Producer captchaProducerMath; + // 圆圈干扰验证码 + @Resource(name = "CircleCaptcha") + private CircleCaptcha circleCaptcha; + // 线段干扰的验证码 + @Resource(name = "LineCaptcha") + private LineCaptcha lineCaptcha; + // 扭曲干扰验证码 + @Resource(name = "ShearCaptcha") + private ShearCaptcha shearCaptcha; @Autowired private RedisCache redisCache; - + // 验证码类型 - @Value("${ruoyi.captchaType}") + @Value("${captcha.captchaType}") private String captchaType; + // 验证码类别 + @Value("${captcha.captchaCategory}") + private String captchaCategory; + // 数字验证码位数 + @Value("${captcha.captchaNumberLength}") + private int numberLength; + // 字符验证码长度 + @Value("${captcha.captchaCharLength}") + private int charLength; /** * 生成验证码 */ @GetMapping("/captchaImage") - public AjaxResult getCode(HttpServletResponse response) throws IOException - { + public AjaxResult getCode() { // 保存验证码信息 - String uuid = IdUtils.simpleUUID(); + String uuid = IdUtil.simpleUUID(); String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; - String capStr = null, code = null; - BufferedImage image = null; - // 生成验证码 - if ("math".equals(captchaType)) - { - String capText = captchaProducerMath.createText(); - capStr = capText.substring(0, capText.lastIndexOf("@")); - code = capText.substring(capText.lastIndexOf("@") + 1); - image = captchaProducerMath.createImage(capStr); + CodeGenerator codeGenerator; + if ("math".equals(captchaType)) { + codeGenerator = new MathGenerator(numberLength); + } else if ("char".equals(captchaType)) { + codeGenerator = new RandomGenerator(charLength); + } else { + throw new IllegalArgumentException("验证码类型异常"); } - else if ("char".equals(captchaType)) - { - capStr = code = captchaProducer.createText(); - image = captchaProducer.createImage(capStr); + if ("line".equals(captchaCategory)) { + lineCaptcha.setGenerator(codeGenerator); + capStr = lineCaptcha.getCode(); + } else if ("circle".equals(captchaCategory)) { + circleCaptcha.setGenerator(codeGenerator); + capStr = circleCaptcha.getCode(); + } else if ("shear".equals(captchaCategory)) { + shearCaptcha.setGenerator(codeGenerator); + capStr = shearCaptcha.getCode(); + } else { + throw new IllegalArgumentException("验证码类别异常"); + } + if ("math".equals(captchaType)) { + code = getCodeResult(capStr); + } else if ("char".equals(captchaType)) { + code = capStr; } redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); - // 转换流信息写出 - FastByteArrayOutputStream os = new FastByteArrayOutputStream(); - try - { - ImageIO.write(image, "jpg", os); - } - catch (IOException e) - { - return AjaxResult.error(e.getMessage()); - } + circleCaptcha.createImage(capStr); AjaxResult ajax = AjaxResult.success(); ajax.put("uuid", uuid); - ajax.put("img", Base64.encode(os.toByteArray())); + ajax.put("img", circleCaptcha.getImageBase64()); return ajax; } + + private String getCodeResult(String capStr) { + int a = Convert.toInt(StrUtil.sub(capStr, 0, numberLength).trim()); + char operator = capStr.charAt(numberLength); + int b = Convert.toInt(StrUtil.sub(capStr, numberLength + 1, numberLength + 1 + numberLength).trim()); + switch (operator) { + case '*': + return a * b + ""; + case '+': + return a + b + ""; + case '-': + return a - b + ""; + default: + return ""; + } + } + } diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 2255d690e..963614d57 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -12,8 +12,16 @@ ruoyi: profile: ${user.dir}/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false + +captcha: # 验证码类型 math 数组计算 char 字符验证 captchaType: math + # line 线段干扰 circle 圆圈干扰 shear 扭曲干扰 + captchaCategory: circle + # 数字验证码位数 + captchaNumberLength: 1 + # 字符验证码长度 + captchaCharLength: 4 # 开发环境配置 server: diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/VerifyCodeUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/VerifyCodeUtils.java deleted file mode 100644 index 5fdf3a9d6..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/VerifyCodeUtils.java +++ /dev/null @@ -1,228 +0,0 @@ -package com.ruoyi.common.utils; - -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.OutputStream; -import java.security.SecureRandom; -import java.util.Arrays; -import java.util.Random; -import javax.imageio.ImageIO; - -/** - * 验证码工具类 - * - * @author ruoyi - */ -public class VerifyCodeUtils -{ - // 使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符 - public static final String VERIFY_CODES = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ"; - - private static Random random = new SecureRandom(); - - /** - * 使用系统默认字符源生成验证码 - * - * @param verifySize 验证码长度 - * @return - */ - public static String generateVerifyCode(int verifySize) - { - return generateVerifyCode(verifySize, VERIFY_CODES); - } - - /** - * 使用指定源生成验证码 - * - * @param verifySize 验证码长度 - * @param sources 验证码字符源 - * @return - */ - public static String generateVerifyCode(int verifySize, String sources) - { - if (sources == null || sources.length() == 0) - { - sources = VERIFY_CODES; - } - int codesLen = sources.length(); - Random rand = new Random(System.currentTimeMillis()); - StringBuilder verifyCode = new StringBuilder(verifySize); - for (int i = 0; i < verifySize; i++) - { - verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1))); - } - return verifyCode.toString(); - } - - /** - * 输出指定验证码图片流 - * - * @param w - * @param h - * @param os - * @param code - * @throws IOException - */ - public static void outputImage(int w, int h, OutputStream os, String code) throws IOException - { - int verifySize = code.length(); - BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); - Random rand = new Random(); - Graphics2D g2 = image.createGraphics(); - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - Color[] colors = new Color[5]; - Color[] colorSpaces = new Color[] { Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, - Color.ORANGE, Color.PINK, Color.YELLOW }; - float[] fractions = new float[colors.length]; - for (int i = 0; i < colors.length; i++) - { - colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)]; - fractions[i] = rand.nextFloat(); - } - Arrays.sort(fractions); - - g2.setColor(Color.GRAY);// 设置边框色 - g2.fillRect(0, 0, w, h); - - Color c = getRandColor(200, 250); - g2.setColor(c);// 设置背景色 - g2.fillRect(0, 2, w, h - 4); - - // 绘制干扰线 - Random random = new Random(); - g2.setColor(getRandColor(160, 200));// 设置线条的颜色 - for (int i = 0; i < 20; i++) - { - int x = random.nextInt(w - 1); - int y = random.nextInt(h - 1); - int xl = random.nextInt(6) + 1; - int yl = random.nextInt(12) + 1; - g2.drawLine(x, y, x + xl + 40, y + yl + 20); - } - - // 添加噪点 - float yawpRate = 0.05f;// 噪声率 - int area = (int) (yawpRate * w * h); - for (int i = 0; i < area; i++) - { - int x = random.nextInt(w); - int y = random.nextInt(h); - int rgb = getRandomIntColor(); - image.setRGB(x, y, rgb); - } - - shear(g2, w, h, c);// 使图片扭曲 - - g2.setColor(getRandColor(100, 160)); - int fontSize = h - 4; - Font font = new Font("Algerian", Font.ITALIC, fontSize); - g2.setFont(font); - char[] chars = code.toCharArray(); - for (int i = 0; i < verifySize; i++) - { - AffineTransform affine = new AffineTransform(); - affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1), - (w / verifySize) * i + fontSize / 2, h / 2); - g2.setTransform(affine); - g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + fontSize / 2 - 10); - } - - g2.dispose(); - ImageIO.write(image, "jpg", os); - } - - private static Color getRandColor(int fc, int bc) - { - if (fc > 255) { - fc = 255; - } - if (bc > 255) { - bc = 255; - } - int r = fc + random.nextInt(bc - fc); - int g = fc + random.nextInt(bc - fc); - int b = fc + random.nextInt(bc - fc); - return new Color(r, g, b); - } - - private static int getRandomIntColor() - { - int[] rgb = getRandomRgb(); - int color = 0; - for (int c : rgb) - { - color = color << 8; - color = color | c; - } - return color; - } - - private static int[] getRandomRgb() - { - int[] rgb = new int[3]; - for (int i = 0; i < 3; i++) - { - rgb[i] = random.nextInt(255); - } - return rgb; - } - - private static void shear(Graphics g, int w1, int h1, Color color) - { - shearX(g, w1, h1, color); - shearY(g, w1, h1, color); - } - - private static void shearX(Graphics g, int w1, int h1, Color color) - { - - int period = random.nextInt(2); - - boolean borderGap = true; - int frames = 1; - int phase = random.nextInt(2); - - for (int i = 0; i < h1; i++) - { - double d = (double) (period >> 1) - * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames); - g.copyArea(0, i, w1, 1, (int) d, 0); - if (borderGap) - { - g.setColor(color); - g.drawLine((int) d, i, 0, i); - g.drawLine((int) d + w1, i, w1, i); - } - } - - } - - private static void shearY(Graphics g, int w1, int h1, Color color) - { - - int period = random.nextInt(40) + 10; // 50; - - boolean borderGap = true; - int frames = 20; - int phase = 7; - for (int i = 0; i < w1; i++) - { - double d = (double) (period >> 1) - * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames); - g.copyArea(i, 0, 1, h1, 0, (int) d); - if (borderGap) - { - g.setColor(color); - g.drawLine(i, (int) d, i, 0); - g.drawLine(i, (int) d + h1, i, h1); - } - - } - } -} \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java index 86141df4c..2d1bc95f7 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java @@ -2,6 +2,8 @@ package com.ruoyi.common.utils.file; import java.io.File; import java.io.IOException; + +import cn.hutool.core.util.IdUtil; import org.apache.commons.io.FilenameUtils; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.config.RuoYiConfig; @@ -11,7 +13,6 @@ import com.ruoyi.common.exception.file.FileSizeLimitExceededException; import com.ruoyi.common.exception.file.InvalidExtensionException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.uuid.IdUtils; /** * 文件上传工具类 @@ -123,7 +124,7 @@ public class FileUploadUtils { String fileName = file.getOriginalFilename(); String extension = getExtension(file); - fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; + fileName = DateUtils.datePath() + "/" + IdUtil.fastUUID() + "." + extension; return fileName; } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/IdUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/IdUtils.java deleted file mode 100644 index 0d14f57d0..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/IdUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.ruoyi.common.utils.uuid; - -import com.ruoyi.common.utils.uuid.UUID; - -/** - * ID生成器工具类 - * - * @author ruoyi - */ -public class IdUtils -{ - /** - * 获取随机UUID - * - * @return 随机UUID - */ - public static String randomUUID() - { - return UUID.randomUUID().toString(); - } - - /** - * 简化的UUID,去掉了横线 - * - * @return 简化的UUID,去掉了横线 - */ - public static String simpleUUID() - { - return UUID.randomUUID().toString(true); - } - - /** - * 获取随机UUID,使用性能更好的ThreadLocalRandom生成UUID - * - * @return 随机UUID - */ - public static String fastUUID() - { - return UUID.fastUUID().toString(); - } - - /** - * 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID - * - * @return 简化的UUID,去掉了横线 - */ - public static String fastSimpleUUID() - { - return UUID.fastUUID().toString(true); - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java deleted file mode 100644 index 062d6336c..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/UUID.java +++ /dev/null @@ -1,484 +0,0 @@ -package com.ruoyi.common.utils.uuid; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; -import com.ruoyi.common.exception.UtilException; - -/** - * 提供通用唯一识别码(universally unique identifier)(UUID)实现 - * - * @author ruoyi - */ -public final class UUID implements java.io.Serializable, Comparable -{ - private static final long serialVersionUID = -1185015143654744140L; - - /** - * SecureRandom 的单例 - * - */ - private static class Holder - { - static final SecureRandom numberGenerator = getSecureRandom(); - } - - /** 此UUID的最高64有效位 */ - private final long mostSigBits; - - /** 此UUID的最低64有效位 */ - private final long leastSigBits; - - /** - * 私有构造 - * - * @param data 数据 - */ - private UUID(byte[] data) - { - long msb = 0; - long lsb = 0; - assert data.length == 16 : "data must be 16 bytes in length"; - for (int i = 0; i < 8; i++) - { - msb = (msb << 8) | (data[i] & 0xff); - } - for (int i = 8; i < 16; i++) - { - lsb = (lsb << 8) | (data[i] & 0xff); - } - this.mostSigBits = msb; - this.leastSigBits = lsb; - } - - /** - * 使用指定的数据构造新的 UUID。 - * - * @param mostSigBits 用于 {@code UUID} 的最高有效 64 位 - * @param leastSigBits 用于 {@code UUID} 的最低有效 64 位 - */ - public UUID(long mostSigBits, long leastSigBits) - { - this.mostSigBits = mostSigBits; - this.leastSigBits = leastSigBits; - } - - /** - * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。 - * - * @return 随机生成的 {@code UUID} - */ - public static UUID fastUUID() - { - return randomUUID(false); - } - - /** - * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的强伪随机数生成器生成该 UUID。 - * - * @return 随机生成的 {@code UUID} - */ - public static UUID randomUUID() - { - return randomUUID(true); - } - - /** - * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的强伪随机数生成器生成该 UUID。 - * - * @param isSecure 是否使用{@link SecureRandom}如果是可以获得更安全的随机码,否则可以得到更好的性能 - * @return 随机生成的 {@code UUID} - */ - public static UUID randomUUID(boolean isSecure) - { - final Random ng = isSecure ? Holder.numberGenerator : getRandom(); - - byte[] randomBytes = new byte[16]; - ng.nextBytes(randomBytes); - randomBytes[6] &= 0x0f; /* clear version */ - randomBytes[6] |= 0x40; /* set to version 4 */ - randomBytes[8] &= 0x3f; /* clear variant */ - randomBytes[8] |= 0x80; /* set to IETF variant */ - return new UUID(randomBytes); - } - - /** - * 根据指定的字节数组获取类型 3(基于名称的)UUID 的静态工厂。 - * - * @param name 用于构造 UUID 的字节数组。 - * - * @return 根据指定数组生成的 {@code UUID} - */ - public static UUID nameUUIDFromBytes(byte[] name) - { - MessageDigest md; - try - { - md = MessageDigest.getInstance("MD5"); - } - catch (NoSuchAlgorithmException nsae) - { - throw new InternalError("MD5 not supported"); - } - byte[] md5Bytes = md.digest(name); - md5Bytes[6] &= 0x0f; /* clear version */ - md5Bytes[6] |= 0x30; /* set to version 3 */ - md5Bytes[8] &= 0x3f; /* clear variant */ - md5Bytes[8] |= 0x80; /* set to IETF variant */ - return new UUID(md5Bytes); - } - - /** - * 根据 {@link #toString()} 方法中描述的字符串标准表示形式创建{@code UUID}。 - * - * @param name 指定 {@code UUID} 字符串 - * @return 具有指定值的 {@code UUID} - * @throws IllegalArgumentException 如果 name 与 {@link #toString} 中描述的字符串表示形式不符抛出此异常 - * - */ - public static UUID fromString(String name) - { - String[] components = name.split("-"); - if (components.length != 5) - { - throw new IllegalArgumentException("Invalid UUID string: " + name); - } - for (int i = 0; i < 5; i++) - { - components[i] = "0x" + components[i]; - } - - long mostSigBits = Long.decode(components[0]).longValue(); - mostSigBits <<= 16; - mostSigBits |= Long.decode(components[1]).longValue(); - mostSigBits <<= 16; - mostSigBits |= Long.decode(components[2]).longValue(); - - long leastSigBits = Long.decode(components[3]).longValue(); - leastSigBits <<= 48; - leastSigBits |= Long.decode(components[4]).longValue(); - - return new UUID(mostSigBits, leastSigBits); - } - - /** - * 返回此 UUID 的 128 位值中的最低有效 64 位。 - * - * @return 此 UUID 的 128 位值中的最低有效 64 位。 - */ - public long getLeastSignificantBits() - { - return leastSigBits; - } - - /** - * 返回此 UUID 的 128 位值中的最高有效 64 位。 - * - * @return 此 UUID 的 128 位值中最高有效 64 位。 - */ - public long getMostSignificantBits() - { - return mostSigBits; - } - - /** - * 与此 {@code UUID} 相关联的版本号. 版本号描述此 {@code UUID} 是如何生成的。 - *

- * 版本号具有以下含意: - *

    - *
  • 1 基于时间的 UUID - *
  • 2 DCE 安全 UUID - *
  • 3 基于名称的 UUID - *
  • 4 随机生成的 UUID - *
- * - * @return 此 {@code UUID} 的版本号 - */ - public int version() - { - // Version is bits masked by 0x000000000000F000 in MS long - return (int) ((mostSigBits >> 12) & 0x0f); - } - - /** - * 与此 {@code UUID} 相关联的变体号。变体号描述 {@code UUID} 的布局。 - *

- * 变体号具有以下含意: - *

    - *
  • 0 为 NCS 向后兼容保留 - *
  • 2 IETF RFC 4122(Leach-Salz), 用于此类 - *
  • 6 保留,微软向后兼容 - *
  • 7 保留供以后定义使用 - *
- * - * @return 此 {@code UUID} 相关联的变体号 - */ - public int variant() - { - // This field is composed of a varying number of bits. - // 0 - - Reserved for NCS backward compatibility - // 1 0 - The IETF aka Leach-Salz variant (used by this class) - // 1 1 0 Reserved, Microsoft backward compatibility - // 1 1 1 Reserved for future definition. - return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) & (leastSigBits >> 63)); - } - - /** - * 与此 UUID 相关联的时间戳值。 - * - *

- * 60 位的时间戳值根据此 {@code UUID} 的 time_low、time_mid 和 time_hi 字段构造。
- * 所得到的时间戳以 100 毫微秒为单位,从 UTC(通用协调时间) 1582 年 10 月 15 日零时开始。 - * - *

- * 时间戳值仅在在基于时间的 UUID(其 version 类型为 1)中才有意义。
- * 如果此 {@code UUID} 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。 - * - * @throws UnsupportedOperationException 如果此 {@code UUID} 不是 version 为 1 的 UUID。 - */ - public long timestamp() throws UnsupportedOperationException - { - checkTimeBase(); - return (mostSigBits & 0x0FFFL) << 48// - | ((mostSigBits >> 16) & 0x0FFFFL) << 32// - | mostSigBits >>> 32; - } - - /** - * 与此 UUID 相关联的时钟序列值。 - * - *

- * 14 位的时钟序列值根据此 UUID 的 clock_seq 字段构造。clock_seq 字段用于保证在基于时间的 UUID 中的时间唯一性。 - *

- * {@code clockSequence} 值仅在基于时间的 UUID(其 version 类型为 1)中才有意义。 如果此 UUID 不是基于时间的 UUID,则此方法抛出 - * UnsupportedOperationException。 - * - * @return 此 {@code UUID} 的时钟序列 - * - * @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1 - */ - public int clockSequence() throws UnsupportedOperationException - { - checkTimeBase(); - return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48); - } - - /** - * 与此 UUID 相关的节点值。 - * - *

- * 48 位的节点值根据此 UUID 的 node 字段构造。此字段旨在用于保存机器的 IEEE 802 地址,该地址用于生成此 UUID 以保证空间唯一性。 - *

- * 节点值仅在基于时间的 UUID(其 version 类型为 1)中才有意义。
- * 如果此 UUID 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。 - * - * @return 此 {@code UUID} 的节点值 - * - * @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1 - */ - public long node() throws UnsupportedOperationException - { - checkTimeBase(); - return leastSigBits & 0x0000FFFFFFFFFFFFL; - } - - /** - * 返回此{@code UUID} 的字符串表现形式。 - * - *

- * UUID 的字符串表示形式由此 BNF 描述: - * - *

-     * {@code
-     * UUID                   = ----
-     * time_low               = 4*
-     * time_mid               = 2*
-     * time_high_and_version  = 2*
-     * variant_and_sequence   = 2*
-     * node                   = 6*
-     * hexOctet               = 
-     * hexDigit               = [0-9a-fA-F]
-     * }
-     * 
- * - * - * - * @return 此{@code UUID} 的字符串表现形式 - * @see #toString(boolean) - */ - @Override - public String toString() - { - return toString(false); - } - - /** - * 返回此{@code UUID} 的字符串表现形式。 - * - *

- * UUID 的字符串表示形式由此 BNF 描述: - * - *

-     * {@code
-     * UUID                   = ----
-     * time_low               = 4*
-     * time_mid               = 2*
-     * time_high_and_version  = 2*
-     * variant_and_sequence   = 2*
-     * node                   = 6*
-     * hexOctet               = 
-     * hexDigit               = [0-9a-fA-F]
-     * }
-     * 
- * - * - * - * @param isSimple 是否简单模式,简单模式为不带'-'的UUID字符串 - * @return 此{@code UUID} 的字符串表现形式 - */ - public String toString(boolean isSimple) - { - final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36); - // time_low - builder.append(digits(mostSigBits >> 32, 8)); - if (false == isSimple) - { - builder.append('-'); - } - // time_mid - builder.append(digits(mostSigBits >> 16, 4)); - if (false == isSimple) - { - builder.append('-'); - } - // time_high_and_version - builder.append(digits(mostSigBits, 4)); - if (false == isSimple) - { - builder.append('-'); - } - // variant_and_sequence - builder.append(digits(leastSigBits >> 48, 4)); - if (false == isSimple) - { - builder.append('-'); - } - // node - builder.append(digits(leastSigBits, 12)); - - return builder.toString(); - } - - /** - * 返回此 UUID 的哈希码。 - * - * @return UUID 的哈希码值。 - */ - @Override - public int hashCode() - { - long hilo = mostSigBits ^ leastSigBits; - return ((int) (hilo >> 32)) ^ (int) hilo; - } - - /** - * 将此对象与指定对象比较。 - *

- * 当且仅当参数不为 {@code null}、而是一个 UUID 对象、具有与此 UUID 相同的 varriant、包含相同的值(每一位均相同)时,结果才为 {@code true}。 - * - * @param obj 要与之比较的对象 - * - * @return 如果对象相同,则返回 {@code true};否则返回 {@code false} - */ - @Override - public boolean equals(Object obj) - { - if ((null == obj) || (obj.getClass() != UUID.class)) - { - return false; - } - UUID id = (UUID) obj; - return (mostSigBits == id.mostSigBits && leastSigBits == id.leastSigBits); - } - - // Comparison Operations - - /** - * 将此 UUID 与指定的 UUID 比较。 - * - *

- * 如果两个 UUID 不同,且第一个 UUID 的最高有效字段大于第二个 UUID 的对应字段,则第一个 UUID 大于第二个 UUID。 - * - * @param val 与此 UUID 比较的 UUID - * - * @return 在此 UUID 小于、等于或大于 val 时,分别返回 -1、0 或 1。 - * - */ - @Override - public int compareTo(UUID val) - { - // The ordering is intentionally set up so that the UUIDs - // can simply be numerically compared as two numbers - return (this.mostSigBits < val.mostSigBits ? -1 : // - (this.mostSigBits > val.mostSigBits ? 1 : // - (this.leastSigBits < val.leastSigBits ? -1 : // - (this.leastSigBits > val.leastSigBits ? 1 : // - 0)))); - } - - // ------------------------------------------------------------------------------------------------------------------- - // Private method start - /** - * 返回指定数字对应的hex值 - * - * @param val 值 - * @param digits 位 - * @return 值 - */ - private static String digits(long val, int digits) - { - long hi = 1L << (digits * 4); - return Long.toHexString(hi | (val & (hi - 1))).substring(1); - } - - /** - * 检查是否为time-based版本UUID - */ - private void checkTimeBase() - { - if (version() != 1) - { - throw new UnsupportedOperationException("Not a time-based UUID"); - } - } - - /** - * 获取{@link SecureRandom},类提供加密的强随机数生成器 (RNG) - * - * @return {@link SecureRandom} - */ - public static SecureRandom getSecureRandom() - { - try - { - return SecureRandom.getInstance("SHA1PRNG"); - } - catch (NoSuchAlgorithmException e) - { - throw new UtilException(e); - } - } - - /** - * 获取随机数生成器对象
- * ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺。 - * - * @return {@link ThreadLocalRandom} - */ - public static ThreadLocalRandom getRandom() - { - return ThreadLocalRandom.current(); - } -} diff --git a/ruoyi-framework/pom.xml b/ruoyi-framework/pom.xml index 1100a2930..d738880e9 100644 --- a/ruoyi-framework/pom.xml +++ b/ruoyi-framework/pom.xml @@ -55,18 +55,6 @@ druid-spring-boot-starter - - - com.github.penggle - kaptcha - - - javax.servlet-api - javax.servlet - - - - com.github.oshi diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java index 43e78aebe..4cd99970c 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java @@ -1,83 +1,55 @@ package com.ruoyi.framework.config; -import java.util.Properties; +import java.awt.*; + +import cn.hutool.captcha.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.google.code.kaptcha.impl.DefaultKaptcha; -import com.google.code.kaptcha.util.Config; -import static com.google.code.kaptcha.Constants.*; /** * 验证码配置 - * - * @author ruoyi + * + * @author Lion Li */ @Configuration -public class CaptchaConfig -{ - @Bean(name = "captchaProducer") - public DefaultKaptcha getKaptchaBean() - { - DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); - Properties properties = new Properties(); - // 是否有边框 默认为true 我们可以自己设置yes,no - properties.setProperty(KAPTCHA_BORDER, "yes"); - // 验证码文本字符颜色 默认为Color.BLACK - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); - // 验证码图片宽度 默认为200 - properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); - // 验证码图片高度 默认为50 - properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); - // 验证码文本字符大小 默认为40 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); - // KAPTCHA_SESSION_KEY - properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); - // 验证码文本字符长度 默认为5 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); - // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); - // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy - properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); - Config config = new Config(properties); - defaultKaptcha.setConfig(config); - return defaultKaptcha; +public class CaptchaConfig { + + private final int width = 160; + private final int height = 60; + private final Color background = Color.PINK; + private final Font font = new Font("Arial", Font.BOLD, 48); + + /** + * 圆圈干扰验证码 + */ + @Bean(name = "CircleCaptcha") + public CircleCaptcha getCircleCaptcha() { + CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(width, height); + captcha.setBackground(background); + captcha.setFont(font); + return captcha; } - @Bean(name = "captchaProducerMath") - public DefaultKaptcha getKaptchaBeanMath() - { - DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); - Properties properties = new Properties(); - // 是否有边框 默认为true 我们可以自己设置yes,no - properties.setProperty(KAPTCHA_BORDER, "yes"); - // 边框颜色 默认为Color.BLACK - properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); - // 验证码文本字符颜色 默认为Color.BLACK - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); - // 验证码图片宽度 默认为200 - properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); - // 验证码图片高度 默认为50 - properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); - // 验证码文本字符大小 默认为40 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); - // KAPTCHA_SESSION_KEY - properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); - // 验证码文本生成器 - properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.ruoyi.framework.config.KaptchaTextCreator"); - // 验证码文本字符间距 默认为2 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); - // 验证码文本字符长度 默认为5 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); - // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); - // 验证码噪点颜色 默认为Color.BLACK - properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); - // 干扰实现类 - properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); - // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy - properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); - Config config = new Config(properties); - defaultKaptcha.setConfig(config); - return defaultKaptcha; + /** + * 线段干扰的验证码 + */ + @Bean(name = "LineCaptcha") + public LineCaptcha getLineCaptcha() { + LineCaptcha captcha = CaptchaUtil.createLineCaptcha(width, height); + captcha.setBackground(background); + captcha.setFont(font); + return captcha; } + + /** + * 扭曲干扰验证码 + */ + @Bean(name = "ShearCaptcha") + public ShearCaptcha getShearCaptcha() { + ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(width, height); + captcha.setBackground(background); + captcha.setFont(font); + return captcha; + } + } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/KaptchaTextCreator.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/KaptchaTextCreator.java deleted file mode 100644 index 3e7458003..000000000 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/KaptchaTextCreator.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.ruoyi.framework.config; - -import java.util.Random; -import com.google.code.kaptcha.text.impl.DefaultTextCreator; - -/** - * 验证码文本生成器 - * - * @author ruoyi - */ -public class KaptchaTextCreator extends DefaultTextCreator -{ - private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(","); - - @Override - public String getText() - { - Integer result = 0; - Random random = new Random(); - int x = random.nextInt(10); - int y = random.nextInt(10); - StringBuilder suChinese = new StringBuilder(); - int randomoperands = (int) Math.round(Math.random() * 2); - if (randomoperands == 0) - { - result = x * y; - suChinese.append(CNUMBERS[x]); - suChinese.append("*"); - suChinese.append(CNUMBERS[y]); - } - else if (randomoperands == 1) - { - if (!(x == 0) && y % x == 0) - { - result = y / x; - suChinese.append(CNUMBERS[y]); - suChinese.append("/"); - suChinese.append(CNUMBERS[x]); - } - else - { - result = x + y; - suChinese.append(CNUMBERS[x]); - suChinese.append("+"); - suChinese.append(CNUMBERS[y]); - } - } - else if (randomoperands == 2) - { - if (x >= y) - { - result = x - y; - suChinese.append(CNUMBERS[x]); - suChinese.append("-"); - suChinese.append(CNUMBERS[y]); - } - else - { - result = y - x; - suChinese.append(CNUMBERS[y]); - suChinese.append("-"); - suChinese.append(CNUMBERS[x]); - } - } - else - { - result = x + y; - suChinese.append(CNUMBERS[x]); - suChinese.append("+"); - suChinese.append(CNUMBERS[y]); - } - suChinese.append("=?@" + result); - return suChinese.toString(); - } -} \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index 002385598..89a81ad16 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; + +import cn.hutool.core.util.IdUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -14,7 +16,6 @@ import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.common.utils.ip.IpUtils; -import com.ruoyi.common.utils.uuid.IdUtils; import eu.bitwalker.useragentutils.UserAgent; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; @@ -101,7 +102,7 @@ public class TokenService */ public String createToken(LoginUser loginUser) { - String token = IdUtils.fastUUID(); + String token = IdUtil.fastUUID(); loginUser.setToken(token); setUserAgent(loginUser); refreshToken(loginUser); From 2b8ab9cc4d538e2f02e6882b0bfa7934ae7bdbb4 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: Fri, 12 Mar 2021 18:02:23 +0800 Subject: [PATCH 10/10] =?UTF-8?q?update=20=E4=BD=BF=E7=94=A8hutool?= =?UTF-8?q?=E9=87=8D=E5=86=99=E7=B3=BB=E7=BB=9F=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/ruoyi/common/utils/Arith.java | 114 ----------- .../com/ruoyi/common/utils/sign/Md5Utils.java | 66 ------ .../ruoyi/framework/web/domain/Server.java | 193 ++++++------------ .../framework/web/domain/server/Cpu.java | 53 ++--- .../framework/web/domain/server/Jvm.java | 60 +++--- .../framework/web/domain/server/Mem.java | 10 +- 7 files changed, 109 insertions(+), 389 deletions(-) delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/Arith.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/sign/Md5Utils.java diff --git a/pom.xml b/pom.xml index 328bad019..f0e37d792 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ - + com.github.oshi diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/Arith.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/Arith.java deleted file mode 100644 index 48a650e89..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/Arith.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.ruoyi.common.utils; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -/** - * 精确的浮点数运算 - * - * @author ruoyi - */ -public class Arith -{ - - /** 默认除法运算精度 */ - private static final int DEF_DIV_SCALE = 10; - - /** 这个类不能实例化 */ - private Arith() - { - } - - /** - * 提供精确的加法运算。 - * @param v1 被加数 - * @param v2 加数 - * @return 两个参数的和 - */ - public static double add(double v1, double v2) - { - BigDecimal b1 = new BigDecimal(Double.toString(v1)); - BigDecimal b2 = new BigDecimal(Double.toString(v2)); - return b1.add(b2).doubleValue(); - } - - /** - * 提供精确的减法运算。 - * @param v1 被减数 - * @param v2 减数 - * @return 两个参数的差 - */ - public static double sub(double v1, double v2) - { - BigDecimal b1 = new BigDecimal(Double.toString(v1)); - BigDecimal b2 = new BigDecimal(Double.toString(v2)); - return b1.subtract(b2).doubleValue(); - } - - /** - * 提供精确的乘法运算。 - * @param v1 被乘数 - * @param v2 乘数 - * @return 两个参数的积 - */ - public static double mul(double v1, double v2) - { - BigDecimal b1 = new BigDecimal(Double.toString(v1)); - BigDecimal b2 = new BigDecimal(Double.toString(v2)); - return b1.multiply(b2).doubleValue(); - } - - /** - * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 - * 小数点以后10位,以后的数字四舍五入。 - * @param v1 被除数 - * @param v2 除数 - * @return 两个参数的商 - */ - public static double div(double v1, double v2) - { - return div(v1, v2, DEF_DIV_SCALE); - } - - /** - * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 - * 定精度,以后的数字四舍五入。 - * @param v1 被除数 - * @param v2 除数 - * @param scale 表示表示需要精确到小数点以后几位。 - * @return 两个参数的商 - */ - public static double div(double v1, double v2, int scale) - { - if (scale < 0) - { - throw new IllegalArgumentException( - "The scale must be a positive integer or zero"); - } - BigDecimal b1 = new BigDecimal(Double.toString(v1)); - BigDecimal b2 = new BigDecimal(Double.toString(v2)); - if (b1.compareTo(BigDecimal.ZERO) == 0) - { - return BigDecimal.ZERO.doubleValue(); - } - return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue(); - } - - /** - * 提供精确的小数位四舍五入处理。 - * @param v 需要四舍五入的数字 - * @param scale 小数点后保留几位 - * @return 四舍五入后的结果 - */ - public static double round(double v, int scale) - { - if (scale < 0) - { - throw new IllegalArgumentException( - "The scale must be a positive integer or zero"); - } - BigDecimal b = new BigDecimal(Double.toString(v)); - BigDecimal one = new BigDecimal("1"); - return b.divide(one, scale, RoundingMode.HALF_UP).doubleValue(); - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/sign/Md5Utils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/sign/Md5Utils.java deleted file mode 100644 index de77ee826..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/sign/Md5Utils.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.ruoyi.common.utils.sign; - -import java.security.MessageDigest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Md5加密方法 - * - * @author ruoyi - */ -public class Md5Utils -{ - private static final Logger log = LoggerFactory.getLogger(Md5Utils.class); - - private static byte[] md5(String s) - { - MessageDigest algorithm; - try - { - algorithm = MessageDigest.getInstance("MD5"); - algorithm.reset(); - algorithm.update(s.getBytes("UTF-8")); - byte[] messageDigest = algorithm.digest(); - return messageDigest; - } - catch (Exception e) - { - log.error("MD5 Error...", e); - } - return null; - } - - private static final String toHex(byte hash[]) - { - if (hash == null) - { - return null; - } - StringBuffer buf = new StringBuffer(hash.length * 2); - int i; - - for (i = 0; i < hash.length; i++) - { - if ((hash[i] & 0xff) < 0x10) - { - buf.append("0"); - } - buf.append(Long.toString(hash[i] & 0xff, 16)); - } - return buf.toString(); - } - - public static String hash(String s) - { - try - { - return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8"); - } - catch (Exception e) - { - log.error("not supported charset...{}", e); - return s; - } - } -} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/Server.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/Server.java index 63b03da78..5195efada 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/Server.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/Server.java @@ -1,35 +1,35 @@ 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.ip.IpUtils; + +import cn.hutool.core.net.NetUtil; +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.Cpu; 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.hardware.CentralProcessor; -import oshi.hardware.CentralProcessor.TickType; +import lombok.Data; import oshi.hardware.GlobalMemory; -import oshi.hardware.HardwareAbstractionLayer; import oshi.software.os.FileSystem; import oshi.software.os.OSFileStore; import oshi.software.os.OperatingSystem; -import oshi.util.Util; /** * 服务器相关信息 - * + * * @author ruoyi */ -public class Server -{ +@Data +public class Server { private static final int OSHI_WAIT_SECOND = 1000; - + /** * CPU相关信息 */ @@ -55,103 +55,33 @@ public class Server */ private List sysFiles = new LinkedList(); - public Cpu getCpu() - { - return cpu; - } - - public void setCpu(Cpu cpu) - { - this.cpu = cpu; - } - - public Mem getMem() - { - return mem; - } - - public void setMem(Mem mem) - { - this.mem = mem; - } - - public Jvm getJvm() - { - return jvm; - } - - public void setJvm(Jvm jvm) - { - this.jvm = jvm; - } - - public Sys getSys() - { - return sys; - } - - public void setSys(Sys sys) - { - this.sys = sys; - } - - public List getSysFiles() - { - return sysFiles; - } - - public void setSysFiles(List sysFiles) - { - this.sysFiles = sysFiles; - } - - public void copyTo() throws Exception - { - SystemInfo si = new SystemInfo(); - HardwareAbstractionLayer hal = si.getHardware(); - - setCpuInfo(hal.getProcessor()); - - setMemInfo(hal.getMemory()); + public void copyTo() { + setCpuInfo(); + setMemInfo(); setSysInfo(); - setJvmInfo(); - - setSysFiles(si.getOperatingSystem()); + setSysFiles(); } /** * 设置CPU信息 */ - private void setCpuInfo(CentralProcessor processor) - { - // CPU信息 - long[] prevTicks = processor.getSystemCpuLoadTicks(); - Util.sleep(OSHI_WAIT_SECOND); - long[] ticks = processor.getSystemCpuLoadTicks(); - long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()]; - long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()]; - long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()]; - long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()]; - long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()]; - long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()]; - long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()]; - long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()]; - long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal; - cpu.setCpuNum(processor.getLogicalProcessorCount()); - cpu.setTotal(totalCpu); - cpu.setSys(cSys); - cpu.setUsed(user); - cpu.setWait(iowait); - cpu.setFree(idle); + 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) - { + private void setMemInfo() { + GlobalMemory memory = OshiUtil.getMemory(); mem.setTotal(memory.getTotal()); mem.setUsed(memory.getTotal() - memory.getAvailable()); mem.setFree(memory.getAvailable()); @@ -160,38 +90,39 @@ public class Server /** * 设置服务器信息 */ - private void setSysInfo() - { - Properties props = System.getProperties(); - sys.setComputerName(IpUtils.getHostName()); - sys.setComputerIp(IpUtils.getHostIp()); - sys.setOsName(props.getProperty("os.name")); - sys.setOsArch(props.getProperty("os.arch")); - sys.setUserDir(props.getProperty("user.dir")); + 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() throws UnknownHostException - { - Properties props = System.getProperties(); - jvm.setTotal(Runtime.getRuntime().totalMemory()); - jvm.setMax(Runtime.getRuntime().maxMemory()); - jvm.setFree(Runtime.getRuntime().freeMemory()); - jvm.setVersion(props.getProperty("java.version")); - jvm.setHome(props.getProperty("java.home")); + 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) - { + private void setSysFiles() { + OperatingSystem os = OshiUtil.getOs(); FileSystem fileSystem = os.getFileSystem(); List fsArray = fileSystem.getFileStores(); - for (OSFileStore fs : fsArray) - { + for (OSFileStore fs : fsArray) { long free = fs.getUsableSpace(); long total = fs.getTotalSpace(); long used = total - free; @@ -202,39 +133,31 @@ public class Server sysFile.setTotal(convertFileSize(total)); sysFile.setFree(convertFileSize(free)); sysFile.setUsed(convertFileSize(used)); - sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100)); + sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100)); sysFiles.add(sysFile); } } /** * 字节转换 - * + * * @param size 字节大小 * @return 转换后值 */ - public String convertFileSize(long size) - { + 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) - { + if (size >= gb) { + return StrUtil.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) - { + return StrUtil.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); + return StrUtil.format(f > 100 ? "%.0f KB" : "%.1f KB", f); + } else { + return StrUtil.format("%d B", size); } } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java index a13a66cf2..4295f6eec 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Cpu.java @@ -1,14 +1,13 @@ package com.ruoyi.framework.web.domain.server; -import com.ruoyi.common.utils.Arith; +import cn.hutool.core.util.NumberUtil; /** * CPU相关信息 - * + * * @author ruoyi */ -public class Cpu -{ +public class Cpu { /** * 核心数 */ @@ -39,63 +38,51 @@ public class Cpu */ private double free; - public int getCpuNum() - { + public int getCpuNum() { return cpuNum; } - public void setCpuNum(int cpuNum) - { + public void setCpuNum(int cpuNum) { this.cpuNum = cpuNum; } - public double getTotal() - { - return Arith.round(Arith.mul(total, 100), 2); + public double getTotal() { + return NumberUtil.round(NumberUtil.mul(total, 100), 2).doubleValue(); } - public void setTotal(double total) - { + public void setTotal(double total) { this.total = total; } - public double getSys() - { - return Arith.round(Arith.mul(sys / total, 100), 2); + public double getSys() { + return NumberUtil.round(NumberUtil.mul(sys / total, 100), 2).doubleValue(); } - public void setSys(double sys) - { + public void setSys(double sys) { this.sys = sys; } - public double getUsed() - { - return Arith.round(Arith.mul(used / total, 100), 2); + public double getUsed() { + return NumberUtil.round(NumberUtil.mul(used / total, 100), 2).doubleValue(); } - public void setUsed(double used) - { + public void setUsed(double used) { this.used = used; } - public double getWait() - { - return Arith.round(Arith.mul(wait / total, 100), 2); + public double getWait() { + return NumberUtil.round(NumberUtil.mul(wait / total, 100), 2).doubleValue(); } - public void setWait(double wait) - { + public void setWait(double wait) { this.wait = wait; } - public double getFree() - { - return Arith.round(Arith.mul(free / total, 100), 2); + public double getFree() { + return NumberUtil.round(NumberUtil.mul(free / total, 100), 2).doubleValue(); } - public void setFree(double free) - { + public void setFree(double free) { this.free = free; } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java index 485d201dd..4b70cbb84 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Jvm.java @@ -1,16 +1,19 @@ package com.ruoyi.framework.web.domain.server; import java.lang.management.ManagementFactory; -import com.ruoyi.common.utils.Arith; +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 -{ +public class Jvm { /** * 当前JVM占用的内存总数(M) */ @@ -36,71 +39,58 @@ public class Jvm */ private String home; - public double getTotal() - { - return Arith.div(total, (1024 * 1024), 2); + public double getTotal() { + return NumberUtil.div(total, (1024 * 1024), 2); } - public void setTotal(double total) - { + public void setTotal(double total) { this.total = total; } - public double getMax() - { - return Arith.div(max, (1024 * 1024), 2); + public double getMax() { + return NumberUtil.div(max, (1024 * 1024), 2); } - public void setMax(double max) - { + public void setMax(double max) { this.max = max; } - public double getFree() - { - return Arith.div(free, (1024 * 1024), 2); + public double getFree() { + return NumberUtil.div(free, (1024 * 1024), 2); } - public void setFree(double free) - { + public void setFree(double free) { this.free = free; } - public double getUsed() - { - return Arith.div(total - free, (1024 * 1024), 2); + public double getUsed() { + return NumberUtil.div(total - free, (1024 * 1024), 2); } - public double getUsage() - { - return Arith.mul(Arith.div(total - free, total, 4), 100); + public double getUsage() { + return NumberUtil.mul(NumberUtil.div(total - free, total, 4), 100); } /** * 获取JDK名称 */ - public String getName() - { + public String getName() { return ManagementFactory.getRuntimeMXBean().getVmName(); } - public String getVersion() - { + public String getVersion() { return version; } - public void setVersion(String version) - { + public void setVersion(String version) { this.version = version; } - public String getHome() - { + public String getHome() { return home; } - public void setHome(String home) - { + public void setHome(String home) { this.home = home; } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java index 13eec521a..757ff5712 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/domain/server/Mem.java @@ -1,6 +1,6 @@ package com.ruoyi.framework.web.domain.server; -import com.ruoyi.common.utils.Arith; +import cn.hutool.core.util.NumberUtil; /** * 內存相关信息 @@ -26,7 +26,7 @@ public class Mem public double getTotal() { - return Arith.div(total, (1024 * 1024 * 1024), 2); + return NumberUtil.div(total, (1024 * 1024 * 1024), 2); } public void setTotal(long total) @@ -36,7 +36,7 @@ public class Mem public double getUsed() { - return Arith.div(used, (1024 * 1024 * 1024), 2); + return NumberUtil.div(used, (1024 * 1024 * 1024), 2); } public void setUsed(long used) @@ -46,7 +46,7 @@ public class Mem public double getFree() { - return Arith.div(free, (1024 * 1024 * 1024), 2); + return NumberUtil.div(free, (1024 * 1024 * 1024), 2); } public void setFree(long free) @@ -56,6 +56,6 @@ public class Mem public double getUsage() { - return Arith.mul(Arith.div(used, total, 4), 100); + return NumberUtil.mul(NumberUtil.div(used, total, 4), 100); } }