Search in sources :

Example 1 with SearchTypeEnum

use of cn.lili.modules.statistics.entity.enums.SearchTypeEnum 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)

Aggregations

ServiceException (cn.lili.common.exception.ServiceException)1 PlatformViewData (cn.lili.modules.statistics.entity.dos.PlatformViewData)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 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1