代码规约扫描

pull/183/head
1332987 3 years ago
parent 7c394a46ac
commit ef29194da6

@ -185,19 +185,19 @@ public class ServletUtils
public static boolean isAjaxRequest(HttpServletRequest request)
{
String accept = request.getHeader("accept");
if (accept != null && accept.contains("application/json"))
if (accept != null && accept.contains(StringUtils.ACCEPT_JSON))
{
return true;
}
String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
if (xRequestedWith != null && xRequestedWith.contains(StringUtils.XML_HTTP))
{
return true;
}
String uri = request.getRequestURI();
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
if (StringUtils.inStringIgnoreCase(uri, StringUtils.DOT+StringUtils.JSON,StringUtils.DOT+StringUtils.XML))
{
return true;
}

@ -16,10 +16,60 @@ import java.util.Map;
public class StringUtils extends org.apache.commons.lang3.StringUtils
{
/** 空字符串 */
private static final String NULLSTR = "";
public static final String NULLSTR = "";
/** 空格字符串 */
public static final String BLANK_SPACE = " ";
/** 斜杠字符串 */
public static final String SLASH = "/";
/** 井号字符串 */
public static final String WELL_NO = "#";
/** 点字符串 */
public static final String DOT = ".";
/** 逗号符串 */
public static final String COMMA = ",";
/** (符串 */
public static final String LEFT_BRACKETS = "(";
/** get字符串 */
public static final String GET = "GET";
/** POST字符串 */
public static final String POST = "POST";
/** DELETE字符串 */
public static final String DELETE = "DELETE";
/** 前端排序字符串 */
public static final String ASC_ENDING = "ascending";
/** 前端排序字符串 */
public static final String DESC_ENDING = "descending";
/** true字符串 */
public static final String TRUE = "true";
/** registerUser字符串 */
public static final String SYS_ACCOUNT_USER = "sys.account.registerUser";
/** char字符串 */
public static final String CHAR = "char";
/** math字符串 */
public static final String MATH = "math";
/** JPG字符串 */
public static final String JPG = "JPG";
/** PNG字符串 */
public static final String PNG = "PNG";
/** 注:字符串 */
public static final String NOTE = "注:";
/** MSIE字符串 */
public static final String MSIE = "MSIE";
/** Firefox字符串 */
public static final String FIREFOX = "Firefox";
/** Chrome字符串 */
public static final String CHROME = "Chrome";
/** json字符串 */
public static final String ACCEPT_JSON = "application/json";
/** XMLHttpRequest字符串 */
public static final String XML_HTTP = "XMLHttpRequest";
/** json字符串 */
public static final String JSON = "json";
/** xml字符串 */
public static final String XML = "xml";
/** 下划线 */
private static final char SEPARATOR = '_';
public static final char SEPARATOR = '_';
/**
*
@ -373,19 +423,17 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
public static String convertToCamelCase(String name)
{
StringBuilder result = new StringBuilder();
String underline = "_";
// 快速检查
if (name == null || name.isEmpty())
{
if (name == null || name.isEmpty()) {
// 没必要转换
return "";
}
else if (!name.contains("_"))
{
} else if (!name.contains(underline)) {
// 不含下划线,仅将首字母大写
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
// 用下划线将原始字符串分割
String[] camels = name.split("_");
String[] camels = name.split(underline);
for (String camel : camels)
{
// 跳过原始字符串中开头、结尾的下换线或双重下划线

@ -1,29 +1,28 @@
package com.ruoyi.common.core.utils.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import com.ruoyi.common.core.utils.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import com.ruoyi.common.core.utils.StringUtils;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
/**
*
*
* @author ruoyi
*/
public class FileUtils
{
/** 字符常量:斜杠 {@code '/'} */
public class FileUtils {
/**
* {@code '/'}
*/
public static final char SLASH = '/';
/** 字符常量:反斜杠 {@code '\\'} */
/**
* {@code '\\'}
*/
public static final char BACKSLASH = '\\';
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
@ -35,49 +34,33 @@ public class FileUtils
* @param os
* @return
*/
public static void writeBytes(String filePath, OutputStream os) throws IOException
{
public static void writeBytes(String filePath, OutputStream os) throws IOException {
FileInputStream fis = null;
try
{
try {
File file = new File(filePath);
if (!file.exists())
{
if (!file.exists()) {
throw new FileNotFoundException(filePath);
}
fis = new FileInputStream(file);
byte[] b = new byte[1024];
int length;
while ((length = fis.read(b)) > 0)
{
while ((length = fis.read(b)) > 0) {
os.write(b, 0, length);
}
}
catch (IOException e)
{
} catch (IOException e) {
throw e;
}
finally
{
if (os != null)
{
try
{
} finally {
if (os != null) {
try {
os.close();
}
catch (IOException e1)
{
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fis != null)
{
try
{
if (fis != null) {
try {
fis.close();
}
catch (IOException e1)
{
} catch (IOException e1) {
e1.printStackTrace();
}
}
@ -90,13 +73,11 @@ public class FileUtils
* @param filePath
* @return
*/
public static boolean deleteFile(String filePath)
{
public static boolean deleteFile(String filePath) {
boolean flag = false;
File file = new File(filePath);
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists())
{
if (file.isFile() && file.exists()) {
file.delete();
flag = true;
}
@ -109,8 +90,7 @@ public class FileUtils
* @param filename
* @return true false
*/
public static boolean isValidFilename(String filename)
{
public static boolean isValidFilename(String filename) {
return filename.matches(FILENAME_PATTERN);
}
@ -120,17 +100,14 @@ public class FileUtils
* @param resource
* @return true false
*/
public static boolean checkAllowDownload(String resource)
{
public static boolean checkAllowDownload(String resource) {
// 禁止目录上跳级别
if (StringUtils.contains(resource, ".."))
{
if (StringUtils.contains(resource, StringUtils.DOT + StringUtils.DOT)) {
return false;
}
// 检查允许下载的文件规则
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource)))
{
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) {
return true;
}
@ -145,28 +122,20 @@ public class FileUtils
* @param fileName
* @return
*/
public static String setFileDownloadHeader(HttpServletRequest request, String fileName) throws UnsupportedEncodingException
{
public static String setFileDownloadHeader(HttpServletRequest request, String fileName) throws UnsupportedEncodingException {
final String agent = request.getHeader("USER-AGENT");
String filename = fileName;
if (agent.contains("MSIE"))
{
if (agent.contains(StringUtils.MSIE)) {
// IE浏览器
filename = URLEncoder.encode(filename, "utf-8");
filename = filename.replace("+", " ");
}
else if (agent.contains("Firefox"))
{
} else if (agent.contains(StringUtils.FIREFOX)) {
// 火狐浏览器
filename = new String(fileName.getBytes(), "ISO8859-1");
}
else if (agent.contains("Chrome"))
{
} else if (agent.contains(StringUtils.CHROME)) {
// google浏览器
filename = URLEncoder.encode(filename, "utf-8");
}
else
{
} else {
// 其它浏览器
filename = URLEncoder.encode(filename, "utf-8");
}
@ -179,30 +148,24 @@ public class FileUtils
* @param filePath
* @return
*/
public static String getName(String filePath)
{
if (null == filePath)
{
public static String getName(String filePath) {
if (null == filePath) {
return null;
}
int len = filePath.length();
if (0 == len)
{
if (0 == len) {
return filePath;
}
if (isFileSeparator(filePath.charAt(len - 1)))
{
if (isFileSeparator(filePath.charAt(len - 1))) {
// 以分隔符结尾的去掉结尾分隔符
len--;
}
int begin = 0;
char c;
for (int i = len - 1; i > -1; i--)
{
for (int i = len - 1; i > -1; i--) {
c = filePath.charAt(i);
if (isFileSeparator(c))
{
if (isFileSeparator(c)) {
// 查找最后一个路径分隔符(/或者\
begin = i + 1;
break;
@ -219,8 +182,7 @@ public class FileUtils
* @param c
* @return WindowsLinuxUnix
*/
public static boolean isFileSeparator(char c)
{
public static boolean isFileSeparator(char c) {
return SLASH == c || BACKSLASH == c;
}
@ -231,8 +193,7 @@ public class FileUtils
* @param realFileName
* @return
*/
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
{
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException {
String percentEncodedFileName = percentEncode(realFileName);
StringBuilder contentDispositionValue = new StringBuilder();
@ -253,8 +214,7 @@ public class FileUtils
* @param s
* @return
*/
public static String percentEncode(String s) throws UnsupportedEncodingException
{
public static String percentEncode(String s) throws UnsupportedEncodingException {
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
return encode.replaceAll("\\+", "%20");
}

@ -13,10 +13,9 @@ public class EscapeUtil
private static final char[][] TEXT = new char[64][];
static
{
for (int i = 0; i < 64; i++)
{
static {
int baseSize = 64;
for (int i = 0; i < baseSize; i++) {
TEXT[i] = new char[] { (char) i };
}

@ -1,5 +1,7 @@
package com.ruoyi.common.core.utils.html;
import com.ruoyi.common.core.utils.StringUtils;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -168,6 +170,7 @@ public final class HtmlFilter {
/**
* my versions of some PHP library functions
*
* @param decimal /
* @return /
*/
@ -383,7 +386,7 @@ public final class HtmlFilter {
if (!inArray(protocol, vAllowedProtocols)) {
// bad protocol, turn into local anchor link instead
s = "#" + s.substring(protocol.length() + 1);
if (s.startsWith("#//")) {
if (s.startsWith(StringUtils.WELL_NO + StringUtils.SLASH + StringUtils.SLASH)) {
s = "#" + s.substring(3);
}
}

@ -62,7 +62,8 @@ public class IpUtils {
* @return
*/
private static boolean internalIp(byte[] addr) {
if (StringUtils.isNull(addr) || addr.length < 2) {
int tow = 2;
if (StringUtils.isNull(addr) || addr.length < tow) {
return true;
}
final byte b0 = addr[0];
@ -118,7 +119,8 @@ public class IpUtils {
switch (elements.length) {
case 1:
l = Long.parseLong(elements[0]);
if ((l < 0L) || (l > 4294967295L)) {
long l1 = 4294967295L;
if ((l < 0L) || (l > l1)) {
return null;
}
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
@ -128,12 +130,14 @@ public class IpUtils {
break;
case 2:
l = Integer.parseInt(elements[0]);
if ((l < 0L) || (l > 255L)) {
long l2 = 255L;
if ((l < 0L) || (l > l2)) {
return null;
}
bytes[0] = (byte) (int) (l & 0xFF);
l = Integer.parseInt(elements[1]);
if ((l < 0L) || (l > 16777215L)) {
long l3 = 16777215L;
if ((l < 0L) || (l > l3)) {
return null;
}
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
@ -141,7 +145,8 @@ public class IpUtils {
bytes[3] = (byte) (int) (l & 0xFF);
break;
case 3:
for (i = 0; i < 2; ++i) {
int i1 = 2;
for (i = 0; i < i1; ++i) {
l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L)) {
return null;
@ -149,14 +154,16 @@ public class IpUtils {
bytes[i] = (byte) (int) (l & 0xFF);
}
l = Integer.parseInt(elements[2]);
if ((l < 0L) || (l > 65535L)) {
long l4 = 65535L;
if ((l < 0L) || (l > l4)) {
return null;
}
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF);
break;
case 4:
for (i = 0; i < 4; ++i) {
int i2 = 4;
for (i = 0; i < i2; ++i) {
l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L)) {
return null;
@ -207,7 +214,7 @@ public class IpUtils {
*/
public static String getMultistageReverseProxyIp(String ip) {
// 多级反向代理检测
if (ip != null && ip.indexOf(",") > 0) {
if (ip != null && ip.indexOf(StringUtils.COMMA) > 0) {
final String[] ips = ip.trim().split(",");
for (String subIp : ips) {
if (false == isUnknown(subIp)) {

@ -555,9 +555,9 @@ public class ExcelUtil<T> {
*/
public int getImageType(byte[] value) {
String type = FileTypeUtils.getFileExtendName(value);
if ("JPG".equalsIgnoreCase(type)) {
if (StringUtils.JPG.equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_JPEG;
} else if ("PNG".equalsIgnoreCase(type)) {
} else if (StringUtils.PNG.equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_PNG;
}
return Workbook.PICTURE_TYPE_JPEG;
@ -567,7 +567,7 @@ public class ExcelUtil<T> {
*
*/
public void setDataValidation(Excel attr, Row row, int column) {
if (attr.name().indexOf("注:") >= 0) {
if (attr.name().indexOf(StringUtils.NOTE) >= 0) {
sheet.setColumnWidth(column, 6000);
} else {
// 设置列宽
@ -777,7 +777,7 @@ public class ExcelUtil<T> {
Object o = field.get(vo);
if (StringUtils.isNotEmpty(excel.targetAttr())) {
String target = excel.targetAttr();
if (target.contains(".")) {
if (target.contains(StringUtils.DOT)) {
String[] targets = target.split("[.]");
for (String name : targets) {
o = getValue(o, name);

@ -35,7 +35,8 @@ public class ReflectUtils
public static <E> E invokeGetter(Object obj, String propertyName)
{
Object object = obj;
for (String name : StringUtils.split(propertyName, "."))
String point = ".";
for (String name : StringUtils.split(propertyName, point))
{
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});

@ -13,23 +13,24 @@ import java.util.concurrent.ThreadLocalRandom;
*
* @author ruoyi
*/
public final class UUID implements java.io.Serializable, Comparable<UUID>
{
public final class UUID implements java.io.Serializable, Comparable<UUID> {
private static final long serialVersionUID = -1185015143654744140L;
/**
* SecureRandom
*
*/
private static class Holder
{
private static class Holder {
static final SecureRandom NUMBER_GENERATOR = getSecureRandom();
}
/** 此UUID的最高64有效位 */
/**
* UUID64
*/
private final long mostSigBits;
/** 此UUID的最低64有效位 */
/**
* UUID64
*/
private final long leastSigBits;
/**
@ -37,18 +38,17 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @param data
*/
private UUID(byte[] 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);
int eight = 8;
int sixteen = 16;
for (int i = 0; i < eight; i++) {
msb = (msb << eight) | (data[i] & 0xff);
}
for (int i = 8; i < 16; i++)
{
lsb = (lsb << 8) | (data[i] & 0xff);
for (int i = eight; i < sixteen; i++) {
lsb = (lsb << eight) | (data[i] & 0xff);
}
this.mostSigBits = msb;
this.leastSigBits = lsb;
@ -60,8 +60,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param mostSigBits {@code UUID} 64
* @param leastSigBits {@code UUID} 64
*/
public UUID(long mostSigBits, long leastSigBits)
{
public UUID(long mostSigBits, long leastSigBits) {
this.mostSigBits = mostSigBits;
this.leastSigBits = leastSigBits;
}
@ -71,8 +70,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return {@code UUID}
*/
public static UUID fastuuid()
{
public static UUID fastuuid() {
return randomuuid(false);
}
@ -81,8 +79,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return {@code UUID}
*/
public static UUID randomuuid()
{
public static UUID randomuuid() {
return randomuuid(true);
}
@ -92,8 +89,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param isSecure 使{@link SecureRandom}
* @return {@code UUID}
*/
public static UUID randomuuid(boolean isSecure)
{
public static UUID randomuuid(boolean isSecure) {
final Random ng = isSecure ? Holder.NUMBER_GENERATOR : getRandom();
byte[] randomBytes = new byte[16];
@ -109,18 +105,13 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* 3UUID
*
* @param name UUID
*
* @return {@code UUID}
*/
public static UUID nameUuidFromBytes(byte[] name)
{
public static UUID nameUuidFromBytes(byte[] name) {
MessageDigest md;
try
{
try {
md = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException nsae)
{
} catch (NoSuchAlgorithmException nsae) {
throw new InternalError("MD5 not supported");
}
byte[] md5Bytes = md.digest(name);
@ -137,17 +128,14 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param name {@code UUID}
* @return {@code UUID}
* @throws IllegalArgumentException name {@link #toString}
*
*/
public static UUID fromString(String name)
{
public static UUID fromString(String name) {
String[] components = name.split("-");
if (components.length != 5)
{
int fastFive = 5;
if (components.length != fastFive) {
throw new IllegalArgumentException("Invalid UUID string: " + name);
}
for (int i = 0; i < 5; i++)
{
for (int i = 0; i < fastFive; i++) {
StringBuilder sb = new StringBuilder();
sb.append(sb);
sb.append(components[i]);
@ -172,8 +160,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return UUID 128 64
*/
public long getLeastSignificantBits()
{
public long getLeastSignificantBits() {
return leastSigBits;
}
@ -182,8 +169,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return UUID 128 64
*/
public long getMostSignificantBits()
{
public long getMostSignificantBits() {
return mostSigBits;
}
@ -200,8 +186,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return {@code UUID}
*/
public int version()
{
public int version() {
// Version is bits masked by 0x000000000000F000 in MS long
return (int) ((mostSigBits >> 12) & 0x0f);
}
@ -219,8 +204,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return {@code UUID}
*/
public int variant()
{
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)
@ -242,8 +226,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @throws UnsupportedOperationException {@code UUID} version 1 UUID
*/
public long timestamp() throws UnsupportedOperationException
{
public long timestamp() throws UnsupportedOperationException {
checkTimeBase();
return (mostSigBits & 0x0FFFL) << 48
| ((mostSigBits >> 16) & 0x0FFFFL) << 32
@ -260,11 +243,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* UnsupportedOperationException
*
* @return {@code UUID}
*
* @throws UnsupportedOperationException UUID version 1
*/
public int clockSequence() throws UnsupportedOperationException
{
public int clockSequence() throws UnsupportedOperationException {
checkTimeBase();
return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48);
}
@ -279,11 +260,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* UUID UUID UnsupportedOperationException
*
* @return {@code UUID}
*
* @throws UnsupportedOperationException UUID version 1
*/
public long node() throws UnsupportedOperationException
{
public long node() throws UnsupportedOperationException {
checkTimeBase();
return leastSigBits & 0x0000FFFFFFFFFFFFL;
}
@ -313,8 +292,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @see #toString(boolean)
*/
@Override
public String toString()
{
public String toString() {
return toString(false);
}
@ -342,31 +320,26 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param isSimple '-'UUID
* @return {@code UUID}
*/
public String toString(boolean isSimple)
{
public String toString(boolean isSimple) {
final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
// time_low
builder.append(digits(mostSigBits >> 32, 8));
if (false == isSimple)
{
if (false == isSimple) {
builder.append('-');
}
// time_mid
builder.append(digits(mostSigBits >> 16, 4));
if (false == isSimple)
{
if (false == isSimple) {
builder.append('-');
}
// time_high_and_version
builder.append(digits(mostSigBits, 4));
if (false == isSimple)
{
if (false == isSimple) {
builder.append('-');
}
// variant_and_sequence
builder.append(digits(leastSigBits >> 48, 4));
if (false == isSimple)
{
if (false == isSimple) {
builder.append('-');
}
// node
@ -381,8 +354,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @return UUID
*/
@Override
public int hashCode()
{
public int hashCode() {
long hilo = mostSigBits ^ leastSigBits;
return ((int) (hilo >> 32)) ^ (int) hilo;
}
@ -393,14 +365,11 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* {@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))
{
public boolean equals(Object obj) {
if ((null == obj) || (obj.getClass() != UUID.class)) {
return false;
}
UUID id = (UUID) obj;
@ -416,13 +385,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* UUID UUID UUID UUID UUID
*
* @param val UUID UUID
*
* @return UUID val -10 1
*
*/
@Override
public int compareTo(UUID val)
{
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 :
@ -434,6 +400,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
// -------------------------------------------------------------------------------------------------------------------
// Private method start
/**
* hex
*
@ -441,8 +408,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param digits
* @return
*/
private static String digits(long val, int digits)
{
private static String digits(long val, int digits) {
long hi = 1L << (digits * 4);
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
}
@ -450,10 +416,8 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
/**
* time-basedUUID
*/
private void checkTimeBase()
{
if (version() != 1)
{
private void checkTimeBase() {
if (version() != 1) {
throw new UnsupportedOperationException("Not a time-based UUID");
}
}
@ -463,14 +427,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return {@link SecureRandom}
*/
public static SecureRandom getSecureRandom()
{
try
{
public static SecureRandom getSecureRandom() {
try {
return SecureRandom.getInstance("SHA1PRNG");
}
catch (NoSuchAlgorithmException e)
{
} catch (NoSuchAlgorithmException e) {
throw new UtilException(e);
}
}
@ -481,8 +441,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return {@link ThreadLocalRandom}
*/
public static ThreadLocalRandom getRandom()
{
public static ThreadLocalRandom getRandom() {
return ThreadLocalRandom.current();
}
}

@ -70,14 +70,13 @@ public class PageDomain
public void setIsAsc(String isAsc)
{
if (StringUtils.isNotEmpty(isAsc))
{
if (StringUtils.isNotEmpty(isAsc)) {
// 兼容前端排序类型
if ("ascending".equals(isAsc))
if (StringUtils.ASC_ENDING.equals(isAsc))
{
isAsc = "asc";
}
else if ("descending".equals(isAsc))
else if (StringUtils.DESC_ENDING.equals(isAsc))
{
isAsc = "desc";
}

@ -22,32 +22,26 @@ public class KaptchaTextCreator extends DefaultTextCreator
int y = random.nextInt(10);
StringBuilder suChinese = new StringBuilder();
int randomoperands = (int) Math.round(Math.random() * 2);
if (randomoperands == 0)
{
int randomoperandsInt = 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)
{
else if (randomoperands == 1) {
if ((x != 0) && y % x == 0) {
result = y / x;
suChinese.append(CNUMBERS[y]);
suChinese.append("/");
suChinese.append(CNUMBERS[x]);
}
else
{
} else {
result = x + y;
suChinese.append(CNUMBERS[x]);
suChinese.append("+");
suChinese.append(CNUMBERS[y]);
}
}
else if (randomoperands == 2)
{
} else if (randomoperands == randomoperandsInt) {
if (x >= y)
{
result = x - y;

@ -2,6 +2,8 @@ package com.ruoyi.gateway.filter;
import java.util.Collections;
import java.util.List;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter;
@ -54,7 +56,7 @@ public class CacheRequestFilter extends AbstractGatewayFilterFactory<CacheReques
{
// GET DELETE 不过滤
HttpMethod method = exchange.getRequest().getMethod();
if (method == null || method.matches("GET") || method.matches("DELETE"))
if (method == null || method.matches(StringUtils.GET) || method.matches(StringUtils.DELETE))
{
return chain.filter(exchange);
}

@ -43,7 +43,7 @@ public class XssFilter implements GlobalFilter, Ordered
ServerHttpRequest request = exchange.getRequest();
// GET DELETE 不过滤
HttpMethod method = request.getMethod();
if (method == null || method.matches("GET") || method.matches("DELETE"))
if (method == null || method.matches(StringUtils.GET) || method.matches(StringUtils.DELETE))
{
return chain.filter(exchange);
}

@ -62,14 +62,14 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
String captchaType = captchaProperties.getType();
// 生成验证码
if ("math".equals(captchaType))
if (StringUtils.MATH.equals(captchaType))
{
String capText = captchaProducerMath.createText();
capStr = capText.substring(0, capText.lastIndexOf("@"));
code = capText.substring(capText.lastIndexOf("@") + 1);
image = captchaProducerMath.createImage(capStr);
}
else if ("char".equals(captchaType))
else if (StringUtils.CHAR.equals(captchaType))
{
capStr = code = captchaProducer.createText();
image = captchaProducer.createImage(capStr);

@ -353,15 +353,12 @@ public class GenTableColumn extends BaseEntity
{
String remarks = StringUtils.substringBetween(this.columnComment, "", "");
StringBuffer sb = new StringBuffer();
if (StringUtils.isNotEmpty(remarks))
{
for (String value : remarks.split(" "))
{
if (StringUtils.isNotEmpty(value))
{
if (StringUtils.isNotEmpty(remarks)) {
for (String value : remarks.split(StringUtils.BLANK_SPACE)) {
if (StringUtils.isNotEmpty(value)) {
Object startStr = value.subSequence(0, 1);
String endStr = value.substring(1);
sb.append("").append(startStr).append("=").append(endStr).append(",");
sb.append(startStr).append("=").append(endStr).append(",");
}
}
return sb.deleteCharAt(sb.length() - 1).toString();

@ -514,7 +514,7 @@ public class GenTableServiceImpl implements IGenTableService
public static String getGenPath(GenTable table, String template)
{
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/"))
if (StringUtils.equals(genPath, StringUtils.SLASH))
{
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}

@ -53,14 +53,18 @@ public class GenUtils {
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
int i = 2;
if (str != null && str.length == i && Integer.parseInt(str[1]) > 0) {
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
} else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
} else {
int i1 = 10;
if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= i1) {
column.setJavaType(GenConstants.TYPE_INTEGER);
} else {
column.setJavaType(GenConstants.TYPE_LONG);
}
}
}
// 插入字段(默认所有字段都需要插入)
column.setIsInsert(GenConstants.REQUIRE);
// 编辑字段
@ -76,20 +80,27 @@ public class GenUtils {
column.setIsQuery(GenConstants.REQUIRE);
}
// 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
String name = "name";
if (StringUtils.endsWithIgnoreCase(columnName, name)) {
column.setQueryType(GenConstants.QUERY_LIKE);
}
// 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
String status = "status";
String type = "type";
String sex = "sex";
String image = "image";
String file = "file";
String content = "content";
if (StringUtils.endsWithIgnoreCase(columnName, status)) {
column.setHtmlType(GenConstants.HTML_RADIO);
} else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) {
} else if (StringUtils.endsWithIgnoreCase(columnName, type)
|| StringUtils.endsWithIgnoreCase(columnName, sex)) {
column.setHtmlType(GenConstants.HTML_SELECT);
} else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
} else if (StringUtils.endsWithIgnoreCase(columnName, image)) {
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
} else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
} else if (StringUtils.endsWithIgnoreCase(columnName, file)) {
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
} else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
} else if (StringUtils.endsWithIgnoreCase(columnName, content)) {
column.setHtmlType(GenConstants.HTML_EDITOR);
}
}
@ -180,8 +191,8 @@ public class GenUtils {
* @return
*/
public static String getDbType(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
return StringUtils.substringBefore(columnType, "(");
if (StringUtils.indexOf(columnType, StringUtils.LEFT_BRACKETS) > 0) {
return StringUtils.substringBefore(columnType, StringUtils.LEFT_BRACKETS);
} else {
return columnType;
}
@ -194,7 +205,7 @@ public class GenUtils {
* @return
*/
public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
if (StringUtils.indexOf(columnType, StringUtils.LEFT_BRACKETS) > 0) {
String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length);
} else {

@ -1,31 +1,37 @@
package com.ruoyi.gen.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.velocity.VelocityContext;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.GenConstants;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn;
import org.apache.velocity.VelocityContext;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
*
* @author ruoyi
*/
public class VelocityUtils
{
/** 项目空间路径 */
public class VelocityUtils {
/**
*
*/
private static final String PROJECT_PATH = "main/java";
/** mybatis空间路径 */
/**
* mybatis
*/
private static final String MYBATIS_PATH = "main/resources/mapper";
/** 默认上级菜单,系统工具 */
/**
*
*/
private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
@ -33,8 +39,7 @@ public class VelocityUtils
*
* @return
*/
public static VelocityContext prepareContext(GenTable genTable)
{
public static VelocityContext prepareContext(GenTable genTable) {
String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName();
String packageName = genTable.getPackageName();
@ -61,27 +66,23 @@ public class VelocityUtils
velocityContext.put("table", genTable);
velocityContext.put("dicts", getDicts(genTable));
setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory))
{
if (GenConstants.TPL_TREE.equals(tplCategory)) {
setTreeVelocityContext(velocityContext, genTable);
}
if (GenConstants.TPL_SUB.equals(tplCategory))
{
if (GenConstants.TPL_SUB.equals(tplCategory)) {
setSubVelocityContext(velocityContext, genTable);
}
return velocityContext;
}
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String parentMenuId = getParentMenuId(paramsObj);
context.put("parentMenuId", parentMenuId);
}
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeCode = getTreecode(paramsObj);
@ -92,18 +93,15 @@ public class VelocityUtils
context.put("treeParentCode", treeParentCode);
context.put("treeName", treeName);
context.put("expandColumn", getExpandColumn(genTable));
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
}
}
public static void setSubVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setSubVelocityContext(VelocityContext context, GenTable genTable) {
GenTable subTable = genTable.getSubTable();
String subTableName = genTable.getSubTableName();
String subTableFkName = genTable.getSubTableFkName();
@ -125,8 +123,7 @@ public class VelocityUtils
*
* @return
*/
public static List<String> getTemplateList(String tplCategory)
{
public static List<String> getTemplateList(String tplCategory) {
List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm");
@ -136,16 +133,11 @@ public class VelocityUtils
templates.add("vm/xml/mapper.xml.vm");
templates.add("vm/sql/sql.vm");
templates.add("vm/js/api.js.vm");
if (GenConstants.TPL_CRUD.equals(tplCategory))
{
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
templates.add("vm/vue/index.vue.vm");
}
else if (GenConstants.TPL_TREE.equals(tplCategory))
{
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
templates.add("vm/vue/index-tree.vue.vm");
}
else if (GenConstants.TPL_SUB.equals(tplCategory))
{
} else if (GenConstants.TPL_SUB.equals(tplCategory)) {
templates.add("vm/vue/index.vue.vm");
templates.add("vm/java/sub-domain.java.vm");
}
@ -155,8 +147,7 @@ public class VelocityUtils
/**
*
*/
public static String getFileName(String template, GenTable genTable)
{
public static String getFileName(String template, GenTable genTable) {
// 文件名称
String fileName = "";
// 包路径
@ -172,48 +163,30 @@ public class VelocityUtils
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue";
if (template.contains("domain.java.vm"))
{
String domainVm = "domain.java.vm";
if (template.contains(domainVm)) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
}
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
{
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
}
else if (template.contains("mapper.java.vm"))
{
} else if (template.contains("mapper.java.vm")) {
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
}
else if (template.contains("service.java.vm"))
{
} else if (template.contains("service.java.vm")) {
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
}
else if (template.contains("serviceImpl.java.vm"))
{
} else if (template.contains("serviceImpl.java.vm")) {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
}
else if (template.contains("controller.java.vm"))
{
} else if (template.contains("controller.java.vm")) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
}
else if (template.contains("mapper.xml.vm"))
{
} else if (template.contains("mapper.xml.vm")) {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
}
else if (template.contains("sql.vm"))
{
} else if (template.contains("sql.vm")) {
fileName = businessName + "Menu.sql";
}
else if (template.contains("api.js.vm"))
{
} else if (template.contains("api.js.vm")) {
fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
}
else if (template.contains("index.vue.vm"))
{
} else if (template.contains("index.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
else if (template.contains("index-tree.vue.vm"))
{
} else if (template.contains("index-tree.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
return fileName;
@ -225,8 +198,7 @@ public class VelocityUtils
* @param packageName
* @return
*/
public static String getPackagePrefix(String packageName)
{
public static String getPackagePrefix(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
return StringUtils.substring(packageName, 0, lastIndex);
}
@ -237,24 +209,18 @@ public class VelocityUtils
* @param genTable
* @return
*/
public static HashSet<String> getImportList(GenTable genTable)
{
public static HashSet<String> getImportList(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
GenTable subGenTable = genTable.getSubTable();
HashSet<String> importList = new HashSet<String>();
if (StringUtils.isNotNull(subGenTable))
{
if (StringUtils.isNotNull(subGenTable)) {
importList.add("java.util.List");
}
for (GenTableColumn column : columns)
{
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
{
for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
importList.add("java.util.Date");
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
}
else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType()))
{
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
importList.add("java.math.BigDecimal");
}
}
@ -267,13 +233,11 @@ public class VelocityUtils
* @param genTable
* @return
*/
public static String getDicts(GenTable genTable)
{
public static String getDicts(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
Set<String> dicts = new HashSet<String>();
addDicts(dicts, columns);
if (StringUtils.isNotNull(genTable.getSubTable()))
{
if (StringUtils.isNotNull(genTable.getSubTable())) {
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
addDicts(dicts, subColumns);
}
@ -286,14 +250,11 @@ public class VelocityUtils
* @param dicts
* @param columns
*/
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns)
{
for (GenTableColumn column : columns)
{
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
column.getHtmlType(),
new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX }))
{
new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) {
dicts.add("'" + column.getDictType() + "'");
}
}
@ -306,8 +267,7 @@ public class VelocityUtils
* @param businessName
* @return
*/
public static String getPermissionPrefix(String moduleName, String businessName)
{
public static String getPermissionPrefix(String moduleName, String businessName) {
return StringUtils.format("{}:{}", moduleName, businessName);
}
@ -317,11 +277,9 @@ public class VelocityUtils
* @param paramsObj
* @return ID
*/
public static String getParentMenuId(JSONObject paramsObj)
{
public static String getParentMenuId(JSONObject paramsObj) {
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
&& StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID)))
{
&& StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) {
return paramsObj.getString(GenConstants.PARENT_MENU_ID);
}
return DEFAULT_PARENT_MENU_ID;
@ -333,10 +291,8 @@ public class VelocityUtils
* @param paramsObj
* @return
*/
public static String getTreecode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_CODE))
{
public static String getTreecode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
return StringUtils.EMPTY;
@ -348,10 +304,8 @@ public class VelocityUtils
* @param paramsObj
* @return
*/
public static String getTreeParentCode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
public static String getTreeParentCode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
return StringUtils.EMPTY;
@ -363,10 +317,8 @@ public class VelocityUtils
* @param paramsObj
* @return
*/
public static String getTreeName(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
public static String getTreeName(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
return StringUtils.EMPTY;
@ -378,20 +330,16 @@ public class VelocityUtils
* @param genTable
* @return
*/
public static int getExpandColumn(GenTable genTable)
{
public static int getExpandColumn(GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns())
{
if (column.isList())
{
for (GenTableColumn column : genTable.getColumns()) {
if (column.isList()) {
num++;
String columnName = column.getColumnName();
if (columnName.equals(treeName))
{
if (columnName.equals(treeName)) {
break;
}
}

@ -134,7 +134,7 @@ public class SysUserController extends BaseController
public Rust<Boolean> register(@RequestBody SysUser sysUser)
{
String username = sysUser.getUserName();
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
if (!(StringUtils.TRUE.equals(configService.selectConfigByKey(StringUtils.SYS_ACCOUNT_USER))))
{
return Rust.fail("当前系统没有开启注册功能!");
}

Loading…
Cancel
Save