package com.ycwl.basic.clickhouse.service.impl;

import com.ycwl.basic.clickhouse.service.StatsQueryService;
import com.ycwl.basic.mapper.StatisticsMapper;
import com.ycwl.basic.model.mobile.statistic.req.CommonQueryReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * MySQL 统计数据查询服务实现
 * 当 clickhouse.enabled 未启用时使用此实现（兜底）
 */
@Slf4j
@Service
@ConditionalOnProperty(prefix = "clickhouse", name = "enabled", havingValue = "false", matchIfMissing = true)
public class MySqlStatsQueryServiceImpl implements StatsQueryService {

    @Autowired
    private StatisticsMapper statisticsMapper;

    @Override
    public Integer countPreviewVideoOfMember(CommonQueryReq query) {
        return statisticsMapper.countPreviewVideoOfMember(query);
    }

    @Override
    public Integer countScanCodeOfMember(CommonQueryReq query) {
        return statisticsMapper.countScanCodeOfMember(query);
    }

    @Override
    public Integer countPushOfMember(CommonQueryReq query) {
        return statisticsMapper.countPushOfMember(query);
    }

    @Override
    public Integer countUploadFaceOfMember(CommonQueryReq query) {
        return statisticsMapper.countUploadFaceOfMember(query);
    }

    @Override
    public Integer countCompleteVideoOfMember(CommonQueryReq query) {
        return statisticsMapper.countCompleteVideoOfMember(query);
    }

    @Override
    public Integer countCompleteOfVideo(CommonQueryReq query) {
        return statisticsMapper.countCompleteOfVideo(query);
    }

    @Override
    public Integer countTotalVisitorOfMember(CommonQueryReq query) {
        return statisticsMapper.countTotalVisitorOfMember(query);
    }

    @Override
    public Integer countPreviewOfVideo(CommonQueryReq query) {
        return statisticsMapper.countPreviewOfVideo(query);
    }

    @Override
    public List<Long> getBrokerIdListForUser(Long memberId, Date startTime, Date endTime) {
        return statisticsMapper.getBrokerIdListForUser(memberId, startTime, endTime);
    }

    @Override
    public Long getUserRecentEnterType(Long memberId, Date endTime) {
        return statisticsMapper.getUserRecentEnterType(memberId, endTime);
    }

    @Override
    public List<Long> getProjectIdListForUser(Long memberId, Date startTime, Date endTime) {
        return statisticsMapper.getProjectIdListForUser(memberId, startTime, endTime);
    }

    @Override
    public Integer countBrokerScanCount(Long brokerId) {
        return statisticsMapper.countBrokerScanCount(brokerId);
    }

    @Override
    public List<HashMap<String, Object>> getDailyScanStats(Long brokerId, Date startTime, Date endTime) {
        return statisticsMapper.getDailyScanStats(brokerId, startTime, endTime);
    }

    @Override
    public List<HashMap<String, String>> scanCodeMemberChartByHour(CommonQueryReq query) {
        return statisticsMapper.scanCodeMemberChartByHour(query);
    }

    @Override
    public List<HashMap<String, String>> scanCodeMemberChartByDate(CommonQueryReq query) {
        return statisticsMapper.scanCodeMemberChartByDate(query);
    }

    @Override
    public List<HashMap<String, String>> printerFromSampleChartByHour(CommonQueryReq query) {
        return statisticsMapper.printerFromSampleChartByHour(query);
    }

    @Override
    public List<HashMap<String, String>> printerFromSampleChartByDate(CommonQueryReq query) {
        return statisticsMapper.printerFromSampleChartByDate(query);
    }
}
