|
|
@ -2,15 +2,33 @@ package com.ruoyi.common.utils; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 桩号计算工具 |
|
|
|
* @Description 桩号工具 |
|
|
|
* |
|
|
|
* @author liuwenge |
|
|
|
* @date 2024/1/17 14:43 |
|
|
|
*/ |
|
|
|
public class StakeMarkUtils { |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 桩号格式校验 |
|
|
|
* |
|
|
|
* 正确格式: K060+010 |
|
|
|
* @author liuwenge |
|
|
|
* @date 2024/3/22 20:05 |
|
|
|
* @param stakeMark |
|
|
|
* @return boolean |
|
|
|
*/ |
|
|
|
public static boolean checkStakeMark(String stakeMark){ |
|
|
|
if (StringUtils.isEmpty(stakeMark)){ |
|
|
|
return false; |
|
|
|
} |
|
|
|
Pattern pattern = Pattern.compile("^K\\d{3}\\+\\d{3}$"); |
|
|
|
return pattern.matcher(stakeMark).matches(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 桩号转公里数 |
|
|
|
* |
|
|
@ -20,7 +38,7 @@ public class StakeMarkUtils { |
|
|
|
* @return 公里数:123.123 |
|
|
|
*/ |
|
|
|
public static String formatKilometre(String stakeMark){ |
|
|
|
if (StringUtils.isEmpty(stakeMark)){ |
|
|
|
if (!checkStakeMark(stakeMark)){ |
|
|
|
return ""; |
|
|
|
} |
|
|
|
return stakeMark.toLowerCase().replace("k","").replace("+","."); |
|
|
@ -35,7 +53,7 @@ public class StakeMarkUtils { |
|
|
|
* @return 公里数:123123 |
|
|
|
*/ |
|
|
|
public static String formatMetre(String stakeMark){ |
|
|
|
if (StringUtils.isEmpty(stakeMark)){ |
|
|
|
if (!checkStakeMark(stakeMark)){ |
|
|
|
return ""; |
|
|
|
} |
|
|
|
return stakeMark.toLowerCase().replace("k","").replace("+",""); |
|
|
@ -51,7 +69,7 @@ public class StakeMarkUtils { |
|
|
|
* @return java.math.BigDecimal 距离 |
|
|
|
*/ |
|
|
|
public static BigDecimal getKilometre(String startStakeMark, String endStakeMark){ |
|
|
|
if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ |
|
|
|
if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){ |
|
|
|
return BigDecimal.ZERO; |
|
|
|
} |
|
|
|
String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); |
|
|
@ -75,7 +93,7 @@ public class StakeMarkUtils { |
|
|
|
* @return java.math.BigDecimal 距离 |
|
|
|
*/ |
|
|
|
public static BigDecimal getMetre(String startStakeMark, String endStakeMark){ |
|
|
|
if (StringUtils.isEmpty(startStakeMark) || StringUtils.isEmpty(endStakeMark)){ |
|
|
|
if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){ |
|
|
|
return BigDecimal.ZERO; |
|
|
|
} |
|
|
|
String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); |
|
|
|