手机号和身份证脱敏

This commit is contained in:
马三炮 2025-07-01 09:43:40 +08:00
parent 758ee01647
commit 9c2ceb01c0
3 changed files with 33 additions and 1 deletions

View File

@ -754,4 +754,28 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
return -1; // 解析错误
}
}
/**
* 身份证脱敏处理
* 保留前6位和后4位中间用*替代
* 示例340826199001011234 -> 340826********1234
*/
public static String desensitizeIdCard(String idCard) {
if (idCard == null || idCard.length() < 10) {
return idCard;
}
return idCard.replaceAll("(?<=\\d{6})\\d(?=\\d{4})", "*");
}
/**
* 手机号脱敏处理
* 保留前3位和后4位中间4位用*替代
* 示例13123456789 -> 131****6789
*/
public static String desensitizePhone(String phone) {
if (phone == null || phone.length() != 11) {
return phone;
}
return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
}
}

View File

@ -34,7 +34,7 @@ import com.bonus.system.service.ISysUserService;
/**
* 用户信息
*
*
* @author ruoyi
*/
@RestController
@ -62,6 +62,10 @@ public class SysUserController extends BaseController
{
startPage();
List<SysUser> list = userService.selectUserList(user);
//手机号脱敏
for (SysUser sysUser:list ) {
sysUser.setPhonenumber(StringUtils.desensitizePhone(sysUser.getPhonenumber()));
}
return getDataTable(list);
}

View File

@ -58,6 +58,10 @@ public class TbCompanyPerfServiceImpl implements TbCompanyPerfService {
for (TbCompanyPerfVo tbCompanyPerf:tbCompanyPerfList) {
//获取项目关键人员信息
List<TbCompanyPerfRelVo> tbCompanyPerfRelList = tbCompanyPerfRelService.getTbCompanyPerRelByPerfId(tbCompanyPerf.getId(),"1");
for (TbCompanyPerfRelVo tbCompanyPerfRelVo:tbCompanyPerfRelList) {
//身份证号脱敏
tbCompanyPerfRelVo.setIdCard(StringUtils.desensitizeIdCard(tbCompanyPerfRelVo.getIdCard()));
}
tbCompanyPerf.setTbCompanyPerfRelList(tbCompanyPerfRelList);
//获取附件信息
List<TbFileSourceVo> tbFileSourceVoList = tbFileSourceService.getTbFileSourceList(tbCompanyPerf.getId(), TableType.TB_COMPANY_PERF.getCode());