package com.ruoyi.dxp.service.impl;

import com.ruoyi.dxp.dto.BarChartDto;
import com.ruoyi.dxp.dto.BarChartParam;
import com.ruoyi.dxp.dto.IndexStaticsDto;
import com.ruoyi.dxp.dto.WholeAccessBarChartDto;
import com.ruoyi.dxp.mapper.*;
import com.ruoyi.dxp.service.IIndexStaticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexStaticsImplService implements IIndexStaticsService {

    @Autowired
    private IndexStaticsMapper indexStaticsMapper;

    /**
     * 获取首页统计
     */
    @Override
    public IndexStaticsDto getIndexStatics() {
        IndexStaticsDto indexStaticsDto = new IndexStaticsDto();
        indexStaticsDto.setAccessTableCount(indexStaticsMapper.selectTableCount());
        indexStaticsDto.setShareTableCount(indexStaticsMapper.selectDataShareCount());
        indexStaticsDto.setAccessDataItemCount(indexStaticsMapper.selectDataItemCount());
        indexStaticsDto.setShareDataItemCount(indexStaticsMapper.selectShareDataItemCount());
        indexStaticsDto.setAccessServiceCount(indexStaticsMapper.selectServiceCount());
        indexStaticsDto.setShareServiceCount(indexStaticsMapper.selectShareServiceCount());
        indexStaticsDto.setLiteratureCount(indexStaticsMapper.selectLiteratureCount());
        indexStaticsDto.setUserCount(indexStaticsMapper.selectUserCount());
        indexStaticsDto.setCompanyCount(indexStaticsMapper.selectCompanyCount());
        indexStaticsDto.setAppCount(indexStaticsMapper.selectAppCount());
        return indexStaticsDto;
    }

    /**
     * 获取资源访问数据
     */
    @Override
    public List<BarChartDto> getCallData(BarChartParam param) {
        // 查询调用数据
        if (param.getUnit().equals("y")) {
            return indexStaticsMapper.selectStaticsByYear(param);
        } else if (param.getUnit().equals("m")) {
            return indexStaticsMapper.selectStaticsByMonth(param);
        } else if (param.getUnit().equals("d")) {
            return indexStaticsMapper.selectStaticsByDay(param);
        }
        return null;
    }

    /**
     * 查询接入数据日分组
     */
    @Override
    public List<WholeAccessBarChartDto> selectAccessAndShareGroupData(BarChartParam param) {
        return indexStaticsMapper.selectAccessAndShareGroupData(param);
    }
}
