package com.ifish.daoImpl;

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

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ifish.dao.PushListDao;
import com.ifish.entity.PushList;
import com.ifish.enums.PushTypeEnum;
import com.ifish.hibernate.HibernateBaseDao;
import com.ifish.hibernate.Pagination;

/** 
 * @ClassName: PushListDaoImpl 
 * @Description: TODO 
 * @author ggw 
 *  
 */

@Repository
public class PushListDaoImpl extends HibernateBaseDao<PushList, Integer> implements PushListDao {

	@Override
	protected Class<PushList> getEntityClass() {
		return PushList.class;
	}

	@Override
	public Pagination<PushList> findByCriteria(Integer pushId,Integer userId,Integer firstResult, Integer pageSize) {
		//查询条件
		List<Criterion> queryList = new ArrayList<Criterion>();
		if(pushId!=null){
			Criterion criterion = Restrictions.gt("pushId", pushId);
			queryList.add(criterion);
		}
		if(userId!=null){
			Criterion criterion = Restrictions.or(Restrictions.eq("userId", userId),Restrictions.eq("pushType", PushTypeEnum.all_push.getKey()));
			queryList.add(criterion);
		}
		else{
			Criterion criterion = Restrictions.eq("pushType", PushTypeEnum.all_push.getKey());
			queryList.add(criterion);
		}
		return this.findByCriteria(firstResult, pageSize,Order.desc("pushId"), queryList.toArray(new Criterion[queryList.size()]));
	}

}
