Showing
1 changed file
with
34 additions
and
7 deletions
@@ -249,13 +249,17 @@ public class SysRoleServiceImpl extends AbstractBaseService<RoleMapper, SysRoleE | @@ -249,13 +249,17 @@ public class SysRoleServiceImpl extends AbstractBaseService<RoleMapper, SysRoleE | ||
249 | .eq(SysRoleEntity::getRoleType, RoleEnum.CUSTOMER_USER.name())); | 249 | .eq(SysRoleEntity::getRoleType, RoleEnum.CUSTOMER_USER.name())); |
250 | customerRoles.forEach(cr -> menuMapper.removeMenuFromRole(cr.getId(), removeMenus)); | 250 | customerRoles.forEach(cr -> menuMapper.removeMenuFromRole(cr.getId(), removeMenus)); |
251 | } | 251 | } |
252 | - newMenus.forEach( | ||
253 | - menu -> { | ||
254 | - SysTenantMenuEntity tenantMenu = new SysTenantMenuEntity(); | ||
255 | - tenantMenu.setMenuId(menu); | ||
256 | - tenantMenu.setTenantId(updateTenantId); | ||
257 | - tenantMenuMapper.insert(tenantMenu); | ||
258 | - }); | 252 | + if (!newMenus.isEmpty()) { |
253 | + // 如果新增的菜单,在该租户下的另外一个角色已经存在了,就不需要再插入数据库 | ||
254 | + List<String> chechResultList = checkNewMenus(updateTenantId, newMenus); | ||
255 | + chechResultList.forEach( | ||
256 | + menu -> { | ||
257 | + SysTenantMenuEntity tenantMenu = new SysTenantMenuEntity(); | ||
258 | + tenantMenu.setMenuId(menu); | ||
259 | + tenantMenu.setTenantId(updateTenantId); | ||
260 | + tenantMenuMapper.insert(tenantMenu); | ||
261 | + }); | ||
262 | + } | ||
259 | }); | 263 | }); |
260 | } | 264 | } |
261 | cacheUtils.invalidateCacheName(FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY); | 265 | cacheUtils.invalidateCacheName(FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY); |
@@ -283,4 +287,27 @@ public class SysRoleServiceImpl extends AbstractBaseService<RoleMapper, SysRoleE | @@ -283,4 +287,27 @@ public class SysRoleServiceImpl extends AbstractBaseService<RoleMapper, SysRoleE | ||
283 | } | 287 | } |
284 | return baseMapper.findRoleInfo(roleDTO); | 288 | return baseMapper.findRoleInfo(roleDTO); |
285 | } | 289 | } |
290 | + | ||
291 | + private List<String> checkNewMenus(String tenantId, List<String> newMenus) { | ||
292 | + List<SysTenantMenuEntity> existEntities = | ||
293 | + tenantMenuMapper.selectList( | ||
294 | + new LambdaQueryWrapper<SysTenantMenuEntity>() | ||
295 | + .eq(SysTenantMenuEntity::getTenantId, tenantId) | ||
296 | + .in(SysTenantMenuEntity::getMenuId, newMenus)); | ||
297 | + if (!existEntities.isEmpty()) { | ||
298 | + List<String> existMenuIds = | ||
299 | + existEntities.stream().map(SysTenantMenuEntity::getMenuId).collect(Collectors.toList()); | ||
300 | + List<String> tempList = existMenuIds; | ||
301 | + for (String newMenu : newMenus) { | ||
302 | + for (String menuId : existMenuIds) { | ||
303 | + if (Objects.equals(menuId, newMenu)) { | ||
304 | + tempList.remove(newMenu); | ||
305 | + break; | ||
306 | + } | ||
307 | + } | ||
308 | + } | ||
309 | + return tempList; | ||
310 | + } | ||
311 | + return newMenus; | ||
312 | + } | ||
286 | } | 313 | } |