package org.jeecg.modules.adweb.dmp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.modules.adweb.dmp.entity.GADeviceReport;
import org.jeecg.modules.adweb.dmp.mapper.GADeviceReportMapper;
import org.jeecg.modules.adweb.dmp.service.IGADeviceReportService;
import org.jeecg.modules.adweb.dmp.vo.report.DeviceStatsVO;
import org.jeecg.modules.redis.CacheConfig;
import org.jeecg.modules.redis.TTLCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @Description: adweb_dmp_ga_device_report @Author: jeecg-boot @Date: 2024-12-16 @Version: V1.0
 */
@Service
@Slf4j
public class GADeviceReportServiceImpl extends ServiceImpl<GADeviceReportMapper, GADeviceReport>
        implements IGADeviceReportService {

    @Autowired private GADeviceReportMapper gaDeviceReportMapper;

    @Override
    @Cacheable(
            cacheManager = CacheConfig.TTL_CACHE_MANAGER,
            cacheNames =
                    "dmp:getDeviceStats" + TTLCacheManager.TTL_SPLITTER + 60 * 10) // Redis TTL为10分钟
    public List<DeviceStatsVO> getDeviceStats(String siteCode, Date start, Date end) {
        List<DeviceStatsVO> deviceStatsVOs =
                gaDeviceReportMapper.getDeviceStats(siteCode, start, end);
        if (CollectionUtils.isEmpty(deviceStatsVOs)) {
            return Collections.EMPTY_LIST;
        }

        return deviceStatsVOs;
    }
}
