user id addded in this code
This commit is contained in:
@@ -3,7 +3,7 @@ package com.billpaymentservice.bbps.util;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.Random;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -210,15 +210,20 @@ public class Helper {
|
||||
}
|
||||
|
||||
private String generateUniqueUserId() {
|
||||
String userId = UUID.randomUUID().toString(); // Generate UUID
|
||||
Random random = new Random();
|
||||
|
||||
// Generate a random 6-digit number (between 100000 and 999999)
|
||||
String userId = String.format("USER%06d", random.nextInt(900000) + 100000); // Format as USER-XXXXXX
|
||||
|
||||
// Check if the userId already exists in the database (theoretically rare but
|
||||
// can happen)
|
||||
while (userRepository.existsByUserId(userId)) {
|
||||
// If it exists, generate a new one
|
||||
userId = UUID.randomUUID().toString();
|
||||
userId = String.format("USER-%06d", random.nextInt(900000) + 100000); // Generate new 6-digit number with
|
||||
// prefix
|
||||
}
|
||||
|
||||
return userId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user