package cn.hmsoft.hmplatform.wxtoken.data.dao;

import org.springframework.stereotype.Repository;

import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.hmplatform.wxtoken.data.model.PWxTokenRequest;
import cn.hmsoft.jdbc.core.PlatformDaoSupport;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.jdbc.entity.QueryOrder;

@Repository
public class PWxTokenRequestDao extends PlatformDaoSupport<PWxTokenRequest> {

	public Pager pageRequest(Integer token_id, Integer start, Integer limit, String query,
			QueryOrder queryOrder) {
		StringBuilder sql = new StringBuilder();
		sql.append("select * from p_wx_token_request ");
		sql.append("where 1=1 ");
		if (token_id != null) {
			sql.append(" and token_id=").append(token_id);
		}
		if (StringHelper.isEmpty(query)) {
			sql.append(" order by request_time desc");
			return this.pageMapBySql(queryOrder, start, limit, sql.toString());
		}
		sql.append(" and (error_code = ? or error_msg like ?) ");
		sql.append(" order by request_time desc ");
		return this.pageMapBySql(queryOrder, start, limit, sql.toString(), query, "%" + query + "%");
	}

}
