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