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

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "sys_menu")
public class Menu extends BaseEntity {
	private static final long serialVersionUID = 6811966432418492127L;
	private String parentId;
	private String menuName;
	private String menuUrl;
	private Date insertDate;
	private Date updateDate;
	private String menuIcon;
	private String menuOrder;
	
	private List<Menu> children;
	/**
	 * 子节点数量
	 */
    private int subCount;
	/**
	 * 是否存在父节点,不持久化
	 */
	private boolean isParent;

	 @Column(name = "parent_id") 
	public String getParentId() {
		return parentId;
	}
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	@Column(name = "menu_name") 
	public String getMenuName() {
		return menuName;
	}
	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}
	@Column(name = "menu_url") 
	public String getMenuUrl() {
		return menuUrl;
	}
	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}
	@Column(name = "insert_date", updatable = false) 
	public Date getInsertDate() {
		return insertDate;
	}
	public void setInsertDate(Date insertDate) {
		this.insertDate = insertDate;
	}
	@Column(name = "update_date", insertable = false) 
	public Date getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	@Column(name = "menu_icon" , insertable = false , updatable = false) 
	public String getMenuIcon() {
		return menuIcon;
	}
	public void setMenuIcon(String menuIcon) {
		this.menuIcon = menuIcon;
	}
	@Column(name = "menu_order") 
	public String getMenuOrder() {
		return menuOrder;
	}
	public void setMenuOrder(String menuOrder) {
		this.menuOrder = menuOrder;
	}
	@Transient
	public List<Menu> getChildren() {
		return children;
	}
	public void setChildren(List<Menu> children) {
		this.children = children;
	}
	@Column(name = "sub_count") 
	public int getSubCount() {
		return subCount;
	}
	public void setSubCount(int subCount) {
		this.subCount = subCount;
	}
	@Transient
	public boolean getIsParent() {
		  if (isParent == true) {
	            return true;
	        } else {
	            return subCount > 0;
	        }
	}
	public void setParent(boolean isParent) {
		this.isParent = isParent;
	}

}
