【修复】优化代码,优化登录查询
This commit is contained in:
parent
26be7b16c2
commit
44b5239f34
@ -44,11 +44,12 @@ public interface SysAppService extends IService<SysApp> {
|
||||
* 获取用户应用相关信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roleIdList 角色id集合
|
||||
* @return 用户拥有的应用信息,格式:[{"code":"system","name":"系统应用","active":true}]
|
||||
* @author xuyuxiang
|
||||
* @date 2020/3/13 16:25
|
||||
*/
|
||||
List<Dict> getLoginApps(Long userId);
|
||||
List<Dict> getLoginApps(Long userId, List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 查询系统应用
|
||||
|
@ -68,7 +68,7 @@ public class SysAppServiceImpl extends ServiceImpl<SysAppMapper, SysApp> impleme
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Override
|
||||
public List<Dict> getLoginApps(Long userId) {
|
||||
public List<Dict> getLoginApps(Long userId, List<Long> roleIdList) {
|
||||
List<Dict> userAppDictList = CollectionUtil.newArrayList();
|
||||
|
||||
LambdaQueryWrapper<SysApp> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@ -81,7 +81,7 @@ public class SysAppServiceImpl extends ServiceImpl<SysAppMapper, SysApp> impleme
|
||||
//如果不是超级管理员则有自己的菜单对应的应用编码
|
||||
if (!AdminTypeEnum.SUPER_ADMIN.getCode().equals(adminType)) {
|
||||
//获取用户菜单对应的应用编码集合
|
||||
List<String> appCodeList = sysMenuService.getUserMenuAppCodeList(userId);
|
||||
List<String> appCodeList = sysMenuService.getUserMenuAppCodeList(userId, roleIdList);
|
||||
//当应用编码不为空时,则限制查询范围
|
||||
if (ObjectUtil.isNotEmpty(appCodeList)) {
|
||||
queryWrapper.in(SysApp::getCode, appCodeList);
|
||||
|
@ -25,6 +25,7 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
||||
package vip.xiaonuo.sys.modular.role.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import vip.xiaonuo.sys.modular.role.entity.SysRoleMenu;
|
||||
@ -34,6 +35,7 @@ import vip.xiaonuo.sys.modular.role.service.SysRoleMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统角色菜单service接口实现类
|
||||
@ -46,15 +48,13 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRo
|
||||
|
||||
@Override
|
||||
public List<Long> getRoleMenuIdList(List<Long> roleIdList) {
|
||||
List<Long> menuIdList = CollectionUtil.newArrayList();
|
||||
|
||||
LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.in(SysRoleMenu::getRoleId, roleIdList);
|
||||
|
||||
this.list(queryWrapper).forEach(sysRoleMenu -> menuIdList.add(sysRoleMenu.getMenuId()));
|
||||
|
||||
return menuIdList;
|
||||
if(ObjectUtil.isNotEmpty(roleIdList)) {
|
||||
LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRoleMenu::getRoleId, roleIdList);
|
||||
return this.list(queryWrapper).stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
|
||||
} else {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,6 +37,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统用户角色service接口实现类
|
||||
@ -52,11 +53,9 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
||||
|
||||
@Override
|
||||
public List<Long> getUserRoleIdList(Long userId) {
|
||||
List<Long> roleIdList = CollectionUtil.newArrayList();
|
||||
LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUserRole::getUserId, userId);
|
||||
this.list(queryWrapper).forEach(sysUserRole -> roleIdList.add(sysUserRole.getRoleId()));
|
||||
return roleIdList;
|
||||
return this.list(queryWrapper).stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,6 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
||||
*/
|
||||
package vip.xiaonuo.core;
|
||||
|
||||
import vip.xiaonuo.SnowyApplication;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@ -33,6 +32,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import vip.xiaonuo.SnowyApplication;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user