mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 04:18:07 +00:00
update 使用 in 优化 or 提升索引命中率
This commit is contained in:
@@ -45,11 +45,14 @@ public class RemoteDataScopeServiceImpl implements RemoteDataScopeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDeptAndChild(Long deptId) {
|
public String getDeptAndChild(Long deptId) {
|
||||||
|
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
||||||
|
.select(SysDept::getDeptId)
|
||||||
|
.apply("find_in_set({0},ancestors) <> 0", deptId));
|
||||||
|
List<Long> ids = deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList());
|
||||||
|
ids.add(deptId);
|
||||||
List<SysDept> list = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
List<SysDept> list = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
||||||
.select(SysDept::getDeptId)
|
.select(SysDept::getDeptId)
|
||||||
.eq(SysDept::getDeptId, deptId)
|
.in(SysDept::getDeptId, ids));
|
||||||
.or()
|
|
||||||
.apply("find_in_set({0},ancestors) <> 0", deptId));
|
|
||||||
if (CollUtil.isNotEmpty(list)) {
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
return list.stream().map(d -> Convert.toStr(d.getDeptId())).collect(Collectors.joining(","));
|
return list.stream().map(d -> Convert.toStr(d.getDeptId())).collect(Collectors.joining(","));
|
||||||
}
|
}
|
||||||
|
@@ -82,9 +82,9 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||||||
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
||||||
.select(SysDept::getDeptId)
|
.select(SysDept::getDeptId)
|
||||||
.apply("find_in_set({0},ancestors) <> 0", user.getDeptId()));
|
.apply("find_in_set({0},ancestors) <> 0", user.getDeptId()));
|
||||||
w.eq("u.dept_id", user.getDeptId())
|
List<Long> ids = deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList());
|
||||||
.or()
|
ids.add(user.getDeptId());
|
||||||
.in("u.dept_id", deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList()));
|
w.in("u.dept_id", ids);
|
||||||
});
|
});
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user