package com.rndchina.aisin.system.modle;

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.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * 系统角色
 */
@Entity
@Scope("prototype")
@Component
@Table(name = "sp_system_role")
public class SystemRole implements java.io.Serializable {

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

	@GeneratedValue(strategy = GenerationType.AUTO)
	 
	private String id;

	private Date createTime;
	private Date updateTime;
	private Integer version;
	private String des;
	private String roleName;
	// private Boolean superManager;
	private Integer ownerUserId;
	// private String reg;
//	private SystemOrg org;

	private String deleled;


	public String getDeleled() {
		return deleled;
	}

	public void setDeleled(String deleled) {
		this.deleled = deleled;
	}

	protected List<PlatModule> modules = new ArrayList<PlatModule>();

	// private Set<UserRole> userRoles = new HashSet<UserRole>(0);
	private List<SystemUser> systemUsers = new ArrayList<SystemUser>();

	// Constructors

	/** default constructor */
	public SystemRole() {
	}

	/** minimal constructor */

	// Property accessors
	@Id
	@Column(name = "id", length = 64)
	public String getId() {
		return this.id;
	}

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

	@Column(name = "createTime", length = 19)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "updateTime", length = 19)
	public Date getUpdateTime() {
		return this.updateTime;
	}

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

	@Column(name = "version")
	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Column(name = "des", nullable = true)
	public String getDes() {
		return this.des;
	}

	public void setDes(String des) {
		this.des = des;
	}

	@Column(name = "roleName",length = 40)
	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

/*	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "org_id")
	public SystemOrg getOrg() {
		return this.org;
	}

	public void setOrg(SystemOrg org) {
		this.org = org;
	}*/

	/*
	 * @Column(name = "superManager", nullable = true) public Boolean getSuperManager() { return this.superManager; }
	 * 
	 * public void setSuperManager(Boolean superManager) { this.superManager = superManager; }
	 */

	@Column(name = "ownerUser_id", nullable = true)
	public Integer getOwnerUserId() {
		return this.ownerUserId;
	}

	public void setOwnerUserId(Integer ownerUserId) {
		this.ownerUserId = ownerUserId;
	}

/*	@Column(name = "reg", nullable = true)
	public String getReg() {
		return reg;
	}

	public void setReg(String reg) {
		this.reg = reg;
	}*/

	/*
	 * public void setModules(List<PlatModule> modules) { this.modules = modules; }
	 * 
	 * @XmlTransient public List<PlatModule> getModules() { return Collections.unmodifiableList(modules); }
	 */

	public void addModules(PlatModule module) {
		this.modules.add(module);
	}

	/**
	 * 角色拥有的命令
	 */
	@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinTable(name = "systemRole_platModule", joinColumns = { @JoinColumn(name = "roleID", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "commandID", referencedColumnName = "id") })
	@OrderBy("orderNum")
	public List<PlatModule> getModules() {
		return modules;
	}

	public void setModules(List<PlatModule> modules) {
		this.modules = modules;
	}

	public void removeModule(PlatModule module) {
		this.modules.remove(module);
	}

	public void clearModule() {
		modules.clear();
	}

	@ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "systemRoles", fetch = FetchType.LAZY)
	public List<SystemUser> getSystemUsers() {
		return systemUsers;
	}

	public void setSystemUsers(List<SystemUser> systemUsers) {
		this.systemUsers = systemUsers;
	}

	/*
	 * @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role") public Set<UserRole> getUserRoles() { return this.userRoles; }
	 * 
	 * public void setUserRoles(Set<UserRole> userRoles) { this.userRoles = userRoles; }
	 */

}