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.WxMsgProcessor;

@Component
public class WxMsgProcessorDao extends PlatformDaoSupport<WxMsgProcessor> {
	private final static String LIST_MSG_PROCESSOR_SQL = "select * from wx_msg_processor where wx_id=0 or wx_id=? order by wx_id";

	public List<WxMsgProcessor> listMsgProcessor(int wx_id) {
		return this.listBySql(LIST_MSG_PROCESSOR_SQL, wx_id);
	}

	public Pager pageMsgProcessor(int wx_id, Integer start, Integer limit, String query, QueryOrder order) {
		String sql = "select * from wx_msg_processor where wx_id=? ";
		if (StringHelper.isEmpty(query))
			return this.pageBySql(order, start, limit, sql, wx_id);
		sql = sql + " and msg_type like ? ";
		return this.pageBySql(order, start, limit, sql, wx_id, "%" + query + "%");
	}
}