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

import com.ssj.dao.weixin.library.dao.BookBorrowQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.framework.weixin.util.Collections3;
import com.ssj.service.weixin.library.dto.out.BookScanViewOutDto;
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;


/**
 * @author  ZhangCaibao
 * @version 2018年8月17日 下午3:59:57
 * 类说明
 */
@Repository
public  class BookBorrowQueryDaoImpl implements  BookBorrowQueryDao {
	@Autowired
	private PagingHibernateJdbcDao dao;

	@Override
	public Page<Map<String, Object>> myWish(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  b.author,b.local_image,b.summary,b.title,w.isbn13,  ");
		selSQL.append(" 5- (SELECT count(id) from  tb_lib_book_borrow  p where p.isbn13 = w.isbn13 and  p.type=4 and p.stat=1 and p.vip_id = w.vip_id and p.lib_id = w.lib_id ) as cishu   ");
		selSQL.append("  ,(TO_DAYS(NOW())-TO_DAYS(w.create_time)) as wish_day ");
		selSQL.append("  from   tb_lib_book_borrow w   join  tb_lib_book_base b  ");
		selSQL.append(" on w.isbn13 =b.isbn13 and   w.type=2 and w.stat=1 ");
		selSQL.append(" where w.vip_id=? and w.lib_id=?  and  w.type=2 and w.stat=1   ");
		queryParams.add(searchParams.get("vipId"));
		queryParams.add(searchParams.get("libId"));
		selSQL.append("   ORDER BY w.create_time desc   ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> othersWish(Map<String, Object> searchParams,
												Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  b.author,b.local_image,b.summary,b.title,w.isbn13,w.vip_id, ");
		selSQL.append(" 5- (SELECT count(id) from  tb_lib_book_borrow  p where p.isbn13 = w.isbn13 and  p.type=4 and p.stat=1 and p.vip_id =w.id  ) as cishu   ");
		selSQL.append(" ,case when c.id is null then '2' else '1' end as ishelp      ");
		selSQL.append("  from   tb_lib_book_borrow w   join  tb_lib_book_base b  ");
		selSQL.append(" on w.isbn13 =b.isbn13  \n");
		selSQL.append("left join tb_lib_book_borrow c on w.isbn13 = c.isbn13 and c.type=4 and c.stat=1 and c.user_id=? and w.vip_id = c.vip_id and w.lib_id = c.lib_id \n");
		selSQL.append(" where  w.lib_id=?  and w.user_id not in (?)");
		selSQL.append(" and   w.type=2 and w.stat=1   ");
		selSQL.append("   ORDER BY w.create_time desc   ");
		queryParams.add(searchParams.get("userId"));
		queryParams.add(searchParams.get("libId"));
		queryParams.add(searchParams.get("userId"));
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Map<String, Object> wishDetails(String isbn13, String vipId,String libId) {
		StringBuilder selSql = new StringBuilder();
		Map<String, Object> map = new HashMap<>();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT   b.author,b.local_image,b.summary,b.title,c.user_id, ");
		selSql.append(" 5-(SELECT count(id) from  tb_lib_book_borrow  o where o.isbn13 = b.isbn13 and o.type=4 and o.stat=1 and o.vip_id = ? and o.lib_id = ?) as cishu,  \n");
		selSql.append("  (TO_DAYS(NOW())-TO_DAYS(c.create_time)) as wish_day ");
		selSql.append(" from   tb_lib_book_base b  ");
		selSql.append(" INNER JOIN tb_lib_book_borrow c on c.isbn13 = b.isbn13 and c.type=2 and c.stat=1 and c.vip_id = ? and c.lib_id = ?  ");
		selSql.append(" where b.isbn13 =?  ");
		queryParams.add(vipId);
		queryParams.add(libId);
		queryParams.add(vipId);
		queryParams.add(libId);
		queryParams.add(isbn13);
		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>> wishUserList(String isbn13, String vipId,String userId,String libId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT  w.isbn13,u.wx_name,u.photo  from   tb_lib_book_borrow w join   tb_user u  on w.user_id = u.id   ");
		selSql.append(" where w.type=4 and w.stat=1 and w.isbn13=? and w.vip_id=? and w.lib_id = ?");
		queryParams.add(isbn13);
		queryParams.add(vipId);
		queryParams.add(libId);
		return  dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> getLibJoinDispatcher(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("  select a.league_name,a.id,sum(a.order_num) as order_num,sum(a.wish_num) as wish_num,case when b.audit_stat =0 then 0 when b.audit_stat is null then 0 else 1 end as audit_stat from  ( ");
		selSQL.append(" SELECT b.league_name,b.id,count(if(a.type=1,true,null)) as order_num,count(if(a.type=2,true,null)) as wish_num from tb_lib_book_borrow a \n ");
		selSQL.append("  INNER JOIN tb_lib_join b on a.lib_id = b.id  \n");
		selSQL.append(" where a.stat = 1 \n ");
		if(params.get("joinName")!=null && !"".equals(params.get("joinName"))){
			selSQL.append(" and b.league_name like concat('%',?,'%') \n ");
			queryParams.add(params.get("joinName"));
		}
		selSQL.append(" GROUP BY b.id   \n");
		selSQL.append(" union all   \n");
		selSQL.append(" select b.league_name,b.id,0,0 from  tb_lib_join b where b.libtype>1   \n");
		if(params.get("joinName")!=null && !"".equals(params.get("joinName"))){
			selSQL.append(" and  b.league_name like concat('%',?,'%') \n ");
			queryParams.add(params.get("joinName"));
		}
		selSQL.append(" )  a left join tb_lib_book_switch b on a.id = b.lib_id  ");
		selSQL.append("  GROUP BY a.id ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> libDispatchingList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" select a.id,a.book_stock,a.title,a.local_image,sum(a.order_num) as order_num,sum(a.wish_num) as wish_num,ifnull(a.parent_name,'') as parent_name,ifnull(a.child_name,'') as child_name,a.color from  ( ");
		selSQL.append(" SELECT b.id,b.book_stock,b.title,b.local_image,count(if(a.type=1,true,null)) as order_num,count(if(a.type=2,true,null)) as wish_num,t11.name as parent_name,t12.name as child_name,t11.aliases as color from tb_lib_book_borrow a  \n ");
		selSQL.append(" INNER JOIN tb_lib_book_info b on a.isbn13 = b.isbn13 and b.lib_id='fa14e041-3823-4dac-b061-1e250e5a7d49'  \n"); //总部调度馆写死
		selSQL.append(" left join sys_sort t11 on b.parent_theme = t11.`code`  ");
		selSQL.append(" left join sys_sort t12 on b.child_theme = t12.`code`   ");
		selSQL.append(" where a.stat = 1 and  a.lib_id = ?  and a.type in (1,2) \n ");
		queryParams.add(params.get("libId"));
		if(params.get("bookName")!=null && !"".equals(params.get("bookName"))){
			selSQL.append(" and b.title like concat('%',?,'%') \n ");
			queryParams.add(params.get("bookName"));
		}
		selSQL.append(" GROUP BY b.isbn13,a.type  \n");
		selSQL.append(" union ALL ");
		selSQL.append(" select b.id,b.book_stock,b.title,b.local_image,0,0,t11.name as parent_name,t12.name as child_name,t11.aliases as color from tb_lib_book_locking a ");
		selSQL.append(" INner  JOIN tb_lib_book_info b on a.isbn13 = b.isbn13 and b.lib_id='fa14e041-3823-4dac-b061-1e250e5a7d49'   ");
		selSQL.append(" left join sys_sort t11 on b.parent_theme = t11.`code`  ");
		selSQL.append(" left join sys_sort t12 on b.child_theme = t12.`code`   ");
		selSQL.append(" where in_lib_id=? and a.type=2 and a.stat=2 ");
		queryParams.add(params.get("libId"));
		if(params.get("bookName")!=null && !"".equals(params.get("bookName"))){
			selSQL.append(" and b.title like concat('%',?,'%') \n ");
			queryParams.add(params.get("bookName"));
		}
		selSQL.append(" ) a where a.id is not null group by a.id ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> orderOverTime() {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT t.vip_id,t.isbn13,t.id,t.lib_id from tb_lib_book_borrow t where t.type=3 ");
		selSql.append(" and TIMESTAMPDIFF(DAY,t.create_time,NOW())>2 and t.stat=1");
		return  dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> findHelpTimes(String libId, String vipId, String isbn13) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("SELECT count(1) as help_count,t11.title,t12.league_name from tb_lib_book_borrow t ");
		selSql.append(" left join tb_lib_book_base t11 on  t.isbn13=t11.isbn13  ");
		selSql.append(" left join tb_lib_join t12 on t.lib_id = t12.id  ");
		selSql.append(" where t.lib_id=? and t.vip_id=? and t.type=4 and t.isbn13=?  ");
		queryParams.add(libId);
		queryParams.add(vipId);
		queryParams.add(isbn13);
		List<Map<String, Object>> list =  dao.findMap(selSql.toString(), queryParams.toArray());
		if(list!=null && list.size()>0){
			return list.get(0);
		}else{
			return null;
		}
	}

	@Override
	public Page<Map<String, Object>> findForPage(Map<String, Object> searchParams, Pageable initPage) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT * from ( ");
		selSQL.append("  SELECT t11.league_name,t12.child_name,count(1) as count1,t13.title,t.isbn13 from tb_lib_book_borrow t   ");
		selSQL.append(" left join tb_lib_join t11 on t.lib_id=t11.id ");
		selSQL.append(" left join tb_lib_read_vip t12 on t.vip_id = t12.id ");
		selSQL.append(" left join tb_lib_book_base t13 on t.isbn13=t13.isbn13 ");
		selSQL.append(" where t.type=4 GROUP BY t.lib_id,t.vip_id,t.isbn13 ");
		selSQL.append(" ) a where a.count1>4 ");
		if(searchParams.get("lib_name")!=null && !"".equals(searchParams.get("lib_name"))){
			selSQL.append(" and a.league_name like concat('%',?,'%') ");
			queryParams.add(searchParams.get("lib_name"));
		}
		return dao.findPage(selSQL.toString(), queryParams.toArray(), initPage);
	}

	@Override
	public List<Map<String, Object>> getExportData(Map<String, Object> searchParams) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT * from ( ");
		selSQL.append("  SELECT t11.league_name,t12.child_name,count(1) as count1,t13.title,t.isbn13 from tb_lib_book_borrow t   ");
		selSQL.append(" left join tb_lib_join t11 on t.lib_id=t11.id ");
		selSQL.append(" left join tb_lib_read_vip t12 on t.vip_id = t12.id ");
		selSQL.append(" left join tb_lib_book_base t13 on t.isbn13=t13.isbn13 ");
		selSQL.append(" where t.type=4 GROUP BY t.lib_id,t.vip_id,t.isbn13 ");
		selSQL.append(" ) a where a.count1>4 ");
		if(searchParams.get("lib_name")!=null && !"".equals(searchParams.get("lib_name"))){
			selSQL.append(" and a.league_name like concat('%',?,'%') ");
			queryParams.add(searchParams.get("lib_name"));
		}
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findLibThemeData(String libId,String vipId) {
		StringBuilder selSql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select t.`name` as parent_name,t.child_count,t.book_count,ifnull(t11.bnum,0) as bnum from (");
		selSql.append("select a.`name`,count(name1) as child_count,sum(count1) as book_count,a.aliases,a.parent_theme  from ( ");
		selSql.append(" SELECT t11.`name`,t11.aliases,t.isbn13,t.title,t12.`name` as name1,count(1) as count1,t.parent_theme from tb_lib_book_info t   ");
		selSql.append(" left join tb_lib_book_detail t13 on t.id = t13.info_id   ");
		selSql.append(" left join sys_sort t11 on t.parent_theme = t11.`code`  ");
		selSql.append(" left join sys_sort t12 on t.child_theme = t12.`code`   ");
		selSql.append(" where t.parent_theme is not NULL and LENGTH(t.parent_theme)>0 and t.lib_id=?  GROUP BY t.parent_theme,t.child_theme  ");
		selSql.append(" )a group by a.parent_theme ");
		selSql.append(" ) t LEFT JOIN ( ");
		selSql.append(" 	SELECT count(1) as bnum,c.parent_theme  from tb_lib_user_history a  ");
		selSql.append(" INNER JOIN tb_lib_book_detail b on a.book_detail_id=b.id ");
		selSql.append("   INNER JOIN tb_lib_book_info c on b.info_id=c.id   ");
		selSql.append(" where a.vip_id=?  ");
		selSql.append("  GROUP BY c.parent_theme ");
		selSql.append(" ) t11 on t.parent_theme = t11.parent_theme ");
		queryParams.add(libId);
		queryParams.add(vipId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findBorrowList(String vipId, String libId) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT c.child_theme,d.`name` as child_name,d.aliases,c.title,c.summary,c.local_image,c.isbn13, ");
		selSQL.append("  (select count(1) from tb_lib_book_info t INNER JOIN tb_lib_book_detail t11 on t.id = t11.info_id where t.child_theme=c.child_theme and t.lib_id=?) as book_num   ");
		selSQL.append(" from  tb_lib_book_detail b ");
		selSQL.append(" INNER JOIN tb_lib_book_info c on b.info_id=c.id  ");
		selSQL.append(" INNER JOIN sys_sort d on c.child_theme = d.`code` ");
		selSQL.append(" where b.vip_id=?  ");
		queryParams.add(libId);
		queryParams.add(vipId);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> findThemeBookList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.title,t.isbn13,t.lib_id,t.local_image,t.author,t.summary,t.child_theme  ");
		selSQL.append("  from tb_lib_book_info t where t.lib_id=? and t.child_theme=? ");
		queryParams.add(params.get("libId"));
		queryParams.add(params.get("childTheme"));
		if(params.get("searchContent")!=null && !"".equals(params.get("searchContent").toString())){
			selSQL.append("  and t.title like concat('%',?,'%')  ");
			queryParams.add(params.get("searchContent"));
		}
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> querySuchList(String inlibId, String outlibId2, String replace, int type) {
		//带书离馆
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT a.book_info_id  ");
		selSQL.append(" from tb_lib_book_locking  a  ");
		selSQL.append(" LEFT   JOIN tb_lib_book_detail b on b.info_id = a.book_info_id  ");
		selSQL.append(" and  b.lib_id = ?  ");
		selSQL.append("and b.id in (?) ");
		selSQL.append(" where  a.in_lib_id = ? and a.out_lib_id = ?  ");
		selSQL.append(" and a.type=? and a.stat=2  and b.id is null ");
		queryParams.add(outlibId2);
		queryParams.add(replace);
		queryParams.add(inlibId);
		queryParams.add(outlibId2);
		queryParams.add(type);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> cancelLibList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.id,t.league_name from tb_lib_join t where t.type>0 \n ");
		if(params.get("joinName")!=null && !"".equals(params.get("joinName"))){
			selSQL.append(" and t.league_name like concat('%',?,'%') \n ");
			queryParams.add(params.get("joinName"));
		}
		selSQL.append(" order by t.create_time \n ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Map<String, Object> findLibCancelInfo(String libId) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.id,t.league_name,t.league_address,count(1) as count_total,  ");
		selSQL.append("  count(IF(t11.vip_id is null,true,null)) as in_book,count(IF(t11.vip_id is not null,true,null)) as out_book  ");
		selSQL.append(" from tb_lib_join  t  ");
		selSQL.append(" left join tb_lib_book_detail t11 on t.id = t11.lib_id  ");
		selSQL.append("	where t.id = ? and t11.info_id is not null ");
		selSQL.append(" group by t.id  ");
		queryParams.add(libId);
		List<Map<String, Object>> list = dao.findMap(selSQL.toString(), queryParams.toArray());
		if(list !=null && list.size()>0){
			return  list.get(0);
		}else{
			return null;
		}
	}

	@Override
	public Page<Map<String, Object>> recoveryList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.id,t11.title,ifnull(t12.name,'') as parent_name,ifnull(t13.`name`,'') as child_name,t11.local_image,t12.aliases  as color  \n ");
		selSQL.append(" 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 sys_sort t12 on t11.parent_theme = t12.`code` \n ");
		selSQL.append(" left join sys_sort t13 on t11.child_theme = t13.`code` \n ");
		selSQL.append(" where t.lib_id = ? and t.recovery_type =? \n ");
		queryParams.add(params.get("libId"));
		queryParams.add(params.get("type"));
		String type = params.get("type").toString();
		String stat= params.get("stat").toString();
		if("1".equals(type)){ //回收
			if("1".equals(stat)){
				selSQL.append(" and t.recovery_stat is null \n ");
			}else if("2".equals(stat)){
				selSQL.append(" and t.recovery_stat =1  and t.isscan = ?\n ");
				queryParams.add(params.get("type"));
			}else{
				selSQL.append(" and t.recovery_stat =?  and t.isscan = ?\n ");
				queryParams.add(params.get("stat"));
				queryParams.add(params.get("type"));
			}
		}else{ //入库
			if("1".equals(stat)){
				selSQL.append(" and t.isscan = 1 \n ");
			}else{
				selSQL.append(" and t.recovery_stat =?  and t.isscan = ?\n ");
				queryParams.add(params.get("stat"));
				queryParams.add(params.get("type"));
			}
		}
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Map<String, Object> cancelLibHeadInfo(String libId,int type) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.id,t.league_name,t.league_address,t12.cancel_user,t12.recovery_user, ");
		if(type==1){
			selSQL.append("  count(IF(t11.recovery_stat is null,true,null)) as count_total, count(IF(t11.recovery_stat=1,true,null)) as in_book,count(IF(t11.recovery_stat=3,true,null)) as out_book  ");
		}else{
			selSQL.append("  count(IF(t11.recovery_stat=1,true,null)) as count_total, count(IF(t11.recovery_stat=2 and isscan=2,true,null)) as in_book,count(IF(t11.recovery_stat=3 and isscan=2 ,true,null)) as out_book  ");
		}
		selSQL.append(" from tb_lib_join  t  ");
		selSQL.append(" left join tb_lib_book_detail t11 on t.id = t11.lib_id  ");
		selSQL.append(" left join tb_lib_cancel_info t12 on t.id = t12.lib_id  ");
		selSQL.append("	where t.id = ? and t11.info_id is not NULL ");
		selSQL.append(" group by t.id  ");
		queryParams.add(libId);
		List<Map<String, Object>> list = dao.findMap(selSQL.toString(), queryParams.toArray());
		if(list !=null && list.size()>0){
			return  list.get(0);
		}else{
			return null;
		}
	}

	@Override
	public Page<Map<String, Object>> scanBookList(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		String type = params.get("type").toString();
		List<Object> queryParams = new ArrayList<Object>();
		if("3".equals(type)){ //送书到馆待调配
			selSQL.append(" select b.id,b.title,b.local_image,t12.name as child_name,a.create_time from tb_lib_book_locking a ");
			selSQL.append(" INner  JOIN tb_lib_book_info b on a.book_info_id = b.id  ");
			selSQL.append(" left join sys_sort t12 on b.child_theme = t12.`code` and t12.pid='a316f70c-1184-44b9-a636-dbe10262f176'  ");
			selSQL.append(" where in_lib_id=? and a.type=2 and a.stat=2 order by a.create_time desc");
			queryParams.add(params.get("libId"));
		}else{
			selSQL.append(" select a.id,b.title,b.local_image,t12.name as child_name,a.create_time from tb_lib_book_switch_info a ");
			selSQL.append(" INner  JOIN tb_lib_book_detail c on a.book_detail_id=c.id  ");
			selSQL.append(" INner  JOIN tb_lib_book_info b on c.info_id = b.id  ");
			selSQL.append(" left join sys_sort t12 on b.child_theme = t12.`code` and t12.pid='a316f70c-1184-44b9-a636-dbe10262f176'  ");
			selSQL.append(" where a.lib_id=? and a.type=? and a.state = 1  order by a.create_time desc ");
			queryParams.add(params.get("libId"));
			queryParams.add(params.get("type"));
		}
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public BookScanViewOutDto findScanForBookDetail(String detailId) {
		StringBuilder sql = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		sql.append("SELECT t.id as detail_id,t11.title,t11.local_image,t14.name as theme_name,t13.league_name as lib_name,t11.summary,t11.author,t11.section as grade,t11.isbn13,t12.child_name as borrow_name,t11.price from tb_lib_book_detail t \n");
		sql.append("left join tb_lib_book_info t11 on t.info_id = t11.id\n");
		sql.append("left join tb_lib_read_vip t12 on t.vip_id = t12.id\n");
		sql.append("left join tb_lib_join t13 on t.lib_id = t13.id\n");
		sql.append("left join sys_sort t14 on t11.child_theme = t14.`code` and t14.pid='a316f70c-1184-44b9-a636-dbe10262f176'\n");
		sql.append("where t.id = ? ");
		queryParams.add(detailId);
		List<BookScanViewOutDto> list = dao.findList(sql.toString(),queryParams.toArray(),BookScanViewOutDto.class);
		return Collections3.isEmpty(list)? new BookScanViewOutDto():list.get(0);
	}
}
