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