Search in sources :

Example 1 with PlatformViewData

use of cn.lili.modules.statistics.entity.dos.PlatformViewData in project lilishop by lilishop.

the class PlatformViewServiceImpl method list.

@Override
public List<PlatformViewVO> list(StatisticsQueryParam queryParam) {
    List<PlatformViewVO> result = new ArrayList<>();
    // 查询开始时间和结束时间,用于数据库查询
    Date endTime = null, startTime = null;
    // 搜索类型判定,如果不为空,则按照搜索类型进行查询
    if (StringUtils.isNotEmpty(queryParam.getSearchType())) {
        SearchTypeEnum searchTypeEnum = SearchTypeEnum.valueOf(queryParam.getSearchType());
        switch(searchTypeEnum) {
            case TODAY:
                PlatformViewVO today = new PlatformViewVO();
                // 查询 平台流量
                if (StringUtils.isEmpty(queryParam.getStoreId())) {
                    // 设置PV UV属性
                    String pv = cache.getString(CachePrefix.PV.getPrefix() + StatisticsSuffix.suffix());
                    if (pv == null) {
                        pv = "0";
                    }
                    today.setPvNum(Long.valueOf(pv));
                    today.setUvNum(cache.counter(CachePrefix.UV.getPrefix() + StatisticsSuffix.suffix()).longValue());
                } else // 店铺流量
                {
                    // 设置PV UV属性
                    String pv = cache.getString(CachePrefix.STORE_PV.getPrefix() + StatisticsSuffix.suffix(queryParam.getStoreId()));
                    if (pv == null) {
                        pv = "0";
                    }
                    today.setPvNum(Long.valueOf(pv));
                    today.setUvNum(cache.counter(CachePrefix.STORE_UV.getPrefix() + StatisticsSuffix.suffix(queryParam.getStoreId())).longValue());
                }
                today.setDate(new Date());
                result.add(today);
                break;
            case YESTERDAY:
            case LAST_SEVEN:
            case LAST_THIRTY:
                {
                    Date[] dates = StatisticsDateUtil.getDateArray(searchTypeEnum);
                    endTime = dates[1];
                    startTime = dates[0];
                    break;
                }
            default:
                throw new ServiceException(ResultCode.ERROR);
        }
    } else {
        // 根据查询时间来确定查询参数
        Integer year = queryParam.getYear();
        Integer month = queryParam.getMonth();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(year, month - 1, 1);
        startTime = calendar.getTime();
        calendar.set(year, month, -1);
        endTime = calendar.getTime();
    }
    // 时间不为空则按照时间开始数据查询
    if (startTime != null) {
        LambdaQueryWrapper<PlatformViewData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.between(PlatformViewData::getDate, startTime, endTime);
        lambdaQueryWrapper.eq(PlatformViewData::getStoreId, StringUtils.isEmpty(queryParam.getStoreId()) ? "-1" : queryParam.getStoreId());
        List<PlatformViewData> dataList = this.list(lambdaQueryWrapper);
        result = builderVOS(startTime, endTime, dataList);
    }
    return result;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) PlatformViewVO(cn.lili.modules.statistics.entity.vo.PlatformViewVO) Date(java.util.Date) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) PlatformViewData(cn.lili.modules.statistics.entity.dos.PlatformViewData) ServiceException(cn.lili.common.exception.ServiceException) SearchTypeEnum(cn.lili.modules.statistics.entity.enums.SearchTypeEnum)

Example 2 with PlatformViewData

use of cn.lili.modules.statistics.entity.dos.PlatformViewData in project lilishop by lilishop.

the class PageViewStatistics method execute.

@Override
public void execute() {
    // 1、缓存keys 模糊匹配
    // 2、过滤今日的数据,即今天只能统计今日以前的数据
    // 4对key value 分别代表平台PV、平台UV、店铺PV、店铺UV
    List<String> pvKeys = filterKeys(cache.keys(CachePrefix.PV.getPrefix() + "*"));
    List<Integer> pvValues = cache.multiGet(pvKeys);
    List<String> storePVKeys = filterKeys(cache.keys(CachePrefix.STORE_PV.getPrefix() + "*"));
    List<Integer> storePvValues = cache.multiGet(storePVKeys);
    // 备份UV数据,这里赋值之后,会被删除
    List<String> uvKeys = new ArrayList<>();
    List<String> storeUvKeys = new ArrayList<>();
    log.debug("开始统计平台数据,PV共计【{}】条", pvKeys.size());
    log.debug("开始统计店铺数据,PV共计【{}】条", storePvValues.size());
    // 定义要统计的数据
    List<PlatformViewData> platformViewDataList = new ArrayList<>();
    // PV 统计
    if (pvKeys.size() > 0) {
        for (int i = 0; i < pvKeys.size(); i++) {
            String key = pvKeys.get(i);
            PageViewStatistics pageViewStatistics = new PageViewStatistics(key);
            PlatformViewData platformPVData = new PlatformViewData();
            BeanUtil.copyProperties(pageViewStatistics, platformPVData);
            platformPVData.setPvNum(pvValues.get(i).longValue());
            // 根据pvkey 获取 uvkey
            String uvKey = getUvKey(key);
            uvKeys.add(uvKey);
            platformPVData.setUvNum(cache.counter(uvKey));
            platformPVData.setStoreId("-1");
            platformViewDataList.add(platformPVData);
        }
        batchSave(pvKeys, uvKeys, platformViewDataList);
    }
    // 店铺 PV 统计
    if (storePVKeys.size() > 0) {
        platformViewDataList = new ArrayList<>();
        for (int i = 0; i < storePVKeys.size(); i++) {
            String key = storePVKeys.get(i);
            PageViewStatistics pageViewStatistics = new PageViewStatistics(key);
            PlatformViewData storePVData = new PlatformViewData();
            BeanUtil.copyProperties(pageViewStatistics, storePVData);
            storePVData.setPvNum(storePvValues.get(i).longValue());
            // 根据pvkey 获取 uvkey
            String uvKey = getUvKey(key);
            uvKeys.add(uvKey);
            storePVData.setUvNum(cache.counter(uvKey));
            platformViewDataList.add(storePVData);
        }
        batchSave(storePVKeys, storeUvKeys, platformViewDataList);
    }
}
Also used : PlatformViewData(cn.lili.modules.statistics.entity.dos.PlatformViewData) ArrayList(java.util.ArrayList)

Aggregations

PlatformViewData (cn.lili.modules.statistics.entity.dos.PlatformViewData)2 ArrayList (java.util.ArrayList)2 ServiceException (cn.lili.common.exception.ServiceException)1 SearchTypeEnum (cn.lili.modules.statistics.entity.enums.SearchTypeEnum)1 PlatformViewVO (cn.lili.modules.statistics.entity.vo.PlatformViewVO)1 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1