refactor(dept):优化部门服务实现

- 将 Collections.EMPTY_LIST 替换为 Collections.emptyList()
-优化树路径删除逻辑,使用预定义模式匹配- 提取重复代码为局部变量
This commit is contained in:
theo
2025-11-14 14:51:54 +08:00
parent 9d6553bbfa
commit 3eb66cb16e

View File

@@ -108,7 +108,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
.orderByAsc(Dept::getSort) .orderByAsc(Dept::getSort)
); );
if (CollectionUtil.isEmpty(deptList)) { if (CollectionUtil.isEmpty(deptList)) {
return Collections.EMPTY_LIST; return Collections.emptyList();
} }
Set<Long> deptIds = deptList.stream() Set<Long> deptIds = deptList.stream()
@@ -238,10 +238,11 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
if (StrUtil.isNotBlank(ids)) { if (StrUtil.isNotBlank(ids)) {
String[] menuIds = ids.split(","); String[] menuIds = ids.split(",");
for (String deptId : menuIds) { for (String deptId : menuIds) {
String patten = "%," + deptId + ",%";
this.update(new LambdaUpdateWrapper<Dept>() this.update(new LambdaUpdateWrapper<Dept>()
.eq(Dept::getId, deptId) .eq(Dept::getId, deptId)
.or() .or()
.apply("CONCAT (',',tree_path,',') LIKE CONCAT('%,',{0},',%')", deptId) .apply("CONCAT (',',tree_path,',') LIKE {0}", patten)
.set(Dept::getIsDeleted, 1) .set(Dept::getIsDeleted, 1)
.set(Dept::getUpdateBy, SecurityUtils.getUserId()) .set(Dept::getUpdateBy, SecurityUtils.getUserId())
); );