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

import com.pcloud.book.group.dao.AppClickRecordDao;
import com.pcloud.book.group.dto.AppClickDTO;
import com.pcloud.book.group.dto.AppStatisticsDTO;
import com.pcloud.book.group.dto.BookGroupAppDTO;
import com.pcloud.book.group.dto.BookGroupIdAndCountDTO;
import com.pcloud.book.group.dto.CountAndTimeDTO;
import com.pcloud.book.group.entity.AppClickRecord;
import com.pcloud.book.group.vo.GroupScanTrendParamVO;
import com.pcloud.book.group.vo.GroupScanTrendVO;
import com.pcloud.book.group.vo.ResourceClickVO;
import com.pcloud.book.group.vo.ResourcesStatisticVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;

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

/**
 * @Description
 * @Author ruansiyuan
 * @Date 2019/5/29 17:43
 **/
@Component("appClickRecordDao")
public class AppClickRecordDaoImpl extends BaseDaoImpl<AppClickRecord> implements AppClickRecordDao {
    @Override
    public List<AppStatisticsDTO> getClickStatisticsByServeIds(List<Long> serveIds, Long qrcodeId, Long bookGroupId) {
        Map<String, Object> map = new HashMap<>();
        map.put("qrcodeId", qrcodeId);
        map.put("bookGroupId", bookGroupId);
        map.put("serveIds", serveIds);
        return this.getSqlSession().selectList(this.getStatement("getClickStatisticsByServeIds"), map);
    }

    @Override
    public List<AppClickDTO> getRecentlyClick(Long wechatUserId, Long qrcodeId, Integer top) {
        Map<String, Object> map = new HashMap<>();
        map.put("qrcodeId", qrcodeId);
        map.put("wechatUserId", wechatUserId);
        map.put("top", top);
        return this.getSqlSession().selectList(this.getStatement("getRecentlyClick"), map);
    }

    @Override
    public List<GroupScanTrendVO> getClickTrend(GroupScanTrendParamVO groupScanTrendParamVO) {
        return this.getSqlSession().selectList(this.getStatement("getClickTrend"), groupScanTrendParamVO);
    }

    @Override
    public Map<Long, ResourceClickVO> getResourceClick(Map<String, Object> map) {
        return this.getSqlSession().selectMap(this.getStatement("getResourceClick"), map,"rescourceId");
    }

    @Override
    public Long getRescourceTotalClick(Long bookGroupId, Long classifyId, Long qrcodeId, String type) {
        Map<String, Object> map = new HashMap<>();
        map.put("qrcodeId", qrcodeId);
        map.put("bookGroupId", bookGroupId);
        map.put("classifyId", classifyId);
        map.put("type", type);
        return this.getSqlSession().selectOne(this.getStatement("getRescourceTotalClick"), map);
    }

    @Override
    public List<Long> getRescourceIds(Long bookGroupId, Long classifyId, Long qrcodeId, String type) {
        Map<String, Object> map = new HashMap<>();
        map.put("qrcodeId", qrcodeId);
        map.put("bookGroupId", bookGroupId);
        map.put("classifyId", classifyId);
        map.put("type", type);
        return this.getSqlSession().selectList(this.getStatement("getRescourceIds"), map);
    }

    @Override
    public List<ResourcesStatisticVO> getClickStatistics(Long bookGroupId, Long classifyId, Long qrcodeId, String type) {
        Map<String, Object> map = new HashMap<>();
        map.put("qrcodeId", qrcodeId);
        map.put("bookGroupId", bookGroupId);
        map.put("classifyId", classifyId);
        map.put("type", type);
        return this.getSqlSession().selectList(this.getStatement("getClickStatistics"), map);
    }

    @Override
    public List<CountAndTimeDTO> getAppClickByTime(Integer joinGroupType, Integer timeType, String startTime, String endTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("joinGroupType", joinGroupType);
        map.put("timeType", timeType);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        return getSessionTemplate().selectList(getStatement("getAppClickByTime"), map);
    }

    @Override
    public List<BookGroupAppDTO> getClickCountByServe(Long bookGroupId, String serveType, List<Long> serveIds) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookGroupId", bookGroupId);
        map.put("serveIds", serveIds);
        map.put("serveType", serveType);
        return getSessionTemplate().selectList(getStatement("getClickCountByServe"), map);
    }

    @Override
    public List<BookGroupAppDTO> getClickPeopleCountByServe(Long bookGroupId, String serveType, List<Long> serveIds) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookGroupId", bookGroupId);
        map.put("serveIds", serveIds);
        map.put("serveType", serveType);
        return getSessionTemplate().selectList(getStatement("getClickPeopleCountByServe"), map);
    }

    @Override
    public List<CountAndTimeDTO> getAppClickByBookGroupId(Long bookGroupId, List<String> dateList) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookGroupId", bookGroupId);
        map.put("dateList", dateList);
        return getSessionTemplate().selectList(getStatement("getAppClickByBookGroupId"), map);
    }

    @Override
    public List<BookGroupIdAndCountDTO> getClPeCoByBookGroupIds(List<Long> bookGroupIds) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookGroupIds", bookGroupIds);
        return getSessionTemplate().selectList(getStatement("getClPeCoByBookGroupIds"), map);
    }

    @Override
    public List<BookGroupIdAndCountDTO> getClCoByBookGroupIds(List<Long> bookGroupIds) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookGroupIds", bookGroupIds);
        return getSessionTemplate().selectList(getStatement("getClCoByBookGroupIds"), map);
    }

    @Override
    public List<CountAndTimeDTO> getAppClickGroupByTime(Long bookGroupId, Long serveId, String serveType) {
        Map<String, Object> map = new HashMap<>();
        map.put("bookGroupId", bookGroupId);
        map.put("serveId", serveId);
        map.put("serveType", serveType);
        return getSessionTemplate().selectList(getStatement("getAppClickGroupByTime"), map);
    }

}
