疯狂的狮子li
2022-03-14 e480f616e055e9fdfdb1bac38de9b01ddbcca476
update 使用 in 优化 or 提升索引命中率
已修改2个文件
15 ■■■■■ 文件已修改
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDataScopeServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDataScopeServiceImpl.java
@@ -44,11 +44,14 @@
    @Override
    public String getDeptAndChild(Long deptId) {
        List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
            .select(SysDept::getDeptId)
            .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
        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(DataBaseHelper.findInSet(deptId, "ancestors")));
            .in(SysDept::getDeptId, ids));
        if (CollUtil.isNotEmpty(list)) {
            return list.stream().map(d -> Convert.toStr(d.getDeptId())).collect(Collectors.joining(","));
        }
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
@@ -82,9 +82,9 @@
                List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
                    .select(SysDept::getDeptId)
                    .apply(DataBaseHelper.findInSet(user.getDeptId(), "ancestors")));
                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;
    }