package com.palmnest.dao.estateserve.impl;

import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.palmnest.dao.estateserve.WatermeterDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.WatermeterInfo;
@Slf4j
@Repository("watermeterDao")
public class WatermeterDaoImpl extends GenericDaoHibernate<WatermeterInfo, Integer> implements WatermeterDao {
	public WatermeterDaoImpl() {
		super(WatermeterInfo.class);
	}

	@Override
	public List<WatermeterInfo> getWatermeterList(int sourseId, int enterType,
												  String floorId, String roomId) throws Exception {
		StringBuilder sql = new StringBuilder("  from WatermeterInfo where sourseId=? and enterType=? ");
		if (StringUtils.isNotBlank(floorId)) {
			sql.append(" and floorId=" + floorId + " ");
		}
		if (StringUtils.isNotBlank(roomId)) {
			sql.append(" and roomId=" + roomId + " ");
		}
		sql.append(" order by  createTime desc ");
		List<WatermeterInfo> list = getSession().createQuery(sql.toString()).setInteger(0, sourseId).setInteger(1, enterType).list();
		return list;
	}

	@Override
	public void removeWaterList(int sourseId, int enterType) throws Exception {
		StringBuilder sql = new StringBuilder("delete  from tb_watermeter where sourseId=? ");
		try {
			getSession().createSQLQuery(sql.toString()).setInteger(0, sourseId).executeUpdate();
		} catch (Exception e) {
			log.error(e.getMessage());
		}

	}
}
