Browse Source

桩号格式校验

develop
lau572 8 months ago
parent
commit
7107a0748f
  1. 28
      ruoyi-common/src/main/java/com/ruoyi/common/utils/StakeMarkUtils.java
  2. 16
      zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java

28
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.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.regex.Pattern;
/** /**
* @Description 桩号计算工具 * @Description 桩号工具
* *
* @author liuwenge * @author liuwenge
* @date 2024/1/17 14:43 * @date 2024/1/17 14:43
*/ */
public class StakeMarkUtils { 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 桩号转公里数 * @Description 桩号转公里数
* *
@ -20,7 +38,7 @@ public class StakeMarkUtils {
* @return 公里数:123.123 * @return 公里数:123.123
*/ */
public static String formatKilometre(String stakeMark){ public static String formatKilometre(String stakeMark){
if (StringUtils.isEmpty(stakeMark)){ if (!checkStakeMark(stakeMark)){
return ""; return "";
} }
return stakeMark.toLowerCase().replace("k","").replace("+","."); return stakeMark.toLowerCase().replace("k","").replace("+",".");
@ -35,7 +53,7 @@ public class StakeMarkUtils {
* @return 公里数:123123 * @return 公里数:123123
*/ */
public static String formatMetre(String stakeMark){ public static String formatMetre(String stakeMark){
if (StringUtils.isEmpty(stakeMark)){ if (!checkStakeMark(stakeMark)){
return ""; return "";
} }
return stakeMark.toLowerCase().replace("k","").replace("+",""); return stakeMark.toLowerCase().replace("k","").replace("+","");
@ -51,7 +69,7 @@ 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)){ if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); String start = startStakeMark.toLowerCase().replace("k","").replace("+",".");
@ -75,7 +93,7 @@ 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)){ if (!checkStakeMark(startStakeMark) || !checkStakeMark(endStakeMark)){
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
String start = startStakeMark.toLowerCase().replace("k","").replace("+","."); String start = startStakeMark.toLowerCase().replace("k","").replace("+",".");

16
zc-business/src/main/java/com/zc/business/service/impl/DcStakeMarkServiceImpl.java

@ -162,7 +162,7 @@ public class DcStakeMarkServiceImpl extends ServiceImpl<DcStakeMarkMapper, DcSta
//桩号格式校验 //桩号格式校验
List<String> errorKey = new ArrayList<>(); List<String> errorKey = new ArrayList<>();
map.keySet().forEach(key ->{ map.keySet().forEach(key ->{
if (!checkStakeMark(key)){ if (!StakeMarkUtils.checkStakeMark(key)){
errorKey.add(key); errorKey.add(key);
} }
DcStakeMark dcStakeMark = new DcStakeMark(); DcStakeMark dcStakeMark = new DcStakeMark();
@ -189,19 +189,5 @@ public class DcStakeMarkServiceImpl extends ServiceImpl<DcStakeMarkMapper, DcSta
return AjaxResult.success(); return AjaxResult.success();
} }
/**
* @Description 桩号格式校验
*
* 正确格式: K060+010
* @author liuwenge
* @date 2024/3/22 20:05
* @param stakeMark
* @return boolean
*/
private boolean checkStakeMark(String stakeMark){
Pattern pattern = Pattern.compile("^K\\d{3}\\+\\d{3}$");
return pattern.matcher(stakeMark).matches();
}
} }

Loading…
Cancel
Save