update 优化 封装部门基于父id查询方法

dev
疯狂的狮子Li 1 year ago
parent 5d29847714
commit a8de81aba7

@ -65,9 +65,7 @@ public class RemoteDataScopeServiceImpl implements RemoteDataScopeService {
if (ObjectUtil.isNull(deptId)) {
return "-1";
}
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
List<SysDept> deptList = deptMapper.selectListByParentId(deptId);
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(deptId);
if (CollUtil.isNotEmpty(ids)) {

@ -1,10 +1,12 @@
package org.dromara.system.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission;
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.vo.SysDeptVo;
import org.apache.ibatis.annotations.Param;
@ -34,6 +36,12 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept, SysDeptVo> {
})
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
*

@ -78,12 +78,8 @@ public class SysPostServiceImpl implements ISysPostService {
} else if (ObjectUtil.isNotNull(bo.getBelongDeptId())) {
//部门树搜索
wrapper.and(x -> {
List<Long> deptIds = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(bo.getBelongDeptId(), "ancestors")))
.stream()
.map(SysDept::getDeptId)
.collect(Collectors.toList());
List<SysDept> deptList = deptMapper.selectListByParentId(bo.getBelongDeptId());
List<Long> deptIds = StreamUtils.toList(deptList, SysDept::getDeptId);
deptIds.add(bo.getBelongDeptId());
x.in(SysPost::getDeptId, deptIds);
});

@ -85,9 +85,7 @@ public class SysUserServiceImpl implements ISysUserService {
.between(params.get("beginTime") != null && params.get("endTime") != null,
"u.create_time", params.get("beginTime"), params.get("endTime"))
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(user.getDeptId(), "ancestors")));
List<SysDept> deptList = deptMapper.selectListByParentId(user.getDeptId());
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(user.getDeptId());
w.in("u.dept_id", ids);

Loading…
Cancel
Save