gaoguangchao 4 months ago
parent
commit
5732855759
  1. 36
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 5
      zc-business/src/main/java/com/zc/business/utils/MathUtil.java

36
zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java

@ -87,18 +87,18 @@ public class DcDeviceOnlineController extends BaseController {
@RequestParam("time") String endTime,
@RequestParam("type") String[] types,
@RequestParam(value = "direction",required = false) String direction) {
Map<String, Map<String, Double>> maps = new HashMap<>();
Map<String, Map<String, String>> 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<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(),direction);
Map<String,List<OnlineSum>> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType));
for (String type : types) {
Map<String, Double> map = new HashMap<>();
Map<String, String> map = new HashMap<>();
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)) {
List<OnlineSum> dayList = localDateListMap.getOrDefault(date, new ArrayList<>());
map.put(date.toString(), MathUtil.doubleTwoDecimal(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)));
map.put(date.toString(), MathUtil.doubleTwoDecimalStr(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%");
}
maps.put(type, new TreeMap<>(map));
}
@ -165,20 +165,20 @@ public class DcDeviceOnlineController extends BaseController {
Map<String,List<OnlineSum>> typeSumGroup = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType));
DeviceType.toMap().forEach((k,v) -> {
Map<String,Object> itemMap = new HashMap<>();
itemMap.put(SUM,totalCounts.getOrDefault(k,0L));//总数
itemMap.put(SUM_USE_STATE,useCounts.getOrDefault(k,0L));//在用数
itemMap.put(SUM,totalCounts.getOrDefault(k,0L).toString());//总数
itemMap.put(SUM_USE_STATE,useCounts.getOrDefault(k,0L).toString());//在用数
List<OnlineSum> onlineSumsOfType = typeSumGroup.getOrDefault(k,new ArrayList<>());
itemMap.put(LOST_RATE, MathUtil.doubleTwoDecimal(onlineSumsOfType.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0)));
itemMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimal(onlineSumsOfType.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)));
itemMap.put(FAIL_RATE,MathUtil.doubleTwoDecimal(onlineSumsOfType.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0)));
itemMap.put(LOST_RATE, MathUtil.doubleTwoDecimalStr(onlineSumsOfType.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0))+"%");
itemMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsOfType.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%");
itemMap.put(FAIL_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsOfType.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0))+"%");
returnMap.put(v,itemMap);
});
Map<String, Object> allMap = new HashMap<>();
allMap.put(SUM,dcDeviceList.size());//总数
allMap.put(SUM_USE_STATE,useDeviceList.size());//在用数
allMap.put(LOST_RATE,MathUtil.doubleTwoDecimal(onlineSums.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0)));
allMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimal(onlineSums.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)));
allMap.put(FAIL_RATE,MathUtil.doubleTwoDecimal(onlineSums.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0)));
allMap.put(SUM,dcDeviceList.size()+"");//总数
allMap.put(SUM_USE_STATE,useDeviceList.size()+"");//在用数
allMap.put(LOST_RATE,MathUtil.doubleTwoDecimalStr(onlineSums.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0))+"%");
allMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimalStr(onlineSums.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%");
allMap.put(FAIL_RATE,MathUtil.doubleTwoDecimalStr(onlineSums.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0))+"%");
returnMap.put(All_TYPE,allMap);
Map<String, Object> sortMap = new TreeMap<>();
String orderRule = redisCache.getCacheObject(ORDERRULE);
@ -211,12 +211,12 @@ public class DcDeviceOnlineController extends BaseController {
Map<Long,List<OnlineSum>> onLineSumMap = onlineSums.stream().filter(onlineSum -> onlineSum.getRoadId() != null).collect(Collectors.groupingBy(OnlineSum::getRoadId));
for(DcRoadSection dcRoadSection : dcRoadSections) {
Map<String,Object> itemMap = new HashMap<>();
itemMap.put(SUM,totalRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L));//总数
itemMap.put(SUM_USE_STATE,useRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L));//在用数
itemMap.put(SUM,totalRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L).toString());//总数
itemMap.put(SUM_USE_STATE,useRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L).toString());//在用数
List<OnlineSum> onlineSumsByRoad = onLineSumMap.getOrDefault(dcRoadSection.getId(),new ArrayList<>());
itemMap.put(LOST_RATE, MathUtil.doubleTwoDecimal(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0)));
itemMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimal(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)));
itemMap.put(FAIL_RATE,MathUtil.doubleTwoDecimal(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0)));
itemMap.put(LOST_RATE, MathUtil.doubleTwoDecimalStr(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0))+"%");
itemMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%");
itemMap.put(FAIL_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0))+"%");
returnMap.put(dcRoadSection.getSectionName(),itemMap);
}
return AjaxResult.success(returnMap);

5
zc-business/src/main/java/com/zc/business/utils/MathUtil.java

@ -15,4 +15,9 @@ public class MathUtil {
BigDecimal roundedNumber = originalNumber.setScale(2, RoundingMode.HALF_UP);
return roundedNumber.doubleValue();
}
public static String doubleTwoDecimalStr(double d){
BigDecimal originalNumber = new BigDecimal(d);
BigDecimal roundedNumber = originalNumber.setScale(2, RoundingMode.HALF_UP);
return roundedNumber.toString();
}
}

Loading…
Cancel
Save