commit
40f5df5bf6
4 changed files with 91 additions and 12 deletions
@ -0,0 +1,43 @@ |
||||
package com.huoran.competition.utils; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
public class HandleNameAsteriskReplacementUtil { |
||||
/** |
||||
* @description: 名字脱敏 |
||||
* 脱敏规则: 隐藏中中间部分,比如:李某人 置换为 李*人 , 李某置换为 *某,司徒司翘置换为 司**翘 |
||||
* @return: |
||||
* @author: *** |
||||
* @time: 2022/6/22 |
||||
*/ |
||||
public static String desensitizedName(String fullName) { |
||||
if (!com.mysql.cj.util.StringUtils.isNullOrEmpty(fullName)) { |
||||
int length = fullName.length(); |
||||
if (length == 2) { |
||||
return fullName.substring(0, 1).concat("*"); |
||||
} else if (length == 3) { |
||||
return StringUtils.left(fullName, 1).concat("*").concat(StringUtils.right(fullName, 1)); |
||||
} else if (length > 3) { |
||||
return StringUtils.left(fullName, 1).concat(generateAsterisk(fullName.substring(1, length - 1).length())).concat(StringUtils.right(fullName, 1)); |
||||
} else { |
||||
return fullName; |
||||
} |
||||
} |
||||
return fullName; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @description: 返回指定长度*字符串 |
||||
* @return: |
||||
* @author: *** |
||||
* @time: 2022/6/22 |
||||
*/ |
||||
private static String generateAsterisk(int length) { |
||||
String result = ""; |
||||
for (int i = 0; i < length; i++) { |
||||
result += "*"; |
||||
} |
||||
return result; |
||||
} |
||||
} |
Loading…
Reference in new issue