package com.dl.system.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.dl.common.core.domain.entity.SysDept; import com.dl.common.helper.DataBaseHelper; import com.dl.common.utils.StreamUtils; import com.dl.system.domain.SysRoleDept; import com.dl.system.mapper.SysDeptMapper; import com.dl.system.mapper.SysRoleDeptMapper; import com.dl.system.service.ISysDataScopeService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; /** * 数据权限 实现 *

* 注意: 此Service内不允许调用标注`数据权限`注解的方法 * 例如: deptMapper.selectList 此 selectList 方法标注了`数据权限`注解 会出现循环解析的问题 * * @author Lion Li */ @RequiredArgsConstructor @Service("sdss") public class SysDataScopeServiceImpl implements ISysDataScopeService { private final SysRoleDeptMapper roleDeptMapper; private final SysDeptMapper deptMapper; @Override public String getRoleCustom(Long roleId) { List list = roleDeptMapper.selectList( new LambdaQueryWrapper() .select(SysRoleDept::getDeptId) .eq(SysRoleDept::getRoleId, roleId)); if (CollUtil.isNotEmpty(list)) { return StreamUtils.join(list, rd -> Convert.toStr(rd.getDeptId())); } return null; } @Override public String getDeptAndChild(Long deptId) { List deptList = deptMapper.selectList(new LambdaQueryWrapper() .select(SysDept::getDeptId) .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); List ids = StreamUtils.toList(deptList, SysDept::getDeptId); ids.add(deptId); List list = deptMapper.selectList(new LambdaQueryWrapper() .select(SysDept::getDeptId) .in(SysDept::getDeptId, ids)); if (CollUtil.isNotEmpty(list)) { return StreamUtils.join(list, d -> Convert.toStr(d.getDeptId())); } return null; } }