Browse Source

1.根据桩号计算距离

2.交通气象检测接口修改
develop
lau572 9 months ago
parent
commit
410e77f28b
  1. 23
      ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java
  2. 49
      zc-business/src/main/java/com/zc/business/service/impl/DcWeatherMonitoringServiceImpl.java

23
ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java

@ -21,9 +21,18 @@ public class StakeMarkUtils {
* @return java.math.BigDecimal 距离 * @return java.math.BigDecimal 距离
*/ */
public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){ 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 start = startStakeMark.toLowerCase().replace("k","").replace("+",".");
String end = endStakeMark.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 距离 * @return java.math.BigDecimal 距离
*/ */
public static BigDecimal getMetre(String startStakeMark, String endStakeMark){ 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 start = startStakeMark.toLowerCase().replace("k","").replace("+",".");
String end = endStakeMark.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);
}
} }
} }

49
zc-business/src/main/java/com/zc/business/service/impl/DcWeatherMonitoringServiceImpl.java

@ -1,7 +1,9 @@
package com.zc.business.service.impl; package com.zc.business.service.impl;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StakeMarkUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcMeteorologicalDetectorData; import com.zc.business.domain.DcMeteorologicalDetectorData;
import com.zc.business.mapper.DcWeatherMonitoringMapper; import com.zc.business.mapper.DcWeatherMonitoringMapper;
import com.zc.business.service.IDcWeatherMonitoringService; import com.zc.business.service.IDcWeatherMonitoringService;
@ -9,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -25,6 +28,8 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi
@Autowired @Autowired
private DcWeatherMonitoringMapper weatherMonitoringMapper; private DcWeatherMonitoringMapper weatherMonitoringMapper;
@Autowired
private DcDeviceServiceImpl dcDeviceService;
/** /**
@ -39,8 +44,12 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi
public AjaxResult getTrafficConditions(){ public AjaxResult getTrafficConditions(){
DcDevice dcDevice = new DcDevice();
dcDevice.setDeviceType(3);
List<DcDevice> deviceList = dcDeviceService.listDevice(dcDevice);
//正常路段里程 //正常路段里程
BigDecimal normalMileage = new BigDecimal("154.585"); BigDecimal normalMileage = BigDecimal.ZERO;
//降水里程 //降水里程
BigDecimal rainfallMileage = BigDecimal.ZERO; BigDecimal rainfallMileage = BigDecimal.ZERO;
//团雾路段(处) //团雾路段(处)
@ -50,10 +59,23 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi
//异常数量 //异常数量
int anomalies = 0; int anomalies = 0;
//设备数量 //设备数量
int deviceNum = 10; int deviceNum = deviceList.size();
Map<String,Object> 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<DcMeteorologicalDetectorData> dataList = weatherMonitoringMapper.selectMeteorologicalDetectorData(); List<DcMeteorologicalDetectorData> dataList = weatherMonitoringMapper.selectMeteorologicalDetectorData();
for (DcMeteorologicalDetectorData meteorologicalDetectorData : dataList) { for (DcMeteorologicalDetectorData meteorologicalDetectorData : dataList) {
@ -61,15 +83,20 @@ public class DcWeatherMonitoringServiceImpl implements IDcWeatherMonitoringServi
if (StringUtils.isNotEmpty(meteorologicalDetectorData.getRainfall()) || StringUtils.isNotEmpty(meteorologicalDetectorData.getVisibilityType())){ if (StringUtils.isNotEmpty(meteorologicalDetectorData.getRainfall()) || StringUtils.isNotEmpty(meteorologicalDetectorData.getVisibilityType())){
BigDecimal rainfall = new BigDecimal(meteorologicalDetectorData.getRainfall()); BigDecimal rainfall = new BigDecimal(meteorologicalDetectorData.getRainfall());
if (rainfall.compareTo(BigDecimal.ZERO) > 0 || !"4".equals(meteorologicalDetectorData.getVisibilityType())){ if (rainfall.compareTo(BigDecimal.ZERO) > 0 || !"4".equals(meteorologicalDetectorData.getVisibilityType())){
normalMileage = normalMileage.subtract(detectionRange);
anomalies ++; if (deviceRange.get(meteorologicalDetectorData.getIotDeviceId()) != null){
if (rainfall.compareTo(BigDecimal.ZERO) > 0){ BigDecimal detectionRange = new BigDecimal(deviceRange.get(meteorologicalDetectorData.getIotDeviceId()).toString());
rainfallMileage = rainfallMileage.add(detectionRange); normalMileage = normalMileage.subtract(detectionRange);
} anomalies ++;
if (!"4".equals(meteorologicalDetectorData.getVisibilityType())){ if (rainfall.compareTo(BigDecimal.ZERO) > 0){
heavyFogNum ++; rainfallMileage = rainfallMileage.add(detectionRange);
heavyFogMileage = heavyFogMileage.add(detectionRange); }
if (!"4".equals(meteorologicalDetectorData.getVisibilityType())){
heavyFogNum ++;
heavyFogMileage = heavyFogMileage.add(detectionRange);
}
} }
} }
} }
} }

Loading…
Cancel
Save