package com.palmnest.dao.estateserve.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.palmnest.dao.estateserve.PushModelDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.FloorInfo;
import com.palmnest.model.PushModel;

/**
 * 推送模板DAO实现类
 *
 * @author longmeizhen
 */
@Repository("pushModelDao")
public class PushModelDaoImpl extends GenericDaoHibernate<PushModel, Integer> implements PushModelDao {
	public PushModelDaoImpl() {
		super(PushModel.class);
	}

	@Override
	public PushModel addPushModel(PushModel push) throws Exception {
		return super.save(push);
	}

	@Override
	public List<PushModel> getPushModelListByUser(int userId) throws Exception {
		StringBuilder strHQL = new StringBuilder("from PushModel where  creatorId=? and isEnabled=1 ");
		List<PushModel> list = getSession().createQuery(strHQL.toString()).setInteger(0, userId).list();
		return list;
	}

	@Override
	public PushModel getPushModel(int billType, int pushWay, String orgId)
			throws Exception {
		StringBuilder strHQL = new StringBuilder("from PushModel where  billType=? and pushWay=? and isEnabled=1 and orgId=? ");
		List<PushModel> list = getSession().createQuery(strHQL.toString()).setInteger(0, billType).setInteger(1, pushWay).setString(2, orgId).list();
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<PushModel> getPushModel(String orgId)
			throws Exception {
		StringBuilder strHQL = new StringBuilder("from PushModel where  isEnabled=1 and orgId=? ");
		List<PushModel> list = getSession().createQuery(strHQL.toString()).setString(0, orgId).list();
		return list;
	}
}
