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

import com.ssj.bean.weixin.libmy.domain.LibReadVip;
import com.ssj.dao.weixin.library.dao.IBookDetailQueryDao;
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.HashMap;
import java.util.List;
import java.util.Map;


@Repository
public class BookDetailQueryDaoImpl implements IBookDetailQueryDao {

	@Autowired
	private PagingHibernateJdbcDao dao;
	
	@Override
	public Map<String, Object> searchBookInfo(String id) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id,t.info_id,t11.author,t11.book_tag,GROUP_CONCAT(t12.`name`) as tag_name,t.back_book_time,t.stat,t.type\n");
		selSql.append(",t11.title,t11.local_image,c.league_name,t.user_id,t11.isbn13,t13.id as detail_id,t.lib_id,t.vip_id \n");
		selSql.append(" from tb_lib_book_detail t \n");
		selSql.append("left join tb_lib_join c on t.lib_id = c.id\n");
		selSql.append("left join tb_lib_book_info t11 on t.info_id = t11.id\n");
		selSql.append("left join sys_sort t12 on     INSTR(t11.book_tag,t12.code)>0 and t12.code like 'book_tag%' and t12.pid<>'0'\n");
		selSql.append("left join tb_order_details t13 on  t13.book_detail_id = t.id and t13.is_close='2' and t.user_id = t13.user_id  \n");
		selSql.append("where t.id = ?   \n");
		selSql.append("group by t.id");	
		queryParams.add(id);
		
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public List<Map<String, Object>> findBookList(String userId,String vipId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id,t11.author,t11.book_tag,GROUP_CONCAT(t12.`name`) as tag_name,DATE_FORMAT(t.back_book_time,'%Y-%m-%d %H:%i:%s') as back_book_time,DATE_FORMAT(a.create_time,'%Y-%m-%d %H:%i:%s') as create_time,t.stat\n");
		selSql.append(",t11.title,t11.local_image,c.league_name,t.user_id,t11.isbn13,a.id as detail_id \n");
		selSql.append("from tb_order_details a\n");
		selSql.append("left join tb_lib_book_detail t on a.book_detail_id = t.id\n");
		selSql.append("left join tb_lib_join c on t.lib_id = c.id\n");
		selSql.append("left join tb_lib_book_info t11 on t.info_id = t11.id\n");
		selSql.append("left join sys_sort t12 on     INSTR(t11.book_tag,t12.code)>0 and t12.code like 'book_tag%' and t12.pid<>'0'\n");
		if(vipId == null || "".equals(vipId)){
			selSql.append("where a.user_id = ? and a.is_close='2' \n");
			queryParams.add(userId);
		}else{
			selSql.append("where a.vip_id = ? and a.is_close='2' \n");
			queryParams.add(vipId);
		}
		
		selSql.append("group by t.id");	
		
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> backBookList(String id,String userId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id,t11.author,t11.book_tag,GROUP_CONCAT(t12.`name`) as tag_name,t.back_book_time,a.create_time,t.stat\n");
		selSql.append(",t11.title,t11.local_image,c.league_name,t.user_id,t11.isbn13 \n");
		selSql.append("from tb_order_details a\n");
		selSql.append("left join tb_lib_book_detail t on a.book_detail_id = t.id\n");
		selSql.append("left join tb_lib_join c on t.lib_id = c.id\n");
		selSql.append("left join tb_lib_book_info t11 on t.info_id = t11.id\n");
		selSql.append("left join sys_sort t12 on     INSTR(t11.book_tag,t12.code)>0 and t12.code like 'book_tag%' and t12.pid<>'0'\n");
		selSql.append("where t.id in ('").append(id).append("')  \n");
		selSql.append("group by t.id");	
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getOrderList(String id, String userId) {
		id = id.replace(",", "','");
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t11.title,DATE_FORMAT(t.back_book_time,'%Y年%m月%d日 %H时%i分') as back_book_time,DATE_FORMAT(t12.create_time,'%Y年%m月%d日 %H时%i分') as create_time,t11.local_image,t.lib_id,ifnull(case when t11.book_gr ='' then 0 else t11.book_gr END,0) as book_gr,ifnull(t13.pone2,0) as pone2 from tb_lib_book_detail t \n");
		selSql.append("left join tb_lib_book_info t11 on t.info_id = t11.id \n");
		selSql.append("left join tb_order_details t12 on t.id = t12.book_detail_id and t12.is_close='2' and t.user_id=t12.user_id \n");
		selSql.append("left join ydz_result t13 on t.user_id = t13.user_id \n");
		selSql.append("where t.id in ('").append(id).append("') and t.user_id = ?\n");
		queryParams.add(userId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> getOrderDetail(String detailIds, String userId) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select GROUP_CONCAT(t.id) as id \n");
		selSql.append("from tb_order_details t \n");
		selSql.append("where t.user_id=? and t.is_close='2'  and t.book_detail_id in ('").append(detailIds).append("') \n");
		selSql.append("group by t.user_id\n");
		queryParams.add(userId);
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public List<Map<String, Object>> jsBookList(String id, String userId,LibReadVip vip) {
		id = id.replace(",", "','");
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t12.local_image,t12.title,t.create_time,t.update_time,(TIMESTAMPDIFF(DAY,t.create_time,t.update_time)+1)  as borrowed_day \n");
		selSql.append(",(ifnull(t.money,0)+ifnull(t13.xjMoney,0)+ifnull(t14.yqMoney,0)) as totol,ifnull(t13.xjTimes,0) as xjTimes,ifnull(t14.yqDay,0) as yqDay,t.user_id,t.vip_id,t11.lib_id \n");
		selSql.append("from tb_order_details t \n");
		selSql.append("left join tb_lib_book_detail t11 on t.book_detail_id = t11.id \n");
		selSql.append("left join tb_lib_book_info t12 on t11.info_id = t12.id  \n");
		selSql.append("left join ( \n");
		selSql.append("select count(1) as xjTimes,sum(a.money) as xjMoney,a.detail_id from tb_lib_user_history a  \n");
		selSql.append("left join tb_order_details b on a.detail_id = b.id \n");
		selSql.append("where b.id in ('").append(id).append("') and a.order_type='2'\n");
		selSql.append("group by a.detail_id \n");
		selSql.append(") t13 on t13.detail_id = t.id \n");
		selSql.append("left join ( \n");
		selSql.append("select sum(a.money) as yqMoney,a.detail_id,sum(TIMESTAMPDIFF(DAY,a.start_time,a.end_time)) as yqDay  from tb_lib_user_history a  \n");
		selSql.append("left join tb_order_details b on a.detail_id = b.id \n");
		selSql.append("where b.id in ('").append(id).append("') and a.order_type='3'\n");
		selSql.append("group by a.detail_id\n");
		selSql.append(") t14 on t14.detail_id = t.id \n");
		selSql.append("where t.id in ('").append(id).append("')\n");
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getManagerList(String bookId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select DISTINCT t13.wx_account,t.lib_id from tb_lib_book_detail t \n");
		selSql.append("left join tb_lib_manager t12 on t.lib_id = t12.lib_id \n");
		selSql.append("left join tb_user t13 on t12.user_id = t13.id \n");
		selSql.append("where t.id = ? and (t12.type='1' or t12.type='4') and  t13.wx_account is not null and t12.state=1 \n");
		queryParams.add(bookId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> libManageList(String id) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t11.wx_account,ifnull(t.name,t11.wx_name) as name from tb_lib_manager t  \n");
		selSql.append("left join tb_user t11 on t.user_id = t11.id \n");
		selSql.append("where t.lib_id=? and (t.type=1 or t.type=0) and t.state=1 \n");
		queryParams.add(id);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> getLibBookCounts(String libId,String stat) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select sum(a.borrow_count) as borrow_count,a.lib_id,count(a.user_id) as user_count from ( \n");
		selSql.append("select count(t11.id) as borrow_count,t13.lib_id,t11.user_id from tb_order_details t11 \n");
		selSql.append("left join tb_lib_book_detail t12 on t11.book_detail_id = t12.id \n");
		selSql.append("left join tb_lib_book_info t13 on t12.info_id = t13.id \n");
		selSql.append("where t13.lib_id=?  \n");
		if(stat != null){
			selSql.append("and  t11.is_close=? \n");
			if(stat.equals("2")){
				selSql.append("and  t11.create_time >= date_add(now(), interval -7 day) \n");
			}else{
				selSql.append("and  t11.update_time >= date_add(now(), interval -7 day) \n");
			}
		}
		selSql.append("group by t13.lib_id,t11.user_id \n");
		selSql.append(")a \n");
		queryParams.add(libId);
		if(stat != null){
			queryParams.add(stat);
		}
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public List<Map<String, Object>> getBookInfoList(String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select '1' as type,count(1) as count_book from tb_lib_user_history a  \n");
		selSql.append("left join tb_lib_book_detail b on a.book_detail_id = b.id \n");
		selSql.append("left join tb_lib_book_info c on b.info_id = c.id \n");
		selSql.append("where order_type='2'  and c.lib_id=?  \n");
		selSql.append("union ALL \n");
		selSql.append("select '2' as type,count(1) as count_book from tb_lib_book_detail a\n");
		selSql.append("left join tb_lib_book_info b on  a.info_id = b.id \n");
		selSql.append("where a.user_id is not null  and b.lib_id=? \n");
		selSql.append("union ALL \n");
		selSql.append("select '3' as type,count(1) as count_book from tb_lib_book_detail a  \n");
		selSql.append("left join tb_lib_book_info b  on a.info_id = b.id \n");
		selSql.append(" where  b.lib_id=? \n");
		queryParams.add(libId);
		queryParams.add(libId);
		queryParams.add(libId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getBookDriftList(String id, String userId) {
		StringBuilder selSql = new StringBuilder();
		id = id.replace(",", "','");
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.user_id,t.title,t11.id from tb_order_details t  \n");
		selSql.append("left join tb_lib_book_detail t11 on t.book_detail_id = t11.id \n");
		selSql.append("where t.is_close='2' and t.user_id <>? and t11.id in ('").append(id).append("')\n\n");
		queryParams.add(userId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> getDirftDetail(String oldUserId, String detailId,String userId) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id,t.old_user_id,t.drift_user_id,t.stat,t.create_time,t.resp_time,t.book_detail_id from tb_lib_drift t \n");
		selSql.append("where t.old_user_id=? and t.book_detail_id=? and t.drift_user_id=? \n");
		selSql.append("and round((UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(t.create_time))/60) <11 \n");
		selSql.append("ORDER BY t.create_time DESC \n");
		queryParams.add(oldUserId);
		queryParams.add(detailId);
		queryParams.add(userId);
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public List<Map<String, Object>> getPlList(String infoId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id,IFNULL(t11.child_name,t12.wx_name) as wx_name,IFNULL(t11.img_url,t12.photo) as user_photo,t.pl_address,t14.mp3url as mp3_url,t15.url as img_url,t.pl_text,t.book_info_id,t.create_time,t.pl_lat,t.pl_lng  \n");
		selSql.append("from tb_lib_book_pl t \n");
		selSql.append("left join tb_lib_read_vip t11 on t.user_id = t11.user_id \n");
		selSql.append("left join tb_user t12 on t.user_id = t12.id  \n");
		selSql.append("left join tb_lib_book_info t13 on t.book_info_id = t13.id \n");
		selSql.append("left join tb_download_file t14 on t.mp3_url  = t14.id and t14.type='2' \n");
		selSql.append("left join tb_download_file t15 on t.img_url  = t15.id and t15.type='1'\n");
		selSql.append("where t.book_info_id = ? \n");
		selSql.append("order by t.create_time desc \n");
		queryParams.add(infoId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> getBookInfo(String id) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t11.id as info_id,t11.author,t11.book_tag,GROUP_CONCAT(t12.`name`) as tag_name,t11.lib_id\n");
		selSql.append(",t11.title,t11.local_image,t11.isbn13 \n");
		selSql.append(" from  tb_lib_book_info t11 \n");
		selSql.append("left join sys_sort t12 on     INSTR(t11.book_tag,t12.code)>0 and t12.code like 'book_tag%' and t12.pid<>'0'\n");
		selSql.append("where t11.id = ?   \n");
		queryParams.add(id);
		
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public List<Map<String, Object>> findIsRead(String id, String userId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id from tb_order_details t  \n");
		selSql.append("left join tb_lib_book_detail t11  on t.book_detail_id = t11.id \n");
		selSql.append("left join tb_lib_book_info t12 on t11.info_id = t12.id \n");
		selSql.append("where t12.id = ? and t.user_id = ? \n");
		queryParams.add(id);
		queryParams.add(userId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> sendBookOverMsg() {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.wx_account,GROUP_CONCAT(t.title) as title,t.back_book_time,t.days1,t.days2,t.parent_name,t.child_name,t.id from (  \n");
		selSql.append("select  t11.wx_account,t.back_book_time,t.borrowed_time,t12.title,datediff(t.back_book_time,now()) as days1,\n");
		selSql.append("DATE_FORMAT(t.back_book_time,'%Y-%m-%d')  as days2 ,t13.parent_name,t13.child_name,t13.id\n");
		selSql.append("from tb_lib_book_detail t  \n");
		selSql.append("left join tb_user t11 on t.user_id = t11.id  \n");
		selSql.append("left join tb_lib_book_info t12 on t.info_id = t12.id  \n");
		selSql.append("left join tb_lib_read_vip t13 on t.user_id = t13.user_id and t.vip_id = t13.id \n");
		selSql.append("where t.user_id is not null   \n");
		selSql.append(" and t.back_book_time is not NULL and ((datediff(t.back_book_time,now())<=1 and datediff(t.back_book_time,now())>=0) or datediff(now(),t.back_book_time)<=9)  \n");
		selSql.append(") t group by t.wx_account,t.days2  \n");
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getVipInfo() {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.card_id,t.user_card_code,t13.user_yj from tb_lib_card_detail t\n");
		selSql.append("left join tb_user t11 on t.open_id = t11.wx_account\n");
		selSql.append("left join tb_user_integral t13 on t11.id = t13.user_id");
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getDetailQrList(String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.id,t11.league_name from tb_lib_book_detail t\n");
		selSql.append("left join tb_lib_join t11 on t.lib_id = t11.id\n");
		selSql.append("where t.stat='1' and t.info_id is null ");
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findServiceList(String userId,String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT t.id,t.user_id,t.child_name,t.img_url,t11.borrow_day,t11.borrow_num,t11.borrow_num-ifnull(t12.alborrowed,0) as canborrow,t11.deposit,t11.lib_id,t11.out_money from tb_lib_read_vip t \n");
		selSql.append("left join tb_lib_vip_service t11 on t.id = t11.vip_id\n");
		selSql.append("left join (\n");
		selSql.append("SELECT a.vip_id,count(a.vip_id) as alborrowed from tb_lib_book_detail a\n");
		selSql.append("left join  tb_lib_vip_service b  on a.vip_id = b.vip_id \n");
		if(libId == null || "".equals(libId)){
			selSql.append("where a.user_id = ? \n");
			queryParams.add(userId);
		}else{
			selSql.append("where b.lib_id= ? and a.user_id = ? \n");
			queryParams.add(libId);
			queryParams.add(userId);
		}
		
		selSql.append("group by a.vip_id\n");
		selSql.append(")t12 on t.id = t12.vip_id \n");
		selSql.append("where t11.species = 'S001' and t11.stat=1 and  TO_DAYS(end_time)  >=  TO_DAYS(now()) \n");
		if(libId == null || "".equals(libId)){
			selSql.append("and t.user_id = ? \n");
			queryParams.add(userId);
		}else{
			selSql.append("and t11.lib_id = ? and t.user_id = ?\n");
			queryParams.add(libId);
			queryParams.add(userId);
		}
		selSql.append(" order by t11.start_time desc \n");
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> findVipServiceByVip(String vipid) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT t.id,t.user_id,t.child_name,t.img_url,t11.borrow_day,t11.borrow_num,t11.borrow_num-ifnull(t12.alborrowed,0) as canborrow,ifnull(t12.alborrowed,0) as alborrowed,t11.deposit,t11.lib_id,t11.out_money from tb_lib_read_vip t \n");
		selSql.append("left join tb_lib_vip_service t11 on t.id = t11.vip_id\n");
		selSql.append("left join (\n");
		selSql.append("SELECT a.vip_id,count(a.vip_id) as alborrowed from tb_lib_book_detail a\n");
		selSql.append("where a.vip_id = ? \n");
		selSql.append("group by a.vip_id\n");
		selSql.append(")t12 on t.id = t12.vip_id \n");
		selSql.append("where t11.species = 'S001' and t11.stat=1 and  TO_DAYS(end_time)  >=  TO_DAYS(now()) \n");
		selSql.append("and t.id = ? \n");
		queryParams.add(vipid);
		queryParams.add(vipid);
		List<Map<String, Object>> listMap = dao.findMap(selSql.toString(), queryParams.toArray());
		if(listMap !=null && listMap.size()>0){
			return listMap.get(0);
		}else{
			return new HashMap<String,Object>();
		}
	}

	@Override
	public List<Map<String, Object>> getLIbBkTagDetail(String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT t.`name`,sum(t.bkcount) as bkcount,tags from (  \n");
		selSql.append("select a.name, a.bkcount,a.tags from (  \n");
		selSql.append("select t11.name,count(1) as bkcount,t.parent_theme as tags from tb_lib_book_info t  \n");
		selSql.append("inner join sys_sort t11 on t.parent_theme = t11.code and t11.pid='44603f84-a4d8-47e7-ab82-11ffd8a3425f'  \n");
		selSql.append("where t.parent_theme is not null \n");
		selSql.append("and lib_id = ? \n");
		selSql.append("group by t.parent_theme\n");
		selSql.append("union \n");
		selSql.append("select t11.name,count(1) as bkcount,t.child_theme as tags from tb_lib_book_info t  \n");
		selSql.append("inner join sys_sort t11 on t.child_theme = t11.code and t11.pid='a316f70c-1184-44b9-a636-dbe10262f176'  \n");
		selSql.append("where t.child_theme is not null \n");
		selSql.append("and lib_id = ? \n");
		selSql.append("group by t.child_theme\n");
		selSql.append(") a \n");
		selSql.append(") t GROUP BY t.`tags` DESC ");
		queryParams.add(libId);
		queryParams.add(libId);
		return  dao.findMap(selSql.toString(), queryParams.toArray());

	}

	@Override
	public Page<Map<String, Object>> libBookList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        String type = params.get("type").toString();
        selSql.append("SELECT t.id,t.local_image,t.summary,t.title,t.author,t.isbn13,t.book_stock from tb_lib_book_info t \n");
        selSql.append("left join ( \n");
        if("1".equals(type)){ //本周借阅量
        	selSql.append("SELECT t2.isbn13,count(t2.id) as phcount from tb_order_details  t \n");
            selSql.append("left join tb_lib_book_detail t1  on t.book_detail_id = t1.id \n");
            selSql.append("	left join tb_lib_book_info t2 on t1.info_id = t2.id \n");
            selSql.append("where t2.isbn13 is not null    and t1.lib_id =?   and t.create_time > date_add(NOW(), interval -7 day) \n");
            selSql.append("GROUP by t2.isbn13 \n");
            selSql.append(") b on t.isbn13 = b.isbn13 \n");
        }else if ("2".equals(type)){ //共读量
        	selSql.append("SELECT a.isbn13,count(1) as phcount from ( \n");
            selSql.append("SELECT t.isbn13,t.id  from tb_lib_book_pl t  \n");
            selSql.append(" inner  join  tb_lib_book_info t11 on t.isbn13 = t11.isbn13 ");
            selSql.append("where t11.lib_id = ? \n");
            selSql.append(") a  \n");
            selSql.append("group by a.isbn13 \n");
            selSql.append(") b on t.isbn13 = b.isbn13 \n");
        }else{ //总借阅量
        	selSql.append("SELECT t2.isbn13,count(t2.id) as phcount from tb_order_details  t \n");
            selSql.append("left join tb_lib_book_detail t1  on t.book_detail_id = t1.id \n");
            selSql.append("	left join tb_lib_book_info t2 on t1.info_id = t2.id \n");
            selSql.append("where t2.isbn13 is not null    and t1.lib_id =?  \n");
            selSql.append("GROUP by t2.isbn13 \n");
            selSql.append(") b on t.isbn13 = b.isbn13 \n");
        }
        queryParams.add(params.get("libId"));
        if("all".equals(params.get("tags"))){
        	selSql.append(" where  t.lib_id = ? \n");
        	queryParams.add(params.get("libId"));
        }else{
        	 selSql.append(" where (t.parent_theme = ? or t.child_theme = ?) and t.lib_id = ? \n");
        	 queryParams.add(params.get("tags"));
        	 queryParams.add(params.get("tags"));
             queryParams.add(params.get("libId"));
        }

        if(params.get("searchContent") != null && !"".equals(params.get("searchContent"))){
        	 selSql.append(" and  t.title LIKE  CONCAT('%',?,'%')   \n");
        	 queryParams.add(params.get("searchContent"));
        }
        selSql.append(" order by b.phcount desc \n");
        
		return dao.findPage(selSql.toString(),queryParams.toArray(), pageable);
	}

	@Override
	public Map<String, Object> findMyMap(String libId, String type) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select ifnull(sum(a.borrow_count),0) as borrow_count,a.lib_id,count(a.user_id) as user_count from ( \n");
		selSql.append("select count(t11.id) as borrow_count,t13.lib_id,t11.user_id from tb_order_details t11 \n");
		selSql.append("left join tb_lib_book_detail t12 on t11.book_detail_id = t12.id \n");
		selSql.append("left join tb_lib_book_info t13 on t12.info_id = t13.id \n");
		selSql.append("where t13.lib_id=? \n");
		selSql.append("and  t11.is_close=? \n");
		if("1".equals(type)){
			selSql.append("and  t11.update_time >= date_add(now(), interval -7 day) \n");
		}else{
			selSql.append("and  t11.create_time >= date_add(now(), interval -7 day) \n");
		}
		selSql.append("group by t13.lib_id,t11.user_id \n");
		selSql.append(")a \n");
		queryParams.add(libId);
		queryParams.add(type);
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public Page<Map<String, Object>> BookWeekList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSql.append("select * from ( \n");
        selSql.append("SELECT DISTINCT case when a.is_close='1' then update_time else create_time end as create_time  from ( \n");
		selSql.append("SELECT t11.id,t.title,t.is_close,t14.local_image,DATE_FORMAT(t.create_time ,'%Y-%m-%d') as create_time,t.vip_id,DATE_FORMAT(t.update_time,'%Y-%m-%d')  as update_time,t11.child_name  \n");
		selSql.append("from tb_order_details t  \n");
		selSql.append("left join tb_lib_read_vip t11 on t.vip_id = t11.id \n");
		selSql.append("left join tb_lib_vip_service t15 on t11.id = t15.vip_id \n");
		selSql.append("left join tb_lib_book_detail t13 on t.book_detail_id = t13.id \n");
		selSql.append("left join tb_lib_book_info t14 on t13.info_id = t14.id \n");
		selSql.append("where t15.lib_id = ?  and t.is_close= ?  and t11.user_id is not null  \n");
		selSql.append(") a ) b order by b.create_time desc\n");
		queryParams.add(params.get("libId"));
		queryParams.add(params.get("type"));
		return dao.findPage(selSql.toString(),queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> getUserBookDetail(String vipId, String rq,String libId,String type) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT t.title,t14.local_image,t14.summary,DATE_FORMAT(ifnull(t13.back_book_time,NOW()),'%Y-%m-%d') as back_book_time,t.create_time,t.vip_id,t.is_close,t.update_time,t11.child_name from tb_order_details t  \n");
		selSql.append("left join tb_lib_read_vip t11 on t.vip_id = t11.id\n");
		selSql.append("left join tb_lib_book_detail t13 on t.book_detail_id = t13.id \n");
		selSql.append("left join tb_lib_book_info t14 on t13.info_id = t14.id\n");
		selSql.append("where t14.lib_id = ?  and t.is_close= ? \n");
		selSql.append("and t.vip_id =?    \n");
		if("1".equals(type)){ //已归还
			selSql.append(" and  DATE_FORMAT(t.update_time,'%Y-%m-%d')= ?  \n");
		}else{
			selSql.append("and  DATE_FORMAT(t.create_time ,'%Y-%m-%d')= ?  \n");
		}
		queryParams.add(libId);
		queryParams.add(type);
		queryParams.add(vipId);
		queryParams.add(rq);
		return  dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getDateBorrowList(String libId, String sdate,String type) {
		StringBuilder selSql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSql.append("select a.* from (");
        selSql.append("SELECT id,local_image,summary,CONCAT(GROUP_CONCAT(CONCAT('《',title,'》')),case when a.is_close='2' then '共借' else '共还' end,count(title),'本') as showstr,case when a.is_close='1' then update_time else create_time end as create_time,vip_id,is_close,child_name  from ( \n");
		selSql.append("SELECT t11.id,t.title,t.is_close,t14.summary, t11.img_url as local_image,DATE_FORMAT(t.create_time ,'%Y-%m-%d') as create_time,t.vip_id,DATE_FORMAT(t.update_time,'%Y-%m-%d')  as update_time,t11.child_name  \n");
		selSql.append("from tb_order_details t  \n");
		selSql.append("left join tb_lib_read_vip t11 on t.vip_id = t11.id \n");
		selSql.append("left join tb_lib_vip_service t15 on t11.id = t15.vip_id\n");
		selSql.append("left join tb_lib_book_detail t13 on t.book_detail_id = t13.id \n");
		selSql.append("left join tb_lib_book_info t14 on t13.info_id = t14.id \n");
		selSql.append("where t15.lib_id = ?  and t.is_close= ?  and t11.user_id is not null  \n");
		selSql.append(") a \n");
		selSql.append("group by case when a.is_close='2' then a.create_time else a.update_time end,a.vip_id \n");
		selSql.append("order by a.create_time DESC\n");
		selSql.append(") a  where a.create_time = ? \n");
		queryParams.add(libId);
		queryParams.add(type);
		queryParams.add(sdate);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> adminCallBack(Map<String, Object> params) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.wx_account,GROUP_CONCAT(t.title) as title,t.back_book_time,t.days1,t.days2,t.parent_name from (  \n");
		selSql.append("select  t11.wx_account,t.back_book_time,t.borrowed_time,t12.title,datediff(t.back_book_time,now()) as days1,\n");
		selSql.append("DATE_FORMAT(t.back_book_time,'%Y-%m-%d')  as days2 ,t13.parent_name\n");
		selSql.append("from tb_lib_book_detail t  \n");
		selSql.append("left join  tb_order_details b on t.id = b.book_detail_id and b.is_close='2' \n");
		selSql.append("left join tb_user t11 on t.user_id = t11.id  \n");
		selSql.append("left join tb_lib_book_info t12 on t.info_id = t12.id  \n");
		selSql.append("left join tb_lib_read_vip t13 on t.user_id = t13.user_id  and  t.vip_id = t13.id\n");
		selSql.append("where t.user_id is not null   \n");
		selSql.append(" and t.back_book_time is not NULL and t13.id=? and  DATE_FORMAT(t.back_book_time ,'%Y-%m-%d') = ?\n");
		selSql.append(") t group by t.wx_account,t.days2  \n");
		queryParams.add(params.get("vipId"));
		queryParams.add(params.get("rq"));
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> borrowInfoWeek(String vipId, String userId,String stat) {
		//查询用户近一周用户的归还与借阅总数
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select count(t11.id) as borrow_count,t11.user_id from tb_order_details t11 \n");
		if("".equals(vipId)){
			selSql.append("where t11.user_id=? \n");
			queryParams.add(userId);
		}else{
			selSql.append("where t11.vip_id=? \n");
			queryParams.add(vipId);
		}
		
		
		if("1".equals(stat)){
			selSql.append("and  t11.update_time >= date_add(now(), interval -7 day) \n");
			selSql.append("and  t11.is_close=? \n");
			queryParams.add(stat);
		}else{
			selSql.append("and  t11.create_time >= date_add(now(), interval -7 day) \n");
		}
		if("".equals(vipId)){
			selSql.append("group by t11.user_id \n");
		}else{
			selSql.append("group by t11.vip_id \n");
		}
		
		
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public Map<String, Object> getRankCheck(LibReadVip vip, String userId, String libId) {
		
		Map<String, Object> map = new HashMap<>();
		
		if(vip ==null){
			return map;
		}else{
			StringBuilder selSql = new StringBuilder();
			List<Object> queryParams = new ArrayList<Object>();
			selSql.append("select c.borrownum,c.vip_id,c.ranking,d.vipcount,concat(FORMAT((d.vipcount-c.ranking)/d.vipcount*100,0),'%') as outrank from \n");
			selSql.append("(select * from (SELECT a.borrownum,a.vip_id,(@rowno\\:=@rowno+1) as ranking from \n");
			selSql.append("(SELECT count(1) as borrownum,t.vip_id \n");
			selSql.append("from tb_lib_user_history t \n");
			selSql.append(" left join tb_lib_vip_service t11 on t.vip_id = t11.vip_id \n");
			selSql.append("where t.vip_id is not null and  t.start_time >= date_add(now(), interval -7 day)\n");
			selSql.append("and t11.lib_id=? and t11.stat=1 and  t11.species ='S001'  and  TO_DAYS(t11.end_time)  >=  TO_DAYS(now())\n");
			selSql.append("GROUP BY t.vip_id \n");
			selSql.append("order by count(1) DESC) a ,(select (@rowno\\:=0)) b\n");
			selSql.append(") a \n");
			selSql.append("where a.vip_id = ?\n");
			selSql.append(") c \n");
			selSql.append("left join (\n");
			selSql.append("SELECT count(1) as vipcount from tb_lib_vip_service t11 \n");
			selSql.append("where t11.species ='S001'  and  t11.stat=1  and  TO_DAYS(t11.end_time)  >=  TO_DAYS(now())\n");
			selSql.append(" and t11.lib_id=?\n");
			selSql.append(") d on 1 = 1");
			queryParams.add(libId);
			queryParams.add(vip.getId());
			queryParams.add(libId);
			List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
			if(list.size()>0){
				map = list.get(0);
			}
			return map;
		}
	}

	@Override
	public Map<String, Object> getLibRank(String libId) {
		Map<String, Object> map = new HashMap<>();
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select c.borrownum,c.lib_id,c.ranking,d.libcount,concat(FORMAT((d.libcount-c.ranking)/d.libcount*100,0),'%') as librank from \n");
		selSql.append("(SELECT a.borrownum,a.lib_id,(@rowno\\:=@rowno+1) as ranking from \n");
		selSql.append("(SELECT count(1) as borrownum,t11.lib_id \n");
		selSql.append("from tb_lib_user_history t \n");
		selSql.append("left join tb_lib_vip_service t11 on t.vip_id = t11.vip_id\n");
		selSql.append("where t11.species ='S001'  and  t11.stat=1  and  TO_DAYS(t11.end_time)  >=  TO_DAYS(now()) and t.start_time >= date_add(now(), interval -7 day)\n");
		selSql.append("GROUP BY t11.lib_id \n");
		selSql.append("order by count(1) DESC) a ,(select (@rowno\\:=0)) b\n");
		selSql.append(" where a.lib_id = ?\n");
		selSql.append(") c \n");
		selSql.append("left join (\n");
		selSql.append("SELECT count(1) as libcount from tb_lib_join t11 where t11.type>0\n");
		selSql.append(") d on 1 = 1");
		queryParams.add(libId);
		List<Map<String, Object>> list = dao.findMap(selSql.toString(), queryParams.toArray());
		if(list.size()>0){
			map = list.get(0);
		}
		return map;
	}

	@Override
	public List<Map<String, Object>> getOrderUserList(String detailIds) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select DISTINCT t.vip_id \n");
		selSql.append("from tb_order_details t \n");
		selSql.append("where t.is_close='2'  and t.book_detail_id in ('").append(detailIds).append("') \n");
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findBorrowList(String infoId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT t11.child_name,CASE when  t.back_book_time > NOW() then '1' ELSE '2' end as type from tb_lib_book_detail t  \n");
		selSql.append("left join tb_lib_read_vip t11 on t.vip_id = t11.id \n");
		selSql.append("where t.vip_id is not null and t.info_id=? \n");
		queryParams.add(infoId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getByLibIdList(String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT  o.title,o.summary,o.local_image ,o.isbn13 from   tb_lib_book_detail  l  join  tb_lib_book_info o on o.id = l.info_id");
		selSql.append(" where l.lib_id =?  ");
		selSql.append(" ORDER BY l.create_time desc  LIMIT  5");
		queryParams.add(libId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> haveToBorrow(String vipId, String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT  o.title,o.author,o.summary,o.local_image,l.id,");
		selSql.append(" to_days(now()) - to_days(l.borrowed_time) as days ");
		selSql.append(" from   tb_lib_book_detail  l  join  tb_lib_book_info o ");
		selSql.append(" on o.id = l.info_id ");
		selSql.append(" where l.vip_id =?  and l.lib_id=?  ");
		queryParams.add(vipId);
		queryParams.add(libId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findBorrowedList(List<String> bookDetailsId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		int i =0;
		int size = bookDetailsId.size();
		for (String string : bookDetailsId) {
			if(i > 0 && i<size){
				selSql.append(" union all  \n");
			}
			selSql.append("SELECT t11.title,t11.local_image,t11.author,t11.summary from tb_lib_book_detail t  \n");
			selSql.append(" INNER JOIN tb_lib_book_info t11 on t.info_id=t11.id  \n");
			selSql.append(" where t.id = ? \n");
			queryParams.add(string);
			i++;
		}
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> getbooksList(Map<String, Object> params,
			Pageable pageable) {
		StringBuilder selSql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        Integer type =(Integer)params.get("type");
        selSql.append("SELECT f.title,f.isbn13,f.local_image,ifnull(t.name,'') ");
		selSql.append(" as theme,  l.id as book_detail_id , l.info_id as    book_info_id ,f.book_stock_remain as book_size,h.heat ");
		if(type==3){
			selSql.append(",(SELECT count(t.id) from tb_lib_book_detail t where t.info_id = f.id  ) as types   ");
		}
		selSql.append(" FROM 	tb_lib_book_detail l ");
		selSql.append(" JOIN tb_lib_book_info f ON l.info_id = f.id ");
		selSql.append(" left JOIN tb_lib_book_isbn_heat h ON f.isbn13 = h.isbn13 ");
		selSql.append("left join sys_sort t on f.child_theme = t.code ");
		selSql.append("  WHERE   ");
		selSql.append("   l.lib_id =? ");
		if("fa14e041-3823-4dac-b061-1e250e5a7d49".equals(params.get("libId").toString())){ //总部馆书籍
			selSql.append("  and   f.book_stock_remain > 0 \n");
			selSql.append(" AND  l.bookcase is not null ");
		}
		queryParams.add(params.get("libId"));

		if(!"".equals(params.get("grade"))){
			selSql.append("  and  f.section in ('").append(params.get("grade").toString().replace(",","','")).append("') ");
		}

		if(!"".equals(params.get("ptheme"))){
			selSql.append("  and (f.parent_theme in ('").append(params.get("ptheme").toString().replace(",","','")).append("') ");
			if(!"".equals(params.get("ctheme"))){
				selSql.append("  or f.child_theme in ('").append(params.get("ctheme").toString().replace(",","','")).append("')) ");
			}else{
				selSql.append("  )");
			}
		}else{
			if(!"".equals(params.get("ctheme"))) {
				selSql.append("  and f.child_theme in ('").append(params.get("ctheme").toString().replace(",", "','")).append("') ");
			}
		}

		if(!"".equals(params.get("title"))){
			selSql.append("  and f.title like CONCAT('%',?,'%') \n");
			queryParams.add(params.get("title"));
		}
		if("fa14e041-3823-4dac-b061-1e250e5a7d49".equals(params.get("libId").toString())) { //总部馆书籍
			selSql.append("  group by f.id \n");
		}
		if(2==type){
			selSql.append(" ORDER BY h.heat desc  ");
		}else if(3==type ){
			selSql.append(" ORDER BY types desc  ");
		}
		return dao.findPage(selSql.toString(),queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> getGoodBooksToRead(
			Map<String, Object> params, Pageable pageable) {
        StringBuilder selSql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        Integer type =(Integer)params.get("type");
        selSql.append("SELECT f.child_theme ,t.name ");
        selSql.append(" as theme,count(f.id) as total,group_concat(f.local_image) as images,f.id,h.heat ");
        if(type==1 || type==3){
			selSql.append(",max(l.create_time) as  odertime ");
        }
        selSql.append(" FROM  (select * from sys_sort where pid='a316f70c-1184-44b9-a636-dbe10262f176')t  ");
        selSql.append(" inner join tb_lib_book_info f on t.code = f.child_theme ");
		selSql.append(" left join tb_lib_book_theme_heat h on f.child_theme = h.book_theme ");
        selSql.append(" left join tb_lib_book_detail l on f.id = l.info_id ");
        selSql.append(" left join tb_lib_user_history y on l.id = y.book_detail_id ");

        selSql.append("  WHERE  f.book_stock_remain >0 ");
        selSql.append(" and  f.lib_id =? and l.bookcase is not null ");
        selSql.append(" AND LENGTH(f.child_theme)>1  ");
        queryParams.add(params.get("libId"));
        if(params.get("title")!=null && !"".equals(params.get("title"))){
            selSql.append("  and f.title like CONCAT('%',?,'%') \n");
            queryParams.add(params.get("title"));
        }
		if(!"".equals(params.get("grade"))){
			selSql.append("  and  f.section in ('").append(params.get("grade").toString().replace(",","','")).append("') ");
		}
		if(!"".equals(params.get("ptheme"))){
			selSql.append("  and (f.parent_theme in ('").append(params.get("ptheme").toString().replace(",","','")).append("') ");
			if(!"".equals(params.get("ctheme"))){
				selSql.append("  or f.child_theme in ('").append(params.get("ctheme").toString().replace(",","','")).append("')) ");
			}else{
				selSql.append("  )");
			}
		}else{
			if(!"".equals(params.get("ctheme"))) {
				selSql.append("  and f.child_theme in ('").append(params.get("ctheme").toString().replace(",", "','")).append("') ");
			}
		}
        selSql.append("  group by t.id ");
        if(2==type){
			selSql.append(" ORDER BY h.heat desc  ");
        }else{
			selSql.append(" ORDER BY odertime desc  ");
        }
        return dao.findPage(selSql.toString(),queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> getBooksAndLibIdAndchildTheme(
			Map<String, Object> params, Pageable pageable) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append(" SELECT  l.id,f.title,f.local_image,f.isbn13 ,  l.id as book_detail_id , l.info_id as    book_info_id,f.book_stock_remain as book_size,t.name as theme,h.heat   ");
		selSql.append(" FROM 	tb_lib_book_detail l ");
		selSql.append(" JOIN tb_lib_book_info f ON l.info_id = f.id ");
		selSql.append(" left JOIN tb_lib_book_isbn_heat h ON f.isbn13 = h.isbn13 ");
		selSql.append(" join (select * from sys_sort where pid='a316f70c-1184-44b9-a636-dbe10262f176')t on f.child_theme=t.code");
		selSql.append(" left join tb_lib_user_history y on l.id = y.book_detail_id ");
		selSql.append("  WHERE  l.user_id is null  ");
		selSql.append(" and  l.lib_id =? 	 AND f.child_theme =?  ");
		selSql.append("    and f.book_stock_remain >0  \n");
		selSql.append("      and l.bookcase is not null ");
		
		queryParams.add(params.get("libId"));
		queryParams.add(params.get("childTheme"));

		if(!"".equals(params.get("grade"))){
			selSql.append("  and  f.section in ('").append(params.get("grade").toString().replace(",","','")).append("') ");
		}
		if(params.get("title")!=null && !"".equals(params.get("title"))){
			selSql.append("  and f.title like CONCAT('%',?,'%') \n");
			queryParams.add(params.get("title"));
		}
        selSql.append(" GROUP BY l.info_id");
		selSql.append(" ORDER BY l.create_time desc ");

		return dao.findPage(selSql.toString(), queryParams.toArray(),pageable);
	}

	@Override
	public Page<Map<String, Object>> getCallOutOrInList(String libId, int type,Pageable pageable) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("  SELECT  l.book_info_id,f.title,f.local_image,f.isbn13 ,  l.id  ,(SELECT  t.`name` from sys_sort t where t.`code` = f.child_theme LIMIT 1 ) as theme,l.book_size as select_size,f.book_stock_remain as book_size,t.heat    ");
		selSql.append("  FROM 	tb_lib_book_locking l  ");
		selSql.append("  JOIN tb_lib_book_info f ON l.book_info_id = f.id  ");
		selSql.append("left join tb_lib_book_isbn_heat t on f.isbn13 = t.isbn13");
		selSql.append("   WHERE   l.stat =? and l.in_lib_id =? ");
		queryParams.add(type);
		queryParams.add(libId);
		selSql.append(" ORDER BY l.create_time desc ");	
		return dao.findPage(selSql.toString(), queryParams.toArray(),pageable);
	}

}
