전투시스템 상태 체크 스케줄

This commit is contained in:
2025-02-24 17:46:28 +09:00
parent cdea8e1780
commit 2b77a46ab6
2 changed files with 73 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
@@ -54,6 +55,7 @@ public class DynamicScheduler {
private final ScheduleService schedulerService;
private final RedisUserInfoService redisUserInfoService;
private final MessageHandlerService messageHandlerService;
private final BattleEventService battleEventService;
private final HistoryService historyService;
private final DynamodbService dynamodbService;
@@ -61,6 +63,72 @@ public class DynamicScheduler {
private final ExcelUtils excelUtils;
private final ObjectMapper objectMapper;
public void battleEventSchedule(){
List<BattleEvent> eventList = battleEventService.getScheduleBattleEventList();
try{
eventList.forEach(event -> {
BattleEvent.BATTLE_STATUS status = event.getStatus();
LocalDateTime start_dt = event.getEventStartDt();
LocalTime startTime = start_dt.toLocalTime();
LocalDateTime now = LocalDateTime.now();
LocalTime currentTime = LocalDateTime.now().toLocalTime();
LocalDateTime end_dt = event.getEventEndDt();
int operation_time = event.getEventOperationTime();
//자정 체크
LocalTime endTime = startTime.plusSeconds(operation_time);
// 현재시간이 자정을 넘어간 경우(00:00 ~ endTime)라면 전날을 기준으로
LocalDate baseDate;
if (startTime.isAfter(endTime)) { // 시작시간이 종료시간보다 늦은 경우 (자정을 걸치는 경우)
if (currentTime.isBefore(endTime)) {
// 현재시간이 00:00 ~ endTime 사이면 전날 기준
baseDate = now.toLocalDate().minusDays(1);
} else if (!currentTime.isBefore(startTime)) {
// 현재시간이 startTime 이후면 현재 날짜 기준
baseDate = now.toLocalDate();
} else {
baseDate = now.toLocalDate();
}
} else {
// 자정을 걸치지 않는 일반적인 경우
baseDate = now.toLocalDate();
}
//오늘자 기준 시작, 종료 시간
LocalDateTime todayStart = LocalDateTime.of(baseDate, startTime);
LocalDateTime todayEnd = todayStart.plusSeconds(operation_time);
BattleEvent.BATTLE_STATUS change_status = null;
Map<String,Object> map = new HashMap<>();
map.put("id", event.getId());
if(status.equals(BattleEvent.BATTLE_STATUS.REGISTER) || status.equals(BattleEvent.BATTLE_STATUS.WAIT)){
if(!now.isBefore(todayStart) && !now.isAfter(todayEnd)){
change_status = BattleEvent.BATTLE_STATUS.RUNNING;
map.put("status", change_status);
battleEventService.updateBattleEventStatus(map);
}
}else if(status.equals(BattleEvent.BATTLE_STATUS.RUNNING)){
if(!(!now.isBefore(todayStart) && !now.isAfter(todayEnd))){
if(!baseDate.isBefore(end_dt.toLocalDate())){
change_status = BattleEvent.BATTLE_STATUS.END;
}else{
change_status = BattleEvent.BATTLE_STATUS.WAIT;
}
map.put("status", change_status);
battleEventService.updateBattleEventStatus(map);
}
}
});
}catch(Exception e){
log.error("battleEventSchedule Exception: {}", e.getMessage());
}
}
public void landAuctionSchedule(){
List<LandAuction> auctionList = landService.getScheduleLandAuctionList();

View File

@@ -181,6 +181,11 @@ public class ScheduleSetter {
// log.info("end landAuctionJob");
}
@Scheduled(cron = "6 * * * * *")
public void battleEventJob(){
dynamicScheduler.battleEventSchedule();
}
//web3
@Scheduled(cron = "1 * * * * *")
public void web3Job(){