|
@@ -18,6 +18,10 @@ import java.util.regex.Pattern;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class CarService {
|
|
|
+ /**
|
|
|
+ * 匹配车牌省份
|
|
|
+ */
|
|
|
+ static final Pattern HAS_CHE_PAI_PROVINCE_PATTERN = Pattern.compile("[" + Pattern.quote("京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁国防") + "]");
|
|
|
/**
|
|
|
* 匹配非车牌字符
|
|
|
*/
|
|
@@ -58,14 +62,20 @@ public class CarService {
|
|
|
if (!StringUtils.hasText(chePai)) {
|
|
|
return "";
|
|
|
}
|
|
|
- // 字母转大写删除非车牌字符
|
|
|
- String s = NOT_CHE_PAI_PATTERN.matcher(chePai.toUpperCase()).replaceAll("");
|
|
|
+ // 字母转大写
|
|
|
+ String upperCase = chePai.toUpperCase();
|
|
|
+ // 删除非车牌字符
|
|
|
+ String s = NOT_CHE_PAI_PATTERN.matcher(upperCase).replaceAll("");
|
|
|
Matcher m = CHE_PAI_PATTERN.matcher(s);
|
|
|
if (m.find()) {
|
|
|
return m.group(0);
|
|
|
}
|
|
|
- log.warn("车牌匹配失败: {} -> {}", chePai, s);
|
|
|
- return s;
|
|
|
+ if (HAS_CHE_PAI_PROVINCE_PATTERN.matcher(chePai).find()) {
|
|
|
+ log.warn("车牌匹配失败: {} -> {}", chePai, s);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+ log.warn("车牌匹配失败: {} -> {}", chePai, upperCase);
|
|
|
+ return upperCase;
|
|
|
}
|
|
|
|
|
|
/**
|