use of cn.lili.modules.statistics.entity.vo.PlatformViewVO 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;
}
use of cn.lili.modules.statistics.entity.vo.PlatformViewVO in project lilishop by lilishop.
the class PlatformViewServiceImpl method builderVOS.
/**
* 根据查询条件,创建数据
*
* @param startDate
* @param endDate
* @param dataList
* @return
*/
private List<PlatformViewVO> builderVOS(Date startDate, Date endDate, List<PlatformViewData> dataList) {
Calendar startTime = Calendar.getInstance();
startTime.setTime(startDate);
Calendar endTime = Calendar.getInstance();
endTime.setTime(endDate);
List<PlatformViewVO> result = new ArrayList<>();
// 构造所有需要统计展示等流量数据
List<Date> listDate = new ArrayList<>();
while (startTime.before(endTime) || startTime.getTime().equals(endTime.getTime())) {
listDate.add(startTime.getTime());
startTime.set(Calendar.DAY_OF_MONTH, startTime.get(Calendar.DAY_OF_MONTH) + 1);
}
// 根据时间集,匹配查询到等数据,构建返回等VO
listDate.forEach(date -> {
PlatformViewVO platformViewVO = new PlatformViewVO(date);
dataList.forEach(platformViewData -> {
if (platformViewData.getDate().equals(date)) {
BeanUtils.copyProperties(platformViewData, platformViewVO);
}
});
// 没有匹配到数据库查询的数据,则初始化数据
result.add(platformViewVO);
});
return result;
}
Aggregations