diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java index 5deafaf7..6168318f 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java @@ -146,7 +146,7 @@ public class DcDeviceOnlineController extends BaseController { Map> maps = new HashMap<>(); LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - List onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(), direction); + List onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start, end, direction); Map> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); for (String type : types) { Map map = new HashMap<>(); @@ -183,7 +183,7 @@ public class DcDeviceOnlineController extends BaseController { } // 查询数据 - List onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(), direction); + List onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start, end, direction); // 按设备类型分组 Map> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); @@ -208,9 +208,9 @@ public class DcDeviceOnlineController extends BaseController { LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0)); LocalDateTime endHour = startHour.plusHours(1); List hourList = dayList.stream() - .filter(os -> os.getStatisticalDate().toLocalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().toLocalDate().isBefore(ChronoLocalDate.from(endHour))) + .filter(os -> os.getStatisticalDate().isAfter(startHour) && + os.getStatisticalDate().isBefore(endHour)) .collect(Collectors.toList()); - double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0); hourlyMap.put(startHour.toString(), MathUtil.doubleTwoDecimalStr(averageRate) + "%"); } diff --git a/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java b/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java index 98da126c..e83159ea 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java @@ -4,6 +4,7 @@ import com.zc.business.controller.queryParams.OnlineQueryParams; import com.zc.business.domain.OnlineSum; import org.apache.ibatis.annotations.Param; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; public interface OnlineSumMapper { @@ -13,8 +14,8 @@ public interface OnlineSumMapper { @Param("endDate") LocalDate endDate); List queryByDeviceTypeAndDate( @Param("types") String[] types, - @Param("startDate") LocalDate startDate, - @Param("endDate") LocalDate endDate, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate, @Param("direction") String direction ); List queryByDateOfDeviceType(@Param("queryDate") LocalDate queryDate); diff --git a/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java b/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java index f6d4460c..e8fde9f0 100644 --- a/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java +++ b/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java @@ -4,6 +4,7 @@ import com.zc.business.controller.queryParams.OnlineQueryParams; import com.zc.business.domain.OnlineSum; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; public interface IOnlineSumService { @@ -13,8 +14,8 @@ public interface IOnlineSumService { List queryByDeviceTypeAndDate( String[] deviceType, - LocalDate startDate, - LocalDate endDate, + LocalDateTime startDate, + LocalDateTime endDate, String direction ); List queryByDateOfDeviceType(LocalDate queryDate); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java index 0194e120..c3b60ff6 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; @Service @@ -29,8 +30,8 @@ public class OnlineSumServiceImpl implements IOnlineSumService { @Override public List queryByDeviceTypeAndDate( String[] deviceType, - LocalDate startDate, - LocalDate endDate, + LocalDateTime startDate, + LocalDateTime endDate, String direction) { return onlineSumMapper.queryByDeviceTypeAndDate(deviceType, startDate, endDate, direction); } diff --git a/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java b/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java index 1c9b8245..bbefa82b 100644 --- a/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java +++ b/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java @@ -236,7 +236,7 @@ public class DeviceOnlineTask { */ private void incrementSummary(OnlineLog onlineLog) { // 获取当天日期 - String date = LocalDate.now().toString(); + String date = LocalDateTime.now().toString(); long deviceId = onlineLog.getDeviceId(); OnlineSum onlineSum = redisCache.getCacheMapValue(RedisKeyConstants.DEVICE_ONLINE , date+":"+deviceId); if (ObjectUtils.isEmpty(onlineSum)){