package cn.com.liandisys.ycjt.ggcx.admin.utils;

import java.util.Collection;

/**
 * Predicate模型对象
 * 
 * @author 袁晓冬
 * 
 */
public class PredicateModel {
	/**
	 * 条件类型
	 * 
	 * @author 袁晓冬
	 * 
	 */
	public enum Operator {
		EQ, LIKE, LIKE_L, LIKE_R, GT, LT, GTE, LTE,
		/** IS NULL */
		NL, IN,
		/** IS NOT NULL */
		NNL,
		/**
		 * NOT EQUAL
		 */
		NEQ
	}

	/**
	 * 子模型连接方式
	 * 
	 * @author 袁晓冬
	 * 
	 */
	public enum JoinType {
		AND, OR
	}

	/** 查询字段名称 */
	private String fieldName;
	/** 查询字段值 */
	private Object value;
	/** 条件类型 */
	private Operator operator;
	/** 子模型链接方式（AND OR) */
	private JoinType joinType;
	/** 子模型集合 */
	private Collection<PredicateModel> subPms;

	/**
	 * 构造无下级的模型对象
	 * 
	 * @param fieldName
	 * @param value
	 * @param operator
	 */
	public PredicateModel(String fieldName, Object value, Operator operator) {
		this(fieldName, value, operator, JoinType.AND);
	}

	/**
	 * 构造无下级的模型对象
	 * 
	 * @param fieldName
	 * @param value
	 * @param operator
	 * @param type
	 */
	public PredicateModel(String fieldName, Object value, Operator operator,
			JoinType type) {
		this.fieldName = fieldName;
		this.value = value;
		this.operator = operator;
		this.joinType = type;
	}

	/**
	 * 构造带下级模型的对象，模型之间用指定的type(AND OR)连接
	 * 
	 * @param type
	 * @param subPms
	 */
	public PredicateModel(JoinType type, Collection<PredicateModel> subPms) {
		this.joinType = type;
		this.subPms = subPms;
	}

	public PredicateModel() {

	}

	/**
	 * 查询字段名称
	 * 
	 * @return
	 */
	public String getFieldName() {
		return fieldName;
	}

	/**
	 * 条件类型
	 * 
	 * @return
	 */
	public Operator getOperator() {
		return operator;
	}

	/**
	 * 子模型集合
	 * 
	 * @return
	 */
	public Collection<PredicateModel> getSubPms() {
		return subPms;
	}

	/**
	 * 子模型链接方式（AND OR)
	 * 
	 * @return
	 */
	public JoinType getJoinType() {
		return joinType;
	}

	/**
	 * 查询字段值
	 * 
	 * @return
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * 是否包含下级模型
	 * 
	 * @return
	 */
	public boolean hasSubPredicateModel() {
		return null != subPms && subPms.size() > 0;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public void setOperator(Operator operator) {
		this.operator = operator;
	}

	public void setSubPms(Collection<PredicateModel> subPms) {
		this.subPms = subPms;
	}

	public void setJoinType(JoinType type) {
		this.joinType = type;
	}

	public void setValue(Object value) {
		this.value = value;
	}

}
