package com.ruoyi.bst.area.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.area.domain.AreaQuery;
import com.ruoyi.bst.area.domain.vo.AreaStatVO;
import com.ruoyi.bst.area.mapper.AreaMapper;
import com.ruoyi.bst.area.service.AreaDashboard;
import com.ruoyi.common.domain.vo.LongIntegerVO;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.dashboard.constants.StatKeys;

@Service
public class AreaDashboardImpl implements AreaDashboard {

    @Autowired
    private AreaMapper areaMapper;

    @Override
    public AreaStatVO selectStat(AreaQuery query, List<String> keys) {
        AreaStatVO vo = new AreaStatVO();
        if (keys.contains(StatKeys.AREA_COUNT)) {
            vo.setCount(this.selectCount(query));
        }
        return vo;
    }

    @Override
    public List<LongIntegerVO> selectMaxOfDeviceCountAreaId(AreaQuery query) {
        PageHelper.orderBy("value desc");
        return areaMapper.selectDeviceCountGroupByAreaId(query);
    }

    @Override
    public Integer selectCount(AreaQuery query) {
        return MathUtils.dv(areaMapper.selectCount(query));
    }
    
}
