|
@ -39,6 +39,8 @@ import java.math.RoundingMode; |
|
|
import java.text.DecimalFormat; |
|
|
import java.text.DecimalFormat; |
|
|
import java.time.LocalDate; |
|
|
import java.time.LocalDate; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
import java.time.LocalTime; |
|
|
|
|
|
import java.time.chrono.ChronoLocalDate; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
@ -158,7 +160,67 @@ public class DcDeviceOnlineController extends BaseController { |
|
|
} |
|
|
} |
|
|
return AjaxResult.success(maps); |
|
|
return AjaxResult.success(maps); |
|
|
} |
|
|
} |
|
|
|
|
|
@ApiOperation("设备状态柱状图按时间和类型24小时制") |
|
|
|
|
|
@GetMapping("/listHourSystem") |
|
|
|
|
|
public AjaxResult getStatusListHourSystem( |
|
|
|
|
|
@RequestParam("startTime") String startTime, |
|
|
|
|
|
@RequestParam("time") String endTime, |
|
|
|
|
|
@RequestParam("type") String[] types, |
|
|
|
|
|
@RequestParam(value = "direction", required = false) String direction) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 解析时间
|
|
|
|
|
|
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")); |
|
|
|
|
|
|
|
|
|
|
|
// 校验时间范围
|
|
|
|
|
|
if (start.isAfter(end)) { |
|
|
|
|
|
return AjaxResult.error("开始时间不能晚于结束时间"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询数据
|
|
|
|
|
|
List<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(), direction); |
|
|
|
|
|
|
|
|
|
|
|
// 按设备类型分组
|
|
|
|
|
|
Map<String, List<OnlineSum>> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); |
|
|
|
|
|
|
|
|
|
|
|
// 构建结果
|
|
|
|
|
|
Map<String, Map<String, Map<String, String>>> maps = new HashMap<>(); |
|
|
|
|
|
for (String type : types) { |
|
|
|
|
|
Map<String, Map<String, String>> dailyMap = new TreeMap<>(); |
|
|
|
|
|
List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); |
|
|
|
|
|
|
|
|
|
|
|
// 按日期分组
|
|
|
|
|
|
Map<LocalDate, List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); |
|
|
|
|
|
|
|
|
|
|
|
// 按日期统计
|
|
|
|
|
|
for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) { |
|
|
|
|
|
Map<String, String> hourlyMap = new TreeMap<>(); |
|
|
|
|
|
List<OnlineSum> dayList = localDateListMap.getOrDefault(date, new ArrayList<>()); |
|
|
|
|
|
|
|
|
|
|
|
// 按小时统计
|
|
|
|
|
|
for (int hour = 0; hour < 24; hour++) { |
|
|
|
|
|
LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0)); |
|
|
|
|
|
LocalDateTime endHour = startHour.plusHours(1); |
|
|
|
|
|
List<OnlineSum> hourList = dayList.stream() |
|
|
|
|
|
.filter(os -> os.getStatisticalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().isBefore(ChronoLocalDate.from(endHour))) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0); |
|
|
|
|
|
hourlyMap.put(startHour.toString(), MathUtil.doubleTwoDecimalStr(averageRate) + "%"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dailyMap.put(date.toString(), hourlyMap); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
maps.put(type, dailyMap); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(maps); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return AjaxResult.error("查询设备状态柱状图数据失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
/** |
|
|
/** |
|
|
* 查询设备在线率 |
|
|
* 查询设备在线率 |
|
|
* |
|
|
* |
|
|