package com.uas.platform.b2b.model;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;

/**
 * 用户简单信息
 * 
 * @author yingp
 * 
 */
public class UserInfo {

	public UserInfo(User user) {
		this.userUU = user.getUserUU();
		this.userEmail = user.getUserEmail();
		this.userName = user.getUserName();
		this.userTel = user.getUserTel();
		this.userSex = user.getUserSex();
		if (user.getRoles() != null && user.getRoles().size() > 0) {
			StringBuffer sb = new StringBuffer();
			for (Role role : user.getRoles()) {
				if (sb.length() > 0)
					sb.append(" ");
				sb.append(role.getDesc());
			}
			this.role = sb.toString();
		}
	}

	public static Page<UserInfo> getUserInfo(Page<User> page) {
		List<UserInfo> infos = new ArrayList<UserInfo>();
		if (page != null && page.getContent() != null && !page.getContent().isEmpty()) {
			for (User user : page.getContent()) {
				infos.add(new UserInfo(user));
			}
		}
		return new PageImpl<UserInfo>(infos);
	}

	private Long userUU;

	private String userName;

	private String userEmail;

	private String userTel;

	private String userSex;

	private String role;

	public Long getUserUU() {
		return userUU;
	}

	public void setUserUU(Long userUU) {
		this.userUU = userUU;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public String getUserTel() {
		return userTel;
	}

	public void setUserTel(String userTel) {
		this.userTel = userTel;
	}

	public String getUserSex() {
		return userSex;
	}

	public void setUserSex(String userSex) {
		this.userSex = userSex;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

}
