kaiyu
2021-04-16 895136cb544ae2f46cd76d184ec14760e82353a7
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
package com.moral.api.pojo.vo.account;
 
import com.fasterxml.jackson.annotation.JsonInclude;
import com.moral.api.entity.ManageRole;
import com.moral.api.pojo.dto.account.AccountDTO;
import com.moral.constant.ResponseCodeEnum;
import lombok.Data;
import org.springframework.util.ObjectUtils;
 
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 AccountInsertVO extends AccountVO {
 
    /**
     * @Description: 用于插入账户返回数据使用
     * @Param: [dto]
     * @return: com.moral.api.pojo.vo.account.AccountVO
     * @Author: 陈凯裕
     * @Date: 2021/3/15
     */
 
    public static AccountInsertVO convert(AccountDTO dto) {
        if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode())
            return null;
 
        AccountInsertVO vo = new AccountInsertVO();
        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();
        //转换成角色名集合
        List<ManageRole> roles = dto.getRoles();
        List<String> roleNames = new ArrayList<>();
        if (!ObjectUtils.isEmpty(roles)) {
            roles.forEach(role -> roleNames.add(role.getName()));
        }
        vo.setId(id);
        vo.setUserName(userName);
        vo.setEmail(email);
        vo.setMobile(mobile);
        vo.setWechat(wechat);
        vo.setRoleNames(roleNames);
 
        return vo;
    }
 
}