refactor(java): 优化Java代码实现细节
This commit is contained in:
+1
-2
@@ -137,8 +137,7 @@ public class KitSpringBeanHolder implements ApplicationContextAware, DisposableB
|
|||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
|
||||||
if (KitSpringBeanHolder.applicationContext != null) {
|
if (KitSpringBeanHolder.applicationContext != null) {
|
||||||
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" +
|
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:{}", KitSpringBeanHolder.applicationContext);
|
||||||
KitSpringBeanHolder.applicationContext);
|
|
||||||
}
|
}
|
||||||
KitSpringBeanHolder.applicationContext = applicationContext;
|
KitSpringBeanHolder.applicationContext = applicationContext;
|
||||||
if (addCallback) {
|
if (addCallback) {
|
||||||
|
|||||||
+1
-1
@@ -179,7 +179,7 @@ public class KitMpQUtil {
|
|||||||
*/
|
*/
|
||||||
private static <R> void handleBlurryQuery(QueryWrapper<R> queryWrapper, String blurry, Object fieldVal) {
|
private static <R> void handleBlurryQuery(QueryWrapper<R> queryWrapper, String blurry, Object fieldVal) {
|
||||||
List<String> blurryList =
|
List<String> blurryList =
|
||||||
Arrays.stream(blurry.split(",")).filter(StrUtil::isNotBlank).distinct().collect(Collectors.toList());
|
Arrays.stream(blurry.split(",")).filter(StrUtil::isNotBlank).distinct().toList();
|
||||||
queryWrapper.and(wrapper -> {
|
queryWrapper.and(wrapper -> {
|
||||||
for (String blurryItem : blurryList) {
|
for (String blurryItem : blurryList) {
|
||||||
String column = StrUtil.toUnderlineCase(blurryItem);
|
String column = StrUtil.toUnderlineCase(blurryItem);
|
||||||
|
|||||||
+1
-2
@@ -280,8 +280,7 @@ public class KitRedisHelper {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (value instanceof List<?>) {
|
if (value instanceof List<?> list) {
|
||||||
List<?> list = (List<?>) value;
|
|
||||||
// 检查每个元素是否为指定类型
|
// 检查每个元素是否为指定类型
|
||||||
if (list.stream().allMatch(clazz::isInstance)) {
|
if (list.stream().allMatch(clazz::isInstance)) {
|
||||||
return list.stream().map(clazz::cast).collect(Collectors.toList());
|
return list.stream().map(clazz::cast).collect(Collectors.toList());
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public final class KitListUtil {
|
|||||||
*/
|
*/
|
||||||
public static <T, K> List<T> distinctByArgs(List<T> items, Function<? super T, ? extends K> classifier) {
|
public static <T, K> List<T> distinctByArgs(List<T> items, Function<? super T, ? extends K> classifier) {
|
||||||
return items.stream().collect(Collectors.groupingBy(classifier)).values().stream()
|
return items.stream().collect(Collectors.groupingBy(classifier)).values().stream()
|
||||||
.map(monitorItem -> monitorItem.iterator().next()).collect(Collectors.toList());
|
.map(List::getFirst).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -288,7 +288,7 @@ public class SystemDeptService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 编辑部门时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
|
// 编辑部门时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
|
||||||
depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList());
|
depts = depts.stream().filter(i -> !ids.contains(i.getId())).toList();
|
||||||
}
|
}
|
||||||
deptSet1.addAll(depts);
|
deptSet1.addAll(depts);
|
||||||
}
|
}
|
||||||
@@ -296,7 +296,7 @@ public class SystemDeptService {
|
|||||||
// 构建部门树
|
// 构建部门树
|
||||||
Set<SystemDeptVo> trees = new LinkedHashSet<>();
|
Set<SystemDeptVo> trees = new LinkedHashSet<>();
|
||||||
Set<SystemDeptVo> deptSet = new LinkedHashSet<>();
|
Set<SystemDeptVo> deptSet = new LinkedHashSet<>();
|
||||||
List<String> deptNames = deptList.stream().map(SystemDeptVo::getName).collect(Collectors.toList());
|
List<String> deptNames = deptList.stream().map(SystemDeptVo::getName).toList();
|
||||||
boolean isChild;
|
boolean isChild;
|
||||||
for (SystemDeptVo dept : deptList) {
|
for (SystemDeptVo dept : deptList) {
|
||||||
isChild = false;
|
isChild = false;
|
||||||
|
|||||||
+2
-2
@@ -147,7 +147,7 @@ public class SystemRoleService {
|
|||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteRoleByIds(Set<Long> ids) {
|
public void deleteRoleByIds(Set<Long> ids) {
|
||||||
List<Integer> roleLevels = systemRoleMapper.selectByIds(ids).stream().map(SystemRoleTb::getLevel).distinct().collect(Collectors.toList());
|
List<Integer> roleLevels = systemRoleMapper.selectByIds(ids).stream().map(SystemRoleTb::getLevel).distinct().toList();
|
||||||
for (Integer roleLevel : roleLevels) {
|
for (Integer roleLevel : roleLevels) {
|
||||||
checkRoleLevels(roleLevel);
|
checkRoleLevels(roleLevel);
|
||||||
}
|
}
|
||||||
@@ -274,7 +274,7 @@ public class SystemRoleService {
|
|||||||
*/
|
*/
|
||||||
private int checkRoleLevels(Integer level) {
|
private int checkRoleLevels(Integer level) {
|
||||||
List<Integer> levels = systemUserRoleService.queryRoleByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
|
List<Integer> levels = systemUserRoleService.queryRoleByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
|
||||||
.map(SystemRoleVo::getLevel).collect(Collectors.toList());
|
.map(SystemRoleVo::getLevel).toList();
|
||||||
int min = Collections.min(levels);
|
int min = Collections.min(levels);
|
||||||
if (level != null) {
|
if (level != null) {
|
||||||
if (level < min) {
|
if (level < min) {
|
||||||
|
|||||||
+1
-1
@@ -215,7 +215,7 @@ public class SystemUserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
List<String> usernameList = systemUserMapper.selectByIds(ids).stream().map(SystemUserTb::getUsername).distinct().collect(Collectors.toList());
|
List<String> usernameList = systemUserMapper.selectByIds(ids).stream().map(SystemUserTb::getUsername).distinct().toList();
|
||||||
for (String username : usernameList) {
|
for (String username : usernameList) {
|
||||||
systemUserInfoDAO.deleteUserLoginInfoByUserName(username);
|
systemUserInfoDAO.deleteUserLoginInfoByUserName(username);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user