kaiyu
2021-03-15 7f56cfa5ec12682d53809e0f4d77a8f3277d36a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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.dto.login.AccountInfoDTO;
import lombok.Data;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @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<>();
        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);
            }
        }
        vo.setAccountId(account.getId());
        vo.setUserName(account.getUserName());
        vo.setMenus(menus);
        vo.setRoleNames(roleNames);
        return vo;
    }
 
}