refactor(java): 优化Java代码实现细节

This commit is contained in:
2026-01-12 17:30:23 +08:00
parent b88254084d
commit 8aa0830213
7 changed files with 9 additions and 11 deletions
@@ -137,8 +137,7 @@ public class KitSpringBeanHolder implements ApplicationContextAware, DisposableB
@Override
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
if (KitSpringBeanHolder.applicationContext != null) {
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" +
KitSpringBeanHolder.applicationContext);
log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:{}", KitSpringBeanHolder.applicationContext);
}
KitSpringBeanHolder.applicationContext = applicationContext;
if (addCallback) {
@@ -179,7 +179,7 @@ public class KitMpQUtil {
*/
private static <R> void handleBlurryQuery(QueryWrapper<R> queryWrapper, String blurry, Object fieldVal) {
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 -> {
for (String blurryItem : blurryList) {
String column = StrUtil.toUnderlineCase(blurryItem);
@@ -280,8 +280,7 @@ public class KitRedisHelper {
if (value == null) {
return null;
}
if (value instanceof List<?>) {
List<?> list = (List<?>) value;
if (value instanceof List<?> list) {
// 检查每个元素是否为指定类型
if (list.stream().allMatch(clazz::isInstance)) {
return list.stream().map(clazz::cast).collect(Collectors.toList());
@@ -40,7 +40,7 @@ public final class KitListUtil {
*/
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()
.map(monitorItem -> monitorItem.iterator().next()).collect(Collectors.toList());
.map(List::getFirst).collect(Collectors.toList());
}
/**
@@ -288,7 +288,7 @@ public class SystemDeptService {
}
}
// 编辑部门时不显示自己以及自己下级的数据, 避免出现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);
}
@@ -296,7 +296,7 @@ public class SystemDeptService {
// 构建部门树
Set<SystemDeptVo> trees = 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;
for (SystemDeptVo dept : deptList) {
isChild = false;
@@ -147,7 +147,7 @@ public class SystemRoleService {
*/
@Transactional(rollbackFor = Exception.class)
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) {
checkRoleLevels(roleLevel);
}
@@ -274,7 +274,7 @@ public class SystemRoleService {
*/
private int checkRoleLevels(Integer level) {
List<Integer> levels = systemUserRoleService.queryRoleByUsersId(KitSecurityHelper.getCurrentUserId()).stream()
.map(SystemRoleVo::getLevel).collect(Collectors.toList());
.map(SystemRoleVo::getLevel).toList();
int min = Collections.min(levels);
if (level != null) {
if (level < min) {
@@ -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) {
systemUserInfoDAO.deleteUserLoginInfoByUserName(username);
}