优化代码

pull/339/MERGE
RuoYi 2022-02-12 21:23:07 +08:00
parent 2f4c975615
commit 0086cc9f53
26 changed files with 44 additions and 65 deletions

View File

@ -1313,7 +1313,7 @@ var table = {
}, },
// 校验封装处理 // 校验封装处理
validate: { validate: {
// 判断返回标识是否唯一 false 不存在 true 存在 // 判断返回标识是否唯一 false 为存在 true 为不存在
unique: function (value) { unique: function (value) {
if (value == "0") { if (value == "0") {
return true; return true;

View File

@ -24,7 +24,6 @@ public class AddressUtils
public static String getRealAddressByIP(String ip) public static String getRealAddressByIP(String ip)
{ {
String address = UNKNOWN;
// 内网不查询 // 内网不查询
if (IpUtils.internalIp(ip)) if (IpUtils.internalIp(ip))
{ {
@ -50,6 +49,6 @@ public class AddressUtils
log.error("获取地理位置异常 {}", e); log.error("获取地理位置异常 {}", e);
} }
} }
return address; return UNKNOWN;
} }
} }

View File

@ -40,8 +40,7 @@ public class DictUtils
Object cacheObj = CacheUtils.get(getCacheName(), getCacheKey(key)); Object cacheObj = CacheUtils.get(getCacheName(), getCacheKey(key));
if (StringUtils.isNotNull(cacheObj)) if (StringUtils.isNotNull(cacheObj))
{ {
List<SysDictData> DictDatas = StringUtils.cast(cacheObj); return StringUtils.cast(cacheObj);
return DictDatas;
} }
return null; return null;
} }
@ -91,7 +90,7 @@ public class DictUtils
{ {
if (value.equals(dict.getDictValue())) if (value.equals(dict.getDictValue()))
{ {
propertyString.append(dict.getDictLabel() + separator); propertyString.append(dict.getDictLabel()).append(separator);
break; break;
} }
} }
@ -131,7 +130,7 @@ public class DictUtils
{ {
if (label.equals(dict.getDictLabel())) if (label.equals(dict.getDictLabel()))
{ {
propertyString.append(dict.getDictValue() + separator); propertyString.append(dict.getDictValue()).append(separator);
break; break;
} }
} }

View File

@ -18,8 +18,7 @@ public class ExceptionUtil
{ {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true)); e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString(); return sw.toString();
return str;
} }
public static String getRootErrorMessage(Exception e) public static String getRootErrorMessage(Exception e)

View File

@ -129,13 +129,13 @@ 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.indexOf("application/json") != -1) if (accept != null && accept.contains("application/json"))
{ {
return true; return true;
} }
String xRequestedWith = request.getHeader("X-Requested-With"); String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
{ {
return true; return true;
} }
@ -147,11 +147,7 @@ public class ServletUtils
} }
String ajax = request.getParameter("__ajax"); String ajax = request.getParameter("__ajax");
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
{
return true;
}
return false;
} }
/** /**

View File

@ -2,6 +2,7 @@ package com.ruoyi.common.utils.file;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.config.RuoYiConfig;
@ -100,7 +101,7 @@ public class FileUploadUtils
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
InvalidExtensionException InvalidExtensionException
{ {
int fileNamelength = file.getOriginalFilename().length(); int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
{ {
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
@ -112,8 +113,7 @@ public class FileUploadUtils
File desc = getAbsoluteFile(baseDir, fileName); File desc = getAbsoluteFile(baseDir, fileName);
file.transferTo(desc); file.transferTo(desc);
String pathFileName = getPathFileName(baseDir, fileName); return getPathFileName(baseDir, fileName);
return pathFileName;
} }
/** /**
@ -121,10 +121,7 @@ public class FileUploadUtils
*/ */
public static final String extractFilename(MultipartFile file) public static final String extractFilename(MultipartFile file)
{ {
String fileName = file.getOriginalFilename(); return DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + getExtension(file);
String extension = getExtension(file);
fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension;
return fileName;
} }
public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
@ -145,8 +142,7 @@ public class FileUploadUtils
{ {
int dirLastIndex = RuoYiConfig.getProfile().length() + 1; int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
String currentDir = StringUtils.substring(uploadDir, dirLastIndex); String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
return pathFileName;
} }
/** /**
@ -161,7 +157,7 @@ public class FileUploadUtils
throws FileSizeLimitExceededException, InvalidExtensionException throws FileSizeLimitExceededException, InvalidExtensionException
{ {
long size = file.getSize(); long size = file.getSize();
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) if (size > DEFAULT_MAX_SIZE)
{ {
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024); throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
} }
@ -227,7 +223,7 @@ public class FileUploadUtils
String extension = FilenameUtils.getExtension(file.getOriginalFilename()); String extension = FilenameUtils.getExtension(file.getOriginalFilename());
if (StringUtils.isEmpty(extension)) if (StringUtils.isEmpty(extension))
{ {
extension = MimeTypeUtils.getExtension(file.getContentType()); extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
} }
return extension; return extension;
} }

View File

@ -59,7 +59,7 @@ public class ImageUtils
/** /**
* *
* *
* @param key * @param url
* @return * @return
*/ */
public static byte[] readFile(String url) public static byte[] readFile(String url)

View File

@ -9,6 +9,7 @@ import java.net.ConnectException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -130,9 +131,8 @@ public class HttpUtils
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
try try
{ {
String urlNameString = url; log.info("sendPost - {}", url);
log.info("sendPost - {}", urlNameString); URL realUrl = new URL(url);
URL realUrl = new URL(urlNameString);
URLConnection conn = realUrl.openConnection(); URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("connection", "Keep-Alive");
@ -144,7 +144,7 @@ public class HttpUtils
out = new PrintWriter(conn.getOutputStream()); out = new PrintWriter(conn.getOutputStream());
out.print(param); out.print(param);
out.flush(); out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line; String line;
while ((line = in.readLine()) != null) while ((line = in.readLine()) != null)
{ {
@ -218,7 +218,7 @@ public class HttpUtils
{ {
if (ret != null && !ret.trim().equals("")) if (ret != null && !ret.trim().equals(""))
{ {
result.append(new String(ret.getBytes("ISO-8859-1"), "utf-8")); result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
} }
} }
log.info("recv - {}", result); log.info("recv - {}", result);

View File

@ -1119,7 +1119,7 @@ public class ExcelUtil<T>
if (StringUtils.isNotEmpty(excel.targetAttr())) if (StringUtils.isNotEmpty(excel.targetAttr()))
{ {
String target = excel.targetAttr(); String target = excel.targetAttr();
if (target.indexOf(".") > -1) if (target.contains("."))
{ {
String[] targets = target.split("[.]"); String[] targets = target.split("[.]");
for (String name : targets) for (String name : targets)
@ -1214,7 +1214,7 @@ public class ExcelUtil<T>
for (Object[] os : this.fields) for (Object[] os : this.fields)
{ {
Excel excel = (Excel) os[1]; Excel excel = (Excel) os[1];
maxHeight = maxHeight > excel.height() ? maxHeight : excel.height(); maxHeight = Math.max(maxHeight, excel.height());
} }
return (short) (maxHeight * 20); return (short) (maxHeight * 20);
} }

View File

@ -1,5 +1,6 @@
package com.ruoyi.common.utils.security; package com.ruoyi.common.utils.security;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -55,7 +56,7 @@ public class Md5Utils
{ {
try try
{ {
return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8"); return new String(toHex(md5(s)).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -50,9 +50,9 @@ public class SqlUtil
return; return;
} }
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|"); String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
for (int i = 0; i < sqlKeywords.length; i++) for (String sqlKeyword : sqlKeywords)
{ {
if (StringUtils.indexOfIgnoreCase(value, sqlKeywords[i]) > -1) if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1)
{ {
throw new UtilException("参数存在SQL注入风险"); throw new UtilException("参数存在SQL注入风险");
} }

View File

@ -146,8 +146,7 @@ public class GenUtils
{ {
int lastIndex = packageName.lastIndexOf("."); int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length(); int nameLength = packageName.length();
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); return StringUtils.substring(packageName, lastIndex + 1, nameLength);
return moduleName;
} }
/** /**
@ -160,8 +159,7 @@ public class GenUtils
{ {
int lastIndex = tableName.lastIndexOf("_"); int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length(); int nameLength = tableName.length();
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); return StringUtils.substring(tableName, lastIndex + 1, nameLength);
return businessName;
} }
/** /**

View File

@ -249,8 +249,7 @@ public class VelocityUtils
public static String getPackagePrefix(String packageName) public static String getPackagePrefix(String packageName)
{ {
int lastIndex = packageName.lastIndexOf("."); int lastIndex = packageName.lastIndexOf(".");
String basePackage = StringUtils.substring(packageName, 0, lastIndex); return StringUtils.substring(packageName, 0, lastIndex);
return basePackage;
} }
/** /**
@ -298,7 +297,7 @@ public class VelocityUtils
/** /**
* ID * ID
* *
* @param options * @param paramsObj
* @return ID * @return ID
*/ */
public static String getParentMenuId(JSONObject paramsObj) public static String getParentMenuId(JSONObject paramsObj)
@ -314,7 +313,7 @@ public class VelocityUtils
/** /**
* *
* *
* @param options * @param paramsObj
* @return * @return
*/ */
public static String getTreecode(JSONObject paramsObj) public static String getTreecode(JSONObject paramsObj)
@ -329,7 +328,7 @@ public class VelocityUtils
/** /**
* *
* *
* @param options * @param paramsObj
* @return * @return
*/ */
public static String getTreeParentCode(JSONObject paramsObj) public static String getTreeParentCode(JSONObject paramsObj)
@ -344,7 +343,7 @@ public class VelocityUtils
/** /**
* *
* *
* @param options * @param paramsObj
* @return * @return
*/ */
public static String getTreeName(JSONObject paramsObj) public static String getTreeName(JSONObject paramsObj)

View File

@ -19,7 +19,7 @@ public interface SysUserMapper
public List<SysUser> selectUserList(SysUser sysUser); public List<SysUser> selectUserList(SysUser sysUser);
/** /**
* *
* *
* @param user * @param user
* @return * @return

View File

@ -54,7 +54,6 @@ public interface ISysConfigService
* *
* *
* @param ids ID * @param ids ID
* @return
*/ */
public void deleteConfigByIds(String ids); public void deleteConfigByIds(String ids);

View File

@ -39,7 +39,6 @@ public interface ISysDictDataService
* *
* *
* @param ids * @param ids
* @return
*/ */
public void deleteDictDataByIds(String ids); public void deleteDictDataByIds(String ids);

View File

@ -55,8 +55,6 @@ public interface ISysDictTypeService
* *
* *
* @param ids * @param ids
* @return
* @throws Exception
*/ */
public void deleteDictTypeByIds(String ids); public void deleteDictTypeByIds(String ids);

View File

@ -29,7 +29,7 @@ public interface ISysLogininforService
* *
* *
* @param ids * @param ids
* @return * @return
*/ */
public int deleteLogininforByIds(String ids); public int deleteLogininforByIds(String ids);

View File

@ -46,9 +46,8 @@ public interface ISysPostService
* *
* @param ids ID * @param ids ID
* @return * @return
* @throws Exception
*/ */
public int deletePostByIds(String ids) throws Exception; public int deletePostByIds(String ids);
/** /**
* *

View File

@ -123,7 +123,6 @@ public class SysConfigServiceImpl implements ISysConfigService
* *
* *
* @param ids ID * @param ids ID
* @return
*/ */
@Override @Override
public void deleteConfigByIds(String ids) public void deleteConfigByIds(String ids)

View File

@ -61,7 +61,6 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* *
* *
* @param ids * @param ids
* @return
*/ */
@Override @Override
public void deleteDictDataByIds(String ids) public void deleteDictDataByIds(String ids)

View File

@ -118,7 +118,6 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* *
* *
* @param ids * @param ids
* @return
*/ */
@Override @Override
public void deleteDictTypeByIds(String ids) public void deleteDictTypeByIds(String ids)

View File

@ -47,7 +47,7 @@ public class SysLogininforServiceImpl implements ISysLogininforService
* *
* *
* @param ids * @param ids
* @return * @return
*/ */
@Override @Override
public int deleteLogininforByIds(String ids) public int deleteLogininforByIds(String ids)

View File

@ -384,6 +384,6 @@ public class SysMenuServiceImpl implements ISysMenuService
*/ */
private boolean hasChild(List<SysMenu> list, SysMenu t) private boolean hasChild(List<SysMenu> list, SysMenu t)
{ {
return getChildList(list, t).size() > 0 ? true : false; return getChildList(list, t).size() > 0;
} }
} }

View File

@ -90,7 +90,7 @@ public class SysPostServiceImpl implements ISysPostService
* *
* *
* @param ids ID * @param ids ID
* @throws Exception * @return
*/ */
@Override @Override
public int deletePostByIds(String ids) public int deletePostByIds(String ids)

View File

@ -394,7 +394,7 @@ public class SysRoleServiceImpl implements ISysRoleService
* *
* *
* @param roleId ID * @param roleId ID
* @param userIds ID * @param userIds ID
* @return * @return
*/ */
@Override @Override