package com.palmnest.dao.estateserve.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.palmnest.application.core.util.DateUtils;
import com.palmnest.dao.estateserve.ScReceiverecordDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.estateserve.WxReceiverecord;


/**
 * 报修文本信息管理实现DAO
 *
 * @author ldb
 */
@Repository("scReceiverecordDao")
public class ScReceiverecordDaoImpl extends GenericDaoHibernate<WxReceiverecord, Integer>
		implements ScReceiverecordDao {
	public ScReceiverecordDaoImpl() {
		super(WxReceiverecord.class);
	}

	@Override
	public WxReceiverecord saveReceiverecord(WxReceiverecord receiverecord) {
		return super.save(receiverecord);
	}

	@Override
	public List<WxReceiverecord> getLastReceivercord(String developId, String openId, String infoType, String eventType) {
		final String strSql1 = "from ScReceiverecord where developId='" + developId + "' and openId='" + openId + "' and infoType='" + infoType + "' and eventType='" + eventType + "' order by createTime desc";
		List<WxReceiverecord> list = getSession().createQuery(strSql1).setFirstResult(0).setMaxResults(1).list();
		return list;
	}

	@Override
	public List<WxReceiverecord> getLastReceivercordByTime(String developId, String openId, String infoType, Date date) {
		final String strSql1 = "from ScReceiverecord where developId='" + developId + "' and openId='" + openId + "' and infoType='" + infoType + "' and createTime>'" + DateUtils.formatDate(date, "yyyy-MM-dd HH:mm:ss") + "' order by createTime desc ";
		List<WxReceiverecord> list = getSession().createQuery(strSql1).setFirstResult(0).setMaxResults(1).list();
		return list;
	}
}
