diff --git a/README.md b/README.md index ef3f394c..4497b8c2 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ com.ruoyi ## TODO +- 添加lombok +- 通过代码规约扫描 - 用smart-doc + Torna 替换掉swagger - 引入mybatis-plus - 日志使用ELK diff --git a/ruoyi-common/ruoyi-common-core/pom.xml b/ruoyi-common/ruoyi-common-core/pom.xml index 8f30556f..a485e339 100644 --- a/ruoyi-common/ruoyi-common-core/pom.xml +++ b/ruoyi-common/ruoyi-common-core/pom.xml @@ -118,6 +118,11 @@ io.swagger swagger-annotations + + org.junit.jupiter + junit-jupiter + test + diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java index f78fbbe7..60b7e839 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java @@ -117,8 +117,11 @@ public @interface Excel public String[] args() default {}; public enum Align - { - AUTO(0), LEFT(1), CENTER(2), RIGHT(3); + { //AUTO( + AUTO(0), + LEFT(1), + CENTER(2), + RIGHT(3); private final int value; Align(int value) @@ -138,8 +141,18 @@ public @interface Excel Type type() default Type.ALL; public enum Type - { - ALL(0), EXPORT(1), IMPORT(2); + { /** + * ALL + */ + ALL(0), + /** + * EXPORT + */ + EXPORT(1), + /** + * IMPORT + */ + IMPORT(2); private final int value; Type(int value) @@ -154,8 +167,18 @@ public @interface Excel } public enum ColumnType - { - NUMERIC(0), STRING(1), IMAGE(2); + { /** + * EXPORT + */ + NUMERIC(0), + /** + * EXPORT + */ + STRING(1), + /** + * EXPORT + */ + IMAGE(2); private final int value; ColumnType(int value) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/UserStatus.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/UserStatus.java index 9ff84960..07665ecd 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/UserStatus.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/UserStatus.java @@ -6,8 +6,18 @@ package com.ruoyi.common.core.enums; * @author ruoyi */ public enum UserStatus -{ - OK("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除"); +{ /** + * EXPORT + */ + OK("0", "正常"), + /** + * EXPORT + */ + DISABLE("1", "停用"), + /** + * EXPORT + */ + DELETED("2", "删除"); private final String code; private final String info; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/GlobalException.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/GlobalException.java index 9beb54bd..05c009e2 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/GlobalException.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/GlobalException.java @@ -18,7 +18,7 @@ public class GlobalException extends RuntimeException /** * 错误明细,内部调试错误 * - * 和 {@link CommonResult#getDetailMessage()} 一致的设计 + * 和 CommonResult#getDetailMessage() 一致的设计 */ private String detailMessage; @@ -45,6 +45,7 @@ public class GlobalException extends RuntimeException return this; } + @Override public String getMessage() { return message; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/ServiceException.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/ServiceException.java index d2b7763b..00df0f4d 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/ServiceException.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/ServiceException.java @@ -22,7 +22,7 @@ public final class ServiceException extends RuntimeException /** * 错误明细,内部调试错误 * - * 和 {@link CommonResult#getDetailMessage()} 一致的设计 + * 和 CommonResult#getDetailMessage() 一致的设计 */ private String detailMessage; @@ -49,6 +49,7 @@ public final class ServiceException extends RuntimeException return detailMessage; } + @Override public String getMessage() { return message; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/job/TaskException.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/job/TaskException.java index c98397c1..3ae3a2ea 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/job/TaskException.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/job/TaskException.java @@ -28,7 +28,25 @@ public class TaskException extends Exception } public enum Code - { - TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE + { /** + * EXPORT + */ + TASK_EXISTS, + /** + * EXPORT + */ + NO_TASK_EXISTS, + /** + * EXPORT + */ + TASK_ALREADY_STARTED, + /** + * EXPORT + */ + UNKNOWN, CONFIG_ERROR, + /** + * EXPORT + */ + TASK_NODE_NOT_AVAILABLE } } \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java index 95a00b73..e34024ab 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java @@ -893,9 +893,9 @@ public class Convert * @param input String. * @return 全角字符串. */ - public static String toSBC(String input) + public static String tosbc(String input) { - return toSBC(input, null); + return tosbc(input, null); } /** @@ -905,7 +905,7 @@ public class Convert * @param notConvertSet 不替换的字符集合 * @return 全角字符串. */ - public static String toSBC(String input, Set notConvertSet) + public static String tosbc(String input, Set notConvertSet) { char c[] = input.toCharArray(); for (int i = 0; i < c.length; i++) @@ -935,9 +935,9 @@ public class Convert * @param input String. * @return 半角字符串 */ - public static String toDBC(String input) + public static String todbc(String input) { - return toDBC(input, null); + return todbc(input, null); } /** @@ -947,7 +947,7 @@ public class Convert * @param notConvertSet 不替换的字符集合 * @return 替换后的字符 */ - public static String toDBC(String text, Set notConvertSet) + public static String todbc(String text, Set notConvertSet) { char c[] = text.toCharArray(); for (int i = 0; i < c.length; i++) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/html/HTMLFilter.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/html/HTMLFilter.java index 1052b55a..2ed9f728 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/html/HTMLFilter.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/html/HTMLFilter.java @@ -104,23 +104,23 @@ public final class HTMLFilter { vAllowed = new HashMap<>(); - final ArrayList a_atts = new ArrayList<>(); - a_atts.add("href"); - a_atts.add("target"); - vAllowed.put("a", a_atts); - - final ArrayList img_atts = new ArrayList<>(); - img_atts.add("src"); - img_atts.add("width"); - img_atts.add("height"); - img_atts.add("alt"); - vAllowed.put("img", img_atts); - - final ArrayList no_atts = new ArrayList<>(); - vAllowed.put("b", no_atts); - vAllowed.put("strong", no_atts); - vAllowed.put("i", no_atts); - vAllowed.put("em", no_atts); + final ArrayList aAtos = new ArrayList<>(); + aAtos.add("href"); + aAtos.add("target"); + vAllowed.put("a", aAtos); + + final ArrayList imgAtts = new ArrayList<>(); + imgAtts.add("src"); + imgAtts.add("width"); + imgAtts.add("height"); + imgAtts.add("alt"); + vAllowed.put("img", imgAtts); + + final ArrayList noAtts = new ArrayList<>(); + vAllowed.put("b", noAtts); + vAllowed.put("strong", noAtts); + vAllowed.put("i", noAtts); + vAllowed.put("em", noAtts); vSelfClosingTags = new String[] { "img" }; vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" }; @@ -202,7 +202,7 @@ public final class HTMLFilter s = escapeComments(s); - s = balanceHTML(s); + s = balancehtml(s); s = checkTags(s); @@ -237,7 +237,7 @@ public final class HTMLFilter return buf.toString(); } - private String balanceHTML(String s) + private String balancehtml(String s) { if (alwaysMakeTags) { @@ -317,9 +317,9 @@ public final class HTMLFilter return result; } - private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) + private static String regexReplace(final Pattern regexPattern, final String replacement, final String s) { - Matcher m = regex_pattern.matcher(s); + Matcher m = regexPattern.matcher(s); return m.replaceAll(replacement); } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/IpUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/IpUtils.java index 78186aca..35857802 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/IpUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/IpUtils.java @@ -1,49 +1,43 @@ package com.ruoyi.common.core.utils.ip; +import com.ruoyi.common.core.utils.StringUtils; + +import javax.servlet.http.HttpServletRequest; import java.net.InetAddress; import java.net.UnknownHostException; -import javax.servlet.http.HttpServletRequest; -import com.ruoyi.common.core.utils.StringUtils; /** * 获取IP方法 - * + * * @author ruoyi */ -public class IpUtils -{ +public class IpUtils { /** * 获取客户端IP - * + * * @param request 请求对象 * @return IP地址 */ - public static String getIpAddr(HttpServletRequest request) - { - if (request == null) - { - return "unknown"; + public static String getIpAddr(HttpServletRequest request) { + String unknown = "unknown"; + if (request == null) { + return unknown; } String ip = request.getHeader("x-forwarded-for"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) - { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) - { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getHeader("X-Forwarded-For"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) - { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) - { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getHeader("X-Real-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) - { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } @@ -52,84 +46,79 @@ public class IpUtils /** * 检查是否为内部IP地址 - * + * * @param ip IP地址 * @return 结果 */ - public static boolean internalIp(String ip) - { + public static boolean internalIp(String ip) { byte[] addr = textToNumericFormatV4(ip); return internalIp(addr) || "127.0.0.1".equals(ip); } /** * 检查是否为内部IP地址 - * + * * @param addr byte地址 * @return 结果 */ - private static boolean internalIp(byte[] addr) - { - if (StringUtils.isNull(addr) || addr.length < 2) - { + private static boolean internalIp(byte[] addr) { + if (StringUtils.isNull(addr) || addr.length < 2) { return true; } final byte b0 = addr[0]; final byte b1 = addr[1]; // 10.x.x.x/8 - final byte SECTION_1 = 0x0A; + final byte SECTION1 = 0x0A; // 172.16.x.x/12 - final byte SECTION_2 = (byte) 0xAC; - final byte SECTION_3 = (byte) 0x10; - final byte SECTION_4 = (byte) 0x1F; + final byte SECTION2 = (byte) 0xAC; + final byte SECTION3 = (byte) 0x10; + final byte SECTION4 = (byte) 0x1F; // 192.168.x.x/16 - final byte SECTION_5 = (byte) 0xC0; - final byte SECTION_6 = (byte) 0xA8; - switch (b0) - { - case SECTION_1: + final byte SECTION5 = (byte) 0xC0; + final byte SECTION6 = (byte) 0xA8; + switch (b0) { + case SECTION1: return true; - case SECTION_2: - if (b1 >= SECTION_3 && b1 <= SECTION_4) - { + case SECTION2: + if (b1 >= SECTION3 && b1 <= SECTION4) { return true; } - case SECTION_5: - switch (b1) - { - case SECTION_6: + case SECTION5: + switch (b1) { + case SECTION6: { return true; + } + default:{ + break; + } } - default: + default: { return false; + } + } } /** * 将IPv4地址转换成字节 - * + * * @param text IPv4地址 * @return byte 字节 */ - public static byte[] textToNumericFormatV4(String text) - { - if (text.length() == 0) - { + public static byte[] textToNumericFormatV4(String text) { + if (text.length() == 0) { return null; } byte[] bytes = new byte[4]; String[] elements = text.split("\\.", -1); - try - { + try { long l; int i; - switch (elements.length) - { + switch (elements.length) { case 1: l = Long.parseLong(elements[0]); - if ((l < 0L) || (l > 4294967295L)) - { + if ((l < 0L) || (l > 4294967295L)) { return null; } bytes[0] = (byte) (int) (l >> 24 & 0xFF); @@ -139,14 +128,12 @@ public class IpUtils break; case 2: l = Integer.parseInt(elements[0]); - if ((l < 0L) || (l > 255L)) - { + if ((l < 0L) || (l > 255L)) { return null; } bytes[0] = (byte) (int) (l & 0xFF); l = Integer.parseInt(elements[1]); - if ((l < 0L) || (l > 16777215L)) - { + if ((l < 0L) || (l > 16777215L)) { return null; } bytes[1] = (byte) (int) (l >> 16 & 0xFF); @@ -154,29 +141,24 @@ public class IpUtils bytes[3] = (byte) (int) (l & 0xFF); break; case 3: - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { l = Integer.parseInt(elements[i]); - if ((l < 0L) || (l > 255L)) - { + if ((l < 0L) || (l > 255L)) { return null; } bytes[i] = (byte) (int) (l & 0xFF); } l = Integer.parseInt(elements[2]); - if ((l < 0L) || (l > 65535L)) - { + if ((l < 0L) || (l > 65535L)) { return null; } bytes[2] = (byte) (int) (l >> 8 & 0xFF); bytes[3] = (byte) (int) (l & 0xFF); break; case 4: - for (i = 0; i < 4; ++i) - { + for (i = 0; i < 4; ++i) { l = Integer.parseInt(elements[i]); - if ((l < 0L) || (l > 255L)) - { + if ((l < 0L) || (l > 255L)) { return null; } bytes[i] = (byte) (int) (l & 0xFF); @@ -185,9 +167,7 @@ public class IpUtils default: return null; } - } - catch (NumberFormatException e) - { + } catch (NumberFormatException e) { return null; } return bytes; @@ -195,34 +175,26 @@ public class IpUtils /** * 获取IP地址 - * + * * @return 本地IP地址 */ - public static String getHostIp() - { - try - { + public static String getHostIp() { + try { return InetAddress.getLocalHost().getHostAddress(); - } - catch (UnknownHostException e) - { + } catch (UnknownHostException e) { } return "127.0.0.1"; } /** * 获取主机名 - * + * * @return 本地主机名 */ - public static String getHostName() - { - try - { + public static String getHostName() { + try { return InetAddress.getLocalHost().getHostName(); - } - catch (UnknownHostException e) - { + } catch (UnknownHostException e) { } return "未知"; } @@ -233,16 +205,12 @@ public class IpUtils * @param ip 获得的IP地址 * @return 第一个非unknown IP地址 */ - public static String getMultistageReverseProxyIp(String ip) - { + public static String getMultistageReverseProxyIp(String ip) { // 多级反向代理检测 - if (ip != null && ip.indexOf(",") > 0) - { + if (ip != null && ip.indexOf(",") > 0) { final String[] ips = ip.trim().split(","); - for (String subIp : ips) - { - if (false == isUnknown(subIp)) - { + for (String subIp : ips) { + if (false == isUnknown(subIp)) { ip = subIp; break; } @@ -257,8 +225,7 @@ public class IpUtils * @param checkString 被检测的字符串 * @return 是否未知 */ - public static boolean isUnknown(String checkString) - { + public static boolean isUnknown(String checkString) { return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString); } } \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index f9df567e..e920a652 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -73,7 +73,7 @@ public class ExcelUtil /** * Excel sheet最大行数,默认65536 */ - public static final int sheetSize = 65536; + public static final int SHEET_SIZE = 65536; /** * 工作表名称 @@ -446,7 +446,7 @@ public class ExcelUtil public void writeSheet() { // 取出一共有多少个sheet. - int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize)); + int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / SHEET_SIZE)); for (int index = 0; index < sheetNo; index++) { createSheet(sheetNo, index); @@ -476,8 +476,8 @@ public class ExcelUtil */ public void fillExcelData(int index, Row row) { - int startNo = index * sheetSize; - int endNo = Math.min(startNo + sheetSize, list.size()); + int startNo = index * SHEET_SIZE; + int endNo = Math.min(startNo + SHEET_SIZE, list.size()); for (int i = startNo; i < endNo; i++) { row = sheet.createRow(i + 1 + rownum - startNo); diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sign/Base64.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sign/Base64.java index 6f6e8d3d..0ae664a1 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sign/Base64.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sign/Base64.java @@ -15,48 +15,48 @@ public final class Base64 static private final int FOURBYTE = 4; static private final int SIGN = -128; static private final char PAD = '='; - static final private byte[] base64Alphabet = new byte[BASELENGTH]; - static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; + static final private byte[] BASE_64_ALPHABET = new byte[BASELENGTH]; + static final private char[] LOOK_UP_BASE_64_ALPHABET = new char[LOOKUPLENGTH]; static { for (int i = 0; i < BASELENGTH; ++i) { - base64Alphabet[i] = -1; + BASE_64_ALPHABET[i] = -1; } for (int i = 'Z'; i >= 'A'; i--) { - base64Alphabet[i] = (byte) (i - 'A'); + BASE_64_ALPHABET[i] = (byte) (i - 'A'); } for (int i = 'z'; i >= 'a'; i--) { - base64Alphabet[i] = (byte) (i - 'a' + 26); + BASE_64_ALPHABET[i] = (byte) (i - 'a' + 26); } for (int i = '9'; i >= '0'; i--) { - base64Alphabet[i] = (byte) (i - '0' + 52); + BASE_64_ALPHABET[i] = (byte) (i - '0' + 52); } - base64Alphabet['+'] = 62; - base64Alphabet['/'] = 63; + BASE_64_ALPHABET['+'] = 62; + BASE_64_ALPHABET['/'] = 63; for (int i = 0; i <= 25; i++) { - lookUpBase64Alphabet[i] = (char) ('A' + i); + LOOK_UP_BASE_64_ALPHABET[i] = (char) ('A' + i); } for (int i = 26, j = 0; i <= 51; i++, j++) { - lookUpBase64Alphabet[i] = (char) ('a' + j); + LOOK_UP_BASE_64_ALPHABET[i] = (char) ('a' + j); } for (int i = 52, j = 0; i <= 61; i++, j++) { - lookUpBase64Alphabet[i] = (char) ('0' + j); + LOOK_UP_BASE_64_ALPHABET[i] = (char) ('0' + j); } - lookUpBase64Alphabet[62] = (char) '+'; - lookUpBase64Alphabet[63] = (char) '/'; + LOOK_UP_BASE_64_ALPHABET[62] = (char) '+'; + LOOK_UP_BASE_64_ALPHABET[63] = (char) '/'; } private static boolean isWhiteSpace(char octect) @@ -71,7 +71,7 @@ public final class Base64 private static boolean isData(char octect) { - return (octect < BASELENGTH && base64Alphabet[octect] != -1); + return (octect < BASELENGTH && BASE_64_ALPHABET[octect] != -1); } /** @@ -118,10 +118,10 @@ public final class Base64 byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val2 | (k << 4)]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[(l << 2) | val3]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[b3 & 0x3f]; } // form integral number of 6-bit groups @@ -130,8 +130,8 @@ public final class Base64 b1 = binaryData[dataIndex]; k = (byte) (b1 & 0x03); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[k << 4]; encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD; } @@ -145,9 +145,9 @@ public final class Base64 byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val2 | (k << 4)]; + encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[l << 2]; encodedData[encodedIndex++] = PAD; } return new String(encodedData); @@ -200,10 +200,10 @@ public final class Base64 return null; } // if found "no data" just return null - b1 = base64Alphabet[d1]; - b2 = base64Alphabet[d2]; - b3 = base64Alphabet[d3]; - b4 = base64Alphabet[d4]; + b1 = BASE_64_ALPHABET[d1]; + b2 = BASE_64_ALPHABET[d2]; + b3 = BASE_64_ALPHABET[d3]; + b4 = BASE_64_ALPHABET[d4]; decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); @@ -215,8 +215,8 @@ public final class Base64 return null;// if found "no data" just return null } - b1 = base64Alphabet[d1]; - b2 = base64Alphabet[d2]; + b1 = BASE_64_ALPHABET[d1]; + b2 = BASE_64_ALPHABET[d2]; d3 = base64Data[dataIndex++]; d4 = base64Data[dataIndex++]; @@ -235,7 +235,7 @@ public final class Base64 } else if (!isPad(d3) && isPad(d4)) { - b3 = base64Alphabet[d3]; + b3 = BASE_64_ALPHABET[d3]; if ((b3 & 0x3) != 0)// last 2 bits should be zero { return null; @@ -253,8 +253,8 @@ public final class Base64 } else { // No PAD e.g 3cQl - b3 = base64Alphabet[d3]; - b4 = base64Alphabet[d4]; + b3 = BASE_64_ALPHABET[d3]; + b4 = BASE_64_ALPHABET[d4]; decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/Seq.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/Seq.java index d0fddd27..d1be983b 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/Seq.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/Seq.java @@ -10,10 +10,10 @@ import com.ruoyi.common.core.utils.StringUtils; public class Seq { // 通用序列类型 - public static final String commSeqType = "COMMON"; + public static final String COMM_SEQ_TYPE = "COMMON"; // 上传序列类型 - public static final String uploadSeqType = "UPLOAD"; + public static final String UPLOAD_SEQ_TYPE = "UPLOAD"; // 通用接口序列数 private static AtomicInteger commSeq = new AtomicInteger(1); @@ -31,7 +31,7 @@ public class Seq */ public static String getId() { - return getId(commSeqType); + return getId(COMM_SEQ_TYPE); } /** @@ -42,7 +42,7 @@ public class Seq public static String getId(String type) { AtomicInteger atomicInt = commSeq; - if (uploadSeqType.equals(type)) + if (UPLOAD_SEQ_TYPE.equals(type)) { atomicInt = uploadSeq; } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/UUID.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/UUID.java index b10955af..a0cf8ddf 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/UUID.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/uuid/UUID.java @@ -22,7 +22,7 @@ public final class UUID implements java.io.Serializable, Comparable */ private static class Holder { - static final SecureRandom numberGenerator = getSecureRandom(); + static final SecureRandom NUMBER_GENERATOR = getSecureRandom(); } /** 此UUID的最高64有效位 */ @@ -93,7 +93,7 @@ public final class UUID implements java.io.Serializable, Comparable */ public static UUID randomUUID(boolean isSecure) { - final Random ng = isSecure ? Holder.numberGenerator : getRandom(); + final Random ng = isSecure ? Holder.NUMBER_GENERATOR : getRandom(); byte[] randomBytes = new byte[16]; ng.nextBytes(randomBytes); diff --git a/ruoyi-common/ruoyi-common-core/src/main/test/java/com/ruoyi/common/core/exception/ServiceExceptionTest.java b/ruoyi-common/ruoyi-common-core/src/main/test/java/com/ruoyi/common/core/exception/ServiceExceptionTest.java new file mode 100644 index 00000000..b8977659 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/test/java/com/ruoyi/common/core/exception/ServiceExceptionTest.java @@ -0,0 +1,40 @@ +package com.ruoyi.common.core.exception; + + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ServiceExceptionTest { + + @BeforeEach + void setUp() { + System.out.println("up"); + } + + @AfterEach + void tearDown() { + System.out.println("down"); + } + + @Test + void testThirdTest() { + GlobalException globalException2 = new GlobalException(""); + globalException2.getMessage(); + globalException2.getDetailMessage(); + globalException2.setDetailMessage(""); + throw globalException2; + } + + @Test + void testThirdTest2() { + GlobalException globalException2 = new GlobalException(); + globalException2.getMessage(); + globalException2.getDetailMessage(); + System.out.println(globalException2.getMessage()); + System.out.println(globalException2.getDetailMessage()); + System.out.println(globalException2.setDetailMessage("")); + globalException2.setDetailMessage(""); + throw globalException2; + } +} \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/WebMvcConfig.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/WebMvcConfig.java index b3fa247a..b2420261 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/WebMvcConfig.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/WebMvcConfig.java @@ -12,14 +12,14 @@ import com.ruoyi.common.security.interceptor.HeaderInterceptor; public class WebMvcConfig implements WebMvcConfigurer { /** 不需要拦截地址 */ - public static final String[] excludeUrls = { "/login", "/logout", "/refresh" }; + public static final String[] EXCLUDE_URLS = { "/login", "/logout", "/refresh" }; @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(getHeaderInterceptor()) .addPathPatterns("/**") - .excludePathPatterns(excludeUrls) + .excludePathPatterns(EXCLUDE_URLS) .order(-10); } diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java index 998b78f5..5a9da772 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java @@ -33,8 +33,8 @@ public class GlobalExceptionHandler @ExceptionHandler(NotPermissionException.class) public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage()); + String requestUri = request.getRequestURI(); + log.error("请求地址'{}',权限码校验失败'{}'", requestUri, e.getMessage()); return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权"); } @@ -44,8 +44,8 @@ public class GlobalExceptionHandler @ExceptionHandler(NotRoleException.class) public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage()); + String requestUri = request.getRequestURI(); + log.error("请求地址'{}',角色权限校验失败'{}'", requestUri, e.getMessage()); return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权"); } @@ -56,8 +56,8 @@ public class GlobalExceptionHandler public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); + String requestUri = request.getRequestURI(); + log.error("请求地址'{}',不支持'{}'请求", requestUri, e.getMethod()); return AjaxResult.error(e.getMessage()); } @@ -78,8 +78,8 @@ public class GlobalExceptionHandler @ExceptionHandler(RuntimeException.class) public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("请求地址'{}',发生未知异常.", requestURI, e); + String requestUri = request.getRequestURI(); + log.error("请求地址'{}',发生未知异常.", requestUri, e); return AjaxResult.error(e.getMessage()); } @@ -89,8 +89,8 @@ public class GlobalExceptionHandler @ExceptionHandler(Exception.class) public AjaxResult handleException(Exception e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("请求地址'{}',发生系统异常.", requestURI, e); + String requestUri = request.getRequestURI(); + log.error("请求地址'{}',发生系统异常.", requestUri, e); return AjaxResult.error(e.getMessage()); } diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java index b3093c9c..bcf90b27 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java @@ -32,7 +32,7 @@ public class TokenService protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; - private final static long expireTime = CacheConstants.EXPIRATION; + private final static long EXPIRE_TIME = CacheConstants.EXPIRATION; private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY; @@ -61,7 +61,7 @@ public class TokenService // 接口返回信息 Map rspMap = new HashMap(); rspMap.put("access_token", JwtUtils.createToken(claimsMap)); - rspMap.put("expires_in", expireTime); + rspMap.put("expires_in", EXPIRE_TIME); return rspMap; } @@ -156,10 +156,10 @@ public class TokenService public void refreshToken(LoginUser loginUser) { loginUser.setLoginTime(System.currentTimeMillis()); - loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); + loginUser.setExpireTime(loginUser.getLoginTime() + EXPIRE_TIME * MILLIS_MINUTE); // 根据uuid将loginUser缓存 String userKey = getTokenKey(loginUser.getToken()); - redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); + redisService.setCacheObject(userKey, loginUser, EXPIRE_TIME, TimeUnit.MINUTES); } private String getTokenKey(String token) diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java index e73631a2..b317ec9d 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java @@ -88,7 +88,7 @@ public class FileUploadUtils public static final String extractFilename(MultipartFile file) { return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), - FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); + FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.UPLOAD_SEQ_TYPE), getExtension(file)); } private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException