From f97762a1584cd80883abc03db8d839e566e88b49 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Tue, 08 Jun 2021 11:11:29 +0800 Subject: [PATCH] screen-manage 后台登陆获取菜单添加排序功能 --- screen-manage/src/main/java/com/moral/api/pojo/vo/login/AccountInfoVO.java | 88 +++++++++++++++++++++++++++++++++---------- 1 files changed, 67 insertions(+), 21 deletions(-) diff --git a/screen-manage/src/main/java/com/moral/api/pojo/vo/login/AccountInfoVO.java b/screen-manage/src/main/java/com/moral/api/pojo/vo/login/AccountInfoVO.java index 4edf55a..1c870d0 100644 --- a/screen-manage/src/main/java/com/moral/api/pojo/vo/login/AccountInfoVO.java +++ b/screen-manage/src/main/java/com/moral/api/pojo/vo/login/AccountInfoVO.java @@ -6,9 +6,9 @@ import com.moral.api.entity.ManageRole; import com.moral.api.pojo.dto.login.AccountInfoDTO; import lombok.Data; +import org.springframework.util.ObjectUtils; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * @ClassName AccountInfoVO @@ -42,33 +42,31 @@ private List<ManageMenu> menus; /** - * @Description: DTO������VO - * @Param: [dto] - * @return: com.moral.api.pojo.vo.login.AccountInfoVO - * @Author: ��������� - * @Date: 2021/3/13 - */ - public static AccountInfoVO convert(AccountInfoDTO dto){ + * @Description: DTO������VO + * @Param: [dto] + * @return: com.moral.api.pojo.vo.login.AccountInfoVO + * @Author: ��������� + * @Date: 2021/3/13 + */ + public static AccountInfoVO convert(AccountInfoDTO dto) { AccountInfoVO vo = new AccountInfoVO(); ManageAccount account = dto.getAccount(); List<ManageMenu> menus = dto.getMenus(); List<ManageRole> roles = dto.getRoles(); //������roleNames ArrayList<String> roleNames = new ArrayList<>(); - roles.forEach(role->roleNames.add(role.getName())); + if (!ObjectUtils.isEmpty(roles)) { + roles.forEach(role -> roleNames.add(role.getName())); + } /*������menu������������*/ - for (ManageMenu menu : menus) { - menu.setCreateTime(null); - menu.setIsDelete(null); - menu.setUpdateTime(null); - menu.setParentId(null); - List<ManageMenu> children = menu.getChildren(); - for (ManageMenu child : children) { - child.setCreateTime(null); - child.setIsDelete(null); - child.setUpdateTime(null); - child.setParentId(null); + if (!ObjectUtils.isEmpty(menus)) { + for (ManageMenu menu : menus) { + removeAttribute(menu); } + } + //menu������������ + if (!ObjectUtils.isEmpty(menus)) { + orderRootMenu(menus); } vo.setAccountId(account.getId()); vo.setUserName(account.getUserName()); @@ -77,4 +75,52 @@ return vo; } + public static void removeAttribute(ManageMenu menu) { + menu.setCreateTime(null); + menu.setIsDelete(null); + menu.setUpdateTime(null); + menu.setParentId(null); + if (ObjectUtils.isEmpty(menu.getChildren())) + return; + List<ManageMenu> children = menu.getChildren(); + for (ManageMenu child : children) { + removeAttribute(child); + } + } + + + /** + * @Description: ������������������������ + * @Param: [menus] + * @return: void + * @Author: ��������� + * @Date: 2021/6/8 + */ + public static void orderRootMenu(List<ManageMenu> menus){ + menus.sort(Comparator.comparing(ManageMenu::getOrder)); + for (ManageMenu menu : menus) { + orderMenu(menu); + } + } + + /** + * @Description: ��������������������������� + * @Param: [menu] + * @return: void + * @Author: ��������� + * @Date: 2021/6/8 + */ + public static void orderMenu(ManageMenu menu){ + List<ManageMenu> children = menu.getChildren(); + if(!ObjectUtils.isEmpty(children)){ + children.sort(Comparator.comparing(ManageMenu::getOrder)); + for (ManageMenu child : children) { + orderMenu(child); + } + }else{ + return; + } + } + + } -- Gitblit v1.8.0