作者 RuoYi

优化代码

1 package com.ruoyi.web.controller.system; 1 package com.ruoyi.web.controller.system;
2 2
3 -import java.util.Iterator;  
4 import java.util.List; 3 import java.util.List;
5 import org.apache.commons.lang3.ArrayUtils; 4 import org.apache.commons.lang3.ArrayUtils;
6 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
@@ -54,16 +53,7 @@ public class SysDeptController extends BaseController @@ -54,16 +53,7 @@ public class SysDeptController extends BaseController
54 public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) 53 public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
55 { 54 {
56 List<SysDept> depts = deptService.selectDeptList(new SysDept()); 55 List<SysDept> depts = deptService.selectDeptList(new SysDept());
57 - Iterator<SysDept> it = depts.iterator();  
58 - while (it.hasNext())  
59 - {  
60 - SysDept d = (SysDept) it.next();  
61 - if (d.getDeptId().intValue() == deptId  
62 - || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))  
63 - {  
64 - it.remove();  
65 - }  
66 - } 56 + depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
67 return AjaxResult.success(depts); 57 return AjaxResult.success(depts);
68 } 58 }
69 59
@@ -131,7 +131,7 @@ public class SysDictData extends BaseEntity @@ -131,7 +131,7 @@ public class SysDictData extends BaseEntity
131 131
132 public boolean getDefault() 132 public boolean getDefault()
133 { 133 {
134 - return UserConstants.YES.equals(this.isDefault) ? true : false; 134 + return UserConstants.YES.equals(this.isDefault);
135 } 135 }
136 136
137 public String getIsDefault() 137 public String getIsDefault()
@@ -124,9 +124,9 @@ public class RedisCache @@ -124,9 +124,9 @@ public class RedisCache
124 * @param collection 多个对象 124 * @param collection 多个对象
125 * @return 125 * @return
126 */ 126 */
127 - public long deleteObject(final Collection collection) 127 + public boolean deleteObject(final Collection collection)
128 { 128 {
129 - return redisTemplate.delete(collection); 129 + return redisTemplate.delete(collection) > 0;
130 } 130 }
131 131
132 /** 132 /**
@@ -232,18 +232,6 @@ public class RedisCache @@ -232,18 +232,6 @@ public class RedisCache
232 } 232 }
233 233
234 /** 234 /**
235 - * 删除Hash中的数据  
236 - *  
237 - * @param key  
238 - * @param hKey  
239 - */  
240 - public void delCacheMapValue(final String key, final String hKey)  
241 - {  
242 - HashOperations hashOperations = redisTemplate.opsForHash();  
243 - hashOperations.delete(key, hKey);  
244 - }  
245 -  
246 - /**  
247 * 获取多个Hash中的数据 235 * 获取多个Hash中的数据
248 * 236 *
249 * @param key Redis键 237 * @param key Redis键
@@ -264,7 +252,7 @@ public class RedisCache @@ -264,7 +252,7 @@ public class RedisCache
264 */ 252 */
265 public boolean deleteCacheMapValue(final String key, final String hKey) 253 public boolean deleteCacheMapValue(final String key, final String hKey)
266 { 254 {
267 - return Boolean.TRUE.equals(redisTemplate.opsForHash().delete(key, hKey)); 255 + return redisTemplate.opsForHash().delete(key, hKey) > 0;
268 } 256 }
269 257
270 /** 258 /**