update 使用 in 优化 or 提升索引命中率

This commit is contained in:
疯狂的狮子li
2022-03-14 16:01:30 +08:00
parent 469ed434fa
commit f4b16090db
2 changed files with 9 additions and 6 deletions

View File

@@ -45,11 +45,14 @@ public class RemoteDataScopeServiceImpl implements RemoteDataScopeService {
@Override
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>()
.select(SysDept::getDeptId)
.eq(SysDept::getDeptId, deptId)
.or()
.apply("find_in_set({0},ancestors) <> 0", deptId));
.in(SysDept::getDeptId, ids));
if (CollUtil.isNotEmpty(list)) {
return list.stream().map(d -> Convert.toStr(d.getDeptId())).collect(Collectors.joining(","));
}

View File

@@ -82,9 +82,9 @@ public class SysUserServiceImpl implements ISysUserService {
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply("find_in_set({0},ancestors) <> 0", user.getDeptId()));
w.eq("u.dept_id", user.getDeptId())
.or()
.in("u.dept_id", deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList()));
List<Long> ids = deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList());
ids.add(user.getDeptId());
w.in("u.dept_id", ids);
});
return wrapper;
}