mengff
1 month ago
1 changed files with 130 additions and 0 deletions
@ -0,0 +1,130 @@ |
|||||
|
package com.zc.business.utils; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
public class WeatherTrafficProposeUtil { |
||||
|
|
||||
|
// 定义天气条件的等级
|
||||
|
@Getter |
||||
|
public enum WeatherCondition { |
||||
|
RAIN_LEVEL_1(3, "1"), |
||||
|
RAIN_LEVEL_2(2, "1"), |
||||
|
RAIN_LEVEL_3(1, "1"), |
||||
|
RAIN_LEVEL_4(0, "1"), |
||||
|
FOG_LEVEL_1(3, "5,11,12"), |
||||
|
FOG_LEVEL_2(2, "5,11,12"), |
||||
|
FOG_LEVEL_3(1, "5,11,12"), |
||||
|
FOG_LEVEL_4(0, "5,11,12"), |
||||
|
SNOW_LEVEL_1(3, "2,9,10,13"), |
||||
|
SNOW_LEVEL_2(2, "2,9,10,13"), |
||||
|
SNOW_LEVEL_3(1, "2,9,10,13"), |
||||
|
SNOW_LEVEL_4(0, "2,9,10,13"); |
||||
|
|
||||
|
private final int level; |
||||
|
private final String description; |
||||
|
|
||||
|
WeatherCondition(int level, String description) { |
||||
|
this.level = level; |
||||
|
this.description = description; |
||||
|
} |
||||
|
|
||||
|
public static WeatherCondition fromLevelAndDescription(int level, String description) { |
||||
|
for (WeatherCondition condition : WeatherCondition.values()) { |
||||
|
if (condition.getLevel() == level && condition.getDescription().contains(description)) { |
||||
|
return condition; |
||||
|
} |
||||
|
} |
||||
|
throw new IllegalArgumentException("No matching WeatherCondition found for level: " + level + " and description: " + description); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 获取限速建议
|
||||
|
public static int getSpeedLimit(WeatherCondition condition) { |
||||
|
switch (condition) { |
||||
|
case RAIN_LEVEL_4: |
||||
|
case FOG_LEVEL_4: |
||||
|
case SNOW_LEVEL_4: |
||||
|
return 80; // 四级
|
||||
|
case RAIN_LEVEL_3: |
||||
|
case FOG_LEVEL_3: |
||||
|
case SNOW_LEVEL_3: |
||||
|
return 60; // 三级
|
||||
|
case RAIN_LEVEL_2: |
||||
|
case FOG_LEVEL_2: |
||||
|
case SNOW_LEVEL_2: |
||||
|
return 40; // 二级
|
||||
|
case RAIN_LEVEL_1: |
||||
|
case FOG_LEVEL_1: |
||||
|
case SNOW_LEVEL_1: |
||||
|
return 20; // 一级(带队通行)
|
||||
|
default: |
||||
|
throw new IllegalArgumentException("Unknown weather condition: " + condition); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 获取流量控制建议
|
||||
|
public static String getTrafficControlAdvice(WeatherCondition condition) { |
||||
|
switch (condition) { |
||||
|
case RAIN_LEVEL_4: |
||||
|
case FOG_LEVEL_4: |
||||
|
case SNOW_LEVEL_4: |
||||
|
case RAIN_LEVEL_3: |
||||
|
case FOG_LEVEL_3: |
||||
|
case SNOW_LEVEL_3: |
||||
|
case RAIN_LEVEL_2: |
||||
|
case FOG_LEVEL_2: |
||||
|
case SNOW_LEVEL_2: |
||||
|
return "建议局部封闭、间断放行。"; |
||||
|
case RAIN_LEVEL_1: |
||||
|
case FOG_LEVEL_1: |
||||
|
case SNOW_LEVEL_1: |
||||
|
return "建议全线封闭收费站、必要时可带队通行的控制措施。全线封闭时,正在高速公路通行的车辆应以不大于 20km/h 的速度就近驶出高速公路或驶入服务区。带队通行时,应保障交通有序通行。"; |
||||
|
default: |
||||
|
throw new IllegalArgumentException("Unknown weather condition: " + condition); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 获取车型控制建议
|
||||
|
public static String getVehicleControlAdvice(WeatherCondition condition) { |
||||
|
switch (condition) { |
||||
|
case RAIN_LEVEL_4: |
||||
|
case FOG_LEVEL_4: |
||||
|
case SNOW_LEVEL_4: |
||||
|
return "所有车型均可通行。"; |
||||
|
case RAIN_LEVEL_3: |
||||
|
case FOG_LEVEL_3: |
||||
|
return "禁止“两客一危”车辆通行。"; |
||||
|
case RAIN_LEVEL_2: |
||||
|
case FOG_LEVEL_2: |
||||
|
return "禁止七座以上(不含七座)客车、危险品运输车辆和黄牌货车通行。"; |
||||
|
case RAIN_LEVEL_1: |
||||
|
case FOG_LEVEL_1: |
||||
|
case SNOW_LEVEL_1: |
||||
|
return "全线封闭;必要时可带队通行。"; |
||||
|
case SNOW_LEVEL_2: |
||||
|
return "仅间隔放行黄牌货车。"; |
||||
|
case SNOW_LEVEL_3: |
||||
|
return "禁止七座以上(不含七座)客车、危险品运输车辆通行。"; |
||||
|
default: |
||||
|
throw new IllegalArgumentException("Unknown weather condition: " + condition); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
int warningLevelStringNumber = 3; |
||||
|
String earlyWarningTypeStringNumber= "1"; |
||||
|
try { |
||||
|
WeatherCondition condition = WeatherCondition.fromLevelAndDescription(warningLevelStringNumber, earlyWarningTypeStringNumber); |
||||
|
System.out.println("Weather Condition: " + condition.name() + ", Level: " + condition.getLevel() + ", Description: " + condition.getDescription()); |
||||
|
|
||||
|
int speedLimit = getSpeedLimit(condition); |
||||
|
String trafficAdvice = getTrafficControlAdvice(condition); |
||||
|
String vehicleAdvice = getVehicleControlAdvice(condition); |
||||
|
|
||||
|
System.out.println("限速建议: " + speedLimit + " km/h"); |
||||
|
System.out.println("流量控制建议: " + trafficAdvice); |
||||
|
System.out.println("车型控制建议: " + vehicleAdvice); |
||||
|
} catch (IllegalArgumentException e) { |
||||
|
System.err.println(e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue