From 85e455737695504304e721cd227bd0e389501dcd Mon Sep 17 00:00:00 2001 From: Odboy Date: Tue, 13 Jan 2026 21:34:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E6=9B=BF=E6=8D=A2=20Collecti?= =?UTF-8?q?onUtil=20=E4=B8=BA=20CollUtil=20=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/mybatisplus/core/KitMpQUtil.java | 6 +++--- .../cn/odboy/system/service/SystemDeptService.java | 13 ++++++++----- .../cn/odboy/system/service/SystemMenuService.java | 6 ++---- .../cn/odboy/system/service/SystemRoleService.java | 5 ++--- .../cn/odboy/system/service/SystemUserService.java | 10 ++-------- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/KitMpQUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/KitMpQUtil.java index ae95afd5..a4bf25e0 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/KitMpQUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/KitMpQUtil.java @@ -15,7 +15,7 @@ */ package cn.odboy.framework.mybatisplus.core; -import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitBaseUserTimeTb; @@ -131,7 +131,7 @@ public class KitMpQUtil { private static void handleInOrNotQuery(boolean b, QueryWrapper queryWrapper, String attributeName, Object fieldVal) { Collection wrapNotInVal = (Collection) fieldVal; - if (CollectionUtil.isNotEmpty(wrapNotInVal)) { + if (CollUtil.isNotEmpty(wrapNotInVal)) { Optional anyValOptional = wrapNotInVal.stream().findAny(); if (anyValOptional.isPresent()) { Object o = anyValOptional.get(); @@ -159,7 +159,7 @@ public class KitMpQUtil { if (fieldVal instanceof List) { List between = new ArrayList<>((List) fieldVal); int minLength = 2; - if (CollectionUtil.isNotEmpty(between) && between.size() >= minLength) { + if (CollUtil.isNotEmpty(between) && between.size() >= minLength) { queryWrapper.between(finalAttributeName, between.get(0), between.get(1)); } else { throw new BadRequestException("BETWEEN类型的对象列表长度必须 >= 2"); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java index 7a0429a6..1cc24c76 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java @@ -16,7 +16,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; @@ -84,7 +83,7 @@ public class SystemDeptService { public void updateDeptById(SystemDeptTb args) { KitValidUtil.notNull(args); // 旧的父部门 - Long oldPid = this.getDeptVoById(args.getId()).getPid(); + Long oldPid = this.getDeptById(args.getId()).getPid(); // 新的父部门 Long newPid = args.getPid(); if (args.getPid() != null && args.getId().equals(args.getPid())) { @@ -97,6 +96,10 @@ public class SystemDeptService { this.updateDeptSubCnt(newPid); } + private SystemDeptTb getDeptById(Long id) { + return systemDeptMapper.selectById(id); + } + /** * 删除 * @@ -322,11 +325,11 @@ public class SystemDeptService { deptSet.add(dept); } } - if (CollectionUtil.isEmpty(trees)) { + if (CollUtil.isEmpty(trees)) { trees = deptSet; } KitPageResult baseResult = new KitPageResult<>(); - baseResult.setContent(CollectionUtil.isEmpty(trees) ? new ArrayList<>(deptSet) : new ArrayList<>(trees)); + baseResult.setContent(CollUtil.isEmpty(trees) ? new ArrayList<>(deptSet) : new ArrayList<>(trees)); baseResult.setTotalElements(deptSet.size()); return baseResult; } @@ -364,7 +367,7 @@ public class SystemDeptService { depts.add(this.getDeptVoById(id)); // 子部门 List deptList = this.listDeptVoByPid(id); - if (CollectionUtil.isNotEmpty(deptList)) { + if (CollUtil.isNotEmpty(deptList)) { queryRelationDeptByArgs(deptList, depts); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java index dc3b84d3..0d7fa156 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java @@ -16,11 +16,9 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.framework.exception.BadRequestException; -import cn.odboy.framework.logging.ExecutionTimeStatisticsFace; import cn.odboy.system.constant.SystemTransferProtocolConst; import cn.odboy.system.constant.SystemYesOrNoChConst; import cn.odboy.system.dal.dataobject.SystemMenuTb; @@ -337,7 +335,7 @@ public class SystemMenuService { } } menuVo.setMeta(new SystemMenuMetaVo(menu.getTitle(), menu.getIcon(), !menu.getCache())); - if (CollectionUtil.isNotEmpty(menuList)) { + if (CollUtil.isNotEmpty(menuList)) { menuVo.setAlwaysShow(true); menuVo.setRedirect("noredirect"); menuVo.setChildren(buildMenuVo(menuList)); @@ -441,7 +439,7 @@ public class SystemMenuService { public List listMenuSuperior(List ids) { Set menus; List systemMenuTbs; - if (CollectionUtil.isNotEmpty(ids)) { + if (CollUtil.isNotEmpty(ids)) { menus = new LinkedHashSet<>(this.listMenuByIds(ids)); for (SystemMenuVo menu : menus) { List menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>()); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java index 4229b702..88412cd2 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java @@ -16,7 +16,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; @@ -74,7 +73,7 @@ public class SystemRoleService { SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class); systemRoleMapper.insert(roleTb); // 判断是否有部门数据, 若有, 则需创建关联 - if (CollectionUtil.isNotEmpty(args.getDepts())) { + if (CollUtil.isNotEmpty(args.getDepts())) { systemRoleDeptService.batchInsertRoleDept(args.getDepts(), roleTb.getId()); } } @@ -113,7 +112,7 @@ public class SystemRoleService { // 删除关联部门数据 systemRoleDeptService.batchDeleteRoleDept(Collections.singleton(args.getId())); // 判断是否有部门数据, 若有, 则需更新关联 - if (CollectionUtil.isNotEmpty(args.getDepts())) { + if (CollUtil.isNotEmpty(args.getDepts())) { systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId()); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java index 81afe958..9a6d1875 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java @@ -16,7 +16,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageArgs; import cn.odboy.base.KitPageResult; @@ -62,7 +61,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; @@ -72,10 +70,6 @@ public class SystemUserService { @Autowired private SystemUserMapper systemUserMapper; @Autowired - private SystemJobService systemJobService; - @Autowired - private SystemRoleService systemRoleService; - @Autowired private SystemDeptService systemDeptService; @Autowired private SystemUserJobService systemUserJobService; @@ -479,10 +473,10 @@ public class SystemUserService { // 数据权限 List dataScopes = systemDataService.queryDeptIdByArgs(this.getUserVoByUsername(currentUsername)); // args.getDeptIds() 不为空并且数据权限不为空则取交集 - if (!CollectionUtils.isEmpty(args.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) { + if (!CollUtil.isEmpty(args.getDeptIds()) && !CollUtil.isEmpty(dataScopes)) { // 取交集 args.getDeptIds().retainAll(dataScopes); - if (!CollectionUtil.isEmpty(args.getDeptIds())) { + if (!CollUtil.isEmpty(args.getDeptIds())) { return this.searchUserByArgs(args, page); } } else {