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;
}
Aggregations