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 6c61fa9a..686b4c29 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 @@ -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("+","."); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java index 7c8c3974..e2d3022b 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java @@ -162,7 +162,7 @@ public class DcStakeMarkServiceImpl extends ServiceImpl errorKey = new ArrayList<>(); map.keySet().forEach(key ->{ - if (!checkStakeMark(key)){ + if (!StakeMarkUtils.checkStakeMark(key)){ errorKey.add(key); } DcStakeMark dcStakeMark = new DcStakeMark(); @@ -189,19 +189,5 @@ public class DcStakeMarkServiceImpl extends ServiceImpl