Skip to content

Commit f9bd909

Browse files
committed
[250608] 배송기능 - 소나큐브 오류 대응
1 parent aeda897 commit f9bd909

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/com/ecommerce/shipment/service/ExternalCarrierService.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.scheduling.annotation.Async;
99
import org.springframework.stereotype.Service;
1010

11+
import java.security.SecureRandom;
1112
import java.util.Random;
1213
import java.util.UUID;
1314
import java.util.concurrent.CompletableFuture;
@@ -19,7 +20,8 @@
1920
public class ExternalCarrierService {
2021

2122
private final ShipmentService shipmentService;
22-
private final Random random = new Random();
23+
@SuppressWarnings("java:S2245")
24+
private final SecureRandom secureRandom = new SecureRandom();
2325

2426
private static final String[] CARRIER_NAMES = {
2527
"Express Delivery", "Fast Shipping", "Quick Carrier", "Safe Transport"
@@ -32,11 +34,11 @@ public void requestDelivery(Shipment shipment) {
3234
log.info("Requesting delivery to external carrier for Shipment : {}", shipment.getShipUUID());
3335

3436
// 택배사 정보 생성 (랜덤)
35-
String carrierName = CARRIER_NAMES[random.nextInt(CARRIER_NAMES.length)];
37+
String carrierName = CARRIER_NAMES[secureRandom.nextInt(CARRIER_NAMES.length)];
3638
String trackingNumber = generateTrackingNumber();
3739

3840
// 배송 접수 처리 시간 시뮬레이션 (1-3초)
39-
TimeUnit.SECONDS.sleep(1 + random.nextInt(3));
41+
TimeUnit.SECONDS.sleep(1 + secureRandom.nextInt(3));
4042

4143
CarrierUpdateRequest readyRequest = CarrierUpdateRequest.of(
4244
carrierName,
@@ -69,12 +71,12 @@ private void simulateDeliveryProcess(UUID shipUUID) {
6971
CompletableFuture.runAsync(() -> {
7072
try {
7173
// 배송출발 단계
72-
TimeUnit.SECONDS.sleep(5 + random.nextInt(10));
74+
TimeUnit.SECONDS.sleep(5 + secureRandom.nextInt(10));
7375
shipmentService.updateShipmentStatusByUUID(shipUUID, ExternalShippingStatus.SHIPPING);
7476

7577
// 최종 배송 완료/실패 (90% 성공률)
76-
TimeUnit.SECONDS.sleep(5 + random.nextInt(10));
77-
if (random.nextInt(10) < 9) {
78+
TimeUnit.SECONDS.sleep(5 + secureRandom.nextInt(10));
79+
if (secureRandom.nextInt(10) < 9) {
7880
shipmentService.updateShipmentStatusByUUID(shipUUID, ExternalShippingStatus.DELIVERED);
7981
log.info("Delivery completed successfully: {}", shipUUID);
8082
} else {
@@ -97,12 +99,12 @@ private String generateTrackingNumber() {
9799

98100
// 2자리 대문자 알파벳
99101
for (int i = 0; i < 2; i++) {
100-
sb.append((char) ('A' + random.nextInt(26)));
102+
sb.append((char) ('A' + secureRandom.nextInt(26)));
101103
}
102104

103105
// 10자리 숫자
104106
for (int i = 0; i < 10; i++) {
105-
sb.append(random.nextInt(10));
107+
sb.append(secureRandom.nextInt(10));
106108
}
107109

108110
return sb.toString();

0 commit comments

Comments
 (0)