diff --git a/src/main/java/com/caliverse/admin/domain/entity/HISTORYTYPEDETAIL.java b/src/main/java/com/caliverse/admin/domain/entity/HISTORYTYPEDETAIL.java index fb7f0b6..96f4940 100644 --- a/src/main/java/com/caliverse/admin/domain/entity/HISTORYTYPEDETAIL.java +++ b/src/main/java/com/caliverse/admin/domain/entity/HISTORYTYPEDETAIL.java @@ -61,7 +61,8 @@ public enum HISTORYTYPEDETAIL { NICKNAME_REGISTRY_DELETE("닉네임 레지스트리 삭제"), NICKNAME_REGISTRY_ADD("닉네임 레지스트리 등록"), NICKNAME_UPDATE("닉네임 수정"), - DATA_INIT_ADD("데이터 초기화 등록") + DATA_INIT_ADD("데이터 초기화 등록"), + SYSTEM_META_MAIL_DELETE("시스템 메타 메일 삭제"), ; private String historyTypeDetail; HISTORYTYPEDETAIL(String type) { diff --git a/src/main/java/com/caliverse/admin/domain/service/BattleEventService.java b/src/main/java/com/caliverse/admin/domain/service/BattleEventService.java index 68f6ab7..4aa97ed 100644 --- a/src/main/java/com/caliverse/admin/domain/service/BattleEventService.java +++ b/src/main/java/com/caliverse/admin/domain/service/BattleEventService.java @@ -156,13 +156,14 @@ public class BattleEventService { .build(); } - int next_event_id = dynamodbBattleEventService.getEventId() + 1; - battleEventRequest.setEventId(next_event_id); +// int next_event_id = dynamodbBattleEventService.getEventId() + 1; +// battleEventRequest.setEventId(next_event_id); int result = battleMapper.postBattleEvent(battleEventRequest); log.info("AdminToolDB BattleEvent Save: {}", battleEventRequest); long battle_event_id = battleEventRequest.getId(); + battleEventRequest.setEventId((int) battle_event_id); HashMap map = new HashMap<>(); map.put("id",String.valueOf(battle_event_id)); diff --git a/src/main/java/com/caliverse/admin/dynamodb/entity/SystemMessage.java b/src/main/java/com/caliverse/admin/dynamodb/entity/SystemMessage.java index 644a808..35acfac 100644 --- a/src/main/java/com/caliverse/admin/dynamodb/entity/SystemMessage.java +++ b/src/main/java/com/caliverse/admin/dynamodb/entity/SystemMessage.java @@ -1,11 +1,15 @@ package com.caliverse.admin.dynamodb.entity; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data @Builder +@NoArgsConstructor +@AllArgsConstructor public class SystemMessage { @JsonProperty("LanguageType") private Integer languageType; diff --git a/src/main/java/com/caliverse/admin/dynamodb/repository/BattleEventRepository.java b/src/main/java/com/caliverse/admin/dynamodb/repository/BattleEventRepository.java index 7717ec6..eba08c1 100644 --- a/src/main/java/com/caliverse/admin/dynamodb/repository/BattleEventRepository.java +++ b/src/main/java/com/caliverse/admin/dynamodb/repository/BattleEventRepository.java @@ -3,11 +3,12 @@ package com.caliverse.admin.dynamodb.repository; import com.caliverse.admin.domain.entity.BattleEvent; import com.caliverse.admin.domain.request.BattleEventRequest; import com.caliverse.admin.dynamodb.domain.doc.BattleEventDoc; +import com.caliverse.admin.dynamodb.entity.DynamodbOperationResult; public interface BattleEventRepository extends DynamoDBRepository { int findEventId(); void insert(BattleEventRequest battleEventRequest); void update(BattleEventRequest battleEventRequest); - void delete(BattleEventRequest battleEventRequest); + DynamodbOperationResult delete(String id); void updateStop(BattleEvent battleEvent); } diff --git a/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/BattleEventRepositoryImpl.java b/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/BattleEventRepositoryImpl.java index 51c26d2..ba6df18 100644 --- a/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/BattleEventRepositoryImpl.java +++ b/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/BattleEventRepositoryImpl.java @@ -5,6 +5,8 @@ import com.caliverse.admin.domain.entity.HISTORYTYPEDETAIL; import com.caliverse.admin.domain.request.BattleEventRequest; import com.caliverse.admin.dynamodb.domain.atrrib.BattleEventAttrib; import com.caliverse.admin.dynamodb.domain.doc.BattleEventDoc; +import com.caliverse.admin.dynamodb.domain.doc.SystemMetaMailDoc; +import com.caliverse.admin.dynamodb.entity.DynamodbOperationResult; import com.caliverse.admin.dynamodb.entity.EDayOfWeekType; import com.caliverse.admin.dynamodb.entity.EOncePeriodRangeType; import com.caliverse.admin.dynamodb.repository.BaseDynamoDBRepository; @@ -172,8 +174,37 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository doc2.getSK().compareTo(doc1.getSK())) .orElse(null); - if(latestDoc == null) return 0; - LandAuctionRegistryAttrib attrib = latestDoc.getAttribValue(); return attrib.getAuctionNumber(); diff --git a/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/SystemMetaMailRepositoryImpl.java b/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/SystemMetaMailRepositoryImpl.java index 8976a07..d3c45a3 100644 --- a/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/SystemMetaMailRepositoryImpl.java +++ b/src/main/java/com/caliverse/admin/dynamodb/repository/Impl/SystemMetaMailRepositoryImpl.java @@ -4,7 +4,9 @@ import com.caliverse.admin.domain.entity.Event; import com.caliverse.admin.domain.entity.HISTORYTYPEDETAIL; import com.caliverse.admin.domain.entity.Message; import com.caliverse.admin.dynamodb.domain.atrrib.SystemMetaMailAttrib; +import com.caliverse.admin.dynamodb.domain.doc.LandAuctionRegistryDoc; import com.caliverse.admin.dynamodb.domain.doc.SystemMetaMailDoc; +import com.caliverse.admin.dynamodb.entity.DynamodbOperationResult; import com.caliverse.admin.dynamodb.repository.BaseDynamoDBRepository; import com.caliverse.admin.dynamodb.repository.SystemMetaMailRepository; import com.caliverse.admin.dynamodb.service.DynamoDBOperations; @@ -17,6 +19,7 @@ import com.caliverse.admin.mongodb.service.DynamodbHistoryLogService; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import software.amazon.awssdk.enhanced.dynamodb.Key; import java.time.LocalDateTime; @@ -69,4 +72,38 @@ public class SystemMetaMailRepositoryImpl extends BaseDynamoDBRepository { void insert(Event event); + DynamodbOperationResult delete(String id); } diff --git a/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbBattleEventService.java b/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbBattleEventService.java index adb6f7e..4d9e8b7 100644 --- a/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbBattleEventService.java +++ b/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbBattleEventService.java @@ -2,11 +2,24 @@ package com.caliverse.admin.dynamodb.service; import com.caliverse.admin.domain.entity.BattleEvent; import com.caliverse.admin.domain.request.BattleEventRequest; +import com.caliverse.admin.dynamodb.domain.atrrib.BattleEventAttrib; +import com.caliverse.admin.dynamodb.domain.atrrib.SystemMetaMailAttrib; +import com.caliverse.admin.dynamodb.domain.doc.BattleEventDoc; +import com.caliverse.admin.dynamodb.domain.doc.SystemMetaMailDoc; +import com.caliverse.admin.dynamodb.entity.EOncePeriodRangeType; import com.caliverse.admin.dynamodb.repository.BattleEventRepository; import com.caliverse.admin.global.common.annotation.DynamoDBTransaction; +import com.caliverse.admin.global.common.constants.DynamoDBConstants; +import com.caliverse.admin.global.common.utils.CommonUtils; +import com.caliverse.admin.global.common.utils.DateUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import software.amazon.awssdk.enhanced.dynamodb.Key; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; @Service @RequiredArgsConstructor @@ -33,4 +46,33 @@ public class DynamodbBattleEventService { battleEventRepository.updateStop(battleEvent); } + @DynamoDBTransaction + public void oldBattleEventClear(){ + Key key = Key.builder() + .partitionValue(DynamoDBConstants.PK_KEY_BATTLE_EVENT) + .build(); + List eventList = battleEventRepository.findAll(key); + eventList.forEach(event -> { + try { + BattleEventAttrib attrib = CommonUtils.stringByObject(event.getAttribValue(), BattleEventAttrib.class); + EOncePeriodRangeType oncePeriodRangeType = attrib.getOncePeriodType(); + LocalDateTime startTime = DateUtils.stringToDateTime(attrib.getStartDay()); + LocalDateTime expiredTime = LocalDateTime.now().minusMonths(1); + if (Objects.requireNonNull(oncePeriodRangeType) == EOncePeriodRangeType.NONE) { + if (startTime.isBefore(expiredTime)) { + battleEventRepository.delete(event.getSK()); + } + } else { + LocalDateTime endDate = DateUtils.stringToDateTime(attrib.getEndDate()); + if (endDate.isBefore(expiredTime)) { + battleEventRepository.delete(event.getSK()); + } + } + + }catch (Exception e){ + log.error("oldSystemMetaMail Clear Fail: {}",e.getMessage()); + } + }); + } + } diff --git a/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbMailService.java b/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbMailService.java index 620239f..26bfac7 100644 --- a/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbMailService.java +++ b/src/main/java/com/caliverse/admin/dynamodb/service/DynamodbMailService.java @@ -10,6 +10,7 @@ import com.caliverse.admin.domain.request.LandRequest; import com.caliverse.admin.dynamodb.domain.atrrib.*; import com.caliverse.admin.dynamodb.domain.doc.MailDoc; import com.caliverse.admin.dynamodb.domain.doc.MailJsonDoc; +import com.caliverse.admin.dynamodb.domain.doc.SystemMetaMailDoc; import com.caliverse.admin.dynamodb.dto.PageResult; import com.caliverse.admin.dynamodb.entity.KeyParam; import com.caliverse.admin.dynamodb.repository.*; @@ -18,6 +19,7 @@ import com.caliverse.admin.global.common.constants.AdminConstants; import com.caliverse.admin.global.common.constants.CommonConstants; import com.caliverse.admin.global.common.constants.DynamoDBConstants; import com.caliverse.admin.global.common.utils.CommonUtils; +import com.caliverse.admin.global.common.utils.DateUtils; import com.caliverse.admin.logs.Indicatordomain.StartEndTime; import com.caliverse.admin.logs.logservice.LogServiceHelper; import com.caliverse.admin.logs.logservice.indicators.IndicatorsMoneyService; @@ -28,6 +30,7 @@ import org.springframework.stereotype.Service; import software.amazon.awssdk.enhanced.dynamodb.Key; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -142,4 +145,24 @@ public class DynamodbMailService { mailRepository.deleteMailItem(key, itemId, count, newCount); } } + + @DynamoDBTransaction + public void oldSystemMetaMailClear(){ + Key key = Key.builder() + .partitionValue(DynamoDBConstants.PK_KEY_SYSTEM_MAIL) + .build(); + List mailList = systemMetaMailRepository.findAll(key); + mailList.forEach(mail -> { + try { + SystemMetaMailAttrib attrib = CommonUtils.stringByObject(mail.getAttribValue(), SystemMetaMailAttrib.class); + LocalDateTime endTime = DateUtils.stringISOToLocalDateTime(attrib.getEndTime()); + LocalDateTime expiredTime = LocalDateTime.now().minusMonths(1); + if(endTime.isBefore(expiredTime)){ + systemMetaMailRepository.delete(mail.getSK()); + } + }catch (Exception e){ + log.error("oldSystemMetaMail Clear Fail: {}",e.getMessage()); + } + }); + } } diff --git a/src/main/java/com/caliverse/admin/global/common/utils/CommonUtils.java b/src/main/java/com/caliverse/admin/global/common/utils/CommonUtils.java index a3f0af0..05cfdeb 100644 --- a/src/main/java/com/caliverse/admin/global/common/utils/CommonUtils.java +++ b/src/main/java/com/caliverse/admin/global/common/utils/CommonUtils.java @@ -313,7 +313,7 @@ public class CommonUtils { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readValue(string, valueType); } catch (JsonProcessingException e) { - throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage()); + throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage() + " : " + e.getMessage()); } } @@ -322,7 +322,7 @@ public class CommonUtils { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { - throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage()); + throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage() + " : " + e.getMessage()); } } @@ -331,7 +331,7 @@ public class CommonUtils { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readTree(data); } catch (JsonProcessingException e) { - throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage()); + throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage() + " : " + e.getMessage()); } } diff --git a/src/main/java/com/caliverse/admin/global/common/utils/DateUtils.java b/src/main/java/com/caliverse/admin/global/common/utils/DateUtils.java index f37fbe6..7aeaf2b 100644 --- a/src/main/java/com/caliverse/admin/global/common/utils/DateUtils.java +++ b/src/main/java/com/caliverse/admin/global/common/utils/DateUtils.java @@ -32,6 +32,10 @@ public class DateUtils { return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); } + public static LocalDateTime stringToDateTime(String str){ + return LocalDateTime.parse(str, DateTimeFormatter.ISO_LOCAL_DATE_TIME); + } + public static LocalDateTime stringToLocalDateTime(String date){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); return LocalDateTime.parse(date, formatter); diff --git a/src/main/java/com/caliverse/admin/scheduler/DynamicScheduler.java b/src/main/java/com/caliverse/admin/scheduler/DynamicScheduler.java index a805c5e..a90f60a 100644 --- a/src/main/java/com/caliverse/admin/scheduler/DynamicScheduler.java +++ b/src/main/java/com/caliverse/admin/scheduler/DynamicScheduler.java @@ -104,7 +104,7 @@ public class DynamicScheduler { map.put("status", change_status); battleEventService.updateBattleEventStatus(map); } - }else if(status.equals(BattleEvent.BATTLE_STATUS.RUNNING)){ + }else if(status.equals(BattleEvent.BATTLE_STATUS.RUNNING) || status.equals(BattleEvent.BATTLE_STATUS.STOP)){ if(!(!now.isBefore(todayStart) && !now.isAfter(todayEnd))){ if(!baseDate.isBefore(end_dt.toLocalDate())){ change_status = BattleEvent.BATTLE_STATUS.END; diff --git a/src/main/java/com/caliverse/admin/scheduler/OneTimeSchedule.java b/src/main/java/com/caliverse/admin/scheduler/OneTimeSchedule.java index 6d2a153..9599599 100644 --- a/src/main/java/com/caliverse/admin/scheduler/OneTimeSchedule.java +++ b/src/main/java/com/caliverse/admin/scheduler/OneTimeSchedule.java @@ -1,5 +1,6 @@ package com.caliverse.admin.scheduler; +import com.caliverse.admin.domain.service.DiagnosisService; import com.caliverse.admin.dynamodb.service.DynamodbService; import com.caliverse.admin.global.common.constants.AdminConstants; import com.caliverse.admin.logs.Indicatordomain.StartEndTime; @@ -31,24 +32,36 @@ public class OneTimeSchedule implements CommandLineRunner { @Autowired private IndicatorsMetaverseServerService metaverseServerService; @Autowired private IndicatorsUserCreateService userCreateService; @Autowired private IndicatorsUserLoginService userLoginService; + @Autowired private IndicatorsCurrencyService currencyService; + @Autowired private DiagnosisService diagnosisService; @Autowired private DynamodbService dynamodbService; @Override public void run(String... args) throws Exception { + log.info("=== OneTimeSchedule starting ==="); try{ log.info("Starting OneTimeSchedule"); // dynamodbService.saveUserMoney(); //유저별 재화 데이터 저장 LocalDate startDate = LocalDate.of(2024, 8, 28); -// LocalDate currentDate = LocalDate.of(2025, 1, 31); +// LocalDate startDate = LocalDate.of(2025, 4, 1); +// LocalDate currentDate = LocalDate.of(2025, 5, 1); LocalDate currentDate = LocalDate.now(); // + log.info("Processing dates from {} to {}", startDate, currentDate); + for (LocalDate date = startDate; !date.isAfter(currentDate); date = date.plusDays(1)) { + log.info("Processing date: {}", date); + StartEndTime dayStartEndTime = LogServiceHelper.getCurrentLogSearchEndTime(date, AdminConstants.STAT_DAY_NUM); StartEndTime weekStartEndTime = LogServiceHelper.getCurrentLogSearchEndTime(date, AdminConstants.STAT_WEEK_NUM); StartEndTime monthStartEndTime = LogServiceHelper.getCurrentLogSearchEndTime(date, AdminConstants.STAT_MONTH_NUM); + log.info("Date: {}, StartTime: {}, EndTime: {}", date, dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime()); + +// currencyService.collectCurrency(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime()); + // userLoginService.collectUserLogin(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime()); // userCreateService.collectUserCreate(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime()); // metaverseServerService.collectMetaverseServerCount(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime(), 13); @@ -63,9 +76,9 @@ public class OneTimeSchedule implements CommandLineRunner { // ugqCreateService.collectUGQCreateCount(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime()); //체크 } - + log.info("=== OneTimeSchedule completed successfully ==="); }catch (Exception e){ - log.error(e.getMessage()); + log.error("OneTimeSchedule execution failed", e); } } } diff --git a/src/main/java/com/caliverse/admin/scheduler/batch/ScheduleRunnerBatch.java b/src/main/java/com/caliverse/admin/scheduler/batch/ScheduleRunnerBatch.java index 819a5da..58bdd10 100644 --- a/src/main/java/com/caliverse/admin/scheduler/batch/ScheduleRunnerBatch.java +++ b/src/main/java/com/caliverse/admin/scheduler/batch/ScheduleRunnerBatch.java @@ -5,6 +5,7 @@ import com.caliverse.admin.logs.Indicatordomain.StartEndTime; import com.caliverse.admin.logs.logservice.LogServiceHelper; import com.caliverse.admin.logs.logservice.indicators.*; import com.caliverse.admin.scheduler.SchedulerManager; +import com.caliverse.admin.scheduler.batch.service.DataClearService; import com.caliverse.admin.scheduler.batch.service.LogCompressService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -22,6 +23,7 @@ public class ScheduleRunnerBatch { private final SchedulerManager schedulerManager; @Autowired private LogCompressService logService; + @Autowired private DataClearService dataClearService; @Autowired private IndicatorsUserCreateService userCreateService; @Autowired private IndicatorsUserLoginService userLoginService; @@ -33,6 +35,12 @@ public class ScheduleRunnerBatch { logService.compressLastMonthLogs(); } + //오래된 데이터 삭제 + @Scheduled(cron = "00 05 00 1 * ?") // 매월 1일에 실행 + public void oldDataClear(){ + dataClearService.oldDataClear(); + } + @Scheduled(cron = "00 30 0 * * *") // 매일 UTC 기준 00시 30분 00초에 실행 public void userCreateScheduler() { StartEndTime startEndTime = LogServiceHelper.getCurrentLogSearchEndTime(AdminConstants.STAT_DAY_NUM); diff --git a/src/main/java/com/caliverse/admin/scheduler/batch/service/DataClearService.java b/src/main/java/com/caliverse/admin/scheduler/batch/service/DataClearService.java new file mode 100644 index 0000000..5af3762 --- /dev/null +++ b/src/main/java/com/caliverse/admin/scheduler/batch/service/DataClearService.java @@ -0,0 +1,5 @@ +package com.caliverse.admin.scheduler.batch.service; + +public interface DataClearService { + void oldDataClear(); +} diff --git a/src/main/java/com/caliverse/admin/scheduler/batch/service/impl/DataClearServiceImpl.java b/src/main/java/com/caliverse/admin/scheduler/batch/service/impl/DataClearServiceImpl.java new file mode 100644 index 0000000..a385d77 --- /dev/null +++ b/src/main/java/com/caliverse/admin/scheduler/batch/service/impl/DataClearServiceImpl.java @@ -0,0 +1,22 @@ +package com.caliverse.admin.scheduler.batch.service.impl; + +import com.caliverse.admin.dynamodb.service.DynamodbBattleEventService; +import com.caliverse.admin.dynamodb.service.DynamodbMailService; +import com.caliverse.admin.scheduler.batch.service.DataClearService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@AllArgsConstructor +public class DataClearServiceImpl implements DataClearService { + private final DynamodbMailService dynamodbMailService; + private final DynamodbBattleEventService dynamodbBattleEventService; + + @Override + public void oldDataClear() { + dynamodbMailService.oldSystemMetaMailClear(); + dynamodbBattleEventService.oldBattleEventClear(); + } +} diff --git a/src/main/resources/mappers/BattleMapper.xml b/src/main/resources/mappers/BattleMapper.xml index 053016a..ae5b4aa 100644 --- a/src/main/resources/mappers/BattleMapper.xml +++ b/src/main/resources/mappers/BattleMapper.xml @@ -360,7 +360,7 @@ , config_id , reward_group_id FROM battle_event - WHERE (status = 'WAIT' or status = 'RUNNING' or status = 'REGISTER') + WHERE (status = 'WAIT' or status = 'RUNNING' or status = 'REGISTER' or status = 'STOP') AND deleted = 0