From 9caf4422917e7bfced598dee1874751497466d1e Mon Sep 17 00:00:00 2001 From: mengff <1198151809@qq.com> Date: Mon, 21 Oct 2024 15:10:12 +0800 Subject: [PATCH] =?UTF-8?q?--=E5=A2=9E=E5=8A=A0=E6=B0=94=E8=B1=A1=E9=A2=84?= =?UTF-8?q?=E8=AD=A6=E9=A2=84=E9=98=B2=E5=BB=BA=E8=AE=AE=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/WeatherTrafficProposeUtil.java | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java diff --git a/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java b/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java new file mode 100644 index 00000000..4b956ef8 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java @@ -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()); + } + } +}