package com.pcloud.book.advertising.dao.impl;

import com.pcloud.book.advertising.dao.AdvertisingDistributionBookDao;
import com.pcloud.book.advertising.dto.QrcodeAdvertisingSpaceCountDTO;
import com.pcloud.book.advertising.entity.AdvertisingDistributionBook;
import com.pcloud.common.core.dao.BaseDaoImpl;

import org.springframework.stereotype.Repository;

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

/**
 * Description 广告位投放书籍数据访问层接口实现类
 * @author PENG
 * @date 2019/2/28
 */
@Repository("advertisingDistributionBookDao")
public class AdvertisingDistributionBookDaoImpl extends BaseDaoImpl<AdvertisingDistributionBook> implements AdvertisingDistributionBookDao {

    /**
     * 批量新增
     */
    @Override
    public long batchInsert(List<AdvertisingDistributionBook> list) {
        return super.getSqlSession().insert(getStatement("batchInsert"), list);
    }

    /**
     * 校验广告位是否已投放微信群
     */
    @Override
    public List<Long> checkQrcodeIdExist(Map<String, Object> paramMap) {
        return super.getSqlSession().selectList(getStatement("checkQrcodeIdExist"), paramMap);
    }

    /**
     * 获取广告位投放的书刊列表
     */
    @Override
    public List<AdvertisingDistributionBook> getByAdId(Long adId) {
        return super.getSqlSession().selectList(getStatement("getByAdId"), adId);
    }

    @Override
    public Map<Long, QrcodeAdvertisingSpaceCountDTO> mapAdvertisingSpaceNum(List<Long> qrcodeIds) {
        return this.getSqlSession().selectMap(this.getStatement("mapAdvertisingSpaceNum"), qrcodeIds, "qrcodeId");
    }

    @Override
    public AdvertisingDistributionBook getChannelIdByAdIdBookId(Long adId, Long bookId) {
        Map<String, Object> map = new HashMap<>();
        map.put("adId", adId);
        map.put("bookId", bookId);
        return getSessionTemplate().selectOne(getStatement("getChannelIdByAdIdBookId"), map);
    }
}
