mirror of https://gitee.com/maxjhandsome/pig
fixed 菜单排序问题
This commit is contained in:
parent
6b023a2b08
commit
533732d107
|
@ -5,6 +5,7 @@ import com.github.pig.common.vo.MenuVO;
|
|||
import com.github.pig.gateway.feign.MenuService;
|
||||
import com.github.pig.gateway.service.PermissionService;
|
||||
import com.xiaoleilu.hutool.collection.CollectionUtil;
|
||||
import com.xiaoleilu.hutool.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
@ -41,13 +42,15 @@ public class PermissionServiceImpl implements PermissionService {
|
|||
|
||||
if (principal != null) {
|
||||
if (CollectionUtil.isEmpty(grantedAuthorityList)) {
|
||||
log.warn("角色列表为空:{}",authentication.getPrincipal());
|
||||
log.warn("角色列表为空:{}", authentication.getPrincipal());
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
Set<MenuVO> urls = new HashSet<>();
|
||||
for (SimpleGrantedAuthority authority : grantedAuthorityList) {
|
||||
urls.addAll(menuService.findMenuByRole(authority.getAuthority()));
|
||||
if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) {
|
||||
urls.addAll(menuService.findMenuByRole(authority.getAuthority()));
|
||||
}
|
||||
}
|
||||
|
||||
for (MenuVO menu : urls) {
|
||||
|
|
Binary file not shown.
|
@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
|
@ -33,7 +32,7 @@ public class MenuController extends BaseController {
|
|||
* @return 菜单列表
|
||||
*/
|
||||
@GetMapping("/findMenuByRole/{role}")
|
||||
public Set<MenuVO> findMenuByRole(@PathVariable String role) {
|
||||
public List<MenuVO> findMenuByRole(@PathVariable String role) {
|
||||
return sysMenuService.findMenuByRole(role);
|
||||
}
|
||||
|
||||
|
@ -65,7 +64,7 @@ public class MenuController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/userTree")
|
||||
public List<Integer> userTree() {
|
||||
Set<MenuVO> menus = sysMenuService.findMenuByRole(getRole().get(0));
|
||||
List<MenuVO> menus = sysMenuService.findMenuByRole(getRole().get(0));
|
||||
List<Integer> menuList = new ArrayList<>();
|
||||
for (MenuVO menuVo : menus) {
|
||||
menuList.add(menuVo.getMenuId());
|
||||
|
@ -81,7 +80,7 @@ public class MenuController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/roleTree/{roleName}")
|
||||
public List<Integer> roleTree(@PathVariable String roleName) {
|
||||
Set<MenuVO> menus = sysMenuService.findMenuByRole(roleName);
|
||||
List<MenuVO> menus = sysMenuService.findMenuByRole(roleName);
|
||||
List<Integer> menuList = new ArrayList<>();
|
||||
for (MenuVO menuVo : menus) {
|
||||
menuList.add(menuVo.getMenuId());
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.pig.admin.model.entity.SysMenu;
|
|||
import com.github.pig.common.vo.MenuVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -23,5 +24,5 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
|||
* @param role 角色名称
|
||||
* @return 菜单列表
|
||||
*/
|
||||
Set<MenuVO> findMenuByRoleName(@Param("role") String role);
|
||||
List<MenuVO> findMenuByRoleName(@Param("role") String role);
|
||||
}
|
|
@ -7,7 +7,6 @@ import com.github.pig.admin.model.entity.SysMenu;
|
|||
import com.github.pig.common.vo.MenuVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -24,7 +23,7 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
* @param role 角色名称
|
||||
* @return 菜单列表
|
||||
*/
|
||||
Set<MenuVO> findMenuByRole(String role);
|
||||
List<MenuVO> findMenuByRole(String role);
|
||||
|
||||
/**
|
||||
* 通过角色获取菜单权限列表
|
||||
|
|
|
@ -36,7 +36,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
|
||||
@Override
|
||||
@Cacheable(value = "menu_details", key = "#role + '_menu'")
|
||||
public Set<MenuVO> findMenuByRole(String role) {
|
||||
public List<MenuVO> findMenuByRole(String role) {
|
||||
return sysMenuMapper.findMenuByRoleName(role);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
public String[] findPermission(String[] roles) {
|
||||
Set<MenuVO> menuVoSet = new HashSet<>();
|
||||
for (String role : roles) {
|
||||
Set<MenuVO> menuVos = findMenuByRole(role);
|
||||
List<MenuVO> menuVos = findMenuByRole(role);
|
||||
menuVoSet.addAll(menuVos);
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Override
|
||||
public List<MenuTree> findUserMenuTree(String roleName) {
|
||||
// 获取符合条件得菜单
|
||||
Set<MenuVO> all = findMenuByRole(roleName);
|
||||
List<MenuVO> all = findMenuByRole(roleName);
|
||||
final List<MenuTree> menuTreeList = new ArrayList<>();
|
||||
all.forEach((menuVo -> {
|
||||
if (CommonConstant.MENU.equals(menuVo.getType())) {
|
||||
|
|
|
@ -48,6 +48,6 @@
|
|||
sys_role.del_flag = 0
|
||||
AND sys_menu.del_flag = 0
|
||||
AND sys_role.role_code = #{role}
|
||||
ORDER BY sys_menu.sort ASC
|
||||
ORDER BY sys_menu.sort DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue