RoleDictServiceImpl.java
5.89 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.meishu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.dto.role.AddPermissionDTO;
import com.meishu.dto.role.DeletePermissionDTO;
import com.meishu.dto.role.GetRoleTeachersDTO;
import com.meishu.dto.role.RoleTeacherDTO;
import com.meishu.dto.rule.GetRuleReportDTO;
import com.meishu.mapper.*;
import com.meishu.model.*;
import com.meishu.service.RoleDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.role.GetAllRolesVO;
import com.meishu.vo.role.GetRoleTeachersVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.management.relation.Role;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 角色表 服务实现类
* </p>
*
* @author Tuyp
* @since 2021-04-26
*/
@Service
public class RoleDictServiceImpl extends ServiceImpl<RoleDictMapper, RoleDictDO> implements RoleDictService {
@Autowired
private RoleAdministerMappingMapper roleAdministerMappingMapper;
@Autowired
private RolePermissionMappingMapper rolePermissionMappingMapper;
@Autowired
private AdministerMapper administerMapper;
public List<GetAllRolesVO> getAllRoles(){
List<GetAllRolesVO> getAllRolesVOS = new ArrayList<>();
List<RoleDictDO> roleDictDOS = this.baseMapper.selectList(null);
for (RoleDictDO roleDictDO : roleDictDOS){
GetAllRolesVO getAllRolesVO = new GetAllRolesVO();
List<PermissionsDictDO> list = rolePermissionMappingMapper.getRolePermission(roleDictDO.getId());
//树形结构
List<PermissionsDictDO> treeList = new ArrayList();
if (list != null) {
list.forEach(permission -> {
if (permission.getParentId() == null) {
treeList.add(permission);
}
list.forEach(p -> {
if (null != p.getParentId() && p.getParentId().equals(permission.getId())) {
if (permission.getChildren() == null) {
permission.setChildren(new ArrayList<>());
}
permission.getChildren().add(p);
}
});
});
}
BeanUtils.copyProperties(roleDictDO,getAllRolesVO);
getAllRolesVO.setPermissionsDictDOS(treeList);
getAllRolesVOS.add(getAllRolesVO);
}
return getAllRolesVOS;
}
public IPage<GetRoleTeachersVO> getRoleTeachers(GetRoleTeachersDTO getRoleTeachersDTO){
Page pager = new Page(getRoleTeachersDTO.getPageNum(), getRoleTeachersDTO.getPageSize());
IPage<GetRoleTeachersVO> getRoleTeachersVOIPage = this.baseMapper.getRoleTeachers(pager,getRoleTeachersDTO.getRoleId(),getRoleTeachersDTO.getUserName());
List<GetRoleTeachersVO> getRoleTeachersVOS = getRoleTeachersVOIPage.getRecords();
for (GetRoleTeachersVO getRoleTeachersVO : getRoleTeachersVOS){
List<DepartmentDictDO> departmentDictDOS = administerMapper.getDepartmentByAdministerId(getRoleTeachersVO.getAdministerId());
getRoleTeachersVO.setDepartmentDictDOS(departmentDictDOS);
}
return getRoleTeachersVOIPage;
}
public String removeTeacher(RoleTeacherDTO roleTeacherDTO){
roleAdministerMappingMapper.delete(new QueryWrapper<RoleAdministerMappingDO>()
.lambda()
.eq(RoleAdministerMappingDO::getRoleId,roleTeacherDTO.getRoleId())
.in(RoleAdministerMappingDO::getId,roleTeacherDTO.getIds()));
return ConstantUtils.DELETE_SUCCESS;
}
public String roleTeacher(RoleTeacherDTO roleTeacherDTO){
roleAdministerMappingMapper.delete(new QueryWrapper<RoleAdministerMappingDO>()
.lambda()
.eq(RoleAdministerMappingDO::getRoleId,roleTeacherDTO.getRoleId()));
List<Long> longs = roleTeacherDTO.getIds();
for (Long lg : longs){
RoleAdministerMappingDO roleAdministerMappingDO = new RoleAdministerMappingDO();
roleAdministerMappingDO.setAdministerId(lg);
roleAdministerMappingDO.setRoleId(roleTeacherDTO.getRoleId());
roleAdministerMappingMapper.insert(roleAdministerMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String addPermission(AddPermissionDTO addPermissionDTO){
List<Long> longs = addPermissionDTO.getPermissionIds();
rolePermissionMappingMapper.delete(new QueryWrapper<RolePermissionMappingDO>()
.lambda()
.eq(RolePermissionMappingDO::getRoleId,addPermissionDTO.getRoleId()));
for (Long lg : longs){
RolePermissionMappingDO rolePermissionMappingDO = new RolePermissionMappingDO();
rolePermissionMappingDO.setRoleId(addPermissionDTO.getRoleId());
rolePermissionMappingDO.setPermissionId(lg);
rolePermissionMappingMapper.insert(rolePermissionMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String deletePermission(DeletePermissionDTO deletePermissionDTO){
List<Long> longs = deletePermissionDTO.getRoleIds();
for (Long lg : longs){
rolePermissionMappingMapper.delete(new QueryWrapper<RolePermissionMappingDO>()
.lambda()
.eq(RolePermissionMappingDO::getPermissionId,deletePermissionDTO.getPermissionId())
.eq(RolePermissionMappingDO::getRoleId,lg));
}
return ConstantUtils.DELETE_SUCCESS;
}
}