update 优化 封装部门基于父id查询方法
This commit is contained in:
parent
73d5fbd085
commit
0a0a16f969
@ -1,10 +1,12 @@
|
|||||||
package org.dromara.system.mapper;
|
package org.dromara.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import org.dromara.common.mybatis.annotation.DataColumn;
|
import org.dromara.common.mybatis.annotation.DataColumn;
|
||||||
import org.dromara.common.mybatis.annotation.DataPermission;
|
import org.dromara.common.mybatis.annotation.DataPermission;
|
||||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||||
|
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
||||||
import org.dromara.system.domain.SysDept;
|
import org.dromara.system.domain.SysDept;
|
||||||
import org.dromara.system.domain.vo.SysDeptVo;
|
import org.dromara.system.domain.vo.SysDeptVo;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
@ -34,6 +36,12 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept, SysDeptVo> {
|
|||||||
})
|
})
|
||||||
long countDeptById(Long deptId);
|
long countDeptById(Long deptId);
|
||||||
|
|
||||||
|
default List<SysDept> selectListByParentId(Long parentId) {
|
||||||
|
return this.selectList(new LambdaQueryWrapper<SysDept>()
|
||||||
|
.select(SysDept::getDeptId)
|
||||||
|
.apply(DataBaseHelper.findInSet(parentId, "ancestors")));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询部门树信息
|
* 根据角色ID查询部门树信息
|
||||||
*
|
*
|
||||||
|
@ -6,7 +6,6 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.dromara.common.core.utils.StreamUtils;
|
import org.dromara.common.core.utils.StreamUtils;
|
||||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
||||||
import org.dromara.system.domain.SysDept;
|
import org.dromara.system.domain.SysDept;
|
||||||
import org.dromara.system.domain.SysRoleDept;
|
import org.dromara.system.domain.SysRoleDept;
|
||||||
import org.dromara.system.mapper.SysDeptMapper;
|
import org.dromara.system.mapper.SysDeptMapper;
|
||||||
@ -63,9 +62,7 @@ public class SysDataScopeServiceImpl implements ISysDataScopeService {
|
|||||||
if (ObjectUtil.isNull(deptId)) {
|
if (ObjectUtil.isNull(deptId)) {
|
||||||
return "-1";
|
return "-1";
|
||||||
}
|
}
|
||||||
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
List<SysDept> deptList = deptMapper.selectListByParentId(deptId);
|
||||||
.select(SysDept::getDeptId)
|
|
||||||
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
||||||
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
|
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
|
||||||
ids.add(deptId);
|
ids.add(deptId);
|
||||||
if (CollUtil.isNotEmpty(ids)) {
|
if (CollUtil.isNotEmpty(ids)) {
|
||||||
|
@ -13,7 +13,6 @@ import org.dromara.common.core.utils.StreamUtils;
|
|||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
||||||
import org.dromara.system.domain.SysDept;
|
import org.dromara.system.domain.SysDept;
|
||||||
import org.dromara.system.domain.SysPost;
|
import org.dromara.system.domain.SysPost;
|
||||||
import org.dromara.system.domain.SysUserPost;
|
import org.dromara.system.domain.SysUserPost;
|
||||||
@ -27,7 +26,6 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位信息 服务层处理
|
* 岗位信息 服务层处理
|
||||||
@ -78,12 +76,8 @@ public class SysPostServiceImpl implements ISysPostService {
|
|||||||
} else if (ObjectUtil.isNotNull(bo.getBelongDeptId())) {
|
} else if (ObjectUtil.isNotNull(bo.getBelongDeptId())) {
|
||||||
//部门树搜索
|
//部门树搜索
|
||||||
wrapper.and(x -> {
|
wrapper.and(x -> {
|
||||||
List<Long> deptIds = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
List<SysDept> deptList = deptMapper.selectListByParentId(bo.getBelongDeptId());
|
||||||
.select(SysDept::getDeptId)
|
List<Long> deptIds = StreamUtils.toList(deptList, SysDept::getDeptId);
|
||||||
.apply(DataBaseHelper.findInSet(bo.getBelongDeptId(), "ancestors")))
|
|
||||||
.stream()
|
|
||||||
.map(SysDept::getDeptId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
deptIds.add(bo.getBelongDeptId());
|
deptIds.add(bo.getBelongDeptId());
|
||||||
x.in(SysPost::getDeptId, deptIds);
|
x.in(SysPost::getDeptId, deptIds);
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,6 @@ import org.dromara.common.core.utils.StreamUtils;
|
|||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
import org.dromara.system.domain.*;
|
import org.dromara.system.domain.*;
|
||||||
import org.dromara.system.domain.bo.SysUserBo;
|
import org.dromara.system.domain.bo.SysUserBo;
|
||||||
@ -89,9 +88,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|||||||
.between(params.get("beginTime") != null && params.get("endTime") != null,
|
.between(params.get("beginTime") != null && params.get("endTime") != null,
|
||||||
"u.create_time", params.get("beginTime"), params.get("endTime"))
|
"u.create_time", params.get("beginTime"), params.get("endTime"))
|
||||||
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
|
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
|
||||||
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
List<SysDept> deptList = deptMapper.selectListByParentId(user.getDeptId());
|
||||||
.select(SysDept::getDeptId)
|
|
||||||
.apply(DataBaseHelper.findInSet(user.getDeptId(), "ancestors")));
|
|
||||||
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
|
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
|
||||||
ids.add(user.getDeptId());
|
ids.add(user.getDeptId());
|
||||||
w.in("u.dept_id", ids);
|
w.in("u.dept_id", ids);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user