package com.palmnest.dao.estateserve.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.palmnest.application.bean.Page;
import com.palmnest.dao.estateserve.ScReplykeywordsDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.estateserve.Replykeywords;

/**
 * 报修图片信息管理实现DAO
 *
 * @author ldb
 */
@Repository("scReplykeywordsDao")
public class ScReplykeywordsDaoImpl extends GenericDaoHibernate<Replykeywords, Integer>
		implements ScReplykeywordsDao {
	public ScReplykeywordsDaoImpl() {
		super(Replykeywords.class);
	}

	public Replykeywords getReplykeywordsById(Integer kid) {
		List<Replykeywords> list = this.getSession().createQuery("from Replykeywords where replyKeywordsId = :id").setParameter("id", kid).list();
		if (list != null && list.size() > 0) {
			return list.get(0);
		} else {
			return null;
		}
	}

	@Override
	public Replykeywords saveScReplykeywords(Replykeywords scReplykeywords) {
		return super.save(scReplykeywords);
	}

	@Override
	public Page getReplykeywords(int pageno, int pagesize, String developId, String name, String state) {
		String sql = "select k.*,p.Name publicname from tb_replykeywords k left join tb_wxpublicno p on k.DevelopId=p.DevelopID";
		sql += " where 1=1";
		if (StringUtils.isNotEmpty(developId)) {
			sql += " and k.DevelopId='" + developId + "'";
		}
		if (StringUtils.isNotEmpty(name)) {
			sql += " and k.name like '%" + name + "%'";
		}
		if (StringUtils.isNotEmpty(state)) {
			sql += " and k.state='" + state + "'";
		}
		sql += " order by k.CreateTime desc";
		return this.pagedQueryByJdbcTemplate(sql, pageno, pagesize);
	}

	@Override
	public void delReplykeywords(final Integer... ids) {
		this.getSession().createQuery("delete from Replykeywords where replyKeywordsId in (:ids)")
				.setParameterList("ids", ids)
				.executeUpdate();
	}

}
