전투시스템 중복 시간체크
전투시스템 이벤트 아이디 dynamodb 기준관리
This commit is contained in:
@@ -22,5 +22,6 @@ public interface BattleMapper {
|
||||
|
||||
int updateStatusBattleEvent(Map map);
|
||||
|
||||
List<BattleEvent> getCheckBattleEventList(BattleEventRequest battleEventRequest);
|
||||
List<BattleEvent> getScheduleBattleEventList();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ public class BattleEvent {
|
||||
private Integer rowNum;
|
||||
@JsonProperty("group_id")
|
||||
private String groupId;
|
||||
@JsonProperty("event_id")
|
||||
private Integer eventId;
|
||||
@JsonProperty("event_name")
|
||||
private String eventName;
|
||||
@JsonProperty("repeat_type")
|
||||
@@ -64,7 +66,7 @@ public class BattleEvent {
|
||||
public enum BATTLE_STATUS {
|
||||
WAIT,
|
||||
REGISTER,
|
||||
CANCEL,
|
||||
STOP,
|
||||
END,
|
||||
FAIL,
|
||||
RUNNING
|
||||
|
||||
@@ -20,6 +20,8 @@ public class BattleEventRequest {
|
||||
private Long id;
|
||||
@JsonProperty("group_id")
|
||||
private String groupId;
|
||||
@JsonProperty("event_id")
|
||||
private Integer eventId;
|
||||
@JsonProperty("event_name")
|
||||
private String eventName;
|
||||
@JsonProperty("repeat_type")
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -126,12 +124,17 @@ public class BattleEventService {
|
||||
battleEventRequest.setEventOperationTime(operation_time);
|
||||
|
||||
// int is_time = battleMapper.chkTimeOver(battleEventRequest);
|
||||
// if(is_time > 0){
|
||||
// return BattleEventResponse.builder()
|
||||
// .status(CommonCode.ERROR.getHttpStatus())
|
||||
// .result(ErrorCode.ERROR_BATTLE_EVENT_TIME_OVER.toString())
|
||||
// .build();
|
||||
// }
|
||||
List<BattleEvent> existingList = battleMapper.getCheckBattleEventList(battleEventRequest);
|
||||
boolean isTime = isTimeOverlapping(existingList, battleEventRequest);
|
||||
if(isTime){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_BATTLE_EVENT_TIME_OVER.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
int next_event_id = dynamodbBattleEventService.getEventId() + 1;
|
||||
battleEventRequest.setEventId(next_event_id);
|
||||
|
||||
int result = battleMapper.postBattleEvent(battleEventRequest);
|
||||
log.info("AdminToolDB BattleEvent Save: {}", battleEventRequest);
|
||||
@@ -171,10 +174,10 @@ public class BattleEventService {
|
||||
|
||||
BattleEvent before_info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
if(!before_info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !before_info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
if(!before_info.getStatus().equals(BattleEvent.BATTLE_STATUS.STOP)){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.result(ErrorCode.ERROR_BATTLE_EVENT_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -284,6 +287,18 @@ public class BattleEventService {
|
||||
|
||||
int total_time = round_time + ((round_count - 1) * (round_time + round_wait_time)) + result_wait_time + server_wait_time;
|
||||
|
||||
return total_time;
|
||||
return total_time; // 초
|
||||
}
|
||||
|
||||
private boolean isTimeOverlapping(List<BattleEvent> existingList, BattleEventRequest battleEventRequest){
|
||||
LocalTime newStartTime = battleEventRequest.getEventStartDt().toLocalTime();
|
||||
LocalTime newEndTime = newStartTime.plusSeconds(battleEventRequest.getEventOperationTime());
|
||||
|
||||
return existingList.stream().anyMatch(schedule -> {
|
||||
LocalTime existingStartTime = schedule.getEventStartDt().toLocalTime();
|
||||
LocalTime existingEndTime = existingStartTime.plusSeconds(schedule.getEventOperationTime());
|
||||
|
||||
return !existingStartTime.isAfter(newEndTime) && !newStartTime.isAfter(existingEndTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.HashSet;
|
||||
public class BattleEventAttrib extends DynamoDBAttribBase {
|
||||
|
||||
@JsonProperty("event_id")
|
||||
private long eventId;
|
||||
private Integer eventId;
|
||||
|
||||
@JsonProperty("is_active")
|
||||
private boolean isActive;
|
||||
|
||||
@@ -70,6 +70,11 @@ public abstract class BaseDynamoDBRepository<T> implements DynamoDBRepository<T>
|
||||
|
||||
@Override
|
||||
public List<T> findByPrefix(String partitionKey, String sortKeyPrefix) {
|
||||
return operations.getItemsByPrefix(partitionKey, sortKeyPrefix, entityClass);
|
||||
if(sortKeyPrefix.isEmpty()){
|
||||
return operations.getItemsByPrefix(partitionKey, entityClass);
|
||||
}
|
||||
else{
|
||||
return operations.getItemsByPrefix(partitionKey, sortKeyPrefix, entityClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,7 @@ import com.caliverse.admin.domain.request.BattleEventRequest;
|
||||
import com.caliverse.admin.dynamodb.domain.doc.BattleEventDoc;
|
||||
|
||||
public interface BattleEventRepository extends DynamoDBRepository<BattleEventDoc> {
|
||||
int findEventId();
|
||||
void insert(BattleEventRequest battleEventRequest);
|
||||
void updateStop(BattleEventRequest battleEventRequest);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import com.caliverse.admin.domain.entity.BattleEvent;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.request.BattleEventRequest;
|
||||
import com.caliverse.admin.dynamodb.domain.atrrib.BattleEventAttrib;
|
||||
import com.caliverse.admin.dynamodb.domain.atrrib.LandAuctionRegistryAttrib;
|
||||
import com.caliverse.admin.dynamodb.domain.doc.BattleEventDoc;
|
||||
import com.caliverse.admin.dynamodb.domain.doc.LandAuctionRegistryDoc;
|
||||
import com.caliverse.admin.dynamodb.entity.EDayOfWeekType;
|
||||
import com.caliverse.admin.dynamodb.entity.EOncePeriodRangeType;
|
||||
import com.caliverse.admin.dynamodb.repository.BaseDynamoDBRepository;
|
||||
@@ -19,9 +21,12 @@ import com.caliverse.admin.history.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;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.caliverse.admin.global.common.utils.CommonUtils.convertUTCDate;
|
||||
import static com.caliverse.admin.global.common.utils.DateUtils.stringToISODateTime;
|
||||
@@ -33,6 +38,27 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
super(operations, BattleEventDoc.class, dynamodbHistoryLogService, objectMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findEventId() {
|
||||
List<BattleEventDoc> docs = findByPrefix(
|
||||
DynamoDBConstants.PK_KEY_BATTLE_EVENT,
|
||||
""
|
||||
);
|
||||
|
||||
if (docs.isEmpty()) return 0;
|
||||
|
||||
BattleEventDoc latestDoc = docs.stream().max(Comparator.comparing(BattleEventDoc::getSK))
|
||||
.orElse(null);
|
||||
|
||||
try {
|
||||
BattleEventAttrib attrib = objectMapper.readValue(latestDoc.getAttribValue(), BattleEventAttrib.class);
|
||||
return attrib.getEventId();
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(BattleEventRequest battleEventRequest) {
|
||||
LocalDateTime nowDate = LocalDateTime.now();
|
||||
@@ -48,7 +74,7 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
try {
|
||||
BattleEventAttrib attrib = new BattleEventAttrib();
|
||||
attrib.setAttribType(DynamoDBConstants.ATTRIB_BATTLE_EVENT);
|
||||
attrib.setEventId(battleEventRequest.getId());
|
||||
attrib.setEventId(battleEventRequest.getEventId());
|
||||
attrib.setStartDay(stringToISODateTime(start_dt.toLocalDate().atStartOfDay()));
|
||||
attrib.setStartHour(start_dt.getHour());
|
||||
attrib.setStartMin(start_dt.getMinute());
|
||||
@@ -60,6 +86,7 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
attrib.setRewardGroupId(battleEventRequest.getRewardGroupId());
|
||||
attrib.setHotTime(battleEventRequest.getHotTime());
|
||||
attrib.setRoundCount(battleEventRequest.getRoundCount());
|
||||
attrib.setActive(true);
|
||||
|
||||
BattleEventDoc doc = new BattleEventDoc();
|
||||
doc.setPK(DynamoDBConstants.PK_KEY_BATTLE_EVENT);
|
||||
@@ -86,6 +113,43 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStop(BattleEventRequest battleEventRequest) {
|
||||
try {
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_BATTLE_EVENT)
|
||||
.sortValue(battleEventRequest.getId())
|
||||
.build();
|
||||
|
||||
BattleEventDoc beforeDoc = findById(key);
|
||||
|
||||
if (beforeDoc != null) {
|
||||
BattleEventDoc afterDoc = deepCopy(beforeDoc, BattleEventDoc.class);
|
||||
|
||||
BattleEventAttrib attrib = objectMapper.readValue(afterDoc.getAttribValue(), BattleEventAttrib.class);
|
||||
attrib.setActive(false);
|
||||
|
||||
afterDoc.setAttribValue(objectMapper.writeValueAsString(attrib));
|
||||
afterDoc.setUpdatedDateTime(CommonUtils.convertUTCDate(LocalDateTime.now()));
|
||||
|
||||
update(afterDoc);
|
||||
|
||||
log.info("BattleEventDoc Update Success: {}", objectMapper.writeValueAsString(afterDoc));
|
||||
|
||||
dynamodbHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE,
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE.name(),
|
||||
beforeDoc,
|
||||
afterDoc,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private EOncePeriodRangeType getOncePeriodRangeType(BattleEvent.BATTLE_REPEAT_TYPE repeatType) {
|
||||
return switch (repeatType) {
|
||||
case DAY -> EOncePeriodRangeType.Daily;
|
||||
|
||||
@@ -227,4 +227,17 @@ public class DynamoDBOperations {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public <T> List<T> getItemsByPrefix(String partitionKey, Class<T> itemClass) {
|
||||
DynamoDbTable<T> table = getTable(itemClass);
|
||||
|
||||
QueryConditional queryConditional = QueryConditional.keyEqualTo(b -> b
|
||||
.partitionValue(partitionKey)
|
||||
.build());
|
||||
|
||||
return table.query(r -> r.queryConditional(queryConditional))
|
||||
.items()
|
||||
.stream()
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,4 +18,12 @@ public class DynamodbBattleEventService {
|
||||
battleEventRepository.insert(battleEventRequest);
|
||||
}
|
||||
|
||||
public int getEventId(){
|
||||
return battleEventRepository.findEventId();
|
||||
}
|
||||
|
||||
public void updateStopBattleEvent(BattleEventRequest battleEventRequest) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public enum ErrorCode {
|
||||
|
||||
//Battle
|
||||
ERROR_BATTLE_EVENT_TIME_OVER("해당 시간에 속하는 이벤트가 존재합니다."),
|
||||
ERROR_BATTLE_EVENT_STATUS_IMPOSSIBLE("수정할 수 없는 이벤트상태입니다."),
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
// DyanamoDB
|
||||
|
||||
@@ -83,6 +83,7 @@ public class DynamicScheduler {
|
||||
return;
|
||||
}
|
||||
|
||||
// 비정상종료일때가 있다고 상시체크로 해달라고 함(23.02.18)
|
||||
// 경매중일때 경매 종료시간이 되지않았다면 체크하지 않는다
|
||||
// if(auction_status.equals(LandAuction.AUCTION_STATUS.AUCTION_START) && nowDate.isBefore(auctionEndDate)){
|
||||
// return;
|
||||
|
||||
Reference in New Issue
Block a user