| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | public InviteRewardDTO customerReward() { |
| | | InviteRewardDTO rewardto = new InviteRewardDTO(); |
| | | List<InviteDTO> reward = customerMapper.getReward(); |
| | | rewardto.setSuccessInvite(reward); |
| | | List<InviteDTO> myreward = reward.stream().filter(s->s!=null&&s.getUserId()== SecurityUtils.getUserId()).collect(Collectors.toList());; |
| | | rewardto.setMyInvite(myreward); |
| | | List<InviteDTO> myreward = customerMapper.getMyReward(SecurityUtils.getUserId()); |
| | | List<InviteDTO> processedReward = reward.stream() |
| | | .filter(Objects::nonNull) |
| | | .peek(dto -> { |
| | | dto.setUserId(maskAll(dto.getUserId())); |
| | | dto.setUserName(maskMiddle(dto.getUserName(), 4)); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | rewardto.setSuccessInvite(processedReward); |
| | | List<InviteDTO> processedMyReward = myreward.stream() |
| | | .filter(Objects::nonNull) |
| | | .peek(dto -> { |
| | | dto.setUserId(maskAll(dto.getUserId())); |
| | | dto.setUserName(maskMiddle(dto.getUserName(), 4)); |
| | | }).collect(Collectors.toList()); |
| | | rewardto.setMyInvite(processedMyReward); |
| | | return rewardto; |
| | | } |
| | | |
| | | |
| | | // 全部字符替换为* |
| | | private String maskAll(String input) { |
| | | if (input == null || input.isEmpty()) { |
| | | return input; |
| | | } |
| | | return input.replaceAll(".", "*"); |
| | | } |
| | | |
| | | // 中间部分替换(最多maxStars个*) |
| | | private String maskMiddle(String input, int maxStars) { |
| | | if (input == null || input.length() <= 2) { |
| | | return input == null ? null : "*"; // 1-2个字符直接返回* |
| | | } |
| | | |
| | | int length = input.length(); |
| | | int stars = Math.min(maxStars, length - 2); // 最多maxStars个* |
| | | |
| | | String starsStr = String.join("", Collections.nCopies(stars, "*")); |
| | | return input.charAt(0) + starsStr + input.charAt(length - 1); |
| | | } |
| | | } |