From 410e77f28b391741efae16614a45de6311c0e328 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Tue, 5 Mar 2024 19:27:57 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=A0=B9=E6=8D=AE=E6=A1=A9=E5=8F=B7=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E8=B7=9D=E7=A6=BB=202.=E4=BA=A4=E9=80=9A=E6=B0=94?= =?UTF-8?q?=E8=B1=A1=E6=A3=80=E6=B5=8B=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/StakeMarkUtils.java | 23 ++++++++- .../impl/DcWeatherMonitoringServiceImpl.java | 49 ++++++++++++++----- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java index b68119ea..651f772a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java @@ -21,9 +21,18 @@ public class StakeMarkUtils { * @return java.math.BigDecimal 距离 */ public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){ + if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ + return BigDecimal.ZERO; + } String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); String end = endStakeMark.toLowerCase().replace("k","").replace("+","."); - return new BigDecimal(end).subtract(new BigDecimal(start)).setScale(3, RoundingMode.HALF_UP); + BigDecimal startKilometre = new BigDecimal(start); + BigDecimal endKilometre = new BigDecimal(end); + if (startKilometre.compareTo(endKilometre) > 0){ + return startKilometre.subtract(endKilometre).setScale(3, RoundingMode.HALF_UP); + } else { + return endKilometre.subtract(startKilometre).setScale(3, RoundingMode.HALF_UP); + } } /** @@ -36,9 +45,19 @@ public class StakeMarkUtils { * @return java.math.BigDecimal 距离 */ public static BigDecimal getMetre(String startStakeMark, String endStakeMark){ + if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ + return BigDecimal.ZERO; + } String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); String end = endStakeMark.toLowerCase().replace("k","").replace("+","."); - return new BigDecimal(end).subtract(new BigDecimal(start)).multiply(new BigDecimal("1000")).setScale(0, RoundingMode.HALF_UP); + BigDecimal startKilometre = new BigDecimal(start); + BigDecimal endKilometre = new BigDecimal(end); + if (startKilometre.compareTo(endKilometre) > 0){ + return startKilometre.subtract(endKilometre).multiply(new BigDecimal("1000")).setScale(0, RoundingMode.HALF_UP); + } else { + return endKilometre.subtract(startKilometre).multiply(new BigDecimal("1000")).setScale(0, RoundingMode.HALF_UP); + } + } } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWeatherMonitoringServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWeatherMonitoringServiceImpl.java index 9b02b980..2b344579 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWeatherMonitoringServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWeatherMonitoringServiceImpl.java @@ -1,7 +1,9 @@ package com.zc.business.service.impl; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StakeMarkUtils; import com.ruoyi.common.utils.StringUtils; +import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcMeteorologicalDetectorData; import com.zc.business.mapper.DcWeatherMonitoringMapper; import com.zc.business.service.IDcWeatherMonitoringService; @@ -9,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,6 +28,8 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi @Autowired private DcWeatherMonitoringMapper weatherMonitoringMapper; + @Autowired + private DcDeviceServiceImpl dcDeviceService; /** @@ -39,8 +44,12 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi public AjaxResult getTrafficConditions(){ + DcDevice dcDevice = new DcDevice(); + dcDevice.setDeviceType(3); + List deviceList = dcDeviceService.listDevice(dcDevice); + //正常路段里程 - BigDecimal normalMileage = new BigDecimal("154.585"); + BigDecimal normalMileage = BigDecimal.ZERO; //降水里程 BigDecimal rainfallMileage = BigDecimal.ZERO; //团雾路段(处) @@ -50,10 +59,23 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi //异常数量 int anomalies = 0; //设备数量 - int deviceNum = 10; + int deviceNum = deviceList.size(); + + Map deviceRange = new HashMap<>(); + + for (DcDevice device : deviceList) { + if (StringUtils.isNotEmpty(device.getStakeMarkRange())){ + String[] stakeMarkRange = device.getStakeMarkRange().split(","); + BigDecimal detectionRange = StakeMarkUtils.getKilometre(stakeMarkRange[1],stakeMarkRange[0]); + normalMileage = normalMileage.add(detectionRange).setScale(2, RoundingMode.HALF_UP); + deviceRange.put(device.getIotDeviceId(),detectionRange); + } else { + deviceRange.put(device.getIotDeviceId(),BigDecimal.ZERO); + } + } //每个设备的检测范围 - BigDecimal detectionRange = new BigDecimal("15.4585"); +// BigDecimal detectionRange = new BigDecimal("15.4585"); List dataList = weatherMonitoringMapper.selectMeteorologicalDetectorData(); for (DcMeteorologicalDetectorData meteorologicalDetectorData : dataList) { @@ -61,15 +83,20 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi if (StringUtils.isNotEmpty(meteorologicalDetectorData.getRainfall()) || StringUtils.isNotEmpty(meteorologicalDetectorData.getVisibilityType())){ BigDecimal rainfall = new BigDecimal(meteorologicalDetectorData.getRainfall()); if (rainfall.compareTo(BigDecimal.ZERO) > 0 || !"4".equals(meteorologicalDetectorData.getVisibilityType())){ - normalMileage = normalMileage.subtract(detectionRange); - anomalies ++; - if (rainfall.compareTo(BigDecimal.ZERO) > 0){ - rainfallMileage = rainfallMileage.add(detectionRange); - } - if (!"4".equals(meteorologicalDetectorData.getVisibilityType())){ - heavyFogNum ++; - heavyFogMileage = heavyFogMileage.add(detectionRange); + + if (deviceRange.get(meteorologicalDetectorData.getIotDeviceId()) != null){ + BigDecimal detectionRange = new BigDecimal(deviceRange.get(meteorologicalDetectorData.getIotDeviceId()).toString()); + normalMileage = normalMileage.subtract(detectionRange); + anomalies ++; + if (rainfall.compareTo(BigDecimal.ZERO) > 0){ + rainfallMileage = rainfallMileage.add(detectionRange); + } + if (!"4".equals(meteorologicalDetectorData.getVisibilityType())){ + heavyFogNum ++; + heavyFogMileage = heavyFogMileage.add(detectionRange); + } } + } } }