package com.moral.api.pojo.vo.login;
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.moral.api.entity.ManageAccount;
|
import com.moral.api.entity.ManageMenu;
|
import com.moral.api.entity.ManageRole;
|
import com.moral.api.pojo.redisBean.AccountInfoDTO;
|
import lombok.Data;
|
import org.springframework.util.ObjectUtils;
|
|
import java.util.*;
|
|
/**
|
* @ClassName AccountInfoVO
|
* @Description TODO
|
* @Author 陈凯裕
|
* @Date 2021/3/13 16:11
|
* @Version TODO
|
**/
|
@Data
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
public class AccountInfoVO {
|
/*
|
* 用户Id
|
* */
|
private Integer accountId;
|
|
/*
|
* 用户名称
|
* */
|
private String userName;
|
|
|
/*
|
* 用户角色
|
* */
|
private List<String> roleNames;
|
|
/*
|
* 用户菜单
|
* */
|
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) {
|
AccountInfoVO vo = new AccountInfoVO();
|
ManageAccount account = dto.getAccount();
|
List<ManageMenu> menus = dto.getMenus();
|
List<ManageRole> roles = dto.getRoles();
|
//封装roleNames
|
ArrayList<String> roleNames = new ArrayList<>();
|
if (!ObjectUtils.isEmpty(roles)) {
|
roles.forEach(role -> roleNames.add(role.getName()));
|
}
|
/*过滤menu无用属性*/
|
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());
|
vo.setMenus(menus);
|
vo.setRoleNames(roleNames);
|
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;
|
}
|
}
|
|
|
}
|