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 AccountUpdateVO
|
* @Description TODO
|
* @Author 陈凯裕
|
* @Date 2021/3/15 17:35
|
* @Version TODO
|
**/
|
@Data
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
|
public class AccountUpdateVO extends AccountVO {
|
|
public static AccountUpdateVO convert(AccountDTO dto) {
|
if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode())
|
return null;
|
|
AccountUpdateVO vo = new AccountUpdateVO();
|
|
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;
|
}
|
|
}
|