diff --git a/zc-business/src/main/java/com/zc/business/controller/StatusController.java b/zc-business/src/main/java/com/zc/business/controller/StatusController.java index c86f20f8..6a1ddcc2 100644 --- a/zc-business/src/main/java/com/zc/business/controller/StatusController.java +++ b/zc-business/src/main/java/com/zc/business/controller/StatusController.java @@ -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 listStatus = statusService.list(status); - // List listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList()); - //根据时间分组 - Map> map = listStatus.stream() - .collect(Collectors.groupingBy(Status -> (Status.getTime().getYear()+"-"+Status.getTime().getMonthValue()+"-"+Status.getTime().getDayOfMonth()))); - //根据类型分组 - // Map> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType)); - //生成有序map - Map> mapTime = new TreeMap<>(map); - Map mapSort=new TreeMap<>(); - for (Map.Entry> entry : mapTime.entrySet()) { - List 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> maps = new HashMap<>(); + + for (String type : types) { + status.setType(type); + List listStatus = statusService.list(status); + // List listStatu=listStatus.stream().filter(iteam ->iteam.getType()!=null && iteam.getType().equals(type)).collect(Collectors.toList()); + //根据时间分组 + Map> map = listStatus.stream() + .collect(Collectors.groupingBy(Status -> (Status.getTime().getYear() + "-" + Status.getTime().getMonthValue() + "-" + Status.getTime().getDayOfMonth()))); + //根据类型分组 + // Map> maps = listStatu.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType)); + //生成有序map + Map> mapTime = new TreeMap<>(map); + Map mapSort = new TreeMap<>(); + for (Map.Entry> entry : mapTime.entrySet()) { + List 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> mapStatus = new TreeMap<>(maps); - return AjaxResult.success(mapSort); + // Map> mapStatus = new TreeMap<>(maps); + return AjaxResult.success(maps); } diff --git a/zc-business/src/main/java/com/zc/business/domain/Status.java b/zc-business/src/main/java/com/zc/business/domain/Status.java index b1e8c7fe..f2f788f2 100644 --- a/zc-business/src/main/java/com/zc/business/domain/Status.java +++ b/zc-business/src/main/java/com/zc/business/domain/Status.java @@ -232,6 +232,9 @@ public class Status { //@Excel(name = "类型") private String type; + private String orderByField; + private String orderDirection; + public Integer getUseState() { return useState; @@ -248,4 +251,20 @@ public class Status { public void setSectionId(String sectionId) { this.sectionId = sectionId; } + + public String getOrderDirection() { + return orderDirection; + } + + public void setOrderDirection(String orderDirection) { + this.orderDirection = orderDirection; + } + + public String getOrderByField() { + return orderByField; + } + + public void setOrderByField(String orderByField) { + this.orderByField = orderByField; + } } diff --git a/zc-business/src/main/resources/mapper/business/StatusMapper.xml b/zc-business/src/main/resources/mapper/business/StatusMapper.xml index d76b633f..2f35802a 100644 --- a/zc-business/src/main/resources/mapper/business/StatusMapper.xml +++ b/zc-business/src/main/resources/mapper/business/StatusMapper.xml @@ -145,6 +145,10 @@ AND d.use_state = #{status.useState} + + + ORDER BY ${status.orderByField} ${status.orderDirection} +