전투시스템 중지 처리
This commit is contained in:
@@ -52,6 +52,13 @@ public class BattleController {
|
||||
|
||||
return ResponseEntity.ok().body(battleEventService.updateBattleEvent(id, battleEventRequest));
|
||||
}
|
||||
|
||||
@PutMapping("/event/stop/{id}")
|
||||
public ResponseEntity<BattleEventResponse> updateStopBattleEvent(
|
||||
@PathVariable("id")Long id, @RequestBody BattleEventRequest battleEventRequest){
|
||||
|
||||
return ResponseEntity.ok().body(battleEventService.updateStopBattleEvent(id, battleEventRequest));
|
||||
}
|
||||
|
||||
@DeleteMapping("/event/delete")
|
||||
public ResponseEntity<BattleEventResponse> deleteBattleEvent(
|
||||
|
||||
@@ -69,6 +69,7 @@ public class BattleEvent {
|
||||
STOP,
|
||||
END,
|
||||
FAIL,
|
||||
CANCEL,
|
||||
RUNNING
|
||||
;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,15 @@ public class BattleEventService {
|
||||
.build();
|
||||
}
|
||||
|
||||
// 일자만 필요해서 UTC시간으로 변경되다보니 한국시간(+9)을 더해서 마지막시간으로 설정
|
||||
LocalDateTime end_dt_kst = battleEventRequest.getEventEndDt()
|
||||
.plusHours(9)
|
||||
.withHour(23)
|
||||
.withMinute(59)
|
||||
.withSecond(59)
|
||||
.withNano(0);
|
||||
battleEventRequest.setEventEndDt(end_dt_kst);
|
||||
|
||||
int next_event_id = dynamodbBattleEventService.getEventId() + 1;
|
||||
battleEventRequest.setEventId(next_event_id);
|
||||
|
||||
@@ -181,6 +190,15 @@ public class BattleEventService {
|
||||
.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 result = battleMapper.updateBattleEvent(battleEventRequest);
|
||||
log.info("AdminToolDB BattleEvent Update Complete: {}", battleEventRequest);
|
||||
|
||||
@@ -199,7 +217,50 @@ public class BattleEventService {
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.updateLandAuction(landRequest);
|
||||
dynamodbBattleEventService.updateBattleEvent(battleEventRequest);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse updateStopBattleEvent(Long id, BattleEventRequest battleEventRequest){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
|
||||
BattleEvent info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
if(info.getStatus().equals(BattleEvent.BATTLE_STATUS.RUNNING)){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_BATTLE_EVENT_STATUS_START_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
map.put("id", id);
|
||||
map.put("status", BattleEvent.BATTLE_STATUS.STOP);
|
||||
map.put("updateBy", CommonUtils.getAdmin().getId());
|
||||
int result = battleMapper.updateStatusBattleEvent(map);
|
||||
try{
|
||||
log.info("BattleEvent Stop Complete: {}", objectMapper.writeValueAsString(info));
|
||||
}catch(Exception e){
|
||||
log.error("BattleEvent Stop Failed: {}", e.getMessage());
|
||||
}
|
||||
|
||||
mysqlHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE.name(),
|
||||
info,
|
||||
battleMapper.getBattleEventDetail(id),
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
dynamodbBattleEventService.updateStopBattleEvent(info);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
@@ -219,7 +280,7 @@ public class BattleEventService {
|
||||
Long id = item.getId();
|
||||
BattleEvent info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
if(!info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
if(!info.getStatus().equals(BattleEvent.BATTLE_STATUS.STOP)){
|
||||
is_falil.set(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
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;
|
||||
|
||||
public interface BattleEventRepository extends DynamoDBRepository<BattleEventDoc> {
|
||||
int findEventId();
|
||||
void insert(BattleEventRequest battleEventRequest);
|
||||
void updateStop(BattleEventRequest battleEventRequest);
|
||||
void update(BattleEventRequest battleEventRequest);
|
||||
void delete(BattleEventRequest battleEventRequest);
|
||||
void updateStop(BattleEvent battleEvent);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
|
||||
if (docs.isEmpty()) return 0;
|
||||
|
||||
BattleEventDoc latestDoc = docs.stream().max(Comparator.comparing(BattleEventDoc::getSK))
|
||||
BattleEventDoc latestDoc = docs.stream().max(Comparator.comparing(doc -> Integer.parseInt(doc.getSK())))
|
||||
.orElse(null);
|
||||
|
||||
try {
|
||||
@@ -59,8 +59,24 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEvent(Integer sk){
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_BATTLE_EVENT)
|
||||
.sortValue(String.valueOf(sk))
|
||||
.build();
|
||||
|
||||
BattleEventDoc doc = findById(key);
|
||||
|
||||
return doc != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(BattleEventRequest battleEventRequest) {
|
||||
if(isEvent(battleEventRequest.getEventId())){
|
||||
log.error("insert EventId: {} is duplication", battleEventRequest.getEventId());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
|
||||
LocalDateTime nowDate = LocalDateTime.now();
|
||||
LocalDateTime start_dt = battleEventRequest.getEventStartDt();
|
||||
BattleEvent.BATTLE_REPEAT_TYPE repeatType = battleEventRequest.getRepeatType();
|
||||
@@ -90,7 +106,7 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
|
||||
BattleEventDoc doc = new BattleEventDoc();
|
||||
doc.setPK(DynamoDBConstants.PK_KEY_BATTLE_EVENT);
|
||||
doc.setSK(String.valueOf(battleEventRequest.getId()));
|
||||
doc.setSK(String.valueOf(battleEventRequest.getEventId()));
|
||||
doc.setDocType(DynamoDBConstants.DOC_BATTLE_EVENT);
|
||||
doc.setAttribValue(objectMapper.writeValueAsString(attrib));
|
||||
doc.setCreatedDateTime(convertUTCDate(nowDate));
|
||||
@@ -114,11 +130,64 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStop(BattleEventRequest battleEventRequest) {
|
||||
public void update(BattleEventRequest battleEventRequest) {
|
||||
LocalDateTime nowDate = LocalDateTime.now();
|
||||
LocalDateTime start_dt = battleEventRequest.getEventStartDt();
|
||||
|
||||
try {
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_BATTLE_EVENT)
|
||||
.sortValue(battleEventRequest.getId())
|
||||
.sortValue(String.valueOf(battleEventRequest.getEventId()))
|
||||
.build();
|
||||
|
||||
BattleEventDoc beforeDoc = findById(key);
|
||||
|
||||
if (beforeDoc != null) {
|
||||
BattleEventDoc afterDoc = deepCopy(beforeDoc, BattleEventDoc.class);
|
||||
|
||||
BattleEventAttrib attrib = objectMapper.readValue(afterDoc.getAttribValue(), BattleEventAttrib.class);
|
||||
attrib.setStartDay(stringToISODateTime(start_dt.toLocalDate().atStartOfDay()));
|
||||
attrib.setStartHour(start_dt.getHour());
|
||||
attrib.setStartMin(start_dt.getMinute());
|
||||
attrib.setEndDate(stringToISODateTime(battleEventRequest.getEventEndDt()));
|
||||
attrib.setConfigDataId(battleEventRequest.getConfigId());
|
||||
attrib.setRewardGroupId(battleEventRequest.getRewardGroupId());
|
||||
attrib.setHotTime(battleEventRequest.getHotTime());
|
||||
attrib.setRoundCount(battleEventRequest.getRoundCount());
|
||||
attrib.setActive(true);
|
||||
|
||||
afterDoc.setAttribValue(objectMapper.writeValueAsString(attrib));
|
||||
afterDoc.setUpdatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
|
||||
update(afterDoc);
|
||||
|
||||
log.info("BattleEventDoc Update Success: {}", objectMapper.writeValueAsString(afterDoc));
|
||||
|
||||
dynamodbHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE,
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE.name(),
|
||||
beforeDoc,
|
||||
afterDoc,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(BattleEventRequest battleEventRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStop(BattleEvent battleEvent) {
|
||||
try {
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_BATTLE_EVENT)
|
||||
.sortValue(String.valueOf(battleEvent.getEventId()))
|
||||
.build();
|
||||
|
||||
BattleEventDoc beforeDoc = findById(key);
|
||||
@@ -134,11 +203,11 @@ public class BattleEventRepositoryImpl extends BaseDynamoDBRepository<BattleEven
|
||||
|
||||
update(afterDoc);
|
||||
|
||||
log.info("BattleEventDoc Update Success: {}", objectMapper.writeValueAsString(afterDoc));
|
||||
log.info("BattleEventDoc Update Stop Success: {}", objectMapper.writeValueAsString(afterDoc));
|
||||
|
||||
dynamodbHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE,
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE.name(),
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE,
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE.name(),
|
||||
beforeDoc,
|
||||
afterDoc,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.repository.BattleEventRepository;
|
||||
import com.caliverse.admin.global.common.annotation.DynamoDBTransaction;
|
||||
@@ -18,12 +19,18 @@ public class DynamodbBattleEventService {
|
||||
battleEventRepository.insert(battleEventRequest);
|
||||
}
|
||||
|
||||
@DynamoDBTransaction
|
||||
public void updateBattleEvent(BattleEventRequest battleEventRequest) {
|
||||
battleEventRepository.update(battleEventRequest);
|
||||
}
|
||||
|
||||
public int getEventId(){
|
||||
return battleEventRepository.findEventId();
|
||||
}
|
||||
|
||||
public void updateStopBattleEvent(BattleEventRequest battleEventRequest) {
|
||||
|
||||
@DynamoDBTransaction
|
||||
public void updateStopBattleEvent(BattleEvent battleEvent) {
|
||||
battleEventRepository.updateStop(battleEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public enum ErrorCode {
|
||||
//Battle
|
||||
ERROR_BATTLE_EVENT_TIME_OVER("해당 시간에 속하는 이벤트가 존재합니다."),
|
||||
ERROR_BATTLE_EVENT_STATUS_IMPOSSIBLE("수정할 수 없는 이벤트상태입니다."),
|
||||
ERROR_BATTLE_EVENT_STATUS_START_IMPOSSIBLE("진행중인 이벤트상태입니다."),
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
// DyanamoDB
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getCheckBattleEventList" resultMap="BattleEventResultMap">
|
||||
<select id="getCheckBattleEventList" parameterType="com.caliverse.admin.domain.request.BattleEventRequest" resultMap="BattleEventResultMap">
|
||||
SELECT id
|
||||
, event_id
|
||||
, repeat_type
|
||||
@@ -164,6 +164,9 @@
|
||||
, event_end_dt
|
||||
FROM battle_event
|
||||
WHERE status NOT IN ('END', 'FAIL')
|
||||
<if test="id != null and id != ''">
|
||||
AND id <> #{id}
|
||||
</if>
|
||||
AND (
|
||||
/* NONE 타입인 경우 */
|
||||
(repeat_type = 'NONE' AND DATE (event_start_dt) BETWEEN
|
||||
@@ -253,11 +256,15 @@
|
||||
<!--수정-->
|
||||
<update id="updateBattleEvent" parameterType="com.caliverse.admin.domain.request.BattleEventRequest">
|
||||
UPDATE battle_event SET group_id = #{groupId}
|
||||
, resv_end_dt = #{resvEndDt}
|
||||
, auction_start_dt = #{auctionStartDt}
|
||||
, auction_end_dt = #{auctionEndDt}
|
||||
, currency_type = #{currencyType}
|
||||
, start_price = #{startPrice}
|
||||
, event_name = #{eventName}
|
||||
, config_id = #{configId}
|
||||
, event_start_dt = #{eventStartDt}
|
||||
, event_end_dt = #{eventEndDt}
|
||||
, reward_group_id = #{rewardGroupId}
|
||||
, round_time = #{roundTime}
|
||||
, round_count = #{roundCount}
|
||||
, hot_time = #{hotTime}
|
||||
, status = 'WAIT'
|
||||
, update_by = #{updateBy}
|
||||
, update_dt = NOW()
|
||||
WHERE id = #{id}
|
||||
@@ -276,6 +283,10 @@
|
||||
<update id="updateStatusBattleEvent" parameterType="map">
|
||||
UPDATE battle_event
|
||||
SET status = #{status}
|
||||
<if test="updateBy != null and updateBy != ''">
|
||||
, update_by = #{updateBy}
|
||||
, update_dt = NOW()
|
||||
</if>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
@@ -295,7 +306,7 @@
|
||||
, a.config_id
|
||||
, a.reward_group_id
|
||||
FROM battle_event
|
||||
WHERE (status = 'WAIT' or status = 'AUCTION_START' or status = 'RESV_START')
|
||||
WHERE (status = 'WAIT' or status = 'RUNNING' or status = 'REGISTER')
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user