package cn.hmsoft.weixin.data.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.jdbc.core.PlatformDaoSupport;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.jdbc.entity.QueryOrder;
import cn.hmsoft.weixin.data.model.WxTemplate;

@Component
public class WxTemplateDao extends PlatformDaoSupport<WxTemplate> {
	public Pager pageTemplate(int wx_id, Integer start, Integer limit,
			String query, QueryOrder order) {
		String sql = "select * from wx_template where wx_id=? ";
		if (StringHelper.isEmpty(query))
			return this.pageBySql(order, start, limit, sql, wx_id);
		String qValue = generateLikeParamter(query);
		sql = sql
				+ " template_name like ? or business_type like  ? or template_code = ?";
		return this.pageBySql(order, start, limit, sql, wx_id, qValue, qValue,
				query);
	}

	public List<WxTemplate> listTemplate(int wx_id) {
		String sql = "select * from wx_template where wx_id=? order by business_type";
		return this.listBySql(sql, wx_id);
	}
	
	public void updateTemplateCode(int template_id,String template_code){
		String sql = "update wx_template set template_code=?,sync_time=null where template_id=?";
		this.updateBySql(sql, template_code,template_id);
	}

}