Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -80,7 +82,7 @@ public class PurchaseOrder {
public PurchaseOrder(String vehicleNumber, String vehicleModel, String receiptNum, String requesterCode,
Long requesterId, String requesterName, String requesterRole)
{
this.requestDate = LocalDateTime.now();
this.requestDate = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
this.orderNumber = generateOrderNumber(this.requestDate);
this.vehicleNumber = vehicleNumber;
this.vehicleModel = vehicleModel;
Expand All @@ -107,27 +109,27 @@ public void decide(OrderStatus nextStatus) {

validateStateTransition(OrderStatus.PENDING, nextStatus);
this.status = nextStatus;
this.processedDate = LocalDateTime.now();
this.processedDate = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}

//출고
public void ship(){
validateStateTransition(OrderStatus.APPROVED, OrderStatus.SHIPPED);
this.status = OrderStatus.SHIPPED;
this.transferDate = LocalDateTime.now();
this.transferDate = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}
//납품 완료
public void complete(){
validateStateTransition(OrderStatus.SHIPPED, OrderStatus.COMPLETED);
this.status = OrderStatus.COMPLETED;
this.completedDate = LocalDateTime.now();
this.completedDate = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}
//발주 취소
public void cancel(){
if (this.completedDate != null) throw new ConflictException(ErrorStatus.ALREADY_PROCESSED_ORDER_EXCEPTION.getMessage());
validateStateTransitionCancel(this.status);
this.status = OrderStatus.CANCELLED;
this.completedDate = LocalDateTime.now();
this.completedDate = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}

//상태 전이 검증
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;

@Slf4j
Expand All @@ -21,11 +23,11 @@ public class SchedulerInitializer implements ApplicationRunner {
private final ScheduledTaskService scheduledTaskService;
@Override
public void run(ApplicationArguments args) throws Exception {
LocalDateTime now = LocalDateTime.now();
LocalDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
List<ScheduledTask> pendingTasks =
scheduledTaskRepository.findByStatusInAndRunAtLessThanEqual(
List.of(TaskStatus.PENDING, TaskStatus.RETRYING, TaskStatus.FAILED),
LocalDateTime.now()
ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime()
);
//위에서 불러온 예약 대상 리스트(pendingTasks) 를 하나씩 순회하며 각 예약을 TaskScheduler.schedule()로 다시 등록
for (ScheduledTask task : pendingTasks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;

Expand All @@ -38,7 +39,7 @@ public void scheduleNewTask(Long orderId) {
log.warn("[중복 예약] orderId={} 이미 등록된 예약이 있습니다.", orderId);
return;
}
LocalDateTime runAt = LocalDateTime.now().plusDays(3);
LocalDateTime runAt = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime().plusDays(3);

ScheduledTask task = ScheduledTask.builder()
.orderId(orderId)
Expand Down Expand Up @@ -94,7 +95,7 @@ public void executeTask(ScheduledTask task, Long orderId) {

if (task.getRetryCount() <= 3) {
// 1시간 뒤 재시도
LocalDateTime retryAt = LocalDateTime.now().plusHours(1);
LocalDateTime retryAt = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime().plusHours(1);
task.setStatus(TaskStatus.RETRYING);
task.setRunAt(retryAt);
scheduledTaskRepository.save(task);
Expand Down