From 91cef4d7c2992556891e9d8b4fffa541f98eeb09 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Mon, 29 Aug 2022 12:41:01 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B1=85=E6=B0=91=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E3=80=91=E6=8A=A4=E7=85=A7=EF=BC=8C=E6=8E=A9=E7=A0=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/tools/processor/MaskProcessor.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java index 24bce5bff3..11b5c5ce4f 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java @@ -161,12 +161,15 @@ public class MaskProcessor { return originString.replaceAll("^(\\d{10})\\d+([a-zA-Z0-9]{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); } else if (regexUtil.getTypeEnum() == IdCardTypeEnum.PASSPORT) { // 护照,前两位,后两位为明文,其他* - String maskStr = StrUtil.repeatByLength("*", originString.length() - 4); - return originString.replaceAll("^([a-zA-Z0-9]{2})\\d+(\\d{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); - } else { - // 其他情况,不码 - return originString; + int clearLength = 4; + int maskedLength = 0; + if ((maskedLength = originString.length() - clearLength) > 0) { + String maskStr = StrUtil.repeatByLength("*", maskedLength); + return originString.replaceAll("^([a-zA-Z0-9]{2})[a-zA-Z0-9]+([a-zA-Z0-9]{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); + } } + + return originString; } /**