kaiyu
2021-04-23 726b056fc2d3b51acdeb0b5fbaf74c8886acc2ac
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
package com.moral.api.pojo.vo.account;
 
import com.fasterxml.jackson.annotation.JsonInclude;
import com.moral.api.entity.ManageAccount;
import com.moral.api.entity.ManageRole;
import com.moral.api.pojo.dto.account.AccountDTO;
import com.moral.api.pojo.dto.account.AccountQueryDTO;
import com.moral.constant.ResponseCodeEnum;
import lombok.Data;
import org.springframework.util.ObjectUtils;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @ClassName AccountPageVO
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/3/15 13:25
 * @Version TODO
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AccountQueryVO {
 
    private long pages;
 
    private long total;
 
    private long current;
 
    private long size;
 
    private List<AccountVO> accountVOs;
 
    public static AccountQueryVO convert(AccountQueryDTO dto) {
        if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode())
            return null;
 
        long total = dto.getTotal();
        long current = dto.getCurrent();
        long pages = dto.getPages();
        long size = dto.getSize();
        List<AccountVO> accountVOs = new ArrayList<>();
        List<AccountDTO> accountDTOs = dto.getAccountDTOS();
        if (!ObjectUtils.isEmpty(accountDTOs)) {
            for (AccountDTO accountDTO : accountDTOs) {
                AccountVO vo = convertToQueryPage(accountDTO);
                accountVOs.add(vo);
            }
        }
        AccountQueryVO vo = new AccountQueryVO();
        vo.setTotal(total);
        vo.setAccountVOs(accountVOs);
        vo.setCurrent(current);
        vo.setPages(pages);
        vo.setSize(size);
        return vo;
    }
 
    public static AccountVO convertToQueryPage(AccountDTO dto) {
        if (dto.getAccount() == null)
            return null;
        AccountVO vo = new AccountVO();
        ManageAccount account = dto.getAccount();
        List<ManageRole> roles = dto.getRoles();
        if(!ObjectUtils.isEmpty(roles)){
            roles.forEach(value-> {
                value.setIsDelete(null);
                value.setCreateTime(null);
                value.setUpdateTime(null);
                value.setDesc(null);
            });
        }
        vo.setId(account.getId());
        vo.setAccount(account.getAccount());
        vo.setUserName(account.getUserName());
        vo.setEmail(account.getEmail());
        vo.setMobile(account.getMobile());
        vo.setWechat(account.getWechat());
        vo.setRoles(roles);
        //Date转换String
        Date createTime = account.getCreateTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createTimeStr = sdf.format(createTime);
        vo.setCreateTime(createTimeStr);
        return vo;
    }
}