/**
 *
 */
package com.pcloud.book.book.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import com.google.common.collect.Maps;
import com.pcloud.book.book.dao.BookDao;
import com.pcloud.book.book.dto.BookDto;
import com.pcloud.book.book.dto.BookInfo4AnlysicsDTO;
import com.pcloud.book.book.dto.BookInfoAnalysicsDTO;
import com.pcloud.book.book.entity.Book;
import com.pcloud.common.core.dao.BaseDaoImpl;

/**
 * @描述：书籍数据访问层实现类
 * @作者：songx
 * @创建时间：2016年12月23日,下午2:58:15
 * @版本：1.0
 */
@Repository("bookDao")
public class BookDaoImpl extends BaseDaoImpl<Book> implements BookDao {

    /**
     * 批量删除
     */
    public Integer deleteByIds(List<Long> bookIds, Long deleteUserId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("bookIds", bookIds);
        paramMap.put("lastModifiedUser", deleteUserId);
        return super.getSqlSession().update(super.getStatement("deleteByIds"), paramMap);
    }

    /**
     * 获取书籍基础信息
     */
    @Override
    public BookDto getBaseById(Long bookId) {
        return super.getSqlSession().selectOne(super.getStatement("getBaseById"), bookId);
    }

    /**
     * 根据ISBN获取图书信息
     */
    @Override
    public BookDto getByIsbnAndSnumContainsDelete(String isbn, String serialNumber) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("isbn", isbn);
        paramMap.put("serialNumber", serialNumber);
        return super.getSqlSession().selectOne(super.getStatement("getByIsbnAndSnumContainsDelete"), paramMap);
    }

    //	/**
    //	 * 根据ISBN获取图书信息
    //	 */
    //	@Override
    //	public BookDto getByIsbn(String isbn) {
    //		return super.getSqlSession().selectOne(super.getStatement("selectByIsbn"), isbn);
    //	}


    /**
     * 获取单个书籍基础信息(包含统计信息)
     */
    @Override
    public BookDto getById(Map<String, Object> paramMap) {
        return super.getSqlSession().selectOne(super.getStatement("getById"), paramMap);
    }

    /**
     * 批量获取书籍信息
     */
    @Override
    public Map<Long, BookDto> getMapByIds(List<Long> bookIds) {
        return super.getSqlSession().selectMap(super.getStatement("getMapByIds"), bookIds, "bookId");
    }

    /**
     * 批量获取书籍信息（书名 与书刊序号 封面图）
     */
    @Override
    public Map<Long, BookDto> listBaseMapByIds(List<Long> bookIds) {
        return super.getSqlSession().selectMap(super.getStatement("listBaseMapByIds"), bookIds, "bookId");
    }

    @Override
    public List<BookDto> listDetailByIds(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(super.getStatement("listDetailByIds"), paramMap);
    }

    /**
     * 根据名称获取ID
     */
    @Override
    public List<Long> getIdsByName(String bookName) {
        return super.getSqlSession().selectList(super.getStatement("getIdsByName"), bookName);
    }

    /**
     * 根据名称获取ID
     */
    @Override
    public List<Long> getIdsByNameMap(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(super.getStatement("getIdsByNameMap"), paramMap);
    }

    /**
     * 图书收益，获取书籍列表(编辑)
     */
    @Override
    public List<BookDto> getList4AdviserProfit(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(super.getStatement("getList4AdviserProfit"), paramMap);
    }

    /**
     * 根据刊物序号获取刊物信息
     */
    @Override
    public BookDto getBySerialNum(String serialNumber) {
        return super.getSqlSession().selectOne(super.getStatement("getBySerialNum"), serialNumber);
    }

    /**
     * 根据ISBN获取书刊信息（包含删除图书数据）
     */
    @Override
    public BookDto getByIsbn(String isbn) {
        return super.getSqlSession().selectOne(super.getStatement("getByIsbn"), isbn);
    }


    /**
     * 获取书籍详细信息（包含书籍关联二维码 商品 应用）
     */
    @Override
    public BookDto getDetailByIsbn(Map<String, Object> paramMap) {
        return super.getSqlSession().selectOne(super.getStatement("getDetailByIsbn"), paramMap);
    }

    /**
     * 获取书刊列表
     */
    @Override
    public List<BookDto> getListPage4Platform(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(super.getStatement("getListPage4Platform"), paramMap);
    }

    /**
     * 获取书籍总数
     */
    @Override
    public int getAllBookCount() {
        return super.getSqlSession().selectOne(super.getStatement("getAllBookCount"));
    }

    /**
     * 条件查询获取书籍总数
     */
    @Override
    public int getBookCount4Platform(Map<String, Object> paramMap) {
        return super.getSqlSession().selectOne(super.getStatement("getBookCount4Platform"), paramMap);
    }

    /**
     * 修改书籍封面图
     */
    @Override
    public void updateCoverImg(Book book) {
        super.getSqlSession().update(this.getStatement("updateCoverImg"), book);
    }

    /**
     * 获取应用关联图书
     */
    @Override
    public List<BookDto> listBookByAppId(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(this.getStatement("listBookByAppId"), paramMap);
    }

    /**
     * 删除图书
     */
    @Override
    public Integer deleteBook(Long bookId, Long deleteUserId) {
        Map<String, Long> paramMap = new HashMap<String, Long>();
        paramMap.put("bookId", bookId);
        paramMap.put("lastModifiedUser", deleteUserId);
        return super.getSqlSession().update(this.getStatement("deleteBook"), paramMap);
    }

    /**
     * 获取出版下除默认生成图书的所有图书总数
     */
    @Override
    public Integer getAllBookCount4Agent(Map<String, Object> param) {
        return super.getSqlSession().selectOne(this.getStatement("getAllBookCount4Agent"), param);
    }

    /**
     * 根据isbn获取图书信息
     */
    @Override
    public Map<Long, BookDto> listByIsbn(String isbn) {
        return super.getSqlSession().selectMap(this.getStatement("listByIsbn"), isbn, "bookId");
    }

    /**
     * 获取图书总数除RAYS现代纸书
     */
    @Override
    public Integer getAllBookCount4Platform(Map<String, Object> param) {
        return super.getSqlSession().selectOne(this.getStatement("getAllBookCount4Platform"), param);
    }

    /**
     * 获取编辑图书模板
     */
    @Override
    public Long getTempletId(Long adviserId, Long channelId, Long bookId) {
        Map<String, Long> paramMap = new HashMap<>();
        paramMap.put("adviserId", adviserId);
        paramMap.put("channelId", channelId);
        paramMap.put("bookId", bookId);
        return super.getSqlSession().selectOne(this.getStatement("getTempletId"), paramMap);
    }

    /**
     * 修改图书基本信息
     */
    @Override
    public void updateByAdviser(Book book) {
        super.getSqlSession().update(this.getStatement("updateByAdviser"), book);
    }

    /**
     * 根据图书isbn和序号获取图书基本信息（不包含删除图书）
     * @param isbn
     * @param serialNumber
     * @return
     */
    public BookDto getByIsbnAndSnum(String isbn, String serialNumber) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("isbn", isbn);
        paramMap.put("serialNumber", serialNumber);
        return super.getSqlSession().selectOne(this.getStatement("getByIsbnAndSnum"), paramMap);
    }

    @Override
    public List<BookDto> getList4Adviser(Map<String, Object> param) {
        return super.getSqlSession().selectList(this.getStatement("getListPage4Adviser"), param);
    }

    @Override
    public void updateTimeById(Map<String, Object> param) {
        super.getSqlSession().update(super.getStatement("updateTimeById"), param);
    }

    @Override
    public void updateTimeByIds(Map<String, Object> param) {
        super.getSqlSession().update(super.getStatement("updateTimeByIds"), param);
    }

    @Override
    public List<BookInfoAnalysicsDTO> getBookInfoBy(Map<String, Object> param) {
        return super.getSqlSession().selectList(this.getStatement("getBookInfoBy"), param);
    }

    @Override
    public List<BookInfo4AnlysicsDTO> getBookAnalysis(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(this.getStatement("getBookAnalysis"), paramMap);
    }

    @Override
    public List<BookDto> listBookIdAndChannelId4Adviser(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(getStatement("listBookIdAndChannelId4Adviser"), paramMap);
    }

    /**
     * 获取社群书列表
     */
    @Override
    public List<BookDto> listSimpleBookGroup4Adviser(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(getStatement("listSimpleBookGroup4Adviser"), paramMap);
    }

    @Override
    public List<BookDto> listBookGroup4Adviser(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(getStatement("listBookGroup4Adviser"),paramMap);
    }

    @Override
    public List<Long> getIdsByNameOrISBN(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(super.getStatement("getIdsByNameOrISBN"), paramMap);
    }
}
