|  |  | 
 |  |  | package com.moral.api.pojo.vo.menu; | 
 |  |  |  | 
 |  |  | import com.moral.api.pojo.dto.menu.MenuQueryDto; | 
 |  |  | import com.fasterxml.jackson.annotation.JsonInclude; | 
 |  |  | import com.moral.api.entity.Menu; | 
 |  |  | import com.moral.api.pojo.dto.menu.MenuDTO; | 
 |  |  | import com.moral.api.pojo.dto.menu.MenuQueryDTO; | 
 |  |  | import com.moral.constant.ResponseCodeEnum; | 
 |  |  | import lombok.Data; | 
 |  |  | import org.springframework.util.ObjectUtils; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Collections; | 
 |  |  | import java.util.Comparator; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |  * @Version TODO | 
 |  |  |  **/ | 
 |  |  | @Data | 
 |  |  | @JsonInclude(JsonInclude.Include.NON_EMPTY) | 
 |  |  | public class MenuQueryVO { | 
 |  |  |  | 
 |  |  |     List<MenuVO> vos; | 
 |  |  |     List<MenuVO> menus; | 
 |  |  |  | 
 |  |  |     public static MenuQueryVO convert(MenuQueryDto dto){ | 
 |  |  |         return null; | 
 |  |  |     public static MenuQueryVO convert(MenuQueryDTO dto) { | 
 |  |  |         if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode()) | 
 |  |  |             return null; | 
 |  |  |         MenuQueryVO vo = new MenuQueryVO(); | 
 |  |  |         List<MenuDTO> dtos = dto.getDtos(); | 
 |  |  |         List<MenuVO> vos = new ArrayList<>(); | 
 |  |  |         for (MenuDTO menuDTO : dtos) { | 
 |  |  |             MenuVO menuVO = convertToQueryPage(menuDTO); | 
 |  |  |             vos.add(menuVO); | 
 |  |  |         } | 
 |  |  |         //对根目录进行排序 | 
 |  |  |         Collections.sort(vos, new Comparator<MenuVO>() { | 
 |  |  |             @Override | 
 |  |  |             public int compare(MenuVO o1, MenuVO o2) { | 
 |  |  |                 return o1.getOrder() - o2.getOrder(); | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |         vo.setMenus(vos); | 
 |  |  |         return vo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private static MenuVO convertToQueryPage(MenuDTO dto) { | 
 |  |  |         Menu menu = dto.getMenu(); | 
 |  |  |         MenuVO menuVO = convertToQueryPage(menu); | 
 |  |  |         return menuVO; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private static MenuVO convertToQueryPage(Menu menu) { | 
 |  |  |         MenuVO vo = new MenuVO(); | 
 |  |  |         vo.setId(menu.getId()); | 
 |  |  |         vo.setParentId(menu.getParentId()); | 
 |  |  |         vo.setUrl(menu.getUrl()); | 
 |  |  |         vo.setIcon(menu.getIcon()); | 
 |  |  |         vo.setName(menu.getName()); | 
 |  |  |         vo.setOrder(menu.getOrder()); | 
 |  |  |         List<MenuVO> vos = new ArrayList<>(); | 
 |  |  |         List<Menu> children = menu.getChildren(); | 
 |  |  |         if (!ObjectUtils.isEmpty(children)) { | 
 |  |  |             //对children进行排序,按照order字段 | 
 |  |  |             Collections.sort(children, new Comparator<Menu>() { | 
 |  |  |                 @Override | 
 |  |  |                 public int compare(Menu o1, Menu o2) { | 
 |  |  |                     return o1.getOrder() - o2.getOrder(); | 
 |  |  |                 } | 
 |  |  |             }); | 
 |  |  |             for (Menu child : children) { | 
 |  |  |                 MenuVO menuVO = convertToQueryPage(child); | 
 |  |  |                 vos.add(menuVO); | 
 |  |  |             } | 
 |  |  |             vo.setChildren(vos); | 
 |  |  |         } | 
 |  |  |         return vo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  |  |