package com.ssj.dao.weixin.card.dao.impl;

import com.ssj.dao.weixin.card.dao.LibMainCardQuery;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

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


@Repository
public class LibMainQueryDaoImpl implements LibMainCardQuery {

	@Autowired
	private PagingHibernateJdbcDao dao;
	@Override
	public Page<Map<String, Object>> findForCardPage(Map<String, Object> searchParams, Pageable initPage) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" select a.id,a.card_type,a.least_cost,a.reduce_cost,a.card_store,a.card_id,a.audit_stat from tb_lib_card a ");
	        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
	            selSQL.append(" and a.card_type =? ");
	            queryParams.add(searchParams.get("type"));
	        }
	        if (searchParams.get("auditStat") != null && !searchParams.get("auditStat").equals("")) {
	            selSQL.append(" and a.audit_stat = ?");
	            queryParams.add(searchParams.get("auditStat"));
	        }
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), initPage);
	}

}
