Bladeren bron

优化代码

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

+ 1 - 2
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ExceptionUtil.java

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

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

@@ -161,9 +161,8 @@ public class ServletUtils
161 161
      * 
162 162
      * @param response 渲染对象
163 163
      * @param string 待渲染的字符串
164
-     * @return null
165 164
      */
166
-    public static String renderString(HttpServletResponse response, String string)
165
+    public static void renderString(HttpServletResponse response, String string)
167 166
     {
168 167
         try
169 168
         {
@@ -176,7 +175,6 @@ public class ServletUtils
176 175
         {
177 176
             e.printStackTrace();
178 177
         }
179
-        return null;
180 178
     }
181 179
 
182 180
     /**
@@ -187,13 +185,13 @@ public class ServletUtils
187 185
     public static boolean isAjaxRequest(HttpServletRequest request)
188 186
     {
189 187
         String accept = request.getHeader("accept");
190
-        if (accept != null && accept.indexOf("application/json") != -1)
188
+        if (accept != null && accept.contains("application/json"))
191 189
         {
192 190
             return true;
193 191
         }
194 192
 
195 193
         String xRequestedWith = request.getHeader("X-Requested-With");
196
-        if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
194
+        if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
197 195
         {
198 196
             return true;
199 197
         }
@@ -205,11 +203,7 @@ public class ServletUtils
205 203
         }
206 204
 
207 205
         String ajax = request.getParameter("__ajax");
208
-        if (StringUtils.inStringIgnoreCase(ajax, "json", "xml"))
209
-        {
210
-            return true;
211
-        }
212
-        return false;
206
+        return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
213 207
     }
214 208
 
215 209
     /**

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

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

+ 2 - 2
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 944
         if (StringUtils.isNotEmpty(excel.targetAttr()))
945 945
         {
946 946
             String target = excel.targetAttr();
947
-            if (target.indexOf(".") > -1)
947
+            if (target.contains("."))
948 948
             {
949 949
                 String[] targets = target.split("[.]");
950 950
                 for (String name : targets)
@@ -1039,7 +1039,7 @@ public class ExcelUtil<T>
1039 1039
         for (Object[] os : this.fields)
1040 1040
         {
1041 1041
             Excel excel = (Excel) os[1];
1042
-            maxHeight = maxHeight > excel.height() ? maxHeight : excel.height();
1042
+            maxHeight = Math.max(maxHeight, excel.height());
1043 1043
         }
1044 1044
         return (short) (maxHeight * 20);
1045 1045
     }

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

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

+ 1 - 2
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/DictUtils.java

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

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

@@ -2,6 +2,7 @@ package com.ruoyi.file.utils;
2 2
 
3 3
 import java.io.File;
4 4
 import java.io.IOException;
5
+import java.util.Objects;
5 6
 import org.apache.commons.io.FilenameUtils;
6 7
 import org.springframework.web.multipart.MultipartFile;
7 8
 import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException;
@@ -65,7 +66,7 @@ public class FileUploadUtils
65 66
             throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
66 67
             InvalidExtensionException
67 68
     {
68
-        int fileNamelength = file.getOriginalFilename().length();
69
+        int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
69 70
         if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
70 71
         {
71 72
             throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
@@ -77,8 +78,7 @@ public class FileUploadUtils
77 78
 
78 79
         File desc = getAbsoluteFile(baseDir, fileName);
79 80
         file.transferTo(desc);
80
-        String pathFileName = getPathFileName(fileName);
81
-        return pathFileName;
81
+        return getPathFileName(fileName);
82 82
     }
83 83
 
84 84
     /**
@@ -186,7 +186,7 @@ public class FileUploadUtils
186 186
         String extension = FilenameUtils.getExtension(file.getOriginalFilename());
187 187
         if (StringUtils.isEmpty(extension))
188 188
         {
189
-            extension = MimeTypeUtils.getExtension(file.getContentType());
189
+            extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
190 190
         }
191 191
         return extension;
192 192
     }

+ 3 - 5
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java

@@ -151,8 +151,7 @@ public class GenUtils
151 151
     {
152 152
         int lastIndex = packageName.lastIndexOf(".");
153 153
         int nameLength = packageName.length();
154
-        String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
155
-        return moduleName;
154
+        return StringUtils.substring(packageName, lastIndex + 1, nameLength);
156 155
     }
157 156
 
158 157
     /**
@@ -165,8 +164,7 @@ public class GenUtils
165 164
     {
166 165
         int lastIndex = tableName.lastIndexOf("_");
167 166
         int nameLength = tableName.length();
168
-        String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
169
-        return businessName;
167
+        return StringUtils.substring(tableName, lastIndex + 1, nameLength);
170 168
     }
171 169
 
172 170
     /**
@@ -255,4 +253,4 @@ public class GenUtils
255 253
             return 0;
256 254
         }
257 255
     }
258
-}
256
+}

+ 1 - 2
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@@ -228,8 +228,7 @@ public class VelocityUtils
228 228
     public static String getPackagePrefix(String packageName)
229 229
     {
230 230
         int lastIndex = packageName.lastIndexOf(".");
231
-        String basePackage = StringUtils.substring(packageName, 0, lastIndex);
232
-        return basePackage;
231
+        return StringUtils.substring(packageName, 0, lastIndex);
233 232
     }
234 233
 
235 234
     /**

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

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

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

@@ -498,7 +498,7 @@ public class SysMenuServiceImpl implements ISysMenuService
498 498
      */
499 499
     private boolean hasChild(List<SysMenu> list, SysMenu t)
500 500
     {
501
-        return getChildList(list, t).size() > 0 ? true : false;
501
+        return getChildList(list, t).size() > 0;
502 502
     }
503 503
 
504 504
     /**

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

@@ -28,7 +28,7 @@
28 28
 	</resultMap>
29 29
 
30 30
 	<sql id="selectMenuVo">
31
-        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 
31
+        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 
32 32
 		from sys_menu
33 33
     </sql>
34 34
     
@@ -49,13 +49,13 @@
49 49
 	</select>
50 50
 	
51 51
 	<select id="selectMenuTreeAll" resultMap="SysMenuResult">
52
-		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
52
+		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
53 53
 		from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0
54 54
 		order by m.parent_id, m.order_num
55 55
 	</select>
56 56
 	
57 57
 	<select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
58
-		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
58
+		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
59 59
 		from sys_menu m
60 60
 		left join sys_role_menu rm on m.menu_id = rm.menu_id
61 61
 		left join sys_user_role ur on rm.role_id = ur.role_id
@@ -74,7 +74,7 @@
74 74
 	</select>
75 75
     
76 76
     <select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
77
-		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
77
+		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
78 78
 		from sys_menu m
79 79
 			 left join sys_role_menu rm on m.menu_id = rm.menu_id
80 80
 			 left join sys_user_role ur on rm.role_id = ur.role_id

+ 1 - 1
ruoyi-ui/src/components/FileUpload/index.vue

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

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


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

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

+ 1 - 1
ruoyi-ui/src/utils/generator/js.js

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

+ 2 - 2
ruoyi-ui/src/views/tool/build/CodeTypeDialog.vue

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

+ 2 - 2
ruoyi-ui/src/views/tool/build/TreeNodeDialog.vue

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

+ 4 - 4
ruoyi-ui/src/views/tool/build/index.vue

@@ -146,7 +146,7 @@ import { beautifierConf, titleCase } from '@/utils/index'
146 146
 import { makeUpHtml, vueTemplate, vueScript, cssStyle } from '@/utils/generator/html'
147 147
 import { makeUpJs } from '@/utils/generator/js'
148 148
 import { makeUpCss } from '@/utils/generator/css'
149
-import drawingDefalut from '@/utils/generator/drawingDefalut'
149
+import drawingDefault from '@/utils/generator/drawingDefault'
150 150
 import logo from '@/assets/logo/logo.png'
151 151
 import CodeTypeDialog from './CodeTypeDialog'
152 152
 import DraggableItem from './DraggableItem'
@@ -171,15 +171,15 @@ export default {
171 171
       selectComponents,
172 172
       layoutComponents,
173 173
       labelWidth: 100,
174
-      drawingList: drawingDefalut,
174
+      drawingList: drawingDefault,
175 175
       drawingData: {},
176
-      activeId: drawingDefalut[0].formId,
176
+      activeId: drawingDefault[0].formId,
177 177
       drawerVisible: false,
178 178
       formData: {},
179 179
       dialogVisible: false,
180 180
       generateConf: null,
181 181
       showFileName: false,
182
-      activeData: drawingDefalut[0]
182
+      activeData: drawingDefault[0]
183 183
     }
184 184
   },
185 185
   created() {