SysDataScopeServiceImpl.java
2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.lego.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lego.system.service.ISysDataScopeService;
import com.lego.common.core.domain.entity.SysDept;
import com.lego.common.helper.DataBaseHelper;
import com.lego.common.utils.StreamUtils;
import com.lego.common.utils.StringUtils;
import com.lego.system.domain.SysRoleDept;
import com.lego.system.mapper.SysDeptMapper;
import com.lego.system.mapper.SysRoleDeptMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 数据权限 实现
* <p>
* 注意: 此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<SysRoleDept> list = roleDeptMapper.selectList(
new LambdaQueryWrapper<SysRoleDept>()
.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(List<Long> deptIdList) {
Set<Long> idAll = new HashSet<>();
for (Long deptId : deptIdList) {
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(deptId);
CollectionUtil.addAll(idAll, ids);
}
if (CollUtil.isNotEmpty(idAll)) {
return StreamUtils.join(idAll, Convert::toStr);
}
return null;
}
@Override
public String getDeptJoin(List<Long> deptIdList) {
if (CollectionUtil.isEmpty(deptIdList)) {
return StringUtils.EMPTY;
}
return deptIdList.stream().map(String::valueOf).collect(Collectors.joining(","));
}
}