package com.palmnest.dao.wechat.impl;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.wechat.ReplayContentDao;
import com.palmnest.model.estateserve.Picandtextdetailstemp;
import com.palmnest.model.estateserve.Replykeywords;
import com.palmnest.model.estateserve.Textpicvoicetemp;
import com.palmnest.model.notice.WxtemplateMessageTypeModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository("replayContentDao")
public class ReplayContentDaoImpl extends GenericDaoHibernate<Object, Integer>
		implements ReplayContentDao {

	public ReplayContentDaoImpl() {
		super(Object.class);
	}

	@Override
	public List<Replykeywords> getReplykeyworsList(String developId,
												   String keywordName) {
		String strHQL = "from Replykeywords where developId='" + developId + "' and name like '%" + keywordName + "%' and state='1' ";
		return getSession().createQuery(strHQL).list();
	}

	@Override
	public List<Textpicvoicetemp> getTextpicvoicetempsList(int replyKeywordsId) {
		return getSession().createQuery("from Textpicvoicetemp where replyKeywordsId=" + replyKeywordsId).list();
	}

	@Override
	public List<Picandtextdetailstemp> getPicandtextdetailstempsList(
			int replyKeywordsId) {
		String strHQL = "from Picandtextdetailstemp where replyKeywordsId=" + replyKeywordsId + " order by sequence asc";
		return getSession().createQuery(strHQL).list();
	}

	@Override
	public List<Map<String, Object>> getWxTemplate(String type,
												   int organizationId) {
		String strSQL = "select templateId from tb_template_library where type='" + type + "' and organizationId=" + organizationId;
		return getJdbcTemplate().queryForList(strSQL);
	}

	@Override
	public List<WxtemplateMessageTypeModel> getWxTemplateByTempId(int publicNo, String tempId) {
		StringBuilder strHQL = new StringBuilder("from WxtemplateMessageTypeModel where isEnabled='1' ");
		if (publicNo != 0) {
			strHQL.append(" and wechat_account_id=" + publicNo);
		}
		if (StringUtils.isNotEmpty(tempId)) {
			strHQL.append(" and templateid='" + tempId + "' ");
		}
		return getSession().createQuery(strHQL.toString()).list();
	}
}
