优化代码

pull/339/MERGE
RuoYi 3 years ago
parent 2f4c975615
commit 0086cc9f53

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

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

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

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

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

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

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

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

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

@ -1,5 +1,6 @@
package com.ruoyi.common.utils.security;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -55,7 +56,7 @@ public class Md5Utils
{
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)
{

@ -50,9 +50,9 @@ public class SqlUtil
return;
}
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注入风险");
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save