代码规约扫描
This commit is contained in:
parent
7c394a46ac
commit
ef29194da6
|
|
@ -185,19 +185,19 @@ public class ServletUtils
|
||||||
public static boolean isAjaxRequest(HttpServletRequest request)
|
public static boolean isAjaxRequest(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
String accept = request.getHeader("accept");
|
String accept = request.getHeader("accept");
|
||||||
if (accept != null && accept.contains("application/json"))
|
if (accept != null && accept.contains(StringUtils.ACCEPT_JSON))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||||
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
|
if (xRequestedWith != null && xRequestedWith.contains(StringUtils.XML_HTTP))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String uri = request.getRequestURI();
|
String uri = request.getRequestURI();
|
||||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
|
if (StringUtils.inStringIgnoreCase(uri, StringUtils.DOT+StringUtils.JSON,StringUtils.DOT+StringUtils.XML))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,60 @@ import java.util.Map;
|
||||||
public class StringUtils extends org.apache.commons.lang3.StringUtils
|
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)
|
public static String convertToCamelCase(String name)
|
||||||
{
|
{
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
String underline = "_";
|
||||||
// 快速检查
|
// 快速检查
|
||||||
if (name == null || name.isEmpty())
|
if (name == null || name.isEmpty()) {
|
||||||
{
|
|
||||||
// 没必要转换
|
// 没必要转换
|
||||||
return "";
|
return "";
|
||||||
}
|
} else if (!name.contains(underline)) {
|
||||||
else if (!name.contains("_"))
|
|
||||||
{
|
|
||||||
// 不含下划线,仅将首字母大写
|
// 不含下划线,仅将首字母大写
|
||||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||||
}
|
}
|
||||||
// 用下划线将原始字符串分割
|
// 用下划线将原始字符串分割
|
||||||
String[] camels = name.split("_");
|
String[] camels = name.split(underline);
|
||||||
for (String camel : camels)
|
for (String camel : camels)
|
||||||
{
|
{
|
||||||
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,28 @@
|
||||||
package com.ruoyi.common.core.utils.file;
|
package com.ruoyi.common.core.utils.file;
|
||||||
|
|
||||||
import java.io.File;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import java.io.FileInputStream;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
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 javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import java.io.*;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件处理工具类
|
* 文件处理工具类
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class FileUtils
|
public class FileUtils {
|
||||||
{
|
/**
|
||||||
/** 字符常量:斜杠 {@code '/'} */
|
* 字符常量:斜杠 {@code '/'}
|
||||||
|
*/
|
||||||
public static final char SLASH = '/';
|
public static final char SLASH = '/';
|
||||||
|
|
||||||
/** 字符常量:反斜杠 {@code '\\'} */
|
/**
|
||||||
|
* 字符常量:反斜杠 {@code '\\'}
|
||||||
|
*/
|
||||||
public static final char BACKSLASH = '\\';
|
public static final char BACKSLASH = '\\';
|
||||||
|
|
||||||
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
||||||
|
|
@ -32,52 +31,36 @@ public class FileUtils
|
||||||
* 输出指定文件的byte数组
|
* 输出指定文件的byte数组
|
||||||
*
|
*
|
||||||
* @param filePath 文件路径
|
* @param filePath 文件路径
|
||||||
* @param os 输出流
|
* @param os 输出流
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static void writeBytes(String filePath, OutputStream os) throws IOException
|
public static void writeBytes(String filePath, OutputStream os) throws IOException {
|
||||||
{
|
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (!file.exists())
|
if (!file.exists()) {
|
||||||
{
|
|
||||||
throw new FileNotFoundException(filePath);
|
throw new FileNotFoundException(filePath);
|
||||||
}
|
}
|
||||||
fis = new FileInputStream(file);
|
fis = new FileInputStream(file);
|
||||||
byte[] b = new byte[1024];
|
byte[] b = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
while ((length = fis.read(b)) > 0)
|
while ((length = fis.read(b)) > 0) {
|
||||||
{
|
|
||||||
os.write(b, 0, length);
|
os.write(b, 0, length);
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
} finally {
|
||||||
finally
|
if (os != null) {
|
||||||
{
|
try {
|
||||||
if (os != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
os.close();
|
os.close();
|
||||||
}
|
} catch (IOException e1) {
|
||||||
catch (IOException e1)
|
|
||||||
{
|
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fis != null)
|
if (fis != null) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
} catch (IOException e1) {
|
||||||
catch (IOException e1)
|
|
||||||
{
|
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,13 +73,11 @@ public class FileUtils
|
||||||
* @param filePath 文件
|
* @param filePath 文件
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean deleteFile(String filePath)
|
public static boolean deleteFile(String filePath) {
|
||||||
{
|
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
// 路径为文件且不为空则进行删除
|
// 路径为文件且不为空则进行删除
|
||||||
if (file.isFile() && file.exists())
|
if (file.isFile() && file.exists()) {
|
||||||
{
|
|
||||||
file.delete();
|
file.delete();
|
||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
|
|
@ -109,8 +90,7 @@ public class FileUtils
|
||||||
* @param filename 文件名称
|
* @param filename 文件名称
|
||||||
* @return true 正常 false 非法
|
* @return true 正常 false 非法
|
||||||
*/
|
*/
|
||||||
public static boolean isValidFilename(String filename)
|
public static boolean isValidFilename(String filename) {
|
||||||
{
|
|
||||||
return filename.matches(FILENAME_PATTERN);
|
return filename.matches(FILENAME_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,17 +100,14 @@ public class FileUtils
|
||||||
* @param resource 需要下载的文件
|
* @param resource 需要下载的文件
|
||||||
* @return true 正常 false 非法
|
* @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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查允许下载的文件规则
|
// 检查允许下载的文件规则
|
||||||
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource)))
|
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,32 +118,24 @@ public class FileUtils
|
||||||
/**
|
/**
|
||||||
* 下载文件名重新编码
|
* 下载文件名重新编码
|
||||||
*
|
*
|
||||||
* @param request 请求对象
|
* @param request 请求对象
|
||||||
* @param fileName 文件名
|
* @param fileName 文件名
|
||||||
* @return 编码后的文件名
|
* @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");
|
final String agent = request.getHeader("USER-AGENT");
|
||||||
String filename = fileName;
|
String filename = fileName;
|
||||||
if (agent.contains("MSIE"))
|
if (agent.contains(StringUtils.MSIE)) {
|
||||||
{
|
|
||||||
// IE浏览器
|
// IE浏览器
|
||||||
filename = URLEncoder.encode(filename, "utf-8");
|
filename = URLEncoder.encode(filename, "utf-8");
|
||||||
filename = filename.replace("+", " ");
|
filename = filename.replace("+", " ");
|
||||||
}
|
} else if (agent.contains(StringUtils.FIREFOX)) {
|
||||||
else if (agent.contains("Firefox"))
|
|
||||||
{
|
|
||||||
// 火狐浏览器
|
// 火狐浏览器
|
||||||
filename = new String(fileName.getBytes(), "ISO8859-1");
|
filename = new String(fileName.getBytes(), "ISO8859-1");
|
||||||
}
|
} else if (agent.contains(StringUtils.CHROME)) {
|
||||||
else if (agent.contains("Chrome"))
|
|
||||||
{
|
|
||||||
// google浏览器
|
// google浏览器
|
||||||
filename = URLEncoder.encode(filename, "utf-8");
|
filename = URLEncoder.encode(filename, "utf-8");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// 其它浏览器
|
// 其它浏览器
|
||||||
filename = URLEncoder.encode(filename, "utf-8");
|
filename = URLEncoder.encode(filename, "utf-8");
|
||||||
}
|
}
|
||||||
|
|
@ -179,30 +148,24 @@ public class FileUtils
|
||||||
* @param filePath 文件
|
* @param filePath 文件
|
||||||
* @return 文件名
|
* @return 文件名
|
||||||
*/
|
*/
|
||||||
public static String getName(String filePath)
|
public static String getName(String filePath) {
|
||||||
{
|
if (null == filePath) {
|
||||||
if (null == filePath)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int len = filePath.length();
|
int len = filePath.length();
|
||||||
if (0 == len)
|
if (0 == len) {
|
||||||
{
|
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
if (isFileSeparator(filePath.charAt(len - 1)))
|
if (isFileSeparator(filePath.charAt(len - 1))) {
|
||||||
{
|
|
||||||
// 以分隔符结尾的去掉结尾分隔符
|
// 以分隔符结尾的去掉结尾分隔符
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
int begin = 0;
|
int begin = 0;
|
||||||
char c;
|
char c;
|
||||||
for (int i = len - 1; i > -1; i--)
|
for (int i = len - 1; i > -1; i--) {
|
||||||
{
|
|
||||||
c = filePath.charAt(i);
|
c = filePath.charAt(i);
|
||||||
if (isFileSeparator(c))
|
if (isFileSeparator(c)) {
|
||||||
{
|
|
||||||
// 查找最后一个路径分隔符(/或者\)
|
// 查找最后一个路径分隔符(/或者\)
|
||||||
begin = i + 1;
|
begin = i + 1;
|
||||||
break;
|
break;
|
||||||
|
|
@ -219,20 +182,18 @@ public class FileUtils
|
||||||
* @param c 字符
|
* @param c 字符
|
||||||
* @return 是否为Windows或者Linux(Unix)文件分隔符
|
* @return 是否为Windows或者Linux(Unix)文件分隔符
|
||||||
*/
|
*/
|
||||||
public static boolean isFileSeparator(char c)
|
public static boolean isFileSeparator(char c) {
|
||||||
{
|
|
||||||
return SLASH == c || BACKSLASH == c;
|
return SLASH == c || BACKSLASH == c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件名重新编码
|
* 下载文件名重新编码
|
||||||
*
|
*
|
||||||
* @param response 响应对象
|
* @param response 响应对象
|
||||||
* @param realFileName 真实文件名
|
* @param realFileName 真实文件名
|
||||||
* @return
|
* @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);
|
String percentEncodedFileName = percentEncode(realFileName);
|
||||||
|
|
||||||
StringBuilder contentDispositionValue = new StringBuilder();
|
StringBuilder contentDispositionValue = new StringBuilder();
|
||||||
|
|
@ -253,8 +214,7 @@ public class FileUtils
|
||||||
* @param s 需要百分号编码的字符串
|
* @param s 需要百分号编码的字符串
|
||||||
* @return 百分号编码后的字符串
|
* @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());
|
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
|
||||||
return encode.replaceAll("\\+", "%20");
|
return encode.replaceAll("\\+", "%20");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,9 @@ public class EscapeUtil
|
||||||
|
|
||||||
private static final char[][] TEXT = new char[64][];
|
private static final char[][] TEXT = new char[64][];
|
||||||
|
|
||||||
static
|
static {
|
||||||
{
|
int baseSize = 64;
|
||||||
for (int i = 0; i < 64; i++)
|
for (int i = 0; i < baseSize; i++) {
|
||||||
{
|
|
||||||
TEXT[i] = new char[] { (char) i };
|
TEXT[i] = new char[] { (char) i };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.ruoyi.common.core.utils.html;
|
package com.ruoyi.common.core.utils.html;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
@ -168,6 +170,7 @@ public final class HtmlFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* my versions of some PHP library functions
|
* my versions of some PHP library functions
|
||||||
|
*
|
||||||
* @param decimal /
|
* @param decimal /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
|
|
@ -383,7 +386,7 @@ public final class HtmlFilter {
|
||||||
if (!inArray(protocol, vAllowedProtocols)) {
|
if (!inArray(protocol, vAllowedProtocols)) {
|
||||||
// bad protocol, turn into local anchor link instead
|
// bad protocol, turn into local anchor link instead
|
||||||
s = "#" + s.substring(protocol.length() + 1);
|
s = "#" + s.substring(protocol.length() + 1);
|
||||||
if (s.startsWith("#//")) {
|
if (s.startsWith(StringUtils.WELL_NO + StringUtils.SLASH + StringUtils.SLASH)) {
|
||||||
s = "#" + s.substring(3);
|
s = "#" + s.substring(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,8 @@ public class IpUtils {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
private static boolean internalIp(byte[] addr) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
final byte b0 = addr[0];
|
final byte b0 = addr[0];
|
||||||
|
|
@ -118,7 +119,8 @@ public class IpUtils {
|
||||||
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)) {
|
long l1 = 4294967295L;
|
||||||
|
if ((l < 0L) || (l > l1)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
|
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
|
||||||
|
|
@ -128,12 +130,14 @@ public class IpUtils {
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
l = Integer.parseInt(elements[0]);
|
l = Integer.parseInt(elements[0]);
|
||||||
if ((l < 0L) || (l > 255L)) {
|
long l2 = 255L;
|
||||||
|
if ((l < 0L) || (l > l2)) {
|
||||||
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)) {
|
long l3 = 16777215L;
|
||||||
|
if ((l < 0L) || (l > l3)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
|
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
|
||||||
|
|
@ -141,7 +145,8 @@ 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) {
|
int i1 = 2;
|
||||||
|
for (i = 0; i < i1; ++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;
|
||||||
|
|
@ -149,14 +154,16 @@ public class IpUtils {
|
||||||
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)) {
|
long l4 = 65535L;
|
||||||
|
if ((l < 0L) || (l > l4)) {
|
||||||
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) {
|
int i2 = 4;
|
||||||
|
for (i = 0; i < i2; ++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;
|
||||||
|
|
@ -207,7 +214,7 @@ public class IpUtils {
|
||||||
*/
|
*/
|
||||||
public static String getMultistageReverseProxyIp(String ip) {
|
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(",");
|
final String[] ips = ip.trim().split(",");
|
||||||
for (String subIp : ips) {
|
for (String subIp : ips) {
|
||||||
if (false == isUnknown(subIp)) {
|
if (false == isUnknown(subIp)) {
|
||||||
|
|
|
||||||
|
|
@ -555,9 +555,9 @@ public class ExcelUtil<T> {
|
||||||
*/
|
*/
|
||||||
public int getImageType(byte[] value) {
|
public int getImageType(byte[] value) {
|
||||||
String type = FileTypeUtils.getFileExtendName(value);
|
String type = FileTypeUtils.getFileExtendName(value);
|
||||||
if ("JPG".equalsIgnoreCase(type)) {
|
if (StringUtils.JPG.equalsIgnoreCase(type)) {
|
||||||
return Workbook.PICTURE_TYPE_JPEG;
|
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_PNG;
|
||||||
}
|
}
|
||||||
return Workbook.PICTURE_TYPE_JPEG;
|
return Workbook.PICTURE_TYPE_JPEG;
|
||||||
|
|
@ -567,7 +567,7 @@ public class ExcelUtil<T> {
|
||||||
* 创建表格样式
|
* 创建表格样式
|
||||||
*/
|
*/
|
||||||
public void setDataValidation(Excel attr, Row row, int column) {
|
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);
|
sheet.setColumnWidth(column, 6000);
|
||||||
} else {
|
} else {
|
||||||
// 设置列宽
|
// 设置列宽
|
||||||
|
|
@ -777,7 +777,7 @@ public class ExcelUtil<T> {
|
||||||
Object o = field.get(vo);
|
Object o = field.get(vo);
|
||||||
if (StringUtils.isNotEmpty(excel.targetAttr())) {
|
if (StringUtils.isNotEmpty(excel.targetAttr())) {
|
||||||
String target = excel.targetAttr();
|
String target = excel.targetAttr();
|
||||||
if (target.contains(".")) {
|
if (target.contains(StringUtils.DOT)) {
|
||||||
String[] targets = target.split("[.]");
|
String[] targets = target.split("[.]");
|
||||||
for (String name : targets) {
|
for (String name : targets) {
|
||||||
o = getValue(o, name);
|
o = getValue(o, name);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ public class ReflectUtils
|
||||||
public static <E> E invokeGetter(Object obj, String propertyName)
|
public static <E> E invokeGetter(Object obj, String propertyName)
|
||||||
{
|
{
|
||||||
Object object = obj;
|
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);
|
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
|
||||||
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
|
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
|
||||||
|
|
|
||||||
|
|
@ -13,23 +13,24 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @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;
|
private static final long serialVersionUID = -1185015143654744140L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SecureRandom 的单例
|
* SecureRandom 的单例
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private static class Holder
|
private static class Holder {
|
||||||
{
|
|
||||||
static final SecureRandom NUMBER_GENERATOR = getSecureRandom();
|
static final SecureRandom NUMBER_GENERATOR = getSecureRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 此UUID的最高64有效位 */
|
/**
|
||||||
|
* 此UUID的最高64有效位
|
||||||
|
*/
|
||||||
private final long mostSigBits;
|
private final long mostSigBits;
|
||||||
|
|
||||||
/** 此UUID的最低64有效位 */
|
/**
|
||||||
|
* 此UUID的最低64有效位
|
||||||
|
*/
|
||||||
private final long leastSigBits;
|
private final long leastSigBits;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,18 +38,17 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
*/
|
*/
|
||||||
private UUID(byte[] data)
|
private UUID(byte[] data) {
|
||||||
{
|
|
||||||
long msb = 0;
|
long msb = 0;
|
||||||
long lsb = 0;
|
long lsb = 0;
|
||||||
assert data.length == 16 : "data must be 16 bytes in length";
|
assert data.length == 16 : "data must be 16 bytes in length";
|
||||||
for (int i = 0; i < 8; i++)
|
int eight = 8;
|
||||||
{
|
int sixteen = 16;
|
||||||
msb = (msb << 8) | (data[i] & 0xff);
|
for (int i = 0; i < eight; i++) {
|
||||||
|
msb = (msb << eight) | (data[i] & 0xff);
|
||||||
}
|
}
|
||||||
for (int i = 8; i < 16; i++)
|
for (int i = eight; i < sixteen; i++) {
|
||||||
{
|
lsb = (lsb << eight) | (data[i] & 0xff);
|
||||||
lsb = (lsb << 8) | (data[i] & 0xff);
|
|
||||||
}
|
}
|
||||||
this.mostSigBits = msb;
|
this.mostSigBits = msb;
|
||||||
this.leastSigBits = lsb;
|
this.leastSigBits = lsb;
|
||||||
|
|
@ -57,11 +57,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
/**
|
/**
|
||||||
* 使用指定的数据构造新的 UUID。
|
* 使用指定的数据构造新的 UUID。
|
||||||
*
|
*
|
||||||
* @param mostSigBits 用于 {@code UUID} 的最高有效 64 位
|
* @param mostSigBits 用于 {@code UUID} 的最高有效 64 位
|
||||||
* @param leastSigBits 用于 {@code UUID} 的最低有效 64 位
|
* @param leastSigBits 用于 {@code UUID} 的最低有效 64 位
|
||||||
*/
|
*/
|
||||||
public UUID(long mostSigBits, long leastSigBits)
|
public UUID(long mostSigBits, long leastSigBits) {
|
||||||
{
|
|
||||||
this.mostSigBits = mostSigBits;
|
this.mostSigBits = mostSigBits;
|
||||||
this.leastSigBits = leastSigBits;
|
this.leastSigBits = leastSigBits;
|
||||||
}
|
}
|
||||||
|
|
@ -71,8 +70,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return 随机生成的 {@code UUID}
|
* @return 随机生成的 {@code UUID}
|
||||||
*/
|
*/
|
||||||
public static UUID fastuuid()
|
public static UUID fastuuid() {
|
||||||
{
|
|
||||||
return randomuuid(false);
|
return randomuuid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,8 +79,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return 随机生成的 {@code UUID}
|
* @return 随机生成的 {@code UUID}
|
||||||
*/
|
*/
|
||||||
public static UUID randomuuid()
|
public static UUID randomuuid() {
|
||||||
{
|
|
||||||
return randomuuid(true);
|
return randomuuid(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,8 +89,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* @param isSecure 是否使用{@link SecureRandom}如果是可以获得更安全的随机码,否则可以得到更好的性能
|
* @param isSecure 是否使用{@link SecureRandom}如果是可以获得更安全的随机码,否则可以得到更好的性能
|
||||||
* @return 随机生成的 {@code UUID}
|
* @return 随机生成的 {@code UUID}
|
||||||
*/
|
*/
|
||||||
public static UUID randomuuid(boolean isSecure)
|
public static UUID randomuuid(boolean isSecure) {
|
||||||
{
|
|
||||||
final Random ng = isSecure ? Holder.NUMBER_GENERATOR : getRandom();
|
final Random ng = isSecure ? Holder.NUMBER_GENERATOR : getRandom();
|
||||||
|
|
||||||
byte[] randomBytes = new byte[16];
|
byte[] randomBytes = new byte[16];
|
||||||
|
|
@ -109,18 +105,13 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* 根据指定的字节数组获取类型 3(基于名称的)UUID 的静态工厂。
|
* 根据指定的字节数组获取类型 3(基于名称的)UUID 的静态工厂。
|
||||||
*
|
*
|
||||||
* @param name 用于构造 UUID 的字节数组。
|
* @param name 用于构造 UUID 的字节数组。
|
||||||
*
|
|
||||||
* @return 根据指定数组生成的 {@code UUID}
|
* @return 根据指定数组生成的 {@code UUID}
|
||||||
*/
|
*/
|
||||||
public static UUID nameUuidFromBytes(byte[] name)
|
public static UUID nameUuidFromBytes(byte[] name) {
|
||||||
{
|
|
||||||
MessageDigest md;
|
MessageDigest md;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
md = MessageDigest.getInstance("MD5");
|
md = MessageDigest.getInstance("MD5");
|
||||||
}
|
} catch (NoSuchAlgorithmException nsae) {
|
||||||
catch (NoSuchAlgorithmException nsae)
|
|
||||||
{
|
|
||||||
throw new InternalError("MD5 not supported");
|
throw new InternalError("MD5 not supported");
|
||||||
}
|
}
|
||||||
byte[] md5Bytes = md.digest(name);
|
byte[] md5Bytes = md.digest(name);
|
||||||
|
|
@ -137,17 +128,14 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* @param name 指定 {@code UUID} 字符串
|
* @param name 指定 {@code UUID} 字符串
|
||||||
* @return 具有指定值的 {@code UUID}
|
* @return 具有指定值的 {@code UUID}
|
||||||
* @throws IllegalArgumentException 如果 name 与 {@link #toString} 中描述的字符串表示形式不符抛出此异常
|
* @throws IllegalArgumentException 如果 name 与 {@link #toString} 中描述的字符串表示形式不符抛出此异常
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static UUID fromString(String name)
|
public static UUID fromString(String name) {
|
||||||
{
|
|
||||||
String[] components = name.split("-");
|
String[] components = name.split("-");
|
||||||
if (components.length != 5)
|
int fastFive = 5;
|
||||||
{
|
if (components.length != fastFive) {
|
||||||
throw new IllegalArgumentException("Invalid UUID string: " + name);
|
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();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(sb);
|
sb.append(sb);
|
||||||
sb.append(components[i]);
|
sb.append(components[i]);
|
||||||
|
|
@ -172,8 +160,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return 此 UUID 的 128 位值中的最低有效 64 位。
|
* @return 此 UUID 的 128 位值中的最低有效 64 位。
|
||||||
*/
|
*/
|
||||||
public long getLeastSignificantBits()
|
public long getLeastSignificantBits() {
|
||||||
{
|
|
||||||
return leastSigBits;
|
return leastSigBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,8 +169,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return 此 UUID 的 128 位值中最高有效 64 位。
|
* @return 此 UUID 的 128 位值中最高有效 64 位。
|
||||||
*/
|
*/
|
||||||
public long getMostSignificantBits()
|
public long getMostSignificantBits() {
|
||||||
{
|
|
||||||
return mostSigBits;
|
return mostSigBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,8 +186,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return 此 {@code UUID} 的版本号
|
* @return 此 {@code UUID} 的版本号
|
||||||
*/
|
*/
|
||||||
public int version()
|
public int version() {
|
||||||
{
|
|
||||||
// Version is bits masked by 0x000000000000F000 in MS long
|
// Version is bits masked by 0x000000000000F000 in MS long
|
||||||
return (int) ((mostSigBits >> 12) & 0x0f);
|
return (int) ((mostSigBits >> 12) & 0x0f);
|
||||||
}
|
}
|
||||||
|
|
@ -219,8 +204,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return 此 {@code UUID} 相关联的变体号
|
* @return 此 {@code UUID} 相关联的变体号
|
||||||
*/
|
*/
|
||||||
public int variant()
|
public int variant() {
|
||||||
{
|
|
||||||
// This field is composed of a varying number of bits.
|
// This field is composed of a varying number of bits.
|
||||||
// 0 - - Reserved for NCS backward compatibility
|
// 0 - - Reserved for NCS backward compatibility
|
||||||
// 1 0 - The IETF aka Leach-Salz variant (used by this class)
|
// 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。
|
* @throws UnsupportedOperationException 如果此 {@code UUID} 不是 version 为 1 的 UUID。
|
||||||
*/
|
*/
|
||||||
public long timestamp() throws UnsupportedOperationException
|
public long timestamp() throws UnsupportedOperationException {
|
||||||
{
|
|
||||||
checkTimeBase();
|
checkTimeBase();
|
||||||
return (mostSigBits & 0x0FFFL) << 48
|
return (mostSigBits & 0x0FFFL) << 48
|
||||||
| ((mostSigBits >> 16) & 0x0FFFFL) << 32
|
| ((mostSigBits >> 16) & 0x0FFFFL) << 32
|
||||||
|
|
@ -260,11 +243,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* UnsupportedOperationException。
|
* UnsupportedOperationException。
|
||||||
*
|
*
|
||||||
* @return 此 {@code UUID} 的时钟序列
|
* @return 此 {@code UUID} 的时钟序列
|
||||||
*
|
|
||||||
* @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
|
* @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
|
||||||
*/
|
*/
|
||||||
public int clockSequence() throws UnsupportedOperationException
|
public int clockSequence() throws UnsupportedOperationException {
|
||||||
{
|
|
||||||
checkTimeBase();
|
checkTimeBase();
|
||||||
return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48);
|
return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48);
|
||||||
}
|
}
|
||||||
|
|
@ -279,11 +260,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* 如果此 UUID 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。
|
* 如果此 UUID 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。
|
||||||
*
|
*
|
||||||
* @return 此 {@code UUID} 的节点值
|
* @return 此 {@code UUID} 的节点值
|
||||||
*
|
|
||||||
* @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
|
* @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
|
||||||
*/
|
*/
|
||||||
public long node() throws UnsupportedOperationException
|
public long node() throws UnsupportedOperationException {
|
||||||
{
|
|
||||||
checkTimeBase();
|
checkTimeBase();
|
||||||
return leastSigBits & 0x0000FFFFFFFFFFFFL;
|
return leastSigBits & 0x0000FFFFFFFFFFFFL;
|
||||||
}
|
}
|
||||||
|
|
@ -313,8 +292,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* @see #toString(boolean)
|
* @see #toString(boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return toString(false);
|
return toString(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,31 +320,26 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* @param isSimple 是否简单模式,简单模式为不带'-'的UUID字符串
|
* @param isSimple 是否简单模式,简单模式为不带'-'的UUID字符串
|
||||||
* @return 此{@code UUID} 的字符串表现形式
|
* @return 此{@code UUID} 的字符串表现形式
|
||||||
*/
|
*/
|
||||||
public String toString(boolean isSimple)
|
public String toString(boolean isSimple) {
|
||||||
{
|
|
||||||
final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
|
final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
|
||||||
// time_low
|
// time_low
|
||||||
builder.append(digits(mostSigBits >> 32, 8));
|
builder.append(digits(mostSigBits >> 32, 8));
|
||||||
if (false == isSimple)
|
if (false == isSimple) {
|
||||||
{
|
|
||||||
builder.append('-');
|
builder.append('-');
|
||||||
}
|
}
|
||||||
// time_mid
|
// time_mid
|
||||||
builder.append(digits(mostSigBits >> 16, 4));
|
builder.append(digits(mostSigBits >> 16, 4));
|
||||||
if (false == isSimple)
|
if (false == isSimple) {
|
||||||
{
|
|
||||||
builder.append('-');
|
builder.append('-');
|
||||||
}
|
}
|
||||||
// time_high_and_version
|
// time_high_and_version
|
||||||
builder.append(digits(mostSigBits, 4));
|
builder.append(digits(mostSigBits, 4));
|
||||||
if (false == isSimple)
|
if (false == isSimple) {
|
||||||
{
|
|
||||||
builder.append('-');
|
builder.append('-');
|
||||||
}
|
}
|
||||||
// variant_and_sequence
|
// variant_and_sequence
|
||||||
builder.append(digits(leastSigBits >> 48, 4));
|
builder.append(digits(leastSigBits >> 48, 4));
|
||||||
if (false == isSimple)
|
if (false == isSimple) {
|
||||||
{
|
|
||||||
builder.append('-');
|
builder.append('-');
|
||||||
}
|
}
|
||||||
// node
|
// node
|
||||||
|
|
@ -381,8 +354,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* @return UUID 的哈希码值。
|
* @return UUID 的哈希码值。
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
|
||||||
long hilo = mostSigBits ^ leastSigBits;
|
long hilo = mostSigBits ^ leastSigBits;
|
||||||
return ((int) (hilo >> 32)) ^ (int) hilo;
|
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}。
|
* 当且仅当参数不为 {@code null}、而是一个 UUID 对象、具有与此 UUID 相同的 varriant、包含相同的值(每一位均相同)时,结果才为 {@code true}。
|
||||||
*
|
*
|
||||||
* @param obj 要与之比较的对象
|
* @param obj 要与之比较的对象
|
||||||
*
|
|
||||||
* @return 如果对象相同,则返回 {@code true};否则返回 {@code false}
|
* @return 如果对象相同,则返回 {@code true};否则返回 {@code false}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj) {
|
||||||
{
|
if ((null == obj) || (obj.getClass() != UUID.class)) {
|
||||||
if ((null == obj) || (obj.getClass() != UUID.class))
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UUID id = (UUID) obj;
|
UUID id = (UUID) obj;
|
||||||
|
|
@ -416,13 +385,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
* 如果两个 UUID 不同,且第一个 UUID 的最高有效字段大于第二个 UUID 的对应字段,则第一个 UUID 大于第二个 UUID。
|
* 如果两个 UUID 不同,且第一个 UUID 的最高有效字段大于第二个 UUID 的对应字段,则第一个 UUID 大于第二个 UUID。
|
||||||
*
|
*
|
||||||
* @param val 与此 UUID 比较的 UUID
|
* @param val 与此 UUID 比较的 UUID
|
||||||
*
|
|
||||||
* @return 在此 UUID 小于、等于或大于 val 时,分别返回 -1、0 或 1。
|
* @return 在此 UUID 小于、等于或大于 val 时,分别返回 -1、0 或 1。
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(UUID val)
|
public int compareTo(UUID val) {
|
||||||
{
|
|
||||||
// The ordering is intentionally set up so that the UUIDs
|
// The ordering is intentionally set up so that the UUIDs
|
||||||
// can simply be numerically compared as two numbers
|
// can simply be numerically compared as two numbers
|
||||||
return (this.mostSigBits < val.mostSigBits ? -1 :
|
return (this.mostSigBits < val.mostSigBits ? -1 :
|
||||||
|
|
@ -434,15 +400,15 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------
|
||||||
// Private method start
|
// Private method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回指定数字对应的hex值
|
* 返回指定数字对应的hex值
|
||||||
*
|
*
|
||||||
* @param val 值
|
* @param val 值
|
||||||
* @param digits 位
|
* @param digits 位
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
private static String digits(long val, int digits)
|
private static String digits(long val, int digits) {
|
||||||
{
|
|
||||||
long hi = 1L << (digits * 4);
|
long hi = 1L << (digits * 4);
|
||||||
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
|
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
|
||||||
}
|
}
|
||||||
|
|
@ -450,10 +416,8 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
/**
|
/**
|
||||||
* 检查是否为time-based版本UUID
|
* 检查是否为time-based版本UUID
|
||||||
*/
|
*/
|
||||||
private void checkTimeBase()
|
private void checkTimeBase() {
|
||||||
{
|
if (version() != 1) {
|
||||||
if (version() != 1)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not a time-based UUID");
|
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}
|
* @return {@link SecureRandom}
|
||||||
*/
|
*/
|
||||||
public static SecureRandom getSecureRandom()
|
public static SecureRandom getSecureRandom() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return SecureRandom.getInstance("SHA1PRNG");
|
return SecureRandom.getInstance("SHA1PRNG");
|
||||||
}
|
} catch (NoSuchAlgorithmException e) {
|
||||||
catch (NoSuchAlgorithmException e)
|
|
||||||
{
|
|
||||||
throw new UtilException(e);
|
throw new UtilException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -481,8 +441,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||||
*
|
*
|
||||||
* @return {@link ThreadLocalRandom}
|
* @return {@link ThreadLocalRandom}
|
||||||
*/
|
*/
|
||||||
public static ThreadLocalRandom getRandom()
|
public static ThreadLocalRandom getRandom() {
|
||||||
{
|
|
||||||
return ThreadLocalRandom.current();
|
return ThreadLocalRandom.current();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,14 +70,13 @@ public class PageDomain
|
||||||
|
|
||||||
public void setIsAsc(String isAsc)
|
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";
|
isAsc = "asc";
|
||||||
}
|
}
|
||||||
else if ("descending".equals(isAsc))
|
else if (StringUtils.DESC_ENDING.equals(isAsc))
|
||||||
{
|
{
|
||||||
isAsc = "desc";
|
isAsc = "desc";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,32 +22,26 @@ public class KaptchaTextCreator extends DefaultTextCreator
|
||||||
int y = random.nextInt(10);
|
int y = random.nextInt(10);
|
||||||
StringBuilder suChinese = new StringBuilder();
|
StringBuilder suChinese = new StringBuilder();
|
||||||
int randomoperands = (int) Math.round(Math.random() * 2);
|
int randomoperands = (int) Math.round(Math.random() * 2);
|
||||||
if (randomoperands == 0)
|
int randomoperandsInt = 2;
|
||||||
{
|
if (randomoperands == 0) {
|
||||||
result = x * y;
|
result = x * y;
|
||||||
suChinese.append(CNUMBERS[x]);
|
suChinese.append(CNUMBERS[x]);
|
||||||
suChinese.append("*");
|
suChinese.append("*");
|
||||||
suChinese.append(CNUMBERS[y]);
|
suChinese.append(CNUMBERS[y]);
|
||||||
}
|
}
|
||||||
else if (randomoperands == 1)
|
else if (randomoperands == 1) {
|
||||||
{
|
if ((x != 0) && y % x == 0) {
|
||||||
if ((x != 0) && y % x == 0)
|
|
||||||
{
|
|
||||||
result = y / x;
|
result = y / x;
|
||||||
suChinese.append(CNUMBERS[y]);
|
suChinese.append(CNUMBERS[y]);
|
||||||
suChinese.append("/");
|
suChinese.append("/");
|
||||||
suChinese.append(CNUMBERS[x]);
|
suChinese.append(CNUMBERS[x]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
result = x + y;
|
result = x + y;
|
||||||
suChinese.append(CNUMBERS[x]);
|
suChinese.append(CNUMBERS[x]);
|
||||||
suChinese.append("+");
|
suChinese.append("+");
|
||||||
suChinese.append(CNUMBERS[y]);
|
suChinese.append(CNUMBERS[y]);
|
||||||
}
|
}
|
||||||
}
|
} else if (randomoperands == randomoperandsInt) {
|
||||||
else if (randomoperands == 2)
|
|
||||||
{
|
|
||||||
if (x >= y)
|
if (x >= y)
|
||||||
{
|
{
|
||||||
result = x - y;
|
result = x - y;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.ruoyi.gateway.filter;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter;
|
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter;
|
||||||
|
|
@ -54,7 +56,7 @@ public class CacheRequestFilter extends AbstractGatewayFilterFactory<CacheReques
|
||||||
{
|
{
|
||||||
// GET DELETE 不过滤
|
// GET DELETE 不过滤
|
||||||
HttpMethod method = exchange.getRequest().getMethod();
|
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);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class XssFilter implements GlobalFilter, Ordered
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
// GET DELETE 不过滤
|
// GET DELETE 不过滤
|
||||||
HttpMethod method = request.getMethod();
|
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);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,14 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
|
||||||
|
|
||||||
String captchaType = captchaProperties.getType();
|
String captchaType = captchaProperties.getType();
|
||||||
// 生成验证码
|
// 生成验证码
|
||||||
if ("math".equals(captchaType))
|
if (StringUtils.MATH.equals(captchaType))
|
||||||
{
|
{
|
||||||
String capText = captchaProducerMath.createText();
|
String capText = captchaProducerMath.createText();
|
||||||
capStr = capText.substring(0, capText.lastIndexOf("@"));
|
capStr = capText.substring(0, capText.lastIndexOf("@"));
|
||||||
code = capText.substring(capText.lastIndexOf("@") + 1);
|
code = capText.substring(capText.lastIndexOf("@") + 1);
|
||||||
image = captchaProducerMath.createImage(capStr);
|
image = captchaProducerMath.createImage(capStr);
|
||||||
}
|
}
|
||||||
else if ("char".equals(captchaType))
|
else if (StringUtils.CHAR.equals(captchaType))
|
||||||
{
|
{
|
||||||
capStr = code = captchaProducer.createText();
|
capStr = code = captchaProducer.createText();
|
||||||
image = captchaProducer.createImage(capStr);
|
image = captchaProducer.createImage(capStr);
|
||||||
|
|
|
||||||
|
|
@ -353,15 +353,12 @@ public class GenTableColumn extends BaseEntity
|
||||||
{
|
{
|
||||||
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
|
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
if (StringUtils.isNotEmpty(remarks))
|
if (StringUtils.isNotEmpty(remarks)) {
|
||||||
{
|
for (String value : remarks.split(StringUtils.BLANK_SPACE)) {
|
||||||
for (String value : remarks.split(" "))
|
if (StringUtils.isNotEmpty(value)) {
|
||||||
{
|
|
||||||
if (StringUtils.isNotEmpty(value))
|
|
||||||
{
|
|
||||||
Object startStr = value.subSequence(0, 1);
|
Object startStr = value.subSequence(0, 1);
|
||||||
String endStr = value.substring(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();
|
return sb.deleteCharAt(sb.length() - 1).toString();
|
||||||
|
|
|
||||||
|
|
@ -514,7 +514,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
public static String getGenPath(GenTable table, String template)
|
public static String getGenPath(GenTable table, String template)
|
||||||
{
|
{
|
||||||
String genPath = table.getGenPath();
|
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);
|
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,12 +53,16 @@ public class GenUtils {
|
||||||
column.setHtmlType(GenConstants.HTML_INPUT);
|
column.setHtmlType(GenConstants.HTML_INPUT);
|
||||||
// 如果是浮点型 统一用BigDecimal
|
// 如果是浮点型 统一用BigDecimal
|
||||||
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
|
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);
|
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
||||||
} else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
|
|
||||||
column.setJavaType(GenConstants.TYPE_INTEGER);
|
|
||||||
} else {
|
} else {
|
||||||
column.setJavaType(GenConstants.TYPE_LONG);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 插入字段(默认所有字段都需要插入)
|
// 插入字段(默认所有字段都需要插入)
|
||||||
|
|
@ -76,20 +80,27 @@ public class GenUtils {
|
||||||
column.setIsQuery(GenConstants.REQUIRE);
|
column.setIsQuery(GenConstants.REQUIRE);
|
||||||
}
|
}
|
||||||
// 查询字段类型
|
// 查询字段类型
|
||||||
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
|
String name = "name";
|
||||||
|
if (StringUtils.endsWithIgnoreCase(columnName, name)) {
|
||||||
column.setQueryType(GenConstants.QUERY_LIKE);
|
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);
|
column.setHtmlType(GenConstants.HTML_RADIO);
|
||||||
} else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|
} else if (StringUtils.endsWithIgnoreCase(columnName, type)
|
||||||
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) {
|
|| StringUtils.endsWithIgnoreCase(columnName, sex)) {
|
||||||
column.setHtmlType(GenConstants.HTML_SELECT);
|
column.setHtmlType(GenConstants.HTML_SELECT);
|
||||||
} else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
|
} else if (StringUtils.endsWithIgnoreCase(columnName, image)) {
|
||||||
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
|
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
|
||||||
} else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
|
} else if (StringUtils.endsWithIgnoreCase(columnName, file)) {
|
||||||
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
|
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
|
||||||
} else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
|
} else if (StringUtils.endsWithIgnoreCase(columnName, content)) {
|
||||||
column.setHtmlType(GenConstants.HTML_EDITOR);
|
column.setHtmlType(GenConstants.HTML_EDITOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -180,8 +191,8 @@ public class GenUtils {
|
||||||
* @return 截取后的列类型
|
* @return 截取后的列类型
|
||||||
*/
|
*/
|
||||||
public static String getDbType(String columnType) {
|
public static String getDbType(String columnType) {
|
||||||
if (StringUtils.indexOf(columnType, "(") > 0) {
|
if (StringUtils.indexOf(columnType, StringUtils.LEFT_BRACKETS) > 0) {
|
||||||
return StringUtils.substringBefore(columnType, "(");
|
return StringUtils.substringBefore(columnType, StringUtils.LEFT_BRACKETS);
|
||||||
} else {
|
} else {
|
||||||
return columnType;
|
return columnType;
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +205,7 @@ public class GenUtils {
|
||||||
* @return 截取后的列类型
|
* @return 截取后的列类型
|
||||||
*/
|
*/
|
||||||
public static Integer getColumnLength(String columnType) {
|
public static Integer getColumnLength(String columnType) {
|
||||||
if (StringUtils.indexOf(columnType, "(") > 0) {
|
if (StringUtils.indexOf(columnType, StringUtils.LEFT_BRACKETS) > 0) {
|
||||||
String length = StringUtils.substringBetween(columnType, "(", ")");
|
String length = StringUtils.substringBetween(columnType, "(", ")");
|
||||||
return Integer.valueOf(length);
|
return Integer.valueOf(length);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,37 @@
|
||||||
package com.ruoyi.gen.util;
|
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.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.common.core.constant.GenConstants;
|
import com.ruoyi.common.core.constant.GenConstants;
|
||||||
import com.ruoyi.common.core.utils.DateUtils;
|
import com.ruoyi.common.core.utils.DateUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.gen.domain.GenTable;
|
import com.ruoyi.gen.domain.GenTable;
|
||||||
import com.ruoyi.gen.domain.GenTableColumn;
|
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
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class VelocityUtils
|
public class VelocityUtils {
|
||||||
{
|
/**
|
||||||
/** 项目空间路径 */
|
* 项目空间路径
|
||||||
|
*/
|
||||||
private static final String PROJECT_PATH = "main/java";
|
private static final String PROJECT_PATH = "main/java";
|
||||||
|
|
||||||
/** mybatis空间路径 */
|
/**
|
||||||
|
* mybatis空间路径
|
||||||
|
*/
|
||||||
private static final String MYBATIS_PATH = "main/resources/mapper";
|
private static final String MYBATIS_PATH = "main/resources/mapper";
|
||||||
|
|
||||||
/** 默认上级菜单,系统工具 */
|
/**
|
||||||
|
* 默认上级菜单,系统工具
|
||||||
|
*/
|
||||||
private static final String DEFAULT_PARENT_MENU_ID = "3";
|
private static final String DEFAULT_PARENT_MENU_ID = "3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,8 +39,7 @@ public class VelocityUtils
|
||||||
*
|
*
|
||||||
* @return 模板列表
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
public static VelocityContext prepareContext(GenTable genTable)
|
public static VelocityContext prepareContext(GenTable genTable) {
|
||||||
{
|
|
||||||
String moduleName = genTable.getModuleName();
|
String moduleName = genTable.getModuleName();
|
||||||
String businessName = genTable.getBusinessName();
|
String businessName = genTable.getBusinessName();
|
||||||
String packageName = genTable.getPackageName();
|
String packageName = genTable.getPackageName();
|
||||||
|
|
@ -61,27 +66,23 @@ public class VelocityUtils
|
||||||
velocityContext.put("table", genTable);
|
velocityContext.put("table", genTable);
|
||||||
velocityContext.put("dicts", getDicts(genTable));
|
velocityContext.put("dicts", getDicts(genTable));
|
||||||
setMenuVelocityContext(velocityContext, genTable);
|
setMenuVelocityContext(velocityContext, genTable);
|
||||||
if (GenConstants.TPL_TREE.equals(tplCategory))
|
if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||||
{
|
|
||||||
setTreeVelocityContext(velocityContext, genTable);
|
setTreeVelocityContext(velocityContext, genTable);
|
||||||
}
|
}
|
||||||
if (GenConstants.TPL_SUB.equals(tplCategory))
|
if (GenConstants.TPL_SUB.equals(tplCategory)) {
|
||||||
{
|
|
||||||
setSubVelocityContext(velocityContext, genTable);
|
setSubVelocityContext(velocityContext, genTable);
|
||||||
}
|
}
|
||||||
return velocityContext;
|
return velocityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
|
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
|
||||||
{
|
|
||||||
String options = genTable.getOptions();
|
String options = genTable.getOptions();
|
||||||
JSONObject paramsObj = JSONObject.parseObject(options);
|
JSONObject paramsObj = JSONObject.parseObject(options);
|
||||||
String parentMenuId = getParentMenuId(paramsObj);
|
String parentMenuId = getParentMenuId(paramsObj);
|
||||||
context.put("parentMenuId", parentMenuId);
|
context.put("parentMenuId", parentMenuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
|
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
|
||||||
{
|
|
||||||
String options = genTable.getOptions();
|
String options = genTable.getOptions();
|
||||||
JSONObject paramsObj = JSONObject.parseObject(options);
|
JSONObject paramsObj = JSONObject.parseObject(options);
|
||||||
String treeCode = getTreecode(paramsObj);
|
String treeCode = getTreecode(paramsObj);
|
||||||
|
|
@ -92,18 +93,15 @@ public class VelocityUtils
|
||||||
context.put("treeParentCode", treeParentCode);
|
context.put("treeParentCode", treeParentCode);
|
||||||
context.put("treeName", treeName);
|
context.put("treeName", treeName);
|
||||||
context.put("expandColumn", getExpandColumn(genTable));
|
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));
|
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));
|
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();
|
GenTable subTable = genTable.getSubTable();
|
||||||
String subTableName = genTable.getSubTableName();
|
String subTableName = genTable.getSubTableName();
|
||||||
String subTableFkName = genTable.getSubTableFkName();
|
String subTableFkName = genTable.getSubTableFkName();
|
||||||
|
|
@ -125,8 +123,7 @@ public class VelocityUtils
|
||||||
*
|
*
|
||||||
* @return 模板列表
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
public static List<String> getTemplateList(String tplCategory)
|
public static List<String> getTemplateList(String tplCategory) {
|
||||||
{
|
|
||||||
List<String> templates = new ArrayList<String>();
|
List<String> templates = new ArrayList<String>();
|
||||||
templates.add("vm/java/domain.java.vm");
|
templates.add("vm/java/domain.java.vm");
|
||||||
templates.add("vm/java/mapper.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/xml/mapper.xml.vm");
|
||||||
templates.add("vm/sql/sql.vm");
|
templates.add("vm/sql/sql.vm");
|
||||||
templates.add("vm/js/api.js.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");
|
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");
|
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/vue/index.vue.vm");
|
||||||
templates.add("vm/java/sub-domain.java.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 = "";
|
String fileName = "";
|
||||||
// 包路径
|
// 包路径
|
||||||
|
|
@ -172,48 +163,30 @@ public class VelocityUtils
|
||||||
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
|
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
|
||||||
String vuePath = "vue";
|
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);
|
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());
|
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);
|
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);
|
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);
|
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);
|
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);
|
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
|
||||||
}
|
} else if (template.contains("sql.vm")) {
|
||||||
else if (template.contains("sql.vm"))
|
|
||||||
{
|
|
||||||
fileName = businessName + "Menu.sql";
|
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);
|
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);
|
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);
|
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
|
||||||
}
|
}
|
||||||
return fileName;
|
return fileName;
|
||||||
|
|
@ -225,8 +198,7 @@ public class VelocityUtils
|
||||||
* @param packageName 包名称
|
* @param packageName 包名称
|
||||||
* @return 包前缀名称
|
* @return 包前缀名称
|
||||||
*/
|
*/
|
||||||
public static String getPackagePrefix(String packageName)
|
public static String getPackagePrefix(String packageName) {
|
||||||
{
|
|
||||||
int lastIndex = packageName.lastIndexOf(".");
|
int lastIndex = packageName.lastIndexOf(".");
|
||||||
return StringUtils.substring(packageName, 0, lastIndex);
|
return StringUtils.substring(packageName, 0, lastIndex);
|
||||||
}
|
}
|
||||||
|
|
@ -237,24 +209,18 @@ public class VelocityUtils
|
||||||
* @param genTable 业务表对象
|
* @param genTable 业务表对象
|
||||||
* @return 返回需要导入的包列表
|
* @return 返回需要导入的包列表
|
||||||
*/
|
*/
|
||||||
public static HashSet<String> getImportList(GenTable genTable)
|
public static HashSet<String> getImportList(GenTable genTable) {
|
||||||
{
|
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
List<GenTableColumn> columns = genTable.getColumns();
|
||||||
GenTable subGenTable = genTable.getSubTable();
|
GenTable subGenTable = genTable.getSubTable();
|
||||||
HashSet<String> importList = new HashSet<String>();
|
HashSet<String> importList = new HashSet<String>();
|
||||||
if (StringUtils.isNotNull(subGenTable))
|
if (StringUtils.isNotNull(subGenTable)) {
|
||||||
{
|
|
||||||
importList.add("java.util.List");
|
importList.add("java.util.List");
|
||||||
}
|
}
|
||||||
for (GenTableColumn column : columns)
|
for (GenTableColumn column : columns) {
|
||||||
{
|
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
|
||||||
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
|
|
||||||
{
|
|
||||||
importList.add("java.util.Date");
|
importList.add("java.util.Date");
|
||||||
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
|
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");
|
importList.add("java.math.BigDecimal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -267,13 +233,11 @@ public class VelocityUtils
|
||||||
* @param genTable 业务表对象
|
* @param genTable 业务表对象
|
||||||
* @return 返回字典组
|
* @return 返回字典组
|
||||||
*/
|
*/
|
||||||
public static String getDicts(GenTable genTable)
|
public static String getDicts(GenTable genTable) {
|
||||||
{
|
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
List<GenTableColumn> columns = genTable.getColumns();
|
||||||
Set<String> dicts = new HashSet<String>();
|
Set<String> dicts = new HashSet<String>();
|
||||||
addDicts(dicts, columns);
|
addDicts(dicts, columns);
|
||||||
if (StringUtils.isNotNull(genTable.getSubTable()))
|
if (StringUtils.isNotNull(genTable.getSubTable())) {
|
||||||
{
|
|
||||||
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
||||||
addDicts(dicts, subColumns);
|
addDicts(dicts, subColumns);
|
||||||
}
|
}
|
||||||
|
|
@ -283,17 +247,14 @@ public class VelocityUtils
|
||||||
/**
|
/**
|
||||||
* 添加字典列表
|
* 添加字典列表
|
||||||
*
|
*
|
||||||
* @param dicts 字典列表
|
* @param dicts 字典列表
|
||||||
* @param columns 列集合
|
* @param columns 列集合
|
||||||
*/
|
*/
|
||||||
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns)
|
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
|
||||||
{
|
for (GenTableColumn column : columns) {
|
||||||
for (GenTableColumn column : columns)
|
|
||||||
{
|
|
||||||
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
||||||
column.getHtmlType(),
|
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() + "'");
|
dicts.add("'" + column.getDictType() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -302,12 +263,11 @@ public class VelocityUtils
|
||||||
/**
|
/**
|
||||||
* 获取权限前缀
|
* 获取权限前缀
|
||||||
*
|
*
|
||||||
* @param moduleName 模块名称
|
* @param moduleName 模块名称
|
||||||
* @param businessName 业务名称
|
* @param businessName 业务名称
|
||||||
* @return 返回权限前缀
|
* @return 返回权限前缀
|
||||||
*/
|
*/
|
||||||
public static String getPermissionPrefix(String moduleName, String businessName)
|
public static String getPermissionPrefix(String moduleName, String businessName) {
|
||||||
{
|
|
||||||
return StringUtils.format("{}:{}", moduleName, businessName);
|
return StringUtils.format("{}:{}", moduleName, businessName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,11 +277,9 @@ public class VelocityUtils
|
||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 上级菜单ID字段
|
* @return 上级菜单ID字段
|
||||||
*/
|
*/
|
||||||
public static String getParentMenuId(JSONObject paramsObj)
|
public static String getParentMenuId(JSONObject paramsObj) {
|
||||||
{
|
|
||||||
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
|
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 paramsObj.getString(GenConstants.PARENT_MENU_ID);
|
||||||
}
|
}
|
||||||
return DEFAULT_PARENT_MENU_ID;
|
return DEFAULT_PARENT_MENU_ID;
|
||||||
|
|
@ -333,10 +291,8 @@ public class VelocityUtils
|
||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 树编码
|
* @return 树编码
|
||||||
*/
|
*/
|
||||||
public static String getTreecode(JSONObject paramsObj)
|
public static String getTreecode(JSONObject paramsObj) {
|
||||||
{
|
if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
|
||||||
if (paramsObj.containsKey(GenConstants.TREE_CODE))
|
|
||||||
{
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
|
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
|
|
@ -348,10 +304,8 @@ public class VelocityUtils
|
||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 树父编码
|
* @return 树父编码
|
||||||
*/
|
*/
|
||||||
public static String getTreeParentCode(JSONObject paramsObj)
|
public static String getTreeParentCode(JSONObject paramsObj) {
|
||||||
{
|
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
|
||||||
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
|
|
||||||
{
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
|
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
|
|
@ -363,10 +317,8 @@ public class VelocityUtils
|
||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 树名称
|
* @return 树名称
|
||||||
*/
|
*/
|
||||||
public static String getTreeName(JSONObject paramsObj)
|
public static String getTreeName(JSONObject paramsObj) {
|
||||||
{
|
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
|
||||||
if (paramsObj.containsKey(GenConstants.TREE_NAME))
|
|
||||||
{
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
|
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
|
|
@ -378,20 +330,16 @@ public class VelocityUtils
|
||||||
* @param genTable 业务表对象
|
* @param genTable 业务表对象
|
||||||
* @return 展开按钮列序号
|
* @return 展开按钮列序号
|
||||||
*/
|
*/
|
||||||
public static int getExpandColumn(GenTable genTable)
|
public static int getExpandColumn(GenTable genTable) {
|
||||||
{
|
|
||||||
String options = genTable.getOptions();
|
String options = genTable.getOptions();
|
||||||
JSONObject paramsObj = JSONObject.parseObject(options);
|
JSONObject paramsObj = JSONObject.parseObject(options);
|
||||||
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (GenTableColumn column : genTable.getColumns())
|
for (GenTableColumn column : genTable.getColumns()) {
|
||||||
{
|
if (column.isList()) {
|
||||||
if (column.isList())
|
|
||||||
{
|
|
||||||
num++;
|
num++;
|
||||||
String columnName = column.getColumnName();
|
String columnName = column.getColumnName();
|
||||||
if (columnName.equals(treeName))
|
if (columnName.equals(treeName)) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ public class SysUserController extends BaseController
|
||||||
public Rust<Boolean> register(@RequestBody SysUser sysUser)
|
public Rust<Boolean> register(@RequestBody SysUser sysUser)
|
||||||
{
|
{
|
||||||
String username = sysUser.getUserName();
|
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("当前系统没有开启注册功能!");
|
return Rust.fail("当前系统没有开启注册功能!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue