Browse Source

身份证 电话号码脱敏处理工具类添加

dev_ycq
21819 2 years ago
parent
commit
af38ac3790
  1. 7
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java
  2. 27
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/util/DesensitizedUtil.java

7
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.biutag.outeradmin.entity.*;
import com.biutag.outeradmin.mapper.MailMapper;
import com.biutag.outeradmin.service.MailService;
import com.biutag.outeradmin.util.DesensitizedUtil;
import com.biutag.util.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@ -38,7 +39,7 @@ public class MailController {
}
/**
* 查询指定信件
* 根据前端表格数据查询指定信件
*
* @param form 前端信件表单数据
* @return 指定信件json
@ -65,6 +66,10 @@ public class MailController {
Page<Mail> page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize());
List<Mail> mailPage = mailMapper.selectPage(page, queryWrapper).getRecords();
for (Mail mail : mailPage) {
mail.setContactIdCard(DesensitizedUtil.encryptIDCard(mail.getContactIdCard()));
mail.setContactPhone(DesensitizedUtil.encryptPhone(mail.getContactPhone()));
}
pageSet.setTotalSize((int) page.getTotal());
MailPageInfo result = new MailPageInfo();
result.setMails(mailPage);

27
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/util/DesensitizedUtil.java

@ -0,0 +1,27 @@
package com.biutag.outeradmin.util;
import com.biutag.util.StringUtils;
/**
* 身份证以及手机号脱敏处理工具类
*/
public class DesensitizedUtil {
public static String encryptIDCard(String idCard) {
if (StringUtils.isNotBlank(idCard)) {
if (idCard.length() == 15) {
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{4})", "$1******$2");
}
if (idCard.length() == 18) {
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{4})", "$1*********$2");
}
}
return idCard;
}
public static String encryptPhone(String phone) {
if (StringUtils.isNotBlank(phone)) {
phone = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
}
return phone;
}
}
Loading…
Cancel
Save