提交 f16a5803 authored 作者: 吕本才's avatar 吕本才

脱敏

上级 8e96503b
......@@ -40,11 +40,20 @@ public enum DesensitizedType
*/
BANK_CARD(s -> s.replaceAll("\\d{15}(\\d{3})", "**** **** **** **** $1")),
/**
* 经销商名称
* 保留前三字 后三字,中间6位星号替换
* 正则表达式:(\S3))(\S*)(\S4)
*/
DEALER_NAME(DesensitizedUtil::dealerNameSentive),
/**
* 车牌号码,包含普通车辆、新能源车辆
*/
CAR_LICENSE(DesensitizedUtil::carLicense);
private final Function<String, String> desensitizer;
DesensitizedType(Function<String, String> desensitizer)
......
......@@ -5,42 +5,77 @@ package com.ruoyi.common.utils;
*
* @author ruoyi
*/
public class DesensitizedUtil
{
public class DesensitizedUtil {
/**
* 密码的全部字符都用*代替,比如:******
*
* @param password 密码
* @return 脱敏后的密码
*/
public static String password(String password)
{
if (StringUtils.isBlank(password))
{
public static String password(String password) {
if (StringUtils.isBlank(password)) {
return StringUtils.EMPTY;
}
return StringUtils.repeat('*', password.length());
}
public static String dealerNameSentive(String dealerName) {
if (StringUtils.isBlank(dealerName)) {
return StringUtils.EMPTY;
}
if (dealerName.length() < 7) {
return dealerName;
}
if (dealerName.contains("市")) {
int indexArea = dealerName.indexOf("市");
int endIndex = dealerName.indexOf("有限公司");
if (endIndex > 0) {
endIndex = dealerName.length() - 5;
}else{
endIndex =dealerName.length() - 3;
}
dealerName = StringUtils.hide(dealerName, indexArea+2, endIndex);
} else {
// 不包含市,需要初始化 超过三个字的市 一个集合 ,像内蒙古 哈尔滨等
String[] citys = {"内蒙古", "黑龙江", "吉林", "辽宁", "河北", "河南", "山东", "山西", "陕西", "新疆", "西藏", "甘肃", "宁夏", "青海", "海南"};
int startIndex = 3;
if (StringUtils.containsAny(dealerName, citys)) {
// 返回包含的 下标
for (String city : citys) {
int indexCity = dealerName.indexOf(city);
if (indexCity > -1) {
startIndex = dealerName.indexOf(indexCity)+1;
break;
}
}
}
int endIndex = dealerName.indexOf("有限公司");
if (endIndex < 0) {
endIndex = dealerName.length() - 4;
}
dealerName = StringUtils.hide(dealerName, startIndex, endIndex);
}
return dealerName;
}
/**
* 车牌中间用*代替,如果是错误的车牌,不处理
*
* @param carLicense 完整的车牌号
* @return 脱敏后的车牌
*/
public static String carLicense(String carLicense)
{
if (StringUtils.isBlank(carLicense))
{
public static String carLicense(String carLicense) {
if (StringUtils.isBlank(carLicense)) {
return StringUtils.EMPTY;
}
// 普通车牌
if (carLicense.length() == 7)
{
if (carLicense.length() == 7) {
carLicense = StringUtils.hide(carLicense, 3, 6);
}
else if (carLicense.length() == 8)
{
} else if (carLicense.length() == 8) {
// 新能源车牌
carLicense = StringUtils.hide(carLicense, 3, 7);
}
......
package com.ruoyi.dealer.domain.dto;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.enums.DesensitizedType;
import lombok.Data;
import java.math.BigDecimal;
......@@ -17,6 +19,7 @@ public class DealerBigScreenDynamicRes {
* 经销商名称(非空)
* TODO 脱敏经销商名称
*/
@Sensitive(desensitizedType = DesensitizedType.DEALER_NAME)
private String dealerName;
/**
......@@ -35,6 +38,7 @@ public class DealerBigScreenDynamicRes {
*/
private String paymentPercentage;
@Sensitive(desensitizedType = DesensitizedType.PHONE)
private String phone;
/**
* 预付款变化 up down
......
package com.ruoyi.dealer.domain.dto;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.enums.DesensitizedType;
import lombok.Data;
@Data
......@@ -7,7 +9,10 @@ public class DealerBigScreenGroupListRes {
private Integer roundTime;
private String groupName;
private String dealerCategory;
@Sensitive(desensitizedType = DesensitizedType.PHONE)
private String phone;
@Sensitive(desensitizedType = DesensitizedType.DEALER_NAME)
private String dealerName;
private Long dealerId;
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论