Browse Source

优化代码

pull/339/MERGE
RuoYi 3 years ago
parent
commit
0086cc9f53
  1. 2
      ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
  2. 3
      ruoyi-common/src/main/java/com/ruoyi/common/utils/AddressUtils.java
  3. 7
      ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java
  4. 3
      ruoyi-common/src/main/java/com/ruoyi/common/utils/ExceptionUtil.java
  5. 10
      ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java
  6. 18
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
  7. 2
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java
  8. 10
      ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
  9. 4
      ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
  10. 3
      ruoyi-common/src/main/java/com/ruoyi/common/utils/security/Md5Utils.java
  11. 4
      ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
  12. 6
      ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
  13. 11
      ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
  14. 2
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java
  15. 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
  16. 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
  17. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
  18. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysLogininforService.java
  19. 3
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java
  20. 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
  21. 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
  22. 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
  23. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysLogininforServiceImpl.java
  24. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
  25. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java
  26. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

2
ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js

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

3
ruoyi-common/src/main/java/com/ruoyi/common/utils/AddressUtils.java

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

7
ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java

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

3
ruoyi-common/src/main/java/com/ruoyi/common/utils/ExceptionUtil.java

@ -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)

10
ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java

@ -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");
}
/**

18
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

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

2
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java

@ -59,7 +59,7 @@ public class ImageUtils
/**
* 读取文件为字节数据
*
* @param key 地址
* @param url 地址
* @return 字节数据
*/
public static byte[] readFile(String url)

10
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java

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

4
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java

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

3
ruoyi-common/src/main/java/com/ruoyi/common/utils/security/Md5Utils.java

@ -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)
{

4
ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java

@ -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注入风险");
}

6
ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java

@ -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);
}
/**

11
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java

@ -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)

2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java

@ -19,7 +19,7 @@ public interface SysUserMapper
public List<SysUser> selectUserList(SysUser sysUser);
/**
* 根据条件分页查询已配用户角色列表
* 根据条件分页查询已配用户角色列表
*
* @param user 用户信息
* @return 用户信息集合信息

1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java

@ -54,7 +54,6 @@ public interface ISysConfigService
* 批量删除参数配置信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public void deleteConfigByIds(String ids);

1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java

@ -39,7 +39,6 @@ public interface ISysDictDataService
* 批量删除字典数据
*
* @param ids 需要删除的数据
* @return 结果
*/
public void deleteDictDataByIds(String ids);

2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java

@ -55,8 +55,6 @@ public interface ISysDictTypeService
* 批量删除字典类型
*
* @param ids 需要删除的数据
* @return 结果
* @throws Exception 异常
*/
public void deleteDictTypeByIds(String ids);

2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysLogininforService.java

@ -29,7 +29,7 @@ public interface ISysLogininforService
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return
* @return 结果
*/
public int deleteLogininforByIds(String ids);

3
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java

@ -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);
/**
* 新增保存岗位信息

1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java

@ -123,7 +123,6 @@ public class SysConfigServiceImpl implements ISysConfigService
* 批量删除参数配置对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public void deleteConfigByIds(String ids)

1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java

@ -61,7 +61,6 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* 批量删除字典数据
*
* @param ids 需要删除的数据
* @return 结果
*/
@Override
public void deleteDictDataByIds(String ids)

1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java

@ -118,7 +118,6 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* 批量删除字典类型
*
* @param ids 需要删除的数据
* @return 结果
*/
@Override
public void deleteDictTypeByIds(String ids)

2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysLogininforServiceImpl.java

@ -47,7 +47,7 @@ public class SysLogininforServiceImpl implements ISysLogininforService
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return
* @return 结果
*/
@Override
public int deleteLogininforByIds(String ids)

2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java

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

2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java

@ -90,7 +90,7 @@ public class SysPostServiceImpl implements ISysPostService
* 批量删除岗位信息
*
* @param ids 需要删除的数据ID
* @throws Exception
* @return 结果
*/
@Override
public int deletePostByIds(String ids)

2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

@ -394,7 +394,7 @@ public class SysRoleServiceImpl implements ISysRoleService
* 批量选择授权用户角色
*
* @param roleId 角色ID
* @param userIds 需要删除的用户数据ID
* @param userIds 需要授权的用户数据ID
* @return 结果
*/
@Override

Loading…
Cancel
Save