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

import com.ssj.dao.sys.lyh.dao.IYbDetailQueryDao;
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 YbDetailQueryDaoImpl implements IYbDetailQueryDao {

	@Autowired
	private PagingHibernateJdbcDao dao;

	@Override
	public Page<Map<String, Object>> findForPage(Object object, Pageable initPage) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("  select * from tb_yb_detail ");

        return dao.findPage(selSQL.toString(), queryParams.toArray(), initPage);
	}

	@Override
	public List<Map<String, Object>> pageFind(int i, int pageSize) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("  select * from tb_yb_detail limit ").append(i).append(",").append(pageSize).append(" ");
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> pageFind2(int i, int pageSize, String tableName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("select t.book_laber,t.site_code,t11.title,t11.book_code,t11.author,\n");
        selSQL.append("t11.publisher,t11.publish_date,t11.age_area,t11.theme,t11.book_state,\n");
        selSQL.append("t11.img_url,t11.content,t11.edit_say,t11.online_read,t11.other_say,t11.info_url \n");
        selSQL.append("from ").append(tableName).append(" t11 \n");
        selSQL.append("left join tb_yb_url t on t.id = t11.site_id \n limit ").append(i).append(",").append(pageSize).append(" ");
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}
}
