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 lombok.Data; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.List; /** * @ClassName AccountVO * @Description TODO * @Author 陈凯裕 * @Date 2021/3/15 14:42 * @Version TODO **/ @Data @JsonInclude(JsonInclude.Include.NON_EMPTY) public class AccountVO { private Integer id; private String userName; private String email; private String mobile; private String wechat; private List roleNames; public static AccountVO convert(AccountDTO dto) { if (dto.getAccount() == null) return null; AccountVO vo = new AccountVO(); ManageAccount account = dto.getAccount(); List roles = dto.getRoles(); List roleNames = new ArrayList<>(); if (!ObjectUtils.isEmpty(roles)) { roles.forEach(role -> roleNames.add(role.getName())); } vo.setId(account.getId()); vo.setUserName(account.getUserName()); vo.setEmail(account.getEmail()); vo.setMobile(account.getMobile()); vo.setWechat(account.getWechat()); vo.setRoleNames(roleNames); return vo; } }