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

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.weixin.libmy.domain.TbLibBookInfo;
import com.ssj.dao.weixin.library.dao.ILibBookDao;
import com.ssj.dao.weixin.library.dao.ILibJoinQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.persistence.DynamicSpecifications;
import com.ssj.framework.core.persistence.SearchFilter;
import com.ssj.service.weixin.library.service.ILibBookService;


@Service(version="1.0")
public class LibBookServiceImpl extends BaseServiceImpl<TbLibBookInfo, String> implements ILibBookService {

	@Autowired
	private ILibBookDao dao;
	
	@Autowired
	private ILibJoinQueryDao  libJoinQueryDao;
	
	@Override
	public PagingAndSortingRepository<TbLibBookInfo, String> getDao() {
		
		return dao;
	}

	@Override
	public TbLibBookInfo findByIsbnAndLibId(String isbn13, String libId) {
		
		return dao.findByIsbn13AndLibId(isbn13,libId);
	}

	@Override
	public Page<TbLibBookInfo> findByPage(Map<String, Object> params,
			Pageable sp) {
		 Map<String, SearchFilter> filters = SearchFilter.parse(params);
			Specification<TbLibBookInfo> specification = DynamicSpecifications.bySearchFilter(filters.values(), TbLibBookInfo.class);    
		return  dao.findAll(specification, sp);
	}

	@Override
	public List<TbLibBookInfo> findByInfoLibId(String libId) {
		return dao.findByInfoLibId(libId);
	}

	@Override
	public Page<Map<String, Object>> findForPageList(
			Map<String, Object> searchParams, Pageable pageable) {
		return libJoinQueryDao.findForPageList(searchParams, pageable);
	}

	@Override
	public TbLibBookInfo findBookInfoByIsbn(String isbn13) {
		
		return dao.findBookInfoByIsbn(isbn13);
	}

	@Override
	public TbLibBookInfo findByIsbn(String isbn13) {
		
		return dao.findByIsbn(isbn13);
	}

	@Override
	public List<Map<String, Object>> getTopAndLibId( int topSize) {
		return libJoinQueryDao.getTopAndLibId( topSize);
	}

	@Override
	public List<Map<String, Object>> getdefaultBookAndLibId(String libId, String[] isbn,String searchContent,String vipId,int type) {
		return libJoinQueryDao.getdefaultBookAndLibId(libId, isbn,searchContent,vipId,type);
	}
	@Override
	public List<Map<String, Object>> getdefaultBookAndLibId(String libId, String bookName) {
		return libJoinQueryDao.getdefaultBookAndLibId(libId,bookName);
	}

	@Override
	public List<Map<String, Object>> getdefaultBookAndLibId(String[] isbn,String searchContent,String vipId) {
		return libJoinQueryDao.getdefaultBookAndLibId(isbn,searchContent,vipId);
	}

	@Override
	public List<Map<String, Object>> alreadyBookAndLibId(String libId,
			String vipId) {
		return libJoinQueryDao.alreadyBookAndLibId(libId, vipId);
	}

	@Override
	public Page<Map<String, Object>> growthRecordList(
			Map<String, Object> params, Pageable pageable) {
		return libJoinQueryDao.growthRecordList(params, pageable);
	}

	@Override
	public Integer findPlCount(String isbn13) {
		return dao.findPlCount(isbn13);
	}

	@Override
	public Map<String, Object> getIsbnBorrowInfo(String isbn13) {
		
		return libJoinQueryDao.getIsbnBorrowInfo(isbn13);
	}

	@Override
	public void delNodetailInfoData(String libId) {
		dao.delNodetailInfoData(libId);
	}

}
