package com.palmnest.dao.estateserve.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.palmnest.application.bean.Page;
import com.palmnest.application.core.util.DateUtils;
import com.palmnest.dao.estateserve.AnnouncementDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.estateserve.Announcement;

/**
 * This class interacts with Hibernate session to save/delete and
 */
@Repository("announcementDao")
public class AnnouncementDaoImpl extends GenericDaoHibernate<Announcement, Integer> implements AnnouncementDao {

	public AnnouncementDaoImpl() {
		super(Announcement.class);
	}

	@Override
	public Page getAnnouncementByPage(int pageno, int pagesize, String wheresql) {
		StringBuffer strSQL = new StringBuffer("select id,type,title,praiseNum,readerNum,commentNum,creator,DATE_FORMAT(createTime,'%Y年%m月%d日') as createTime,isTop,coverImageUrl,DATE_FORMAT(timerSendTime,'%Y-%m-%d %H:%i:%s') as timerSendTime,sendStatus from tb_announcement ");
		strSQL.append(wheresql);
		strSQL.append(" order by isTop desc, createTime desc");
		return pagedQueryByJdbcTemplate(strSQL.toString(), pageno, pagesize);
	}

	@Override
	public List<Announcement> queryTimerAnnouncementList() {
		String currentTime = DateUtils.getDate("yyyy-MM-dd HH:mm");
		String strHQL = "from Announcement where sendStatus='0' and timerSendTime like '" + currentTime + "%' ";
		return getSession().createQuery(strHQL).list();
	}
}
