package com.ssj.bean.sys.role.domain;

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

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.ssj.bean.common.framework.core.domain.BaseEntity;

@Entity
@Table(name = "sys_admin")
public class Admin extends BaseEntity{
	

		/**
	 * 
	 */
	private static final long serialVersionUID = 909640412919521239L;

		private String loginName; //登录名

	    private String nickName;//昵称

	    private String password;//密码

	    private Date createTime; //创建时间
	    private Date updateTime; //修改时间
	    
	    private Integer status;//2停用1启动



	    private List<AdminOrg> adminOrgList = new ArrayList<AdminOrg>();
	    private List<String> orgcodeList = new ArrayList<String>();
	    private String orgCodeStr ;
	    private String  operId;

		private List<String> jxOrgcodeList = new ArrayList<String>();
		private String jxOrgCodeStr ;
		private List<String> authorities;
	    
	    @Column(name = "login_name",updatable =false) 
		public String getLoginName() {
			return loginName;
		}

		public void setLoginName(String loginName) {
			this.loginName = loginName;
		}
		@Column(name = "nick_name") 
		public String getNickName() {
			return nickName;
		}

		public void setNickName(String nickName) {
			this.nickName = nickName;
		}
		@Column(name = "password") 
		public String getPassword() {
			return password;
		}

		public void setPassword(String password) {
			this.password = password;
		}
		@Column(name = "create_time") 
		public Date getCreateTime() {
			return createTime;
		}

		public void setCreateTime(Date createTime) {
			this.createTime = createTime;
		}
		@Column(name = "update_time") 
		public Date getUpdateTime() {
			return updateTime;
		}

		public void setUpdateTime(Date updateTime) {
			this.updateTime = updateTime;
		}

		@Column(name = "status") 
		public Integer getStatus() {
			return status;
		}

		public void setStatus(Integer status) {
			this.status = status;
		}
		@Column(name = "oper_id") 
		public String getOperId() {
			return operId;
		}

		public void setOperId(String operId) {
			this.operId = operId;
		}
		@OneToMany(cascade = { CascadeType.REFRESH}, fetch=FetchType.EAGER)
		@JoinColumn(name="adminId",updatable =false,insertable =false)
		@Fetch(FetchMode.SELECT)
		public List<AdminOrg> getAdminOrgList() {
			return adminOrgList;
		}

		public void setAdminOrgList(List<AdminOrg> adminOrgList) {
			this.adminOrgList = adminOrgList;
		}

		@Transient
		public List<String> getOrgcodeList() {
			if(orgcodeList.size()>0){
				return orgcodeList;
			}
			if(adminOrgList!=null && adminOrgList.size()>0){
				for (AdminOrg adminOrg : adminOrgList) {
					if(!adminOrg.getOrgCode().contains("SSJ-JX")){
						orgcodeList.add(adminOrg.getOrgCode().trim());
					}
				}
				return orgcodeList;
			}
			return orgcodeList;
		}

		public void setOrgcodeList(List<String> orgcodeList) {
			this.orgcodeList = orgcodeList;
		}
		@Transient
		public String getOrgCodeStr() {
			if(orgCodeStr !=null && orgCodeStr.length()>0){
				return orgCodeStr;
			}
			if(adminOrgList!=null && adminOrgList.size()>0){
				StringBuffer str =new StringBuffer();
				for (AdminOrg adminOrg : adminOrgList) {
					if(!adminOrg.getOrgCode().contains("SSJ-JX")) {
						orgcodeList.add(adminOrg.getOrgCode());
						str.append("'" + adminOrg.getOrgCode() + "'");
						str.append(",");
					}
				}
				orgCodeStr = str.substring(0, str.length()-1).toString();
				return orgCodeStr;
			}
			return "0";
		}

		public void setOrgCodeStr(String orgCodeStr) {
			this.orgCodeStr = orgCodeStr;
		}

	@Transient
	public List<String> getJxOrgcodeList() {
		 if(jxOrgcodeList !=null && jxOrgcodeList.size()>0){
		 	return  jxOrgcodeList;
		 }
		  if(adminOrgList!=null && adminOrgList.size()>0){
		  	   for (AdminOrg adminOrg : adminOrgList) {
		  	   	    if(adminOrg.getOrgCode().contains("SSJ-JX")) {
		  	   	    	  jxOrgcodeList.add(adminOrg.getOrgCode().trim());
					}
			   }
		  }
		  return   jxOrgcodeList;
	}                                                           
		                                                           
	public void setJxOrgcodeList(List<String> jxOrgcodeList) {
		this.jxOrgcodeList = jxOrgcodeList;
	}

	@Transient
	public String getJxOrgCodeStr() {
	    if(jxOrgCodeStr !=null && jxOrgCodeStr.length()>0){
				return jxOrgCodeStr;
			}
			if(adminOrgList!=null && adminOrgList.size()>0){
				StringBuffer str =new StringBuffer();
				for (AdminOrg adminOrg : adminOrgList) {
					if(adminOrg.getOrgCode().contains("SSJ-JX")) {
						jxOrgcodeList.add(adminOrg.getOrgCode());
						str.append("'" + adminOrg.getOrgCode() + "'");
						str.append(",");
					}
				}
				jxOrgCodeStr = str.substring(0, str.length()-1).toString();
				return jxOrgCodeStr;
			}
			return "0";
	}

	public void setJxOrgCodeStr(String jxOrgCodeStr) {
		this.jxOrgCodeStr = jxOrgCodeStr;
	}
	@Transient
	public List<String> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(List<String> authorities) {
		this.authorities = authorities;
	}
}
