添加TODO 代码规约扫描

pull/183/head
1332987 3 years ago
parent d1783d9d83
commit c392e8fb16

@ -79,6 +79,8 @@ com.ruoyi
## TODO ## TODO
- 添加lombok
- 通过代码规约扫描
- 用smart-doc + Torna 替换掉swagger - 用smart-doc + Torna 替换掉swagger
- 引入mybatis-plus - 引入mybatis-plus
- 日志使用ELK - 日志使用ELK

@ -118,6 +118,11 @@
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

@ -117,8 +117,11 @@ public @interface Excel
public String[] args() default {}; public String[] args() default {};
public enum Align public enum Align
{ { //AUTO(
AUTO(0), LEFT(1), CENTER(2), RIGHT(3); AUTO(0),
LEFT(1),
CENTER(2),
RIGHT(3);
private final int value; private final int value;
Align(int value) Align(int value)
@ -138,8 +141,18 @@ public @interface Excel
Type type() default Type.ALL; Type type() default Type.ALL;
public enum Type public enum Type
{ { /**
ALL(0), EXPORT(1), IMPORT(2); * ALL
*/
ALL(0),
/**
* EXPORT
*/
EXPORT(1),
/**
* IMPORT
*/
IMPORT(2);
private final int value; private final int value;
Type(int value) Type(int value)
@ -154,8 +167,18 @@ public @interface Excel
} }
public enum ColumnType public enum ColumnType
{ { /**
NUMERIC(0), STRING(1), IMAGE(2); * EXPORT
*/
NUMERIC(0),
/**
* EXPORT
*/
STRING(1),
/**
* EXPORT
*/
IMAGE(2);
private final int value; private final int value;
ColumnType(int value) ColumnType(int value)

@ -6,8 +6,18 @@ package com.ruoyi.common.core.enums;
* @author ruoyi * @author ruoyi
*/ */
public enum UserStatus 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 code;
private final String info; private final String info;

@ -18,7 +18,7 @@ public class GlobalException extends RuntimeException
/** /**
* *
* *
* {@link CommonResult#getDetailMessage()} * CommonResult#getDetailMessage()
*/ */
private String detailMessage; private String detailMessage;
@ -45,6 +45,7 @@ public class GlobalException extends RuntimeException
return this; return this;
} }
@Override
public String getMessage() public String getMessage()
{ {
return message; return message;

@ -22,7 +22,7 @@ public final class ServiceException extends RuntimeException
/** /**
* *
* *
* {@link CommonResult#getDetailMessage()} * CommonResult#getDetailMessage()
*/ */
private String detailMessage; private String detailMessage;
@ -49,6 +49,7 @@ public final class ServiceException extends RuntimeException
return detailMessage; return detailMessage;
} }
@Override
public String getMessage() public String getMessage()
{ {
return message; return message;

@ -28,7 +28,25 @@ public class TaskException extends Exception
} }
public enum Code 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
} }
} }

@ -893,9 +893,9 @@ public class Convert
* @param input String. * @param input String.
* @return . * @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 * @param notConvertSet
* @return . * @return .
*/ */
public static String toSBC(String input, Set<Character> notConvertSet) public static String tosbc(String input, Set<Character> notConvertSet)
{ {
char c[] = input.toCharArray(); char c[] = input.toCharArray();
for (int i = 0; i < c.length; i++) for (int i = 0; i < c.length; i++)
@ -935,9 +935,9 @@ public class Convert
* @param input String. * @param input String.
* @return * @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 * @param notConvertSet
* @return * @return
*/ */
public static String toDBC(String text, Set<Character> notConvertSet) public static String todbc(String text, Set<Character> notConvertSet)
{ {
char c[] = text.toCharArray(); char c[] = text.toCharArray();
for (int i = 0; i < c.length; i++) for (int i = 0; i < c.length; i++)

@ -104,23 +104,23 @@ public final class HTMLFilter
{ {
vAllowed = new HashMap<>(); vAllowed = new HashMap<>();
final ArrayList<String> a_atts = new ArrayList<>(); final ArrayList<String> aAtos = new ArrayList<>();
a_atts.add("href"); aAtos.add("href");
a_atts.add("target"); aAtos.add("target");
vAllowed.put("a", a_atts); vAllowed.put("a", aAtos);
final ArrayList<String> img_atts = new ArrayList<>(); final ArrayList<String> imgAtts = new ArrayList<>();
img_atts.add("src"); imgAtts.add("src");
img_atts.add("width"); imgAtts.add("width");
img_atts.add("height"); imgAtts.add("height");
img_atts.add("alt"); imgAtts.add("alt");
vAllowed.put("img", img_atts); vAllowed.put("img", imgAtts);
final ArrayList<String> no_atts = new ArrayList<>(); final ArrayList<String> noAtts = new ArrayList<>();
vAllowed.put("b", no_atts); vAllowed.put("b", noAtts);
vAllowed.put("strong", no_atts); vAllowed.put("strong", noAtts);
vAllowed.put("i", no_atts); vAllowed.put("i", noAtts);
vAllowed.put("em", no_atts); vAllowed.put("em", noAtts);
vSelfClosingTags = new String[] { "img" }; vSelfClosingTags = new String[] { "img" };
vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" }; vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" };
@ -202,7 +202,7 @@ public final class HTMLFilter
s = escapeComments(s); s = escapeComments(s);
s = balanceHTML(s); s = balancehtml(s);
s = checkTags(s); s = checkTags(s);
@ -237,7 +237,7 @@ public final class HTMLFilter
return buf.toString(); return buf.toString();
} }
private String balanceHTML(String s) private String balancehtml(String s)
{ {
if (alwaysMakeTags) if (alwaysMakeTags)
{ {
@ -317,9 +317,9 @@ public final class HTMLFilter
return result; 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); return m.replaceAll(replacement);
} }

@ -1,49 +1,43 @@
package com.ruoyi.common.core.utils.ip; 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.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
import com.ruoyi.common.core.utils.StringUtils;
/** /**
* IP * IP
* *
* @author ruoyi * @author ruoyi
*/ */
public class IpUtils public class IpUtils {
{
/** /**
* IP * IP
* *
* @param request * @param request
* @return IP * @return IP
*/ */
public static String getIpAddr(HttpServletRequest request) public static String getIpAddr(HttpServletRequest request) {
{ String unknown = "unknown";
if (request == null) if (request == null) {
{ return unknown;
return "unknown";
} }
String ip = request.getHeader("x-forwarded-for"); 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"); 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"); 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"); 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"); 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(); ip = request.getRemoteAddr();
} }
@ -56,8 +50,7 @@ public class IpUtils
* @param ip IP * @param ip IP
* @return * @return
*/ */
public static boolean internalIp(String ip) public static boolean internalIp(String ip) {
{
byte[] addr = textToNumericFormatV4(ip); byte[] addr = textToNumericFormatV4(ip);
return internalIp(addr) || "127.0.0.1".equals(ip); return internalIp(addr) || "127.0.0.1".equals(ip);
} }
@ -68,41 +61,42 @@ public class IpUtils
* @param addr byte * @param addr byte
* @return * @return
*/ */
private static boolean internalIp(byte[] addr) private static boolean internalIp(byte[] addr) {
{ if (StringUtils.isNull(addr) || addr.length < 2) {
if (StringUtils.isNull(addr) || addr.length < 2)
{
return true; return true;
} }
final byte b0 = addr[0]; final byte b0 = addr[0];
final byte b1 = addr[1]; final byte b1 = addr[1];
// 10.x.x.x/8 // 10.x.x.x/8
final byte SECTION_1 = 0x0A; final byte SECTION1 = 0x0A;
// 172.16.x.x/12 // 172.16.x.x/12
final byte SECTION_2 = (byte) 0xAC; final byte SECTION2 = (byte) 0xAC;
final byte SECTION_3 = (byte) 0x10; final byte SECTION3 = (byte) 0x10;
final byte SECTION_4 = (byte) 0x1F; final byte SECTION4 = (byte) 0x1F;
// 192.168.x.x/16 // 192.168.x.x/16
final byte SECTION_5 = (byte) 0xC0; final byte SECTION5 = (byte) 0xC0;
final byte SECTION_6 = (byte) 0xA8; final byte SECTION6 = (byte) 0xA8;
switch (b0) switch (b0) {
{ case SECTION1:
case SECTION_1:
return true; return true;
case SECTION_2: case SECTION2:
if (b1 >= SECTION_3 && b1 <= SECTION_4) if (b1 >= SECTION3 && b1 <= SECTION4) {
{
return true; return true;
} }
case SECTION_5: case SECTION5:
switch (b1) switch (b1) {
{ case SECTION6: {
case SECTION_6:
return true; return true;
} }
default: default:{
break;
}
}
default: {
return false; return false;
} }
}
} }
/** /**
@ -111,25 +105,20 @@ public class IpUtils
* @param text IPv4 * @param text IPv4
* @return byte * @return byte
*/ */
public static byte[] textToNumericFormatV4(String text) public static byte[] textToNumericFormatV4(String text) {
{ if (text.length() == 0) {
if (text.length() == 0)
{
return null; return null;
} }
byte[] bytes = new byte[4]; byte[] bytes = new byte[4];
String[] elements = text.split("\\.", -1); String[] elements = text.split("\\.", -1);
try try {
{
long l; long l;
int i; int i;
switch (elements.length) switch (elements.length) {
{
case 1: case 1:
l = Long.parseLong(elements[0]); l = Long.parseLong(elements[0]);
if ((l < 0L) || (l > 4294967295L)) if ((l < 0L) || (l > 4294967295L)) {
{
return null; return null;
} }
bytes[0] = (byte) (int) (l >> 24 & 0xFF); bytes[0] = (byte) (int) (l >> 24 & 0xFF);
@ -139,14 +128,12 @@ public class IpUtils
break; break;
case 2: case 2:
l = Integer.parseInt(elements[0]); l = Integer.parseInt(elements[0]);
if ((l < 0L) || (l > 255L)) if ((l < 0L) || (l > 255L)) {
{
return null; return null;
} }
bytes[0] = (byte) (int) (l & 0xFF); bytes[0] = (byte) (int) (l & 0xFF);
l = Integer.parseInt(elements[1]); l = Integer.parseInt(elements[1]);
if ((l < 0L) || (l > 16777215L)) if ((l < 0L) || (l > 16777215L)) {
{
return null; return null;
} }
bytes[1] = (byte) (int) (l >> 16 & 0xFF); bytes[1] = (byte) (int) (l >> 16 & 0xFF);
@ -154,29 +141,24 @@ public class IpUtils
bytes[3] = (byte) (int) (l & 0xFF); bytes[3] = (byte) (int) (l & 0xFF);
break; break;
case 3: case 3:
for (i = 0; i < 2; ++i) for (i = 0; i < 2; ++i) {
{
l = Integer.parseInt(elements[i]); l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L)) if ((l < 0L) || (l > 255L)) {
{
return null; return null;
} }
bytes[i] = (byte) (int) (l & 0xFF); bytes[i] = (byte) (int) (l & 0xFF);
} }
l = Integer.parseInt(elements[2]); l = Integer.parseInt(elements[2]);
if ((l < 0L) || (l > 65535L)) if ((l < 0L) || (l > 65535L)) {
{
return null; return null;
} }
bytes[2] = (byte) (int) (l >> 8 & 0xFF); bytes[2] = (byte) (int) (l >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF); bytes[3] = (byte) (int) (l & 0xFF);
break; break;
case 4: case 4:
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i) {
{
l = Integer.parseInt(elements[i]); l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L)) if ((l < 0L) || (l > 255L)) {
{
return null; return null;
} }
bytes[i] = (byte) (int) (l & 0xFF); bytes[i] = (byte) (int) (l & 0xFF);
@ -185,9 +167,7 @@ public class IpUtils
default: default:
return null; return null;
} }
} } catch (NumberFormatException e) {
catch (NumberFormatException e)
{
return null; return null;
} }
return bytes; return bytes;
@ -198,14 +178,10 @@ public class IpUtils
* *
* @return IP * @return IP
*/ */
public static String getHostIp() public static String getHostIp() {
{ try {
try
{
return InetAddress.getLocalHost().getHostAddress(); return InetAddress.getLocalHost().getHostAddress();
} } catch (UnknownHostException e) {
catch (UnknownHostException e)
{
} }
return "127.0.0.1"; return "127.0.0.1";
} }
@ -215,14 +191,10 @@ public class IpUtils
* *
* @return * @return
*/ */
public static String getHostName() public static String getHostName() {
{ try {
try
{
return InetAddress.getLocalHost().getHostName(); return InetAddress.getLocalHost().getHostName();
} } catch (UnknownHostException e) {
catch (UnknownHostException e)
{
} }
return "未知"; return "未知";
} }
@ -233,16 +205,12 @@ public class IpUtils
* @param ip IP * @param ip IP
* @return unknown 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(","); final String[] ips = ip.trim().split(",");
for (String subIp : ips) for (String subIp : ips) {
{ if (false == isUnknown(subIp)) {
if (false == isUnknown(subIp))
{
ip = subIp; ip = subIp;
break; break;
} }
@ -257,8 +225,7 @@ public class IpUtils
* @param checkString * @param checkString
* @return * @return
*/ */
public static boolean isUnknown(String checkString) public static boolean isUnknown(String checkString) {
{
return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString); return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString);
} }
} }

@ -73,7 +73,7 @@ public class ExcelUtil<T>
/** /**
* Excel sheet65536 * Excel sheet65536
*/ */
public static final int sheetSize = 65536; public static final int SHEET_SIZE = 65536;
/** /**
* *
@ -446,7 +446,7 @@ public class ExcelUtil<T>
public void writeSheet() public void writeSheet()
{ {
// 取出一共有多少个sheet. // 取出一共有多少个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++) for (int index = 0; index < sheetNo; index++)
{ {
createSheet(sheetNo, index); createSheet(sheetNo, index);
@ -476,8 +476,8 @@ public class ExcelUtil<T>
*/ */
public void fillExcelData(int index, Row row) public void fillExcelData(int index, Row row)
{ {
int startNo = index * sheetSize; int startNo = index * SHEET_SIZE;
int endNo = Math.min(startNo + sheetSize, list.size()); int endNo = Math.min(startNo + SHEET_SIZE, list.size());
for (int i = startNo; i < endNo; i++) for (int i = startNo; i < endNo; i++)
{ {
row = sheet.createRow(i + 1 + rownum - startNo); row = sheet.createRow(i + 1 + rownum - startNo);

@ -15,48 +15,48 @@ public final class Base64
static private final int FOURBYTE = 4; static private final int FOURBYTE = 4;
static private final int SIGN = -128; static private final int SIGN = -128;
static private final char PAD = '='; static private final char PAD = '=';
static final private byte[] base64Alphabet = new byte[BASELENGTH]; static final private byte[] BASE_64_ALPHABET = new byte[BASELENGTH];
static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; static final private char[] LOOK_UP_BASE_64_ALPHABET = new char[LOOKUPLENGTH];
static static
{ {
for (int i = 0; i < BASELENGTH; ++i) for (int i = 0; i < BASELENGTH; ++i)
{ {
base64Alphabet[i] = -1; BASE_64_ALPHABET[i] = -1;
} }
for (int i = 'Z'; i >= 'A'; i--) 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--) 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--) for (int i = '9'; i >= '0'; i--)
{ {
base64Alphabet[i] = (byte) (i - '0' + 52); BASE_64_ALPHABET[i] = (byte) (i - '0' + 52);
} }
base64Alphabet['+'] = 62; BASE_64_ALPHABET['+'] = 62;
base64Alphabet['/'] = 63; BASE_64_ALPHABET['/'] = 63;
for (int i = 0; i <= 25; i++) 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++) 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++) 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) '+'; LOOK_UP_BASE_64_ALPHABET[62] = (char) '+';
lookUpBase64Alphabet[63] = (char) '/'; LOOK_UP_BASE_64_ALPHABET[63] = (char) '/';
} }
private static boolean isWhiteSpace(char octect) private static boolean isWhiteSpace(char octect)
@ -71,7 +71,7 @@ public final class Base64
private static boolean isData(char octect) 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 val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val2 | (k << 4)];
encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[(l << 2) | val3];
encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[b3 & 0x3f];
} }
// form integral number of 6-bit groups // form integral number of 6-bit groups
@ -130,8 +130,8 @@ public final class Base64
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
k = (byte) (b1 & 0x03); k = (byte) (b1 & 0x03);
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[k << 4];
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
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 val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val2 | (k << 4)];
encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[l << 2];
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
} }
return new String(encodedData); return new String(encodedData);
@ -200,10 +200,10 @@ public final class Base64
return null; return null;
} // if found "no data" just return null } // if found "no data" just return null
b1 = base64Alphabet[d1]; b1 = BASE_64_ALPHABET[d1];
b2 = base64Alphabet[d2]; b2 = BASE_64_ALPHABET[d2];
b3 = base64Alphabet[d3]; b3 = BASE_64_ALPHABET[d3];
b4 = base64Alphabet[d4]; b4 = BASE_64_ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); 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 return null;// if found "no data" just return null
} }
b1 = base64Alphabet[d1]; b1 = BASE_64_ALPHABET[d1];
b2 = base64Alphabet[d2]; b2 = BASE_64_ALPHABET[d2];
d3 = base64Data[dataIndex++]; d3 = base64Data[dataIndex++];
d4 = base64Data[dataIndex++]; d4 = base64Data[dataIndex++];
@ -235,7 +235,7 @@ public final class Base64
} }
else if (!isPad(d3) && isPad(d4)) else if (!isPad(d3) && isPad(d4))
{ {
b3 = base64Alphabet[d3]; b3 = BASE_64_ALPHABET[d3];
if ((b3 & 0x3) != 0)// last 2 bits should be zero if ((b3 & 0x3) != 0)// last 2 bits should be zero
{ {
return null; return null;
@ -253,8 +253,8 @@ public final class Base64
} }
else else
{ // No PAD e.g 3cQl { // No PAD e.g 3cQl
b3 = base64Alphabet[d3]; b3 = BASE_64_ALPHABET[d3];
b4 = base64Alphabet[d4]; b4 = BASE_64_ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);

@ -10,10 +10,10 @@ import com.ruoyi.common.core.utils.StringUtils;
public class Seq 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); private static AtomicInteger commSeq = new AtomicInteger(1);
@ -31,7 +31,7 @@ public class Seq
*/ */
public static String getId() 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) public static String getId(String type)
{ {
AtomicInteger atomicInt = commSeq; AtomicInteger atomicInt = commSeq;
if (uploadSeqType.equals(type)) if (UPLOAD_SEQ_TYPE.equals(type))
{ {
atomicInt = uploadSeq; atomicInt = uploadSeq;
} }

@ -22,7 +22,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*/ */
private static class Holder private static class Holder
{ {
static final SecureRandom numberGenerator = getSecureRandom(); static final SecureRandom NUMBER_GENERATOR = getSecureRandom();
} }
/** 此UUID的最高64有效位 */ /** 此UUID的最高64有效位 */
@ -93,7 +93,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*/ */
public static UUID randomUUID(boolean isSecure) 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]; byte[] randomBytes = new byte[16];
ng.nextBytes(randomBytes); ng.nextBytes(randomBytes);

@ -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;
}
}

@ -12,14 +12,14 @@ import com.ruoyi.common.security.interceptor.HeaderInterceptor;
public class WebMvcConfig implements WebMvcConfigurer public class WebMvcConfig implements WebMvcConfigurer
{ {
/** 不需要拦截地址 */ /** 不需要拦截地址 */
public static final String[] excludeUrls = { "/login", "/logout", "/refresh" }; public static final String[] EXCLUDE_URLS = { "/login", "/logout", "/refresh" };
@Override @Override
public void addInterceptors(InterceptorRegistry registry) public void addInterceptors(InterceptorRegistry registry)
{ {
registry.addInterceptor(getHeaderInterceptor()) registry.addInterceptor(getHeaderInterceptor())
.addPathPatterns("/**") .addPathPatterns("/**")
.excludePathPatterns(excludeUrls) .excludePathPatterns(EXCLUDE_URLS)
.order(-10); .order(-10);
} }

@ -33,8 +33,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(NotPermissionException.class) @ExceptionHandler(NotPermissionException.class)
public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request) public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request)
{ {
String requestURI = request.getRequestURI(); String requestUri = request.getRequestURI();
log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage()); log.error("请求地址'{}',权限码校验失败'{}'", requestUri, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权"); return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
} }
@ -44,8 +44,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(NotRoleException.class) @ExceptionHandler(NotRoleException.class)
public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request) public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request)
{ {
String requestURI = request.getRequestURI(); String requestUri = request.getRequestURI();
log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage()); log.error("请求地址'{}',角色权限校验失败'{}'", requestUri, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权"); return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
} }
@ -56,8 +56,8 @@ public class GlobalExceptionHandler
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
HttpServletRequest request) HttpServletRequest request)
{ {
String requestURI = request.getRequestURI(); String requestUri = request.getRequestURI();
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); log.error("请求地址'{}',不支持'{}'请求", requestUri, e.getMethod());
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
@ -78,8 +78,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
{ {
String requestURI = request.getRequestURI(); String requestUri = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e); log.error("请求地址'{}',发生未知异常.", requestUri, e);
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
@ -89,8 +89,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public AjaxResult handleException(Exception e, HttpServletRequest request) public AjaxResult handleException(Exception e, HttpServletRequest request)
{ {
String requestURI = request.getRequestURI(); String requestUri = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e); log.error("请求地址'{}',发生系统异常.", requestUri, e);
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }

@ -32,7 +32,7 @@ public class TokenService
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; 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; private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
@ -61,7 +61,7 @@ public class TokenService
// 接口返回信息 // 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>(); Map<String, Object> rspMap = new HashMap<String, Object>();
rspMap.put("access_token", JwtUtils.createToken(claimsMap)); rspMap.put("access_token", JwtUtils.createToken(claimsMap));
rspMap.put("expires_in", expireTime); rspMap.put("expires_in", EXPIRE_TIME);
return rspMap; return rspMap;
} }
@ -156,10 +156,10 @@ public class TokenService
public void refreshToken(LoginUser loginUser) public void refreshToken(LoginUser loginUser)
{ {
loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); loginUser.setExpireTime(loginUser.getLoginTime() + EXPIRE_TIME * MILLIS_MINUTE);
// 根据uuid将loginUser缓存 // 根据uuid将loginUser缓存
String userKey = getTokenKey(loginUser.getToken()); 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) private String getTokenKey(String token)

@ -88,7 +88,7 @@ public class FileUploadUtils
public static final String extractFilename(MultipartFile file) public static final String extractFilename(MultipartFile file)
{ {
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), 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 private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException

Loading…
Cancel
Save