From b01c35549287b8c7433a43f35731a77803071a74 Mon Sep 17 00:00:00 2001 From: bcjang Date: Tue, 5 Aug 2025 18:21:35 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=A4=84=20aop=20=EB=8F=99?= =?UTF-8?q?=EC=9E=91=EC=95=88=ED=95=A8=EC=9C=BC=EB=A1=9C=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/scheduler/CommonScheduler.java | 17 +++++++- .../polling/service/BattleEventScheduler.java | 40 +++++++++++++------ .../polling/service/BlackListScheduler.java | 12 ++++-- .../service/DataInitializeScheduler.java | 14 ++++--- .../polling/service/EventScheduler.java | 11 +++-- .../polling/service/LandAuctionScheduler.java | 11 +++-- .../service/LandOwnerChangesScheduler.java | 12 ++++-- .../polling/service/MailScheduler.java | 11 +++-- .../polling/service/NoticeScheduler.java | 11 +++-- .../polling/service/cleanupScheduler.java | 12 ++++-- src/main/resources/mappers/BattleMapper.xml | 31 -------------- 11 files changed, 109 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/caliverse/admin/scheduler/CommonScheduler.java b/src/main/java/com/caliverse/admin/scheduler/CommonScheduler.java index f171e2e..8a744ad 100644 --- a/src/main/java/com/caliverse/admin/scheduler/CommonScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/CommonScheduler.java @@ -1,6 +1,8 @@ package com.caliverse.admin.scheduler; +import com.caliverse.admin.domain.entity.log.LogAction; import com.caliverse.admin.domain.entity.log.LogStatus; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -13,9 +15,11 @@ import java.util.Map; public abstract class CommonScheduler implements Scheduler { protected final BusinessLogService businessLogService; + protected final BusinessProcessIdManager processIdManager; - protected CommonScheduler(BusinessLogService businessLogService) { + protected CommonScheduler(BusinessLogService businessLogService, BusinessProcessIdManager processIdManager) { this.businessLogService = businessLogService; + this.processIdManager = processIdManager; } @Override @@ -46,4 +50,15 @@ public abstract class CommonScheduler implements Scheduler { * 스케줄러 구현체에서 실제 작업을 수행하는 메소드 */ protected abstract void executeInternal(); + + protected void executeWithProcessId(LogAction action, Runnable businessLogic) { + processIdManager.createNewProcessId(); + processIdManager.setCurrentAction(action); + + try { + businessLogic.run(); + } finally { + processIdManager.clear(); + } + } } diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/BattleEventScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/BattleEventScheduler.java index 0d8d0b3..6e6d2e7 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/BattleEventScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/BattleEventScheduler.java @@ -5,6 +5,7 @@ import com.caliverse.admin.domain.entity.log.LogAction; import com.caliverse.admin.domain.entity.log.LogStatus; import com.caliverse.admin.domain.service.BattleEventService; import com.caliverse.admin.global.common.annotation.BusinessProcess; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.entity.SchedulerType; @@ -26,14 +27,18 @@ public class BattleEventScheduler extends CommonScheduler { private final BattleEventService battleEventService; public BattleEventScheduler(BattleEventService battleEventService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.battleEventService = battleEventService; } - @BusinessProcess(action = LogAction.SCHEDULE_BATTLE_EVENT) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_BATTLE_EVENT, this::executeLogic); + } + + private void executeLogic(){ List eventList = battleEventService.getScheduleBattleEventList(); LocalDateTime startTime = LocalDateTime.now(); @@ -89,24 +94,33 @@ public class BattleEventScheduler extends CommonScheduler { eventIds.add(event.getId()); processCount.incrementAndGet(); } - }else if(status.equals(BattleEvent.BATTLE_STATUS.RUNNING) || status.equals(BattleEvent.BATTLE_STATUS.STOP)){ + }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; - processCount.incrementAndGet(); - }else{ - change_status = status.equals(BattleEvent.BATTLE_STATUS.STOP) ? BattleEvent.BATTLE_STATUS.STOP : BattleEvent.BATTLE_STATUS.WAIT; - if (change_status.equals(BattleEvent.BATTLE_STATUS.STOP)) { - processCount.incrementAndGet(); - } else { - processCount.incrementAndGet(); - } + } else { + change_status = BattleEvent.BATTLE_STATUS.WAIT; } - log.info("battle event_id: {}, start_dt: {}, end_dt: {}, todayStart: {}, todayEnd: {} STATUS CHANGE {}", event.getId(), start_dt, end_dt, todayStart, todayEnd, change_status); + + log.info("battle event_id: {}, start_dt: {}, end_dt: {}, todayStart: {}, todayEnd: {} STATUS CHANGE {}", + event.getId(), start_dt, end_dt, todayStart, todayEnd, change_status); map.put("status", change_status); battleEventService.updateBattleEventStatus(map); eventIds.add(event.getId()); + processCount.incrementAndGet(); + } + } else if(status.equals(BattleEvent.BATTLE_STATUS.STOP)){ + if(!baseDate.isBefore(end_dt.toLocalDate())){ + change_status = BattleEvent.BATTLE_STATUS.END; + + log.info("battle event_id: {}, end_dt: {}, baseDate: {} STATUS CHANGE END (from STOP)", + event.getId(), end_dt, baseDate); + map.put("status", change_status); + battleEventService.updateBattleEventStatus(map); + + eventIds.add(event.getId()); + processCount.incrementAndGet(); } } }); diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/BlackListScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/BlackListScheduler.java index b6373dd..a3c51cf 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/BlackListScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/BlackListScheduler.java @@ -6,6 +6,7 @@ import com.caliverse.admin.domain.entity.log.LogStatus; import com.caliverse.admin.domain.service.BlackListService; import com.caliverse.admin.domain.service.UserGameSessionService; import com.caliverse.admin.global.common.annotation.BusinessProcess; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.entity.SchedulerType; @@ -27,15 +28,20 @@ public class BlackListScheduler extends CommonScheduler { public BlackListScheduler(UserGameSessionService userGameSessionService, BlackListService blackListService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.userGameSessionService = userGameSessionService; this.blackListService = blackListService; } - @BusinessProcess(action = LogAction.SCHEDULE_BLACK_LIST) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_BLACK_LIST, this::executeLogic); + + } + + private void executeLogic() { List blackList = blackListService.getScheduleBlackList(); LocalDateTime startTime = LocalDateTime.now(); diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/DataInitializeScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/DataInitializeScheduler.java index 4831cc2..8565d2a 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/DataInitializeScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/DataInitializeScheduler.java @@ -14,6 +14,7 @@ import com.caliverse.admin.dynamodb.service.DynamodbLandAuctionService; import com.caliverse.admin.dynamodb.service.DynamodbLandService; import com.caliverse.admin.dynamodb.service.DynamodbService; import com.caliverse.admin.global.common.annotation.BusinessProcess; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.entity.SchedulerType; @@ -41,17 +42,21 @@ public class DataInitializeScheduler extends CommonScheduler { DynamodbDataService dynamodbDataService, LandService landService, DynamodbLandAuctionService dynamodbLandAuctionService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.dataService = dataService; this.dynamodbDataService = dynamodbDataService; this.landService = landService; this.dynamodbLandAuctionService = dynamodbLandAuctionService; } - @BusinessProcess(action = LogAction.SCHEDULE_DATA_INIT) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_DATA_INIT, this::executeLogic); + } + + private void executeLogic() { List scheduleList = dataService.getScheduleDataInitList(); scheduleList.forEach(dataInit -> { @@ -66,7 +71,6 @@ public class DataInitializeScheduler extends CommonScheduler { }); } - @BusinessProcess(action = LogAction.DATA_INIT) private void initLandAuction(LocalDateTime createDt){ List landAuctions = landService.getAllLandAuctionList(); landAuctions.forEach(landAuction -> { @@ -77,12 +81,10 @@ public class DataInitializeScheduler extends CommonScheduler { dynamodbDataService.InitDataLandAuction(); } - @BusinessProcess(action = LogAction.DATA_INIT) private void initLandDesc(){ dynamodbDataService.InitDataLandDesc(); } - @BusinessProcess(action = LogAction.DATA_INIT) private void initLandOwner(LocalDateTime createDt){ List landOwnerChanges = landService.getAllLandOwnerChangesList(); landOwnerChanges.forEach(dataService::initLandOwned); diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/EventScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/EventScheduler.java index 7e9c378..c38c6e4 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/EventScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/EventScheduler.java @@ -5,6 +5,7 @@ import com.caliverse.admin.domain.entity.log.LogAction; import com.caliverse.admin.domain.entity.log.LogStatus; import com.caliverse.admin.domain.service.EventService; import com.caliverse.admin.global.common.annotation.BusinessProcess; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.entity.SchedulerType; @@ -24,14 +25,18 @@ public class EventScheduler extends CommonScheduler { private final EventService eventService; public EventScheduler(EventService eventService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.eventService = eventService; } - @BusinessProcess(action = LogAction.SCHEDULE_EVENT) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_EVENT, this::executeLogic); + } + + private void executeLogic() { List eventList = eventService.getScheduleMailList(); LocalDateTime startTime = LocalDateTime.now(); diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/LandAuctionScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/LandAuctionScheduler.java index 1139575..cf0ac39 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/LandAuctionScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/LandAuctionScheduler.java @@ -10,6 +10,7 @@ import com.caliverse.admin.dynamodb.entity.ELandAuctionResult; import com.caliverse.admin.dynamodb.entity.ELandAuctionState; import com.caliverse.admin.global.common.annotation.BusinessProcess; import com.caliverse.admin.global.common.utils.CommonUtils; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.entity.SchedulerType; @@ -29,14 +30,18 @@ public class LandAuctionScheduler extends CommonScheduler { private final LandService landService; public LandAuctionScheduler(LandService landService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.landService = landService; } - @BusinessProcess(action = LogAction.SCHEDULE_LAND_AUCTION) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_LAND_AUCTION, this::executeLogic); + } + + private void executeLogic() { List auctionList = landService.getScheduleLandAuctionList(); LocalDateTime startTime = LocalDateTime.now(); diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/LandOwnerChangesScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/LandOwnerChangesScheduler.java index ae9f58a..bb35023 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/LandOwnerChangesScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/LandOwnerChangesScheduler.java @@ -6,6 +6,7 @@ import com.caliverse.admin.domain.service.UserGameSessionService; import com.caliverse.admin.dynamodb.service.DynamodbMailService; import com.caliverse.admin.dynamodb.service.DynamodbService; import com.caliverse.admin.global.common.annotation.BusinessProcess; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.entity.SchedulerType; @@ -35,17 +36,22 @@ public class LandOwnerChangesScheduler extends CommonScheduler { DynamodbLandService dynamodbLandService, DynamodbMailService dynamodbMailService, UserGameSessionService userGameSessionService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.landService = landService; this.dynamodbLandService = dynamodbLandService; this.dynamodbMailService = dynamodbMailService; this.userGameSessionService = userGameSessionService; } - @BusinessProcess(action = LogAction.SCHEDULE_LAND_OWNER_CHANGE) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_LAND_OWNER_CHANGE, this::executeLogic); + + } + + private void executeLogic() { List scheduleList = landService.getScheduleLandOwnerChangesList(); LocalDateTime startTime = LocalDateTime.now(); diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/MailScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/MailScheduler.java index 6a90767..dc11c1f 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/MailScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/MailScheduler.java @@ -12,6 +12,7 @@ import com.caliverse.admin.domain.service.MailService; import com.caliverse.admin.global.common.annotation.BusinessProcess; import com.caliverse.admin.global.common.utils.CommonUtils; import com.caliverse.admin.global.common.utils.ExcelUtils; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.redis.service.RedisUserInfoService; import com.caliverse.admin.scheduler.CommonScheduler; @@ -48,8 +49,9 @@ public class MailScheduler extends CommonScheduler { MessageHandlerService messageHandlerService, ScheduleService schedulerService, ExcelUtils excelUtils, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.mailService = mailService; this.redisUserInfoService = redisUserInfoService; this.messageHandlerService = messageHandlerService; @@ -57,9 +59,12 @@ public class MailScheduler extends CommonScheduler { this.excelUtils = excelUtils; } - @BusinessProcess(action = LogAction.SCHEDULE_MAIL) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_MAIL, this::executeLogic); + } + + private void executeLogic(){ List mailList = mailService.getScheduleMailList(); if (mailList.isEmpty()) { diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/NoticeScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/NoticeScheduler.java index bcb3e70..39ec1b2 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/NoticeScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/NoticeScheduler.java @@ -9,6 +9,7 @@ import com.caliverse.admin.domain.entity.log.LogStatus; import com.caliverse.admin.domain.service.NoticeService; import com.caliverse.admin.global.common.annotation.BusinessProcess; import com.caliverse.admin.global.common.utils.CommonUtils; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.redis.service.RedisUserInfoService; import com.caliverse.admin.scheduler.CommonScheduler; @@ -40,17 +41,21 @@ public class NoticeScheduler extends CommonScheduler { RedisUserInfoService redisUserInfoService, ScheduleService schedulerService, MessageHandlerService messageHandlerService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.noticeService = noticeService; this.redisUserInfoService = redisUserInfoService; this.schedulerService = schedulerService; this.messageHandlerService = messageHandlerService; } - @BusinessProcess(action = LogAction.SCHEDULE_NOTICE) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_NOTICE, this::executeLogic); + } + + private void executeLogic(){ List noticeList = noticeService.getScheduleNoticeList(); if(noticeList.isEmpty()) return; diff --git a/src/main/java/com/caliverse/admin/scheduler/polling/service/cleanupScheduler.java b/src/main/java/com/caliverse/admin/scheduler/polling/service/cleanupScheduler.java index 8b31920..f92016c 100644 --- a/src/main/java/com/caliverse/admin/scheduler/polling/service/cleanupScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/polling/service/cleanupScheduler.java @@ -1,7 +1,7 @@ package com.caliverse.admin.scheduler.polling.service; import com.caliverse.admin.domain.entity.log.LogAction; -import com.caliverse.admin.global.common.annotation.BusinessProcess; +import com.caliverse.admin.global.component.manager.BusinessProcessIdManager; import com.caliverse.admin.mongodb.service.BusinessLogService; import com.caliverse.admin.scheduler.CommonScheduler; import com.caliverse.admin.scheduler.ScheduleService; @@ -16,14 +16,18 @@ public class cleanupScheduler extends CommonScheduler { private final ScheduleService scheduleService; public cleanupScheduler(ScheduleService scheduleService, - BusinessLogService businessLogService) { - super(businessLogService); + BusinessLogService businessLogService, + BusinessProcessIdManager processIdManager) { + super(businessLogService, processIdManager); this.scheduleService = scheduleService; } - @BusinessProcess(action = LogAction.SCHEDULE_CLEANUP) @Override protected void executeInternal() { + executeWithProcessId(LogAction.SCHEDULE_CLEANUP, this::executeLogic); + } + + private void executeLogic() { scheduleService.cleanupCompletedTasks(); scheduleService.cleanupMailTasks(); scheduleService.cleanupNoticeTasks(); diff --git a/src/main/resources/mappers/BattleMapper.xml b/src/main/resources/mappers/BattleMapper.xml index ac29a9a..2ba7710 100644 --- a/src/main/resources/mappers/BattleMapper.xml +++ b/src/main/resources/mappers/BattleMapper.xml @@ -211,37 +211,6 @@ - -