Browse Source

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

dev_ycq
21819 2 years ago
parent
commit
af38ac3790
  1. 9
      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

9
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.entity.*;
import com.biutag.outeradmin.mapper.MailMapper; import com.biutag.outeradmin.mapper.MailMapper;
import com.biutag.outeradmin.service.MailService; import com.biutag.outeradmin.service.MailService;
import com.biutag.outeradmin.util.DesensitizedUtil;
import com.biutag.util.StringUtils; import com.biutag.util.StringUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -38,7 +39,7 @@ public class MailController {
} }
/** /**
* 查询指定信件 * 根据前端表格数据查询指定信件
* *
* @param form 前端信件表单数据 * @param form 前端信件表单数据
* @return 指定信件json * @return 指定信件json
@ -49,7 +50,7 @@ public class MailController {
System.out.println(form); System.out.println(form);
FormPage formPage = JSON.parseObject(form, FormPage.class); FormPage formPage = JSON.parseObject(form, FormPage.class);
QueryWrapper<Mail> queryWrapper = new QueryWrapper<>(); QueryWrapper<Mail> queryWrapper = new QueryWrapper<>();
if(formPage != null && formPage.getFormData()!= null && formPage.getPageData()!= null){ if (formPage != null && formPage.getFormData() != null && formPage.getPageData() != null) {
FormData formData = formPage.getFormData(); FormData formData = formPage.getFormData();
queryWrapper.lambda().like(StringUtils.isNotEmpty(formData.getContactName()), Mail::getContactName, formData.getContactName()) queryWrapper.lambda().like(StringUtils.isNotEmpty(formData.getContactName()), Mail::getContactName, formData.getContactName())
@ -65,6 +66,10 @@ public class MailController {
Page<Mail> page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize()); Page<Mail> page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize());
List<Mail> mailPage = mailMapper.selectPage(page, queryWrapper).getRecords(); 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()); pageSet.setTotalSize((int) page.getTotal());
MailPageInfo result = new MailPageInfo(); MailPageInfo result = new MailPageInfo();
result.setMails(mailPage); 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