Browse Source

优化养护运营-智慧养护-统计分析-设备查询相关接口

develop
zhaoxianglong 6 months ago
parent
commit
6daaf5f129
  1. 48
      zc-business/src/main/java/com/zc/business/controller/StatusController.java
  2. 19
      zc-business/src/main/java/com/zc/business/domain/Status.java
  3. 4
      zc-business/src/main/resources/mapper/business/StatusMapper.xml

48
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<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);
}

19
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;
}
}

4
zc-business/src/main/resources/mapper/business/StatusMapper.xml

@ -145,6 +145,10 @@
AND d.use_state = #{status.useState}
</if>
</where>
<if test="status.orderByField != null and status.orderDirection != null">
ORDER BY ${status.orderByField} ${status.orderDirection}
</if>
</select>

Loading…
Cancel
Save