|
|
@ -81,32 +81,38 @@ public class StatusController extends BaseController { |
|
|
|
|
|
|
|
//按时间划分设备柱状图
|
|
|
|
@ApiOperation("设备状态柱状图按时间和类型") |
|
|
|
@GetMapping ("/list") |
|
|
|
public AjaxResult getStatusList(Status status) |
|
|
|
{ |
|
|
|
@GetMapping("/list") |
|
|
|
public AjaxResult getStatusList(Status status) { |
|
|
|
LocalDateTime todayStart = status.getStartTime().truncatedTo(ChronoUnit.DAYS); |
|
|
|
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(1); |
|
|
|
status.setStartTime(todayStart); |
|
|
|
status.setTime(currentTime); |
|
|
|
String type=status.getType(); |
|
|
|
List<Status> listStatus = statusService.list(status); |
|
|
|
// List<Status> listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList());
|
|
|
|
//根据时间分组
|
|
|
|
Map<String, List<Status>> map = listStatus.stream() |
|
|
|
.collect(Collectors.groupingBy(Status -> (Status.getTime().getYear()+"-"+Status.getTime().getMonthValue()+"-"+Status.getTime().getDayOfMonth()))); |
|
|
|
//根据类型分组
|
|
|
|
// Map<String, List<Status>> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType));
|
|
|
|
//生成有序map
|
|
|
|
Map<String, List<Status>> mapTime = new TreeMap<>(map); |
|
|
|
Map<String,String> mapSort=new TreeMap<>(); |
|
|
|
for (Map.Entry<String, List<Status>> entry : mapTime.entrySet()) { |
|
|
|
List<Status> groupItems = entry.getValue(); |
|
|
|
long count = groupItems.stream().filter(iteam -> Objects.equals(iteam.getDeviceStatus(), "1")).count(); |
|
|
|
String onlineRate=String.format("%.2f%%", (double) count / groupItems.size() * 100); |
|
|
|
mapSort.put(entry.getKey(),onlineRate); |
|
|
|
String[] types = status.getType().split(","); |
|
|
|
|
|
|
|
Map<String, Map<String, String>> maps = new HashMap<>(); |
|
|
|
|
|
|
|
for (String type : types) { |
|
|
|
status.setType(type); |
|
|
|
List<Status> listStatus = statusService.list(status); |
|
|
|
// List<Status> listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList());
|
|
|
|
//根据时间分组
|
|
|
|
Map<String, List<Status>> map = listStatus.stream() |
|
|
|
.collect(Collectors.groupingBy(Status -> (Status.getTime().getYear() + "-" + Status.getTime().getMonthValue() + "-" + Status.getTime().getDayOfMonth()))); |
|
|
|
//根据类型分组
|
|
|
|
// Map<String, List<Status>> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType));
|
|
|
|
//生成有序map
|
|
|
|
Map<String, List<Status>> mapTime = new TreeMap<>(map); |
|
|
|
Map<String, String> mapSort = new TreeMap<>(); |
|
|
|
for (Map.Entry<String, List<Status>> entry : mapTime.entrySet()) { |
|
|
|
List<Status> groupItems = entry.getValue(); |
|
|
|
long count = groupItems.stream().filter(iteam -> Objects.equals(iteam.getDeviceStatus(), "1")).count(); |
|
|
|
String onlineRate = String.format("%.2f%%", (double) count / groupItems.size() * 100); |
|
|
|
mapSort.put(entry.getKey(), onlineRate); |
|
|
|
} |
|
|
|
maps.put(type, mapSort); |
|
|
|
} |
|
|
|
// Map<String, List<Status>> mapStatus = new TreeMap<>(maps);
|
|
|
|
return AjaxResult.success(mapSort); |
|
|
|
// Map<String, List<Status>> mapStatus = new TreeMap<>(maps);
|
|
|
|
return AjaxResult.success(maps); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|