From 35beb3d87d13a1e9ddb819f8f8c6c1ec031808ce Mon Sep 17 00:00:00 2001 From: Renpc-kilig <308442850@qq.com> Date: Mon, 4 Mar 2024 20:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E8=84=B1?= =?UTF-8?q?=E6=95=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../houseuser/impl/HouseUserServiceImpl.java | 9 ++- .../impl/HouseUserSubServiceImpl.java | 9 ++- .../utils/datacover/DataCoverUtils.java | 75 +++++++++++++++++++ src/main/resources/application-test.yml | 6 +- 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 src/main/java/cn/com/tenlion/systemhouse/utils/datacover/DataCoverUtils.java diff --git a/src/main/java/cn/com/tenlion/systemhouse/service/houseuser/impl/HouseUserServiceImpl.java b/src/main/java/cn/com/tenlion/systemhouse/service/houseuser/impl/HouseUserServiceImpl.java index beb3a32..3efbad6 100644 --- a/src/main/java/cn/com/tenlion/systemhouse/service/houseuser/impl/HouseUserServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemhouse/service/houseuser/impl/HouseUserServiceImpl.java @@ -7,6 +7,7 @@ import cn.com.tenlion.systemhouse.pojo.dtos.houseuser.HouseUserDTO; import cn.com.tenlion.systemhouse.pojo.pos.houseuser.HouseUserPO; import cn.com.tenlion.systemhouse.pojo.vos.houseuser.HouseUserVO; import cn.com.tenlion.systemhouse.service.houseuser.IHouseUserService; +import cn.com.tenlion.systemhouse.utils.datacover.DataCoverUtils; import ink.wgink.common.base.DefaultBaseService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.result.SuccessResultList; @@ -144,7 +145,13 @@ public class HouseUserServiceImpl extends DefaultBaseService implements IHouseUs @Override public List list(Map params) { - return houseUserDao.list(params); + List list = houseUserDao.list(params); + for(HouseUserDTO houseUserDTO: list) { + houseUserDTO.setName(DataCoverUtils.desensitizeName(houseUserDTO.getName())); + houseUserDTO.setCardNum(DataCoverUtils.desensitizeIdCardNumber(houseUserDTO.getCardNum())); + houseUserDTO.setPhone(DataCoverUtils.desensitizePhoneNumber(houseUserDTO.getPhone())); + } + return list; } @Override diff --git a/src/main/java/cn/com/tenlion/systemhouse/service/houseusersub/impl/HouseUserSubServiceImpl.java b/src/main/java/cn/com/tenlion/systemhouse/service/houseusersub/impl/HouseUserSubServiceImpl.java index 348b35b..ede17a1 100644 --- a/src/main/java/cn/com/tenlion/systemhouse/service/houseusersub/impl/HouseUserSubServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemhouse/service/houseusersub/impl/HouseUserSubServiceImpl.java @@ -6,6 +6,7 @@ import cn.com.tenlion.systemhouse.pojo.dtos.houseusersub.HouseUserSubDTO; import cn.com.tenlion.systemhouse.pojo.pos.houseusersub.HouseUserSubPO; import cn.com.tenlion.systemhouse.pojo.vos.houseusersub.HouseUserSubVO; import cn.com.tenlion.systemhouse.service.houseusersub.IHouseUserSubService; +import cn.com.tenlion.systemhouse.utils.datacover.DataCoverUtils; import ink.wgink.common.base.DefaultBaseService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.result.SuccessResultList; @@ -140,7 +141,13 @@ public class HouseUserSubServiceImpl extends DefaultBaseService implements IHous @Override public List list(Map params) { - return houseUserSubDao.list(params); + List list = houseUserSubDao.list(params); + for (HouseUserSubDTO houseUserSubDTO : list) { + houseUserSubDTO.setName(DataCoverUtils.desensitizeName(houseUserSubDTO.getName())); + houseUserSubDTO.setCardNum(DataCoverUtils.desensitizeIdCardNumber(houseUserSubDTO.getCardNum())); + houseUserSubDTO.setPhone(DataCoverUtils.desensitizePhoneNumber(houseUserSubDTO.getPhone())); + } + return list; } @Override diff --git a/src/main/java/cn/com/tenlion/systemhouse/utils/datacover/DataCoverUtils.java b/src/main/java/cn/com/tenlion/systemhouse/utils/datacover/DataCoverUtils.java new file mode 100644 index 0000000..3733130 --- /dev/null +++ b/src/main/java/cn/com/tenlion/systemhouse/utils/datacover/DataCoverUtils.java @@ -0,0 +1,75 @@ +package cn.com.tenlion.systemhouse.utils.datacover; + +/** + * 姓名和身份证脱敏工具类 + */ +public class DataCoverUtils { + + /** + * 脱敏人名 + * @param fullName 完整的人名 + * @return 脱敏后的人名 + */ + public static String desensitizeName(String fullName) { + if (fullName == null || fullName.isEmpty()) { + return ""; + } + + // 将名字拆分为姓和名 + String[] nameParts = fullName.split(" "); + if (nameParts.length == 1) { + // 如果只有一个名字,脱敏第二个字符 + if (nameParts[0].length() > 1) { + return nameParts[0].charAt(0) + "*" + nameParts[0].charAt(nameParts[0].length() - 1); + } else { + // 如果只有一个字符,则直接返回星号 + return "*"; + } + } else { + // 如果有姓和名,脱敏名字中的第一个字符 + return nameParts[0] + " " + "*" + nameParts[1].charAt(nameParts[1].length() - 1); + } + } + + /** + * 脱敏身份证号码 + * @param idCardNumber 完整的身份证号码 + * @return 脱敏后的身份证号码 + */ + public static String desensitizeIdCardNumber(String idCardNumber) { + if (idCardNumber == null || idCardNumber.isEmpty() || idCardNumber.length() != 18) { + return ""; + } + + // 保留前6位和后4位,中间8位脱敏 + return idCardNumber.substring(0, 6) + "**********" + idCardNumber.substring(14); + } + + /** + * 脱敏手机号码 + * @param phoneNumber 完整的手机号码 + * @return 脱敏后的手机号码 + */ + public static String desensitizePhoneNumber(String phoneNumber) { + if (phoneNumber == null || phoneNumber.isEmpty() || phoneNumber.length() != 11) { + return ""; + } + + // 保留前3位和后4位,中间4位脱敏 + return phoneNumber.substring(0, 3) + "****" + phoneNumber.substring(7); + } + + public static void main(String[] args) { + String fullName = "张三"; + String idCardNumber = "123456789012345678"; + + String desensitizedName = desensitizeName(fullName); + String desensitizedIdCardNumber = desensitizeIdCardNumber(idCardNumber); + + System.out.println("原始人名: " + fullName); + System.out.println("脱敏后人名: " + desensitizedName); + System.out.println("原始身份证号码: " + idCardNumber); + System.out.println("脱敏后身份证号码: " + desensitizedIdCardNumber); + } + +} diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 1ace158..8adb430 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,6 +1,6 @@ server: port: 8083 - url: http://192.168.0.111:8083/systemhouse + url: http://192.168.0.4:8083/systemhouse system-title: 房屋管理系统 system-sub-title: 房屋管理系统 nav-page: http://192.168.0.155:7011/usercenter @@ -125,8 +125,8 @@ security: oauth-server: http://192.168.0.155:7011/usercenter oauth-logout: ${security.oauth2.oauth-server}/logout?redirect_uri=${server.url} client: - client-id: 347b893bfd034c43b2349d84c7df1591 - client-secret: SnJnTWJ2TS9LMGJMZXFobS9kY1NQOHNEa01EVGtaVk9HU1hoMEZNa2RKSGxIdG9KZmEyTjJIRnI0dG1McEdEVA== + client-id: 0df0a2df7ffc409ba5ca1b95c64899e4 + client-secret: R3ZDY2xDRnlWREZBb2g5SmRscnpuZVhhRjQ1a2RuSXNsWHg5UUN2M09nbmxIdG9KZmEyTjJIRnI0dG1McEdEVA== user-authorization-uri: ${security.oauth2.oauth-server}/oauth2_client/authorize access-token-uri: ${security.oauth2.oauth-server}/oauth2_client/token grant-type: authorization_code