package com.ssj.dao.sys.jxy.dao.impl;

import com.ssj.dao.sys.jxy.dao.JxyQueryDao;
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 JxyQueryDaoImpl implements JxyQueryDao {
	@Autowired
	private PagingHibernateJdbcDao dao;
	@Override
	public Page<Map<String, Object>> findTeacherIdForPage(
			Map<String, Object> searchParams, Pageable pageable) {
			 StringBuilder selSQL = new StringBuilder();
		        List<Object> queryParams = new ArrayList<Object>();
		        selSQL.append("  select t.*");
		        selSQL.append(" from tb_jxy_read_leady t");
		        selSQL.append("  WHERE  1=1");
		        if (searchParams.get("isbn13") != null && !searchParams.get("isbn13").equals("")) {
		        	selSQL.append(" and t.isbn13 = ?  ");
		        	queryParams.add(searchParams.get("isbn13"));
		        }
		        if (searchParams.get("title") != null && !searchParams.get("title").equals("")) {
		        	selSQL.append(" and t.title = ?  ");
		        	queryParams.add(searchParams.get("title"));
		        }
		        selSQL.append("  ORDER BY  t.create_time  desc   ");
		        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
		}
	@Override
	public Page<Map<String, Object>> getJxylib(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append("  SELECT t.isbn13,t.title FROM tb_lib_book_base t where 1=1");
	        if (searchParams.get("isbn13") != null && !searchParams.get("isbn13").equals("")) {
	        	selSQL.append(" and t.isbn13 = ?  ");
	        	queryParams.add(searchParams.get("isbn13"));
	        }
	        if (searchParams.get("title") != null && !searchParams.get("title").equals("")) {
	        	selSQL.append(" and t.title = ?  ");
	        	queryParams.add(searchParams.get("title"));
	        }
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	
	}
	
	

}
