From 2d24dd5a9ea2de6d61bfe396c4980d459cf8954b Mon Sep 17 00:00:00 2001 From: sangelxiu1 <15781802@163.com> Date: Fri, 17 Oct 2025 10:50:56 +0800 Subject: [PATCH] =?UTF-8?q?##=20Opt=20-=20=E5=A5=96=E9=87=91=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/MemberStatisticsServiceImpl.java | 4 +- .../member/statis/MemberStatisticsMapper.xml | 112 +++++++++------- .../sale/component/load/RedisComponent.java | 2 +- .../common/core/utils/DataMaskingUtil.java | 123 ++++++++---------- .../statis/DirectStatisticsTop30VO.java | 2 +- 5 files changed, 128 insertions(+), 115 deletions(-) diff --git a/bd-business/bd-business-member/src/main/java/com/hzs/member/statis/service/impl/MemberStatisticsServiceImpl.java b/bd-business/bd-business-member/src/main/java/com/hzs/member/statis/service/impl/MemberStatisticsServiceImpl.java index bbe5a734..820d5d63 100644 --- a/bd-business/bd-business-member/src/main/java/com/hzs/member/statis/service/impl/MemberStatisticsServiceImpl.java +++ b/bd-business/bd-business-member/src/main/java/com/hzs/member/statis/service/impl/MemberStatisticsServiceImpl.java @@ -74,9 +74,9 @@ public class MemberStatisticsServiceImpl implements IMemberStatisticsService { for (DirectStatisticsTop30VO directStatisticsTop30VO : result) { if(param.getFaker()){ directStatisticsTop30VO.setMemberCode(DataMaskingUtil.mask(directStatisticsTop30VO.getMemberCode(), 2, 2)); - directStatisticsTop30VO.setMemberName(DataMaskingUtil.mask(directStatisticsTop30VO.getMemberName(), 1, 0, 6)); + directStatisticsTop30VO.setMemberName(DataMaskingUtil.maskFirstLast(directStatisticsTop30VO.getMemberName())); } - directStatisticsTop30VO.setNumberOfAmount(directStatisticsTop30VO.getNumberOfAmount().divide(new BigDecimal(10000))); +// directStatisticsTop30VO.setNumberOfAmount(directStatisticsTop30VO.getNumberOfAmount().divide(new BigDecimal(10000))); } return result; } diff --git a/bd-business/bd-business-member/src/main/resources/mapper/member/statis/MemberStatisticsMapper.xml b/bd-business/bd-business-member/src/main/resources/mapper/member/statis/MemberStatisticsMapper.xml index 05233d8c..cea9cc83 100644 --- a/bd-business/bd-business-member/src/main/resources/mapper/member/statis/MemberStatisticsMapper.xml +++ b/bd-business/bd-business-member/src/main/resources/mapper/member/statis/MemberStatisticsMapper.xml @@ -4,54 +4,78 @@ diff --git a/bd-business/bd-business-sale/src/main/java/com/hzs/sale/component/load/RedisComponent.java b/bd-business/bd-business-sale/src/main/java/com/hzs/sale/component/load/RedisComponent.java index dceb5c1a..d701a7a3 100644 --- a/bd-business/bd-business-sale/src/main/java/com/hzs/sale/component/load/RedisComponent.java +++ b/bd-business/bd-business-sale/src/main/java/com/hzs/sale/component/load/RedisComponent.java @@ -46,7 +46,7 @@ class RedisComponent { public void initConfig() { // 商品信息 - initWaresConfig(); +// initWaresConfig(); // 邮费 initPostageTemp(); } diff --git a/bd-common/bd-common-core/src/main/java/com/hzs/common/core/utils/DataMaskingUtil.java b/bd-common/bd-common-core/src/main/java/com/hzs/common/core/utils/DataMaskingUtil.java index e50a409a..52946d4c 100644 --- a/bd-common/bd-common-core/src/main/java/com/hzs/common/core/utils/DataMaskingUtil.java +++ b/bd-common/bd-common-core/src/main/java/com/hzs/common/core/utils/DataMaskingUtil.java @@ -5,101 +5,90 @@ package com.hzs.common.core.utils; * 提供字符串脱敏功能,可指定保留前几位和后几位字符 */ public class DataMaskingUtil { - - // 默认脱敏字符 - private static final char DEFAULT_MASK_CHAR = '*'; - /** - * 对字符串进行脱敏处理 - * @param input 原始字符串 - * @param keepPrefix 保留的前缀位数 - * @param keepSuffix 保留的后缀位数 + * 数据脱敏方法 - 前一后一格式 + * @param input 输入字符串 + * @param keepPrefix 保留前缀长度 + * @param keepSuffix 保留后缀长度 * @return 脱敏后的字符串 */ public static String mask(String input, int keepPrefix, int keepSuffix) { - // 参数验证 - if (input == null) { - return null; - } - - // 处理边界情况 - if (keepPrefix < 0 || keepSuffix < 0) { - throw new IllegalArgumentException("保留位数不能为负数"); + // 处理空值或null情况 + if (input == null || input.isEmpty()) { + return input; } int length = input.length(); - // 如果字符串长度小于等于需要保留的位数之和,直接返回原字符串 - if (length <= keepPrefix + keepSuffix) { + // 特殊情况:长度为2时,只保留第一位 + if (length == 2) { + return input.substring(0, 1) + "*"; + } + + // 特殊情况:长度小于等于1时,直接返回 + if (length <= 1) { return input; } - // 构建StringBuilder用于高效拼接字符串 - StringBuilder result = new StringBuilder(length); + // 调整保留长度,确保合理 + keepPrefix = Math.min(keepPrefix, length); + keepSuffix = Math.min(keepSuffix, length - keepPrefix); - // 添加前缀保留字符 - result.append(input, 0, keepPrefix); + StringBuilder result = new StringBuilder(); - // 添加脱敏字符 - int maskCount = length - keepPrefix - keepSuffix; - for (int i = 0; i < maskCount; i++) { - result.append(DEFAULT_MASK_CHAR); + // 添加前缀 + result.append(input.substring(0, keepPrefix)); + + // 添加脱敏部分(使用*代替) + int maskLength = length - keepPrefix - keepSuffix; + for (int i = 0; i < maskLength; i++) { + result.append('*'); } - // 添加后缀保留字符 - result.append(input, length - keepSuffix, length); + // 添加后缀 + if (keepSuffix > 0) { + result.append(input.substring(length - keepSuffix)); + } return result.toString(); } + + /** + * 带最大长度限制的数据脱敏方法 + * @param input 输入字符串 + * @param keepPrefix 保留前缀长度 + * @param keepSuffix 保留后缀长度 + * @param maxLength 最大输出长度 + * @return 脱敏后的字符串 + */ public static String mask(String input, int keepPrefix, int keepSuffix, int maxLength) { + // 调用基础脱敏方法 String str = mask(input, keepPrefix, keepSuffix); - if(str.length() > maxLength) { + + // 限制最大长度 + if (str.length() > maxLength) { str = str.substring(0, maxLength); } + return str; } /** - * 对字符串进行脱敏处理,可自定义脱敏字符 - * @param input 原始字符串 - * @param keepPrefix 保留的前缀位数 - * @param keepSuffix 保留的后缀位数 - * @param maskChar 自定义脱敏字符 + * 前一后一格式的快捷脱敏方法 + * @param input 输入字符串 * @return 脱敏后的字符串 */ - public static String mask(String input, int keepPrefix, int keepSuffix, char maskChar) { - // 参数验证 - if (input == null) { - return null; - } + public static String maskFirstLast(String input) { + return mask(input, 1, 1); + } - // 处理边界情况 - if (keepPrefix < 0 || keepSuffix < 0) { - throw new IllegalArgumentException("保留位数不能为负数"); - } - - int length = input.length(); - - // 如果字符串长度小于等于需要保留的位数之和,直接返回原字符串 - if (length <= keepPrefix + keepSuffix) { - return input; - } - - // 构建StringBuilder用于高效拼接字符串 - StringBuilder result = new StringBuilder(length); - - // 添加前缀保留字符 - result.append(input, 0, keepPrefix); - - // 添加脱敏字符 - int maskCount = length - keepPrefix - keepSuffix; - for (int i = 0; i < maskCount; i++) { - result.append(maskChar); - } - - // 添加后缀保留字符 - result.append(input, length - keepSuffix, length); - - return result.toString(); + /** + * 带最大长度限制的前一后一格式脱敏方法 + * @param input 输入字符串 + * @param maxLength 最大输出长度 + * @return 脱敏后的字符串 + */ + public static String maskFirstLast(String input, int maxLength) { + return mask(input, 1, 1, maxLength); } } diff --git a/bd-common/bd-common-domain/src/main/java/com/hzs/common/domain/member/statis/DirectStatisticsTop30VO.java b/bd-common/bd-common-domain/src/main/java/com/hzs/common/domain/member/statis/DirectStatisticsTop30VO.java index 10c55e0d..c6d707ce 100644 --- a/bd-common/bd-common-domain/src/main/java/com/hzs/common/domain/member/statis/DirectStatisticsTop30VO.java +++ b/bd-common/bd-common-domain/src/main/java/com/hzs/common/domain/member/statis/DirectStatisticsTop30VO.java @@ -37,6 +37,6 @@ public class DirectStatisticsTop30VO implements Serializable { /** * 直推金额 */ - @BigDecimalFormat(value = "#0.0000") + @BigDecimalFormat(value = "#0.00") private BigDecimal numberOfAmount; }