Commit f73d7c0a by levphon

首页统计代码优化

1 parent dfb98e97
......@@ -166,11 +166,9 @@ public class HomeService {
//List<ActiveDeviceVo> list = vehicleMapper.getActiveDeviceInfoWithAuth(appendSql, period);
StatSearch search = new StatSearch();
StatSearch search = new StatSearch().setStatPattern("%Y-%m-%d");
if (period == 1 || period == 2) {
search.setStatPattern("%H");
} else {
search.setStatPattern("%Y-%m-%d");
}
search.setAppendSql(appendSql);
List<StatActivatedVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceWithAuth(search);
......@@ -331,7 +329,6 @@ public class HomeService {
}
public List<DeviceBindVo> getNewBindDeviceInfo() throws ParseException {
List<DeviceBindVo> retList = Lists.newArrayList();
String appendSql = DateUtil.appendSqlByTimeRange(11, "tvd.created_date");
//List<DeviceBindVo> list = vehicleMapper.getBindDeviceInfoWithAuth(appendSql);
......@@ -340,7 +337,8 @@ public class HomeService {
search.setAppendSql(appendSql);
List<StatActivatedVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceWithAuth(search);
Map<String, List<StatActivatedVehicleDevice>> groupByActiveTimeMap = activeDeviceList.stream().collect(Collectors.groupingBy(StatActivatedVehicleDevice::getActiveTime));
Map<String, Map<Long, List<StatActivatedVehicleDevice>>> groupByActiveTimeMap = activeDeviceList.stream()
.collect(Collectors.groupingBy(StatActivatedVehicleDevice::getActiveTime, Collectors.groupingBy(StatActivatedVehicleDevice::getVehicleId)));
List<DeviceBindVo> list = convertDeviceBindVoList(groupByActiveTimeMap);
if (CollectionUtils.isEmpty(list)) {
......@@ -348,14 +346,20 @@ public class HomeService {
}
Date recThirtyBegin = DateUtils.parseDate(DateUtil.getReductionDay(29), PARSE_PATTERN);
Date recThirtyEnd = DateUtils.parseDate(DateUtil.getTodayDate(), PARSE_PATTERN);
retList = fillIfNullByDateForBind(recThirtyBegin, recThirtyEnd, list);
List<DeviceBindVo> retList = fillIfNullByDateForBind(recThirtyBegin, recThirtyEnd, list);
ComparatorBindDeviceModel comparator = new ComparatorBindDeviceModel();
retList.sort(comparator);
return retList;
}
public List<DeviceBindVo> convertDeviceBindVoList(Map<String, List<StatActivatedVehicleDevice>> groupByActiveTimeMap) {
/**
* 按激活设备日期统计的绑定车辆
*
* @param groupByActiveTimeMap
* @return
*/
public List<DeviceBindVo> convertDeviceBindVoList(Map<String, Map<Long, List<StatActivatedVehicleDevice>>> groupByActiveTimeMap) {
List<DeviceBindVo> list = Lists.newArrayList();
groupByActiveTimeMap.forEach((k, v) -> list.add(new DeviceBindVo(k, v.size())));
return list;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!