package com.uas.platform.b2b.model;

import java.util.Set;

import javax.persistence.Cacheable;
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.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 权限
 * 
 * @author yingp
 *
 */
@Table(name = "sec$authorities")
@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "com.uas.platform.b2b.model.Authority")
public class Authority {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sec$authorities_gen")
	@SequenceGenerator(name = "sec$authorities_gen", sequenceName = "sec$authorities_seq", allocationSize = 1)
	@Column(name = "auth_id")
	private Long id;

	/**
	 * 权限名称
	 */
	@Column(name = "auth_name")
	private String name;

	/**
	 * 权限的具体作业范围描述
	 */
	@Column(name = "auth_desc")
	private String desc;

	/**
	 * 权限可操控的资源
	 */
	@ManyToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.EAGER)
	@JoinTable(name = "sec$authorityresource", joinColumns = @JoinColumn(name = "auth_id", referencedColumnName = "auth_id"), inverseJoinColumns = @JoinColumn(name = "res_id", referencedColumnName = "res_id"))
	@OrderBy("id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private Set<Resource> resources;
	
	/**
	 * 所属企业UU
	 */
	@Column(name = "auth_enuu")
	private Long enUU;

	public Long getId() {
		return id;
	}

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

	public String getName() {
		return name;
	}

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

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public Set<Resource> getResources() {
		return resources;
	}

	public void setResources(Set<Resource> resources) {
		this.resources = resources;
	}

	public Long getEnUU() {
		return enUU;
	}

	public void setEnUU(Long enUU) {
		this.enUU = enUU;
	}

}
