package com.qmth.qrzk.repository.user.model;

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

import com.qmth.qrzk.security.LoginUser;

/**
 * 用户表
 * @author 钟辉
 *
 */
public class User implements LoginUser{

	private Integer id; 					//主键id
	
	private Integer isEnabled;				//是否启用
	
	private Date lastLoginDate;			//最后登录时间
	
	private String name;				//用户名
	
	private String password;			//密码
	
	private String remark;				//备注
	
	private Date updateDate;			//更新时间
	
	private String loginName;			//登录名
	
	private String certino;				//身份证号	
	
	private String bankno;				//银行账号
	
	private String phone;				//电话
	
	private String email;				//eamil
	
	private String position;			//职称
	
	private String department;			//院系
	
	private String school;				//单位
	
	private String gender;				//性别
	
	private String officePhone;			//办公电话
	
	private String major;				//专业
	
	private Integer instituteId;			
	
	private Integer userType;				//用户类型
	
	private String[] role;
	
	private List<Role> roles = new ArrayList<Role>();
	
	private List<Course> courses = new ArrayList<Course>();
	
	private String guid;
	
	public String getGuid() {
		return guid;
	}
	public void setGuid(String guid) {
		this.guid = guid;
	}

	public Integer getIsEnabled() {
		return isEnabled;
	}

	public void setIsEnabled(Integer isEnabled) {
		this.isEnabled = isEnabled;
	}

	public Date getLastLoginDate() {
		return lastLoginDate;
	}

	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}

	

	public String getSchool() {
		return school;
	}

	public void setSchool(String school) {
		this.school = school;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String[] getRole() {
		return role;
	}

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

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getCertino() {
		return certino;
	}

	public void setCertino(String certino) {
		this.certino = certino;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public Integer getUserType() {
		return userType;
	}

	public String getUserTypeText() {
		if(userType == null){
			return "";
		}else if(userType == 10){
			return "命题教师";
		}else if(userType == 11){
			return "学科秘书";
		}else if(userType == 12){
			return "录入员";
		}
		return ""; 
	}

	public void setUserType(Integer userType) {
		this.userType = userType;
	}

	

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getInstituteId() {
		return instituteId;
	}

	public void setInstituteId(Integer instituteId) {
		this.instituteId = instituteId;
	}

	@Override
	public boolean isEnabled() {
		return isEnabled != null && isEnabled == 1;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public List<Course> getCourses() {
		return courses;
	}

	public void setCourses(List<Course> courses) {
		this.courses = courses;
	}
	
	public String getRoleString(){
		if(roles != null){
			StringBuffer sb = new StringBuffer();
			for(Role role : roles){
				sb.append(role.getName()).append(" ; ");
			}
			return sb.toString();
		}else{
			return "";
		}
	}
	
	public String getCourseString(){
		if(courses != null){
			StringBuffer sb = new StringBuffer();
			for(Course course : courses){
				sb.append(course.getCode()).append("-").append(course.getName()).append(" ; ");
			}
			return sb.toString();
		}else{
			return "";
		}
	}

	public User(String loginName) {
		super();
		this.loginName = loginName;
	}

	public User() {
		super();
		// TODO Auto-generated constructor stub
	}

	public User(Integer isEnabled, String name, String password, String loginName,
			Integer userType) {
		super();
		this.isEnabled = isEnabled;
		this.name = name;
		this.password = password;
		this.loginName = loginName;
		this.userType = userType;
	}

	public User(Integer id, String password) {
		super();
		this.id = id;
		this.password = password;
	}

	public User(Integer id, String name, String loginName) {
		super();
		this.id = id;
		this.name = name;
		this.loginName = loginName;
	}

	public User(Integer id, Integer isEnabled, Date lastLoginDate, String name,
			String password, String remark, Date updateDate, String loginName,
			String certino, String phone, String email, String position,
			String department, Integer instituteId, Integer userType, List<Role> roles,
			List<Course> courses) {
		super();
		this.id = id;
		this.isEnabled = isEnabled;
		this.lastLoginDate = lastLoginDate;
		this.name = name;
		this.password = password;
		this.remark = remark;
		this.updateDate = updateDate;
		this.loginName = loginName;
		this.certino = certino;
		this.phone = phone;
		this.email = email;
		this.position = position;
		this.department = department;
		this.instituteId = instituteId;
		this.userType = userType;
		this.roles = roles;
		this.courses = courses;
	}
	
	public String getOfficePhone() {
		return officePhone;
	}
	public void setOfficePhone(String officePhone) {
		this.officePhone = officePhone;
	}
	public String getMajor() {
		return major;
	}
	public void setMajor(String major) {
		this.major = major;
	}
	public String getBankno() {
		return bankno;
	}
	public void setBankno(String bankno) {
		this.bankno = bankno;
	}
}
