kaiyu
2021-03-15 2ddf3630707aa6515f8c193334f928d5255542cd
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.moral.api.pojo.vo;
 
import com.fasterxml.jackson.annotation.JsonInclude;
import com.moral.api.entity.ManageRole;
import com.moral.api.pojo.dto.AccountDTO;
import lombok.Data;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @ClassName AccountVO
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/3/13 17:25
 * @Version TODO
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AccountVO {
    /*
     * 添加成功
     * */
    public static final String SUCCESS = "0";
 
    /*
     * 账号长度不符合规则
     * */
    public static final String ACCOUNT_LENGTH_INVALID = "-1";
 
    /*
     * 密码长度不符合规则
     * */
    public static final String PASSWORD_LENGTH_INVALID = "-2";
 
    /*
     * 手机号不符合规则
     * */
    public static final String MOBILE_INVALID = "-3";
 
    /*
     * 邮箱不符合规则
     * */
    public static final String EMAIL_INVALID = "-4";
 
    /*
     * 用户名已经存在
     * */
    public static final String ACCOUNT_EXIST = "-5";
 
    /*
     * 用户名包含特殊字符
     * */
    public static final String ACCOUNT_EXIST_SPECIAL_CHAR = "-6";
 
    /*
     * 密码包含特殊字符
     * */
    public static final String PASSWORD_EXIST_SPECIAL_CHAR = "-7";
 
    private String code;
 
    private Integer id;
 
    private String userName;
 
    private String password;
 
    private String email;
 
    private String mobile;
 
    private String wechat;
 
    private String createTime;
 
    private String updateTime;
 
    private String isDelete;
 
    private List<String> roleNames;
 
    private List<ManageRole> roles;
 
    public static AccountVO convertToInsert(AccountDTO dto){
        AccountVO vo = new AccountVO();
        if(dto.getCode()==AccountDTO.SUCCESS){
            Integer id = dto.getAccount().getId();
            String userName = dto.getAccount().getUserName();
            String email = dto.getAccount().getEmail();
            String mobile = dto.getAccount().getMobile();
            String wechat = dto.getAccount().getWechat();
            String isDelete = dto.getAccount().getIsDelete();
 
            //转换成角色名集合
            List<ManageRole> roles = dto.getRoles();
            List<String> roleNames = new ArrayList<>();
            roles.forEach(role->roleNames.add(role.getName()));
 
            vo.setId(id);
            vo.setUserName(userName);
            vo.setEmail(email);
            vo.setMobile(mobile);
            vo.setWechat(wechat);
            vo.setIsDelete(isDelete);
            vo.setRoleNames(roleNames);
        }
 
        String code = dto.getCode();
        vo.setCode(code);
        return vo;
    }
 
}