mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 12:28:10 +00:00
add 新增 StringUtils splitTo 与 splitList 方法 优化业务代码
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
@@ -48,7 +48,8 @@ public class SysDeptController extends BaseController {
|
||||
@GetMapping("/list/exclude/{deptId}")
|
||||
public R<List<SysDept>> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
|
||||
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
||||
depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtil.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
|
||||
depts.removeIf(d -> d.getDeptId().intValue() == deptId
|
||||
|| StringUtils.splitList(d.getAncestors()).contains(Convert.toStr(deptId)));
|
||||
return R.ok(depts);
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,6 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
@@ -131,13 +130,13 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
@Override
|
||||
public String selectDeptNameByIds(String deptIds) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Long id : Arrays.stream(deptIds.split(",")).map(Long::parseLong).collect(Collectors.toList())) {
|
||||
for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) {
|
||||
SysDept dept = SpringUtils.getAopProxy(this).selectDeptById(id);
|
||||
if (ObjectUtil.isNotNull(dept)) {
|
||||
list.add(dept.getDeptName());
|
||||
}
|
||||
}
|
||||
return String.join(",", list);
|
||||
return String.join(StringUtils.SEPARATOR, list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,7 +224,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
||||
throw new ServiceException("部门停用,不允许新增");
|
||||
}
|
||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||
dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId());
|
||||
return baseMapper.insert(dept);
|
||||
}
|
||||
|
||||
@@ -241,7 +240,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
SysDept newParentDept = baseMapper.selectById(dept.getParentId());
|
||||
SysDept oldDept = baseMapper.selectById(dept.getDeptId());
|
||||
if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) {
|
||||
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
||||
String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getDeptId();
|
||||
String oldAncestors = oldDept.getAncestors();
|
||||
dept.setAncestors(newAncestors);
|
||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||
|
@@ -92,7 +92,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (String perm : perms) {
|
||||
if (StringUtils.isNotEmpty(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
|
||||
permsSet.addAll(StringUtils.splitList(perm.trim()));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
@@ -110,7 +110,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (String perm : perms) {
|
||||
if (StringUtils.isNotEmpty(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
|
||||
permsSet.addAll(StringUtils.splitList(perm.trim()));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
|
@@ -5,11 +5,11 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.satoken.utils.LoginHelper;
|
||||
@@ -106,7 +106,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (SysRole perm : perms) {
|
||||
if (ObjectUtil.isNotNull(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
|
||||
permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim()));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
|
Reference in New Issue
Block a user