Browse Source

优化代码

tags/v3.5.0
RuoYi 3 years ago
parent
commit
dbca691746
  1. 3
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ExceptionUtil.java
  2. 14
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java
  3. 2
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/ImageUtils.java
  4. 4
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java
  5. 4
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java
  6. 3
      ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/DictUtils.java
  7. 8
      ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java
  8. 6
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java
  9. 3
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java
  10. 3
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
  11. 2
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
  12. 8
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml
  13. 2
      ruoyi-ui/src/components/FileUpload/index.vue
  14. 0
      ruoyi-ui/src/utils/generator/drawingDefault.js
  15. 4
      ruoyi-ui/src/utils/generator/html.js
  16. 2
      ruoyi-ui/src/utils/generator/js.js
  17. 4
      ruoyi-ui/src/views/tool/build/CodeTypeDialog.vue
  18. 4
      ruoyi-ui/src/views/tool/build/TreeNodeDialog.vue
  19. 8
      ruoyi-ui/src/views/tool/build/index.vue

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

@ -18,8 +18,7 @@ public class ExceptionUtil @@ -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)

14
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java

@ -161,9 +161,8 @@ public class ServletUtils @@ -161,9 +161,8 @@ public class ServletUtils
*
* @param response 渲染对象
* @param string 待渲染的字符串
* @return null
*/
public static String renderString(HttpServletResponse response, String string)
public static void renderString(HttpServletResponse response, String string)
{
try
{
@ -176,7 +175,6 @@ public class ServletUtils @@ -176,7 +175,6 @@ public class ServletUtils
{
e.printStackTrace();
}
return null;
}
/**
@ -187,13 +185,13 @@ public class ServletUtils @@ -187,13 +185,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;
}
@ -205,11 +203,7 @@ public class ServletUtils @@ -205,11 +203,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
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/ImageUtils.java

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

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

@ -944,7 +944,7 @@ public class ExcelUtil<T> @@ -944,7 +944,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)
@ -1039,7 +1039,7 @@ public class ExcelUtil<T> @@ -1039,7 +1039,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);
}

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

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

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

@ -37,8 +37,7 @@ public class DictUtils @@ -37,8 +37,7 @@ public class DictUtils
Object cacheObj = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key));
if (StringUtils.isNotNull(cacheObj))
{
List<SysDictData> dictDatas = StringUtils.cast(cacheObj);
return dictDatas;
return StringUtils.cast(cacheObj);
}
return null;
}

8
ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java

@ -2,6 +2,7 @@ package com.ruoyi.file.utils; @@ -2,6 +2,7 @@ package com.ruoyi.file.utils;
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.core.exception.file.FileNameLengthLimitExceededException;
@ -65,7 +66,7 @@ public class FileUploadUtils @@ -65,7 +66,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);
@ -77,8 +78,7 @@ public class FileUploadUtils @@ -77,8 +78,7 @@ public class FileUploadUtils
File desc = getAbsoluteFile(baseDir, fileName);
file.transferTo(desc);
String pathFileName = getPathFileName(fileName);
return pathFileName;
return getPathFileName(fileName);
}
/**
@ -186,7 +186,7 @@ public class FileUploadUtils @@ -186,7 +186,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;
}

6
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java

@ -151,8 +151,7 @@ public class GenUtils @@ -151,8 +151,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);
}
/**
@ -165,8 +164,7 @@ public class GenUtils @@ -165,8 +164,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);
}
/**

3
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@ -228,8 +228,7 @@ public class VelocityUtils @@ -228,8 +228,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);
}
/**

3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@ -63,9 +63,8 @@ public class SysDeptServiceImpl implements ISysDeptService @@ -63,9 +63,8 @@ public class SysDeptServiceImpl implements ISysDeptService
{
tempList.add(dept.getDeptId());
}
for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
for (SysDept dept : depts)
{
SysDept dept = (SysDept) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dept.getParentId()))
{

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

@ -498,7 +498,7 @@ public class SysMenuServiceImpl implements ISysMenuService @@ -498,7 +498,7 @@ 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;
}
/**

8
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
</resultMap>
<sql id="selectMenuVo">
select menu_id, menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time
select menu_id, menu_name, parent_id, order_num, path, component, `query`, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time
from sys_menu
</sql>
@ -49,13 +49,13 @@ @@ -49,13 +49,13 @@
</select>
<select id="selectMenuTreeAll" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0
order by m.parent_id, m.order_num
</select>
<select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
</select>
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id

2
ruoyi-ui/src/components/FileUpload/index.vue

@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
<!-- 文件列表 -->
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
<li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
<li :key="file.url" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
<el-link :href="file.url" :underline="false" target="_blank">
<span class="el-icon-document"> {{ getFileName(file.name) }} </span>
</el-link>

0
ruoyi-ui/src/utils/generator/drawingDefalut.js → ruoyi-ui/src/utils/generator/drawingDefault.js

4
ruoyi-ui/src/utils/generator/html.js

@ -5,11 +5,11 @@ let confGlobal @@ -5,11 +5,11 @@ let confGlobal
let someSpanIsNot24
export function dialogWrapper(str) {
return `<el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Titile">
return `<el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Title">
${str}
<div slot="footer">
<el-button @click="close">取消</el-button>
<el-button type="primary" @click="handelConfirm">确定</el-button>
<el-button type="primary" @click="handleConfirm">确定</el-button>
</div>
</el-dialog>`
}

2
ruoyi-ui/src/utils/generator/js.js

@ -98,7 +98,7 @@ function mixinMethod(type) { @@ -98,7 +98,7 @@ function mixinMethod(type) {
close: `close() {
this.$emit('update:visible', false)
},`,
handelConfirm: `handelConfirm() {
handleConfirm: `handleConfirm() {
this.$refs['${confGlobal.formRef}'].validate(valid => {
if(!valid) return
this.close()

4
ruoyi-ui/src/views/tool/build/CodeTypeDialog.vue

@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
<el-button @click="close">
取消
</el-button>
<el-button type="primary" @click="handelConfirm">
<el-button type="primary" @click="handleConfirm">
确定
</el-button>
</div>
@ -94,7 +94,7 @@ export default { @@ -94,7 +94,7 @@ export default {
close(e) {
this.$emit('update:visible', false)
},
handelConfirm() {
handleConfirm() {
this.$refs.elForm.validate(valid => {
if (!valid) return
this.$emit('confirm', { ...this.formData })

4
ruoyi-ui/src/views/tool/build/TreeNodeDialog.vue

@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
<div slot="footer">
<el-button
type="primary"
@click="handelConfirm"
@click="handleConfirm"
>
确定
</el-button>
@ -133,7 +133,7 @@ export default { @@ -133,7 +133,7 @@ export default {
close() {
this.$emit('update:visible', false)
},
handelConfirm() {
handleConfirm() {
this.$refs.elForm.validate(valid => {
if (!valid) return
if (this.dataType === 'number') {

8
ruoyi-ui/src/views/tool/build/index.vue

@ -146,7 +146,7 @@ import { beautifierConf, titleCase } from '@/utils/index' @@ -146,7 +146,7 @@ import { beautifierConf, titleCase } from '@/utils/index'
import { makeUpHtml, vueTemplate, vueScript, cssStyle } from '@/utils/generator/html'
import { makeUpJs } from '@/utils/generator/js'
import { makeUpCss } from '@/utils/generator/css'
import drawingDefalut from '@/utils/generator/drawingDefalut'
import drawingDefault from '@/utils/generator/drawingDefault'
import logo from '@/assets/logo/logo.png'
import CodeTypeDialog from './CodeTypeDialog'
import DraggableItem from './DraggableItem'
@ -171,15 +171,15 @@ export default { @@ -171,15 +171,15 @@ export default {
selectComponents,
layoutComponents,
labelWidth: 100,
drawingList: drawingDefalut,
drawingList: drawingDefault,
drawingData: {},
activeId: drawingDefalut[0].formId,
activeId: drawingDefault[0].formId,
drawerVisible: false,
formData: {},
dialogVisible: false,
generateConf: null,
showFileName: false,
activeData: drawingDefalut[0]
activeData: drawingDefault[0]
}
},
created() {

Loading…
Cancel
Save