From 020afb92a834091081630e9c500257c835a43c6a Mon Sep 17 00:00:00 2001 From: xins Date: Thu, 9 Nov 2023 14:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?9.3=20business=EF=BC=9A=201=E3=80=81=E6=89=8B=E6=9C=BA=E7=AB=AF?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=9B=91=E6=8E=A7=E5=8D=95=E5=85=83=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/HwAppController.java | 8 ++-- .../service/impl/HwDeviceServiceImpl.java | 46 +++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java index 387c752..0eb7d45 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java @@ -127,12 +127,12 @@ public class HwAppController extends BaseController { * @date 2023-09-28 13:31 * @return AjaxResult */ - @RequiresPermissions("business:app:monitorUnit") +// @RequiresPermissions("business:app:monitorUnit") @GetMapping("/getDevicesInfoByMonitorUnitId/{monitorUnitId}") public AjaxResult getDevicesInfoByMonitorUnitId(@PathVariable("monitorUnitId") Long monitorUnitId){ - HwDevice queryDevice = new HwDevice(); - queryDevice.setMonitorUnitId(monitorUnitId); - return success(hwDeviceService.selectDeviceNum(queryDevice)); +// HwDevice queryDevice = new HwDevice(); +// queryDevice.setMonitorUnitId(monitorUnitId); + return success(hwDeviceService.getDevicesInfoByMonitorUnitId(monitorUnitId)); } /** diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java index 02ced13..69a020a 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java @@ -641,21 +641,39 @@ public class HwDeviceServiceImpl implements IHwDeviceService { .collect(Collectors.groupingBy(HwDevice::getDeviceType)); List gatewayDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE); List subDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT); - //根据关联网关设备ID进行分组 - Map> releatedDeviceIdDevicesMap = subDevices.stream() - .collect(Collectors.groupingBy(HwDevice::getReleatedDeviceId)); + List directConnectDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE); + int onlineDevicesCount = 0; int offlineDevicesCount = 0; - for (HwDevice gatewayDevice : gatewayDevices) { - String onlineStatus = gatewayDevice.getOnlineStatus(); - //获取关联子设备的数量 - int gatewaySubPublishedDevicesCount = - releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()) == null ? - 0 : releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()).size(); - if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) { - onlineDevicesCount += gatewaySubPublishedDevicesCount; - } else if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_OFFLINE)) { - offlineDevicesCount += gatewaySubPublishedDevicesCount; + //网关设备和网关子设备,根据网关设备状态来判断网关子设备的状态 + if (gatewayDevices != null && !gatewayDevices.isEmpty() && subDevices != null && !subDevices.isEmpty()) { + //根据关联网关设备ID进行分组 + Map> releatedDeviceIdDevicesMap = subDevices.stream() + .collect(Collectors.groupingBy(HwDevice::getReleatedDeviceId)); + + for (HwDevice gatewayDevice : gatewayDevices) { + String onlineStatus = gatewayDevice.getOnlineStatus(); + //获取关联子设备的数量 + int gatewaySubPublishedDevicesCount = + releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()) == null ? + 0 : releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()).size(); + if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) { + onlineDevicesCount += gatewaySubPublishedDevicesCount; + } else if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_OFFLINE)) { + offlineDevicesCount += gatewaySubPublishedDevicesCount; + } + } + } + + //直连设备直接获取设备状态 + if (directConnectDevices != null && !directConnectDevices.isEmpty()) { + for (HwDevice directConnectDevice : directConnectDevices) { + String onlineStatus = directConnectDevice.getOnlineStatus(); + if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) { + onlineDevicesCount += 1; + } else if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_OFFLINE)) { + offlineDevicesCount += 1; + } } } @@ -778,7 +796,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { @Override @DataScope(tenantAlias = "hd") public List selectHwDeviceListWithDeviceMode(HwDevice hwDevice) { - return hwDeviceMapper.selectHwDeviceListByMonitor(hwDevice); + return hwDeviceMapper.selectHwDeviceListByMonitor(hwDevice); } private Map computeDeviceCountPerDay(Long startTime, Long endTime) {