提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.service.permission; |
H |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
d9f9ba
|
4 |
import cn.hutool.core.util.ObjUtil; |
7da8f1
|
5 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
d9f9ba
|
6 |
import com.google.common.annotations.VisibleForTesting; |
H |
7 |
import com.google.common.collect.Lists; |
|
8 |
import com.iailab.framework.common.enums.CommonStatusEnum; |
e7c126
|
9 |
import com.iailab.framework.common.util.object.BeanUtils; |
H |
10 |
import com.iailab.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
|
11 |
import com.iailab.module.system.controller.admin.permission.vo.menu.MenuSaveVO; |
818a01
|
12 |
import com.iailab.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; |
H |
13 |
import com.iailab.module.system.dal.dataobject.app.AppDO; |
874287
|
14 |
import com.iailab.module.system.dal.dataobject.app.AppMenuDO; |
e7c126
|
15 |
import com.iailab.module.system.dal.dataobject.permission.MenuDO; |
818a01
|
16 |
import com.iailab.module.system.dal.dataobject.permission.RoleDO; |
7da8f1
|
17 |
import com.iailab.module.system.dal.dataobject.permission.RoleMenuDO; |
818a01
|
18 |
import com.iailab.module.system.dal.dataobject.tenant.TenantDO; |
H |
19 |
import com.iailab.module.system.dal.dataobject.tenant.TenantPackageDO; |
874287
|
20 |
import com.iailab.module.system.dal.mysql.app.AppMapper; |
H |
21 |
import com.iailab.module.system.dal.mysql.app.AppMenuMapper; |
e7c126
|
22 |
import com.iailab.module.system.dal.mysql.permission.MenuMapper; |
7da8f1
|
23 |
import com.iailab.module.system.dal.mysql.permission.RoleMenuMapper; |
e7c126
|
24 |
import com.iailab.module.system.dal.redis.RedisKeyConstants; |
H |
25 |
import com.iailab.module.system.enums.permission.MenuTypeEnum; |
818a01
|
26 |
import com.iailab.module.system.service.app.AppService; |
H |
27 |
import com.iailab.module.system.service.tenant.TenantPackageService; |
e7c126
|
28 |
import com.iailab.module.system.service.tenant.TenantService; |
H |
29 |
import lombok.extern.slf4j.Slf4j; |
874287
|
30 |
import org.springframework.beans.factory.annotation.Autowired; |
e7c126
|
31 |
import org.springframework.cache.annotation.CacheEvict; |
H |
32 |
import org.springframework.cache.annotation.Cacheable; |
|
33 |
import org.springframework.context.annotation.Lazy; |
|
34 |
import org.springframework.stereotype.Service; |
|
35 |
import org.springframework.transaction.annotation.Transactional; |
|
36 |
|
|
37 |
import javax.annotation.Resource; |
d9f9ba
|
38 |
import java.util.*; |
7da8f1
|
39 |
import java.util.stream.Collectors; |
e7c126
|
40 |
|
H |
41 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
7da8f1
|
42 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
H |
43 |
import static com.iailab.framework.common.util.collection.CollectionUtils.*; |
|
44 |
import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
818a01
|
45 |
import static com.iailab.framework.tenant.core.context.TenantContextHolder.getTenantId; |
e7c126
|
46 |
import static com.iailab.module.system.dal.dataobject.permission.MenuDO.ID_ROOT; |
H |
47 |
import static com.iailab.module.system.enums.ErrorCodeConstants.*; |
d9f9ba
|
48 |
|
e7c126
|
49 |
|
H |
50 |
/** |
|
51 |
* 菜单 Service 实现 |
|
52 |
* |
4d4165
|
53 |
* @author iailab |
e7c126
|
54 |
*/ |
H |
55 |
@Service |
|
56 |
@Slf4j |
|
57 |
public class MenuServiceImpl implements MenuService { |
|
58 |
|
|
59 |
@Resource |
|
60 |
private MenuMapper menuMapper; |
|
61 |
@Resource |
|
62 |
private PermissionService permissionService; |
|
63 |
@Resource |
|
64 |
@Lazy // 延迟,避免循环依赖报错 |
|
65 |
private TenantService tenantService; |
|
66 |
|
818a01
|
67 |
@Resource |
H |
68 |
private TenantPackageService tenantPackageService; |
|
69 |
|
|
70 |
@Resource |
|
71 |
private AppService appService; |
|
72 |
|
|
73 |
@Resource |
|
74 |
private RoleService roleService; |
7da8f1
|
75 |
|
H |
76 |
@Resource |
|
77 |
private RoleMenuMapper roleMenuMapper; |
874287
|
78 |
@Autowired |
H |
79 |
private AppMapper appMapper; |
|
80 |
@Autowired |
|
81 |
private AppMenuMapper appMenuMapper; |
818a01
|
82 |
|
e7c126
|
83 |
@Override |
H |
84 |
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#createReqVO.permission", |
|
85 |
condition = "#createReqVO.permission != null") |
818a01
|
86 |
@Transactional(rollbackFor = Exception.class) |
e7c126
|
87 |
public Long createMenu(MenuSaveVO createReqVO) { |
H |
88 |
// 校验父菜单存在 |
|
89 |
validateParentMenu(createReqVO.getParentId(), null); |
|
90 |
// 校验菜单(自己) |
|
91 |
validateMenu(createReqVO.getParentId(), createReqVO.getName(), null); |
|
92 |
|
|
93 |
// 插入数据库 |
|
94 |
MenuDO menu = BeanUtils.toBean(createReqVO, MenuDO.class); |
|
95 |
initMenuProperty(menu); |
818a01
|
96 |
|
H |
97 |
//菜单归属租户和应用 |
|
98 |
Long tenantId = getTenantId(); |
|
99 |
menu.setTenantId(tenantId); |
|
100 |
menu.setAppId(createReqVO.getAppId()); |
e7c126
|
101 |
menuMapper.insert(menu); |
818a01
|
102 |
if(tenantId != 1L) { |
H |
103 |
dealPermission(menu); |
|
104 |
} |
e7c126
|
105 |
// 返回 |
H |
106 |
return menu.getId(); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, |
|
111 |
allEntries = true) // allEntries 清空所有缓存,因为 permission 如果变更,涉及到新老两个 permission。直接清理,简单有效 |
818a01
|
112 |
@Transactional(rollbackFor = Exception.class) |
e7c126
|
113 |
public void updateMenu(MenuSaveVO updateReqVO) { |
H |
114 |
// 校验更新的菜单是否存在 |
|
115 |
if (menuMapper.selectById(updateReqVO.getId()) == null) { |
|
116 |
throw exception(MENU_NOT_EXISTS); |
|
117 |
} |
|
118 |
// 校验父菜单存在 |
|
119 |
validateParentMenu(updateReqVO.getParentId(), updateReqVO.getId()); |
|
120 |
// 校验菜单(自己) |
|
121 |
validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getId()); |
|
122 |
|
|
123 |
// 更新到数据库 |
|
124 |
MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class); |
|
125 |
initMenuProperty(updateObj); |
818a01
|
126 |
//菜单归属租户和应用 |
H |
127 |
Long tenantId = getTenantId(); |
|
128 |
AppDO appDO = appService.getAppByTenantId(tenantId); |
874287
|
129 |
if(appDO.getTenantId() != 1) { |
H |
130 |
updateObj.setTenantId(tenantId); |
|
131 |
updateObj.setAppId(appDO.getId()); |
|
132 |
} |
e7c126
|
133 |
menuMapper.updateById(updateObj); |
H |
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
@Transactional(rollbackFor = Exception.class) |
|
138 |
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, |
|
139 |
allEntries = true) // allEntries 清空所有缓存,因为此时不知道 id 对应的 permission 是多少。直接清理,简单有效 |
|
140 |
public void deleteMenu(Long id) { |
|
141 |
// 校验是否还有子菜单 |
|
142 |
if (menuMapper.selectCountByParentId(id) > 0) { |
|
143 |
throw exception(MENU_EXISTS_CHILDREN); |
|
144 |
} |
|
145 |
// 校验删除的菜单是否存在 |
|
146 |
if (menuMapper.selectById(id) == null) { |
|
147 |
throw exception(MENU_NOT_EXISTS); |
|
148 |
} |
|
149 |
// 标记删除 |
|
150 |
menuMapper.deleteById(id); |
|
151 |
// 删除授予给角色的权限 |
|
152 |
permissionService.processMenuDeleted(id); |
|
153 |
} |
|
154 |
|
|
155 |
@Override |
|
156 |
public List<MenuDO> getMenuList() { |
|
157 |
return menuMapper.selectList(); |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO) { |
d9f9ba
|
162 |
// 查询所有菜单,并过滤掉关闭的节点 |
e7c126
|
163 |
List<MenuDO> menus = getMenuList(reqVO); |
818a01
|
164 |
// 开启多租户的情况下,需要过滤掉未开通的菜单 |
H |
165 |
tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId()))); |
|
166 |
return menus; |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public List<MenuDO> getAppMenuListByTenant(MenuListReqVO reqVO) { |
ce910c
|
171 |
// 获取 tenantId |
H |
172 |
Long tenantId = getTenantId(); |
818a01
|
173 |
// 查询所有菜单,并过滤掉关闭的节点 |
ce910c
|
174 |
List<MenuDO> menus = getAppMenuList(tenantId, reqVO); |
e7c126
|
175 |
// 开启多租户的情况下,需要过滤掉未开通的菜单 |
H |
176 |
tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId()))); |
|
177 |
return menus; |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
d9f9ba
|
181 |
public List<MenuDO> filterDisableMenus(List<MenuDO> menuList) { |
H |
182 |
if (CollUtil.isEmpty(menuList)){ |
|
183 |
return Collections.emptyList(); |
|
184 |
} |
|
185 |
Map<Long, MenuDO> menuMap = convertMap(menuList, MenuDO::getId); |
|
186 |
|
|
187 |
// 遍历 menu 菜单,查找不是禁用的菜单,添加到 enabledMenus 结果 |
|
188 |
List<MenuDO> enabledMenus = new ArrayList<>(); |
|
189 |
Set<Long> disabledMenuCache = new HashSet<>(); // 存下递归搜索过被禁用的菜单,防止重复的搜索 |
|
190 |
for (MenuDO menu : menuList) { |
|
191 |
if (isMenuDisabled(menu, menuMap, disabledMenuCache)) { |
|
192 |
continue; |
|
193 |
} |
|
194 |
enabledMenus.add(menu); |
|
195 |
} |
|
196 |
return enabledMenus; |
|
197 |
} |
|
198 |
|
874287
|
199 |
@Override |
H |
200 |
public List<MenuDO> filterMenus(List<MenuDO> menuList, String type) { |
|
201 |
if (CollUtil.isEmpty(menuList)){ |
|
202 |
return Collections.emptyList(); |
|
203 |
} |
|
204 |
Map<Long, MenuDO> menuMap = convertMap(menuList, MenuDO::getId); |
|
205 |
LambdaQueryWrapper<AppDO> queryWrapper = new LambdaQueryWrapper<>(); |
|
206 |
|
|
207 |
//查询所有的系统应用菜单 |
|
208 |
if("system".equals(type)) { |
|
209 |
queryWrapper.eq(AppDO::getType, 0); |
|
210 |
} else if("app".equals(type)) { |
|
211 |
queryWrapper.eq(AppDO::getType, 1); |
|
212 |
} |
|
213 |
List<AppDO> appDOS = appMapper.selectList(queryWrapper); |
|
214 |
List<Long> appIds = appDOS.stream().map(AppDO::getId).collect(Collectors.toList()); |
|
215 |
List<MenuDO> menuDOS = menuMapper.selectList(new LambdaQueryWrapper<MenuDO>().in(MenuDO::getAppId, appIds)); |
|
216 |
List<Long> systemMenuIds = menuDOS.stream().map(MenuDO::getId).collect(Collectors.toList()); |
|
217 |
|
|
218 |
// 遍历 menu 菜单,查找不是禁用的菜单,添加到 系统菜单(应用菜单) 结果 |
|
219 |
List<MenuDO> systemMenus = new ArrayList<>(); |
|
220 |
Set<Long> appMenuCache = new HashSet<>(); // 存下递归搜索过被禁用的菜单,防止重复的搜索 |
|
221 |
for (MenuDO menu : menuList) { |
|
222 |
if (isAppMenu(menu, menuMap, appMenuCache, systemMenuIds)) { |
|
223 |
continue; |
|
224 |
} |
|
225 |
systemMenus.add(menu); |
|
226 |
} |
|
227 |
return systemMenus; |
|
228 |
} |
|
229 |
|
d9f9ba
|
230 |
private boolean isMenuDisabled(MenuDO node, Map<Long, MenuDO> menuMap, Set<Long> disabledMenuCache) { |
H |
231 |
// 如果已经判定是禁用的节点,直接结束 |
|
232 |
if (disabledMenuCache.contains(node.getId())) { |
|
233 |
return true; |
|
234 |
} |
|
235 |
|
|
236 |
// 1. 遍历到 parentId 为根节点,则无需判断 |
|
237 |
Long parentId = node.getParentId(); |
|
238 |
if (ObjUtil.equal(parentId, ID_ROOT)) { |
|
239 |
if (CommonStatusEnum.isDisable(node.getStatus())) { |
|
240 |
disabledMenuCache.add(node.getId()); |
|
241 |
return true; |
|
242 |
} |
|
243 |
return false; |
|
244 |
} |
|
245 |
|
|
246 |
// 2. 继续遍历 parent 节点 |
|
247 |
MenuDO parent = menuMap.get(parentId); |
|
248 |
if (parent == null || isMenuDisabled(parent, menuMap, disabledMenuCache)) { |
|
249 |
disabledMenuCache.add(node.getId()); |
|
250 |
return true; |
|
251 |
} |
|
252 |
return false; |
|
253 |
} |
|
254 |
|
874287
|
255 |
private boolean isAppMenu(MenuDO node, Map<Long, MenuDO> menuMap, Set<Long> menuCache, List<Long> systemMenuIds) { |
H |
256 |
// 如果已经判定是禁用的节点,直接结束 |
|
257 |
if (menuCache.contains(node.getId())) { |
|
258 |
return true; |
|
259 |
} |
|
260 |
|
|
261 |
// 2. 遍历到 parentId 为根节点,则无需判断 |
|
262 |
Long parentId = node.getParentId(); |
|
263 |
if (ObjUtil.equal(parentId, ID_ROOT)) { |
|
264 |
if (!systemMenuIds.contains(node.getId())) { |
|
265 |
menuCache.add(node.getId()); |
|
266 |
return true; |
|
267 |
} |
|
268 |
return false; |
|
269 |
} |
|
270 |
|
|
271 |
// 3. 继续遍历 parent 节点 |
|
272 |
MenuDO parent = menuMap.get(parentId); |
|
273 |
if (parent == null || isAppMenu(parent, menuMap, menuCache, systemMenuIds)) { |
|
274 |
menuCache.add(node.getId()); |
|
275 |
return true; |
|
276 |
} |
|
277 |
return false; |
|
278 |
} |
|
279 |
|
d9f9ba
|
280 |
@Override |
e7c126
|
281 |
public List<MenuDO> getMenuList(MenuListReqVO reqVO) { |
H |
282 |
return menuMapper.selectList(reqVO); |
818a01
|
283 |
} |
H |
284 |
|
|
285 |
@Override |
ce910c
|
286 |
public List<MenuDO> getAppMenuList(Long tenantId, MenuListReqVO reqVO) { |
874287
|
287 |
List<MenuDO> menuDOS = menuMapper.selectAppMenuList(reqVO); |
H |
288 |
menuDOS = filterMenus(menuDOS, "app"); |
7da8f1
|
289 |
Set<Long> menuDOIds = menuDOS.stream().map(MenuDO::getId).collect(Collectors.toSet()); |
874287
|
290 |
TenantDO tenant = tenantService.getTenant(tenantId); |
H |
291 |
TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(tenant.getPackageId()); |
|
292 |
Set<Long> tenantMenuIds = tenantPackage.getMenuIds(); |
|
293 |
menuDOS = menuDOS.stream().filter(menuDO -> tenantMenuIds.contains(menuDO.getId())).collect(Collectors.toList()); |
7da8f1
|
294 |
// 获得角色列表 |
H |
295 |
Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(getLoginUserId()); |
|
296 |
List<RoleDO> roles = roleService.getRoleList(roleIds); |
|
297 |
roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色 |
|
298 |
if (roles.stream().noneMatch(role -> role.getCode().equals("tenant_admin"))) { |
|
299 |
// 获得菜单列表 |
|
300 |
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); |
|
301 |
//取交集 |
|
302 |
menuIds.retainAll(menuDOIds); |
|
303 |
List<MenuDO> menuList = getMenuList(menuIds); |
|
304 |
menuList = filterDisableMenus(menuList); |
|
305 |
return menuList; |
|
306 |
} |
|
307 |
return menuDOS; |
e7c126
|
308 |
} |
H |
309 |
|
|
310 |
@Override |
|
311 |
@Cacheable(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#permission") |
|
312 |
public List<Long> getMenuIdListByPermissionFromCache(String permission) { |
|
313 |
List<MenuDO> menus = menuMapper.selectListByPermission(permission); |
|
314 |
return convertList(menus, MenuDO::getId); |
|
315 |
} |
|
316 |
|
|
317 |
@Override |
|
318 |
public MenuDO getMenu(Long id) { |
|
319 |
return menuMapper.selectById(id); |
|
320 |
} |
|
321 |
|
|
322 |
@Override |
7da8f1
|
323 |
public MenuDO getMenuByAppId(Long id) { |
H |
324 |
return menuMapper.selectOne(new LambdaQueryWrapper<MenuDO>().eq(MenuDO::getAppId, id).eq(MenuDO::getParentId, 0l)); |
|
325 |
} |
|
326 |
|
|
327 |
@Override |
e7c126
|
328 |
public List<MenuDO> getMenuList(Collection<Long> ids) { |
H |
329 |
// 当 ids 为空时,返回一个空的实例对象 |
|
330 |
if (CollUtil.isEmpty(ids)) { |
|
331 |
return Lists.newArrayList(); |
|
332 |
} |
|
333 |
return menuMapper.selectBatchIds(ids); |
7da8f1
|
334 |
} |
H |
335 |
|
|
336 |
@Override |
|
337 |
public List<MenuDO> selectListByParentId(Collection<Long> ids) { |
|
338 |
return menuMapper.selectListByParentId(ids); |
e7c126
|
339 |
} |
H |
340 |
|
|
341 |
/** |
|
342 |
* 校验父菜单是否合法 |
|
343 |
* <p> |
|
344 |
* 1. 不能设置自己为父菜单 |
|
345 |
* 2. 父菜单不存在 |
|
346 |
* 3. 父菜单必须是 {@link MenuTypeEnum#MENU} 菜单类型 |
|
347 |
* |
|
348 |
* @param parentId 父菜单编号 |
|
349 |
* @param childId 当前菜单编号 |
|
350 |
*/ |
|
351 |
@VisibleForTesting |
|
352 |
void validateParentMenu(Long parentId, Long childId) { |
|
353 |
if (parentId == null || ID_ROOT.equals(parentId)) { |
|
354 |
return; |
|
355 |
} |
|
356 |
// 不能设置自己为父菜单 |
|
357 |
if (parentId.equals(childId)) { |
|
358 |
throw exception(MENU_PARENT_ERROR); |
|
359 |
} |
|
360 |
MenuDO menu = menuMapper.selectById(parentId); |
|
361 |
// 父菜单不存在 |
|
362 |
if (menu == null) { |
|
363 |
throw exception(MENU_PARENT_NOT_EXISTS); |
|
364 |
} |
|
365 |
// 父菜单必须是目录或者菜单类型 |
|
366 |
if (!MenuTypeEnum.DIR.getType().equals(menu.getType()) |
|
367 |
&& !MenuTypeEnum.MENU.getType().equals(menu.getType())) { |
|
368 |
throw exception(MENU_PARENT_NOT_DIR_OR_MENU); |
|
369 |
} |
|
370 |
} |
|
371 |
|
|
372 |
/** |
|
373 |
* 校验菜单是否合法 |
|
374 |
* <p> |
|
375 |
* 1. 校验相同父菜单编号下,是否存在相同的菜单名 |
|
376 |
* |
|
377 |
* @param name 菜单名字 |
|
378 |
* @param parentId 父菜单编号 |
|
379 |
* @param id 菜单编号 |
|
380 |
*/ |
|
381 |
@VisibleForTesting |
|
382 |
void validateMenu(Long parentId, String name, Long id) { |
|
383 |
MenuDO menu = menuMapper.selectByParentIdAndName(parentId, name); |
|
384 |
if (menu == null) { |
|
385 |
return; |
|
386 |
} |
|
387 |
// 如果 id 为空,说明不用比较是否为相同 id 的菜单 |
|
388 |
if (id == null) { |
|
389 |
throw exception(MENU_NAME_DUPLICATE); |
|
390 |
} |
|
391 |
if (!menu.getId().equals(id)) { |
|
392 |
throw exception(MENU_NAME_DUPLICATE); |
|
393 |
} |
|
394 |
} |
|
395 |
|
|
396 |
/** |
|
397 |
* 初始化菜单的通用属性。 |
|
398 |
* <p> |
|
399 |
* 例如说,只有目录或者菜单类型的菜单,才设置 icon |
|
400 |
* |
|
401 |
* @param menu 菜单 |
|
402 |
*/ |
|
403 |
private void initMenuProperty(MenuDO menu) { |
|
404 |
// 菜单为按钮类型时,无需 component、icon、path 属性,进行置空 |
|
405 |
if (MenuTypeEnum.BUTTON.getType().equals(menu.getType())) { |
|
406 |
menu.setComponent(""); |
|
407 |
menu.setComponentName(""); |
|
408 |
menu.setIcon(""); |
|
409 |
menu.setPath(""); |
|
410 |
} |
|
411 |
} |
|
412 |
|
818a01
|
413 |
/** |
H |
414 |
* 新创建菜单赋权给租户管理员 |
|
415 |
*/ |
|
416 |
|
|
417 |
private void dealPermission(MenuDO menu) { |
|
418 |
Long tenantId = menu.getTenantId(); |
7da8f1
|
419 |
RoleDO tenantRole = roleService.getTenantAdminRole(tenantId); |
818a01
|
420 |
TenantDO tenant = tenantService.getTenant(tenantId); |
H |
421 |
TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(tenant.getPackageId()); |
|
422 |
Set<Long> menuIds = tenantPackage.getMenuIds(); |
|
423 |
menuIds.add(menu.getId()); |
|
424 |
tenantPackage.setMenuIds(menuIds); |
|
425 |
tenantPackageService.updateTenantPackage(BeanUtils.toBean(tenantPackage, TenantPackageSaveReqVO.class)); |
7da8f1
|
426 |
permissionService.assignRoleMenu(tenantRole.getId(), menuIds); |
H |
427 |
// 开发者自己创建的应用菜单默认赋权给创建者所拥有的角色 |
|
428 |
//查询当前用户所拥有的角色 |
|
429 |
Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(getLoginUserId()); |
|
430 |
List<RoleDO> roles = roleService.getRoleList(roleIds); |
|
431 |
roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色 |
|
432 |
roles.removeIf(role -> tenantRole.getId().equals(role.getId())); // 移除租户管理员角色 |
|
433 |
if (!roles.isEmpty()) { |
|
434 |
roles.stream().forEach(roleDO -> { |
|
435 |
RoleMenuDO roleMenuDO = new RoleMenuDO(); |
|
436 |
roleMenuDO.setMenuId(menu.getId()); |
|
437 |
roleMenuDO.setRoleId(roleDO.getId()); |
|
438 |
roleMenuDO.setTenantId(tenant.getId()); |
|
439 |
roleMenuMapper.insert(roleMenuDO); |
|
440 |
}); |
|
441 |
} |
818a01
|
442 |
} |
H |
443 |
|
e7c126
|
444 |
} |