From b9bae5407179776f0a0ad94ba836a83e4b772046 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Tue, 30 Jul 2024 14:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=8E=87tab=E9=A1=B5=E5=AF=BC=E5=87=BA=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceOnlineController.java | 146 ++++++++++-------- 1 file changed, 80 insertions(+), 66 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java index fb8958dd..18d17428 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java @@ -64,42 +64,48 @@ public class DcDeviceOnlineController extends BaseController { @Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, OnlineQueryParams params) { - if(ObjectUtils.isEmpty(params.getType())) { + if (ObjectUtils.isEmpty(params.getType())) { return; } - if(StringUtil.isEmpty(params.getOrderByField()) ||"time".equals(params.getOrderByField())) { + if (StringUtil.isEmpty(params.getOrderByField()) || "time".equals(params.getOrderByField())) { params.setOrderByField("online_rate"); } - params.setStakeMark(params.getStakeMark().replace(" ","+")); + String stakeMark = params.getStakeMark(); + if (stakeMark!=null) { + params.setStakeMark(stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); + } List sums = onlineSumService.queryByDeviceTypesOfToday(params); - Map> sumsMap = sums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); - LinkedHashMap map = new LinkedHashMap<>(); - for(String deviceType:params.getType()){ - List list = sumsMap.getOrDefault(deviceType,new ArrayList<>()); + Map> sumsMap = sums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); + LinkedHashMap map = new LinkedHashMap<>(); + for (String deviceType : params.getType()) { + List list = sumsMap.getOrDefault(deviceType, new ArrayList<>()); String typeName = DeviceType.getDescriptionByValue(deviceType); - if(StringUtil.isNotEmpty(typeName)) { - map.put(DeviceType.getDescriptionByValue(deviceType),list); + if (StringUtil.isNotEmpty(typeName)) { + map.put(DeviceType.getDescriptionByValue(deviceType), list); } } ExcelMultipleSheetsUtil multipleSheetsUtil = new ExcelMultipleSheetsUtil(); - multipleSheetsUtil.excelMultipleSheets(map,UniversalEnum.DEVICE_STATUS_LIST.getValue()+ DateUtil.format(new Date(), "yyyyMMddHHmmss"), - "xlsx", response); + multipleSheetsUtil.excelMultipleSheets(map, UniversalEnum.DEVICE_STATUS_LIST.getValue() + DateUtil.format(new Date(), "yyyyMMddHHmmss"), + "xlsx", response); } @ApiOperation("设备状态列表按时间和类型") @GetMapping("/tablist") public TableDataInfo getTabList(OnlineQueryParams params) { - if(ObjectUtils.isEmpty(params.getType())) { + if (ObjectUtils.isEmpty(params.getType())) { return getDataTable(new ArrayList<>()); } - if(StringUtil.isEmpty(params.getOrderByField()) ||"time".equals(params.getOrderByField())) { + if (StringUtil.isEmpty(params.getOrderByField()) || "time".equals(params.getOrderByField())) { params.setOrderByField("online_rate"); } startPage(); - params.setStakeMark(params.getStakeMark().replace(" ","+")); + String stakeMark = params.getStakeMark(); + if (stakeMark != null) { + params.setStakeMark(stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); + } List sums = onlineSumService.queryByDeviceTypesOfToday(params); /*Map onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE); String date = LocalDate.now().toString();*/ @@ -115,26 +121,27 @@ public class DcDeviceOnlineController extends BaseController { }*/ return getDataTable(sums); } + //按时间划分设备柱状图 @ApiOperation("设备状态柱状图按时间和类型") @GetMapping("/list") public AjaxResult getStatusList( @RequestParam("startTime") String startTime, - @RequestParam("time") String endTime, + @RequestParam("time") String endTime, @RequestParam("type") String[] types, - @RequestParam(value = "direction",required = false) String direction) { + @RequestParam(value = "direction", required = false) String direction) { Map> 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 onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(),direction); - Map> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); + List onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(), direction); + Map> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); for (String type : types) { Map map = new HashMap<>(); List listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); - Map> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); - for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date=date.plusDays(1)) { + Map> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); + for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) { List dayList = localDateListMap.getOrDefault(date, new ArrayList<>()); - map.put(date.toString(), MathUtil.doubleTwoDecimalStr(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)); } @@ -143,6 +150,7 @@ public class DcDeviceOnlineController extends BaseController { /** * 查询设备在线率 + * * @param deviceId * @return */ @@ -152,7 +160,7 @@ public class DcDeviceOnlineController extends BaseController { LocalDate startDate = LocalDate.now().minusDays(30); LocalDate endDate = LocalDate.now(); List onlineSums = onlineSumService.queryByDateRangeOfDevice(deviceId, startDate, endDate); - if(onlineSums.isEmpty()) { + if (onlineSums.isEmpty()) { return AjaxResult.success(UniversalEnum.NO_DATA_AVAILABLE.getValue()); } Map map = new HashMap<>(); @@ -164,6 +172,7 @@ public class DcDeviceOnlineController extends BaseController { /** * 缓存类型卡片排序规则 + * * @param rule 排序规则 * @return AjaxResult */ @@ -175,7 +184,7 @@ public class DcDeviceOnlineController extends BaseController { } /** - * 设备分类当日在线率 + * 设备分类当日在线率 */ @ApiOperation("设备分类当日在线率") @GetMapping("/type") @@ -191,31 +200,31 @@ public class DcDeviceOnlineController extends BaseController { Map returnMap = new HashMap<>(); List onlineSums = onlineSumService.queryByDateOfDeviceType(LocalDate.now()); List dcDeviceList = dcDeviceService.list(); - List useDeviceList = dcDeviceList.stream().filter(device ->device.getUseState()!=null && device.getUseState()==1).collect(Collectors.toList()); + List useDeviceList = dcDeviceList.stream().filter(device -> device.getUseState() != null && device.getUseState() == 1).collect(Collectors.toList()); //分类总数 Map totalCounts = dcDeviceList.stream() .collect(Collectors.groupingBy(DcDevice::getRealType, Collectors.counting())); //分类在用数 - Map useCounts = useDeviceList.stream() + Map useCounts = useDeviceList.stream() .collect(Collectors.groupingBy(DcDevice::getRealType, Collectors.counting())); - Map> typeSumGroup = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); + Map> typeSumGroup = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); DeviceType.toMap().forEach((k, v) -> { - Map itemMap = new HashMap<>(); - itemMap.put(SUM,totalCounts.getOrDefault(k,0L).toString());//总数 - itemMap.put(SUM_USE_STATE,useCounts.getOrDefault(k,0L).toString());//在用数 - List onlineSumsOfType = typeSumGroup.getOrDefault(k,new ArrayList<>()); - 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 itemMap = new HashMap<>(); + itemMap.put(SUM, totalCounts.getOrDefault(k, 0L).toString());//总数 + itemMap.put(SUM_USE_STATE, useCounts.getOrDefault(k, 0L).toString());//在用数 + List onlineSumsOfType = typeSumGroup.getOrDefault(k, new ArrayList<>()); + 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 allMap = new HashMap<>(); - 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); + 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 sortMap = new TreeMap<>(); String orderRule = redisCache.getCacheObject(ORDERRULE); if (StringUtil.isNotEmpty(orderRule)) { @@ -230,7 +239,7 @@ public class DcDeviceOnlineController extends BaseController { //按路段统计设备在线率 @ApiOperation("设备状态列表按路段") @GetMapping("/section") - public AjaxResult getSectionList() { + public AjaxResult getSectionList() { String LOST_RATE = "lostRate";//丢包率 String SUCESS_RATE = "sucessRate";//在线率 String FAIL_RATE = "failRate";//离线率 @@ -240,20 +249,20 @@ public class DcDeviceOnlineController extends BaseController { List> deviceOfRoad = dcDeviceService.selectDeviceOfRoad(); List dcRoadSections = dcRoadSectionService.selectDcRoadSectionList(new DcRoadSection()); List onlineSums = onlineSumService.queryByDateOfRoad(LocalDate.now()); - Map totalRoadCounts = deviceOfRoad.stream() - .collect(Collectors.groupingBy(m -> m.get("roadId").toString(),Collectors.counting())); - Map useRoadCounts = deviceOfRoad.stream().filter(dr -> dr.get("useStata")!=null && dr.get("useStata").toString().equals("1")) - .collect(Collectors.groupingBy(m -> m.get("roadId").toString(),Collectors.counting())); - Map> onLineSumMap = onlineSums.stream().filter(onlineSum -> onlineSum.getRoadId() != null).collect(Collectors.groupingBy(OnlineSum::getRoadId)); - for(DcRoadSection dcRoadSection : dcRoadSections) { - Map itemMap = new HashMap<>(); - itemMap.put(SUM,totalRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L).toString());//总数 - itemMap.put(SUM_USE_STATE,useRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L).toString());//在用数 - List onlineSumsByRoad = onLineSumMap.getOrDefault(dcRoadSection.getId(),new ArrayList<>()); - 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); + Map totalRoadCounts = deviceOfRoad.stream() + .collect(Collectors.groupingBy(m -> m.get("roadId").toString(), Collectors.counting())); + Map useRoadCounts = deviceOfRoad.stream().filter(dr -> dr.get("useStata") != null && dr.get("useStata").toString().equals("1")) + .collect(Collectors.groupingBy(m -> m.get("roadId").toString(), Collectors.counting())); + Map> onLineSumMap = onlineSums.stream().filter(onlineSum -> onlineSum.getRoadId() != null).collect(Collectors.groupingBy(OnlineSum::getRoadId)); + for (DcRoadSection dcRoadSection : dcRoadSections) { + Map itemMap = new HashMap<>(); + itemMap.put(SUM, totalRoadCounts.getOrDefault(dcRoadSection.getId().toString(), 0L).toString());//总数 + itemMap.put(SUM_USE_STATE, useRoadCounts.getOrDefault(dcRoadSection.getId().toString(), 0L).toString());//在用数 + List onlineSumsByRoad = onLineSumMap.getOrDefault(dcRoadSection.getId(), new ArrayList<>()); + 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); } @@ -262,25 +271,26 @@ public class DcDeviceOnlineController extends BaseController { @GetMapping("/networkLogTable") public TableDataInfo networkLogTable( @RequestParam("deviceId") Long deviceId, - @RequestParam("queryDate")String queryDate) { + @RequestParam("queryDate") String queryDate) { LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); //startPage(); - List onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); + List onlineLogs = onlineLogService.queryByDateAndDevice(start, end, deviceId); return getDataTable(onlineLogs); } + @ApiOperation("查询设备网络日志") @GetMapping("/networkLogEcharts") public AjaxResult networkLogEcharts( @RequestParam("deviceId") Long deviceId, - @RequestParam("queryDate")String queryDate) { + @RequestParam("queryDate") String queryDate) { String LOST_RATE = "lostRate";//丢包率 String RTT_AVG = "rttAvg";//平均往返时延 String MONITOR_TIME = "time";//监控时间 LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - List onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); - Map returnMap = new HashMap<>(); + List onlineLogs = onlineLogService.queryByDateAndDevice(start, end, deviceId); + Map returnMap = new HashMap<>(); List xAxis = new ArrayList<>(); List lossRate = new ArrayList<>(); List rttAvg = new ArrayList<>(); @@ -289,13 +299,14 @@ public class DcDeviceOnlineController extends BaseController { lossRate.add(onlineLog.getLossRate()); rttAvg.add(onlineLog.getRttAvg()); }); - returnMap.put(LOST_RATE,lossRate); - returnMap.put(RTT_AVG,rttAvg); - returnMap.put(MONITOR_TIME,xAxis); + returnMap.put(LOST_RATE, lossRate); + returnMap.put(RTT_AVG, rttAvg); + returnMap.put(MONITOR_TIME, xAxis); return AjaxResult.success(new TreeMap<>(returnMap)); } + enum DeviceType { - GUN_CAMERA("1-1","高清网络枪型固定摄像机"), + GUN_CAMERA("1-1", "高清网络枪型固定摄像机"), SPHERICAL_CAMERA("1-2", "高清网络球形摄像机"), SPHERICAL_CAMERA_BRIDGE("1-3", "桥下高清网络球形摄像机"), PANORAMIC_CAMERA_360("1-4", "360°全景摄像机"), @@ -336,9 +347,10 @@ public class DcDeviceOnlineController extends BaseController { /** * map转换{value,description} + * * @return 转换后的map */ - static Map toMap(){ + static Map toMap() { Map map = new HashMap<>(); for (DeviceType deviceType : DeviceType.values()) { map.put(deviceType.getValue(), deviceType.getDescription()); @@ -348,9 +360,10 @@ public class DcDeviceOnlineController extends BaseController { /** * 默认排序规则 + * * @return 排序规则 */ - static String defaultSortRule(){ + static String defaultSortRule() { StringBuilder stringBuilder = new StringBuilder(); String ALL_TYPE = "全部设备"; stringBuilder.append(ALL_TYPE); @@ -359,6 +372,7 @@ public class DcDeviceOnlineController extends BaseController { } return stringBuilder.toString(); } + static String getDescriptionByValue(String value) { for (DeviceType type : DeviceType.values()) { if (type.value.equals(value)) {