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. 8
      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
{ {
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)

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

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

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

@ -55,7 +55,7 @@ public class ImageUtils
/** /**
* 读取文件为字节数据 * 读取文件为字节数据
* *
* @param key 地址 * @param url 地址
* @return 字节数据 * @return 字节数据
*/ */
public static byte[] readFile(String url) 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>
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)
@ -1039,7 +1039,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);
} }

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

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

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

@ -37,8 +37,7 @@ public class DictUtils
Object cacheObj = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key)); Object cacheObj = SpringUtils.getBean(RedisService.class).getCacheObject(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;
} }

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

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

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

@ -151,8 +151,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;
} }
/** /**
@ -165,8 +164,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;
} }
/** /**
@ -255,4 +253,4 @@ public class GenUtils
return 0; return 0;
} }
} }
} }

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

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

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

@ -63,9 +63,8 @@ public class SysDeptServiceImpl implements ISysDeptService
{ {
tempList.add(dept.getDeptId()); 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())) 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
*/ */
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;
} }
/** /**

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

@ -28,7 +28,7 @@
</resultMap> </resultMap>
<sql id="selectMenuVo"> <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 from sys_menu
</sql> </sql>
@ -49,13 +49,13 @@
</select> </select>
<select id="selectMenuTreeAll" resultMap="SysMenuResult"> <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 from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0
order by m.parent_id, m.order_num order by m.parent_id, m.order_num
</select> </select>
<select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult"> <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 from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id 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 left join sys_user_role ur on rm.role_id = ur.role_id
@ -74,7 +74,7 @@
</select> </select>
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult"> <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 from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id 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 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 @@
<!-- 文件列表 --> <!-- 文件列表 -->
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul"> <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"> <el-link :href="file.url" :underline="false" target="_blank">
<span class="el-icon-document"> {{ getFileName(file.name) }} </span> <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
</el-link> </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
let someSpanIsNot24 let someSpanIsNot24
export function dialogWrapper(str) { 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} ${str}
<div slot="footer"> <div slot="footer">
<el-button @click="close">取消</el-button> <el-button @click="close">取消</el-button>
<el-button type="primary" @click="handelConfirm">确定</el-button> <el-button type="primary" @click="handleConfirm">确定</el-button>
</div> </div>
</el-dialog>` </el-dialog>`
} }

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

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

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

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

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

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

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

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

Loading…
Cancel
Save