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

import com.pcloud.book.group.dao.ResourcePageDao;
import com.pcloud.book.group.dto.AddBookGroupServeDTO;
import com.pcloud.book.group.entity.ResourcePage;
import com.pcloud.common.core.dao.BaseDaoImpl;

import org.springframework.stereotype.Component;

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

/**
 * @ClassName com.pcloud.book.group.dao.impl.ResourcePageDaoImpl
 * @Author zhuyajie
 * @Description 自有码H5页面
 * @Date 2021/3/26 15:32
 * @Version 1.0
 **/
@Component
public class ResourcePageDaoImpl extends BaseDaoImpl<ResourcePage> implements ResourcePageDao {
    @Override
    public ResourcePage getByBookGroupId(Long bookGroupId) {
        return getSessionTemplate().selectOne(getStatement("getByBookGroupId"), bookGroupId);
    }

    @Override
    public ResourcePage getByBookId(Long bookId, Long channelId, Long adviserId) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookId", bookId);
        map.put("channelId", channelId);
        map.put("adviserId", adviserId);
        return getSessionTemplate().selectOne(getStatement("getByBookId"), map);
    }

    @Override
    public void updatePageUpdateTime(Long resourcePageId) {
        getSessionTemplate().update(getStatement("updatePageUpdateTime"), resourcePageId);
    }

    @Override
    public ResourcePage getBySceneId(Long sceneId) {
        return getSessionTemplate().selectOne(getStatement("getBySceneId"), sceneId);
    }

    @Override
    public ResourcePage getPageByOfficialScene(Long officialSceneId) {
        return getSessionTemplate().selectOne(getStatement("getPageByOfficialScene"), officialSceneId);
    }

    @Override
    public List<Long> getOpenRaysSceneIds(List<Long> sceneIds) {
        return getSessionTemplate().selectList(getStatement("getOpenRaysSceneIds"), sceneIds);
    }

    @Override
    public void batchUpdateSceneIdByBookGroup(List<AddBookGroupServeDTO> list) {
        getSessionTemplate().update(getStatement("batchUpdateSceneIdByBookGroup"), list);
    }

    @Override
    public ResourcePage getPageByColumnId(Long resourcePageColumnId) {
        return getSessionTemplate().selectOne(getStatement("getPageByColumnId"), resourcePageColumnId);
    }

    @Override
    public List<Long> getSceneIdsByResourceId(Long resourceId) {
        return getSessionTemplate().selectList(getStatement("getSceneIdsByResourceId"), resourceId);
    }

    @Override
    public void updateBookBySceneIds(List<Long> sceneIds, Long bookId, Long channelId) {
        Map<String, Object> map = new HashMap<>();
        map.put("sceneIds", sceneIds);
        map.put("bookId", bookId);
        map.put("channelId", channelId);
        getSessionTemplate().update(getStatement("updateBookBySceneIds"), map);
    }

    @Override
    public void setOtherPageRaysClose(Long bookId, Long channelId, Long createUser, Long sceneId, Long bookGroupId) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookId", bookId);
        map.put("channelId", channelId);
        map.put("createUser", createUser);
        map.put("bookGroupId", bookGroupId);
        map.put("sceneId", sceneId);
        getSessionTemplate().update(getStatement("setOtherPageRaysClose"), map);
    }

    @Override
    public Boolean isOpenRaysBook(Long bookId, Long channelId, Long adviserId) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookId", bookId);
        map.put("channelId", channelId);
        map.put("adviserId", adviserId);
        return getSessionTemplate().selectOne(getStatement("isOpenRaysBook"), map);
    }
}
