init
This commit is contained in:
@@ -0,0 +1,285 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.BattleMapper;
|
||||
import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
|
||||
import com.caliverse.admin.domain.entity.BattleEvent;
|
||||
import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
||||
import com.caliverse.admin.domain.entity.LandAuction;
|
||||
import com.caliverse.admin.domain.entity.metadata.MetaBattleConfigData;
|
||||
import com.caliverse.admin.domain.entity.metadata.MetaBattleRewardData;
|
||||
import com.caliverse.admin.domain.request.BattleEventRequest;
|
||||
import com.caliverse.admin.domain.response.BattleEventResponse;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import com.caliverse.admin.global.common.code.SuccessCode;
|
||||
import com.caliverse.admin.global.common.constants.CommonConstants;
|
||||
import com.caliverse.admin.global.common.constants.MysqlConstants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
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;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BattleEventService {
|
||||
|
||||
private final BattleMapper battleMapper;
|
||||
private final MetaDataHandler metaDataHandler;
|
||||
private final HistoryService historyService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
|
||||
//전투시스템 설정 데이터
|
||||
public BattleEventResponse getBattleConfigList(){
|
||||
|
||||
List<MetaBattleConfigData> list = metaDataHandler.getMetaBattleConfigsListData();
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleConfigList(list)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
//전투시스템 보상 데이터
|
||||
public BattleEventResponse getBattleRewardList(){
|
||||
|
||||
List<MetaBattleRewardData> list = metaDataHandler.getMetaBattleRewardsListData();
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleRewardList(list)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 전투시스템 이벤트 조회
|
||||
public BattleEventResponse getBattleEventList(@RequestParam Map<String, String> requestParam){
|
||||
|
||||
requestParam = CommonUtils.pageSetting(requestParam);
|
||||
|
||||
List<BattleEvent> list = battleMapper.getBattleEventList(requestParam);
|
||||
|
||||
int allCnt = battleMapper.getAllCnt(requestParam);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleEventList(list)
|
||||
.total(battleMapper.getTotal())
|
||||
.totalAll(allCnt)
|
||||
.pageNo(requestParam.get("page_no")!=null?
|
||||
Integer.parseInt(requestParam.get("page_no")):1)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 전투시스템 이벤트 상세조회
|
||||
public BattleEventResponse getBattleEventDetail(Long id){
|
||||
|
||||
BattleEvent battleEvent = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.battleEvent(battleEvent)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse postBattleEvent(BattleEventRequest battleEventRequest){
|
||||
if(battleEventRequest.getRepeatType().equals(BattleEvent.BATTLE_REPEAT_TYPE.NONE)){
|
||||
LocalDateTime start_dt = battleEventRequest.getEventStartDt();
|
||||
LocalDateTime end_dt = start_dt.plusHours(12);
|
||||
battleEventRequest.setEventEndDt(end_dt);
|
||||
}
|
||||
|
||||
int operation_time = calcEndTime(battleEventRequest);
|
||||
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();
|
||||
// }
|
||||
|
||||
int result = battleMapper.postBattleEvent(battleEventRequest);
|
||||
log.info("AdminToolDB BattleEvent Save: {}", battleEventRequest);
|
||||
|
||||
long battle_event_id = battleEventRequest.getId();
|
||||
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
map.put("id",String.valueOf(battle_event_id));
|
||||
|
||||
BattleEvent event_info = battleMapper.getBattleEventDetail(battle_event_id);
|
||||
|
||||
mysqlHistoryLogService.insertHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_ADD,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_ADD.name(),
|
||||
event_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.insertLandAuctionRegistryWithActivity(landRequest);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse updateBattleEvent(Long id, BattleEventRequest battleEventRequest) {
|
||||
battleEventRequest.setId(id);
|
||||
battleEventRequest.setUpdateBy(CommonUtils.getAdmin().getId());
|
||||
battleEventRequest.setUpdateDt(LocalDateTime.now());
|
||||
|
||||
BattleEvent before_info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
if(!before_info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !before_info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
int result = battleMapper.updateBattleEvent(battleEventRequest);
|
||||
log.info("AdminToolDB BattleEvent Update Complete: {}", battleEventRequest);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", String.valueOf(id));
|
||||
|
||||
BattleEvent after_info = battleMapper.getBattleEventDetail(id);
|
||||
|
||||
mysqlHistoryLogService.updateHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_UPDATE.name(),
|
||||
before_info,
|
||||
after_info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.updateLandAuction(landRequest);
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public BattleEventResponse deleteBattleEvent(BattleEventRequest battleEventRequest){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
AtomicBoolean is_falil = new AtomicBoolean(false);
|
||||
|
||||
battleEventRequest.getList().forEach(
|
||||
item->{
|
||||
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)){
|
||||
is_falil.set(true);
|
||||
return;
|
||||
}
|
||||
|
||||
map.put("id", id);
|
||||
map.put("updateBy", CommonUtils.getAdmin().getId());
|
||||
int result = battleMapper.deleteBattleEvent(map);
|
||||
log.info("BattleEvent Delete Complete: {}", item);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE,
|
||||
MysqlConstants.TABLE_NAME_BATTLE_EVENT,
|
||||
HISTORYTYPE.BATTLE_EVENT_DELETE.name(),
|
||||
info,
|
||||
CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
// dynamodbLandAuctionService.cancelLandAuction(auction_info);
|
||||
}
|
||||
);
|
||||
|
||||
if(is_falil.get()){
|
||||
return BattleEventResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_AUCTION_STATUS_IMPOSSIBLE.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
return BattleEventResponse.builder()
|
||||
.resultData(BattleEventResponse.ResultData.builder()
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<BattleEvent> getScheduleBattleEventList(){
|
||||
return battleMapper.getScheduleBattleEventList();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void updateBattleEventStatus(Map<String,Object> map){
|
||||
try{
|
||||
battleMapper.updateStatusBattleEvent(map);
|
||||
log.info("BattleEvent status changed: {}", map.get("status"));
|
||||
}catch(Exception e){
|
||||
log.error("BattleEvent Status Update Fail map: {}", map);
|
||||
}
|
||||
}
|
||||
|
||||
// 이벤트 동작 시간 계산
|
||||
private int calcEndTime(BattleEventRequest battleEventRequest){
|
||||
MetaBattleConfigData config = metaDataHandler.getMetaBattleConfigsListData().stream()
|
||||
.filter(data -> data.getId().equals(battleEventRequest.getConfigId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if(config == null) return 0;
|
||||
|
||||
int round_time = battleEventRequest.getRoundTime();
|
||||
int round_count = battleEventRequest.getRoundCount();
|
||||
int round_wait_time = config.getNextRoundWaitTime();
|
||||
int result_wait_time = config.getResultUIWaitTime();
|
||||
int server_wait_time = CommonConstants.BATTLE_SERVER_WAIT_TIME;
|
||||
|
||||
int total_time = round_time + ((round_count - 1) * (round_time + round_wait_time)) + result_wait_time + server_wait_time;
|
||||
|
||||
return total_time;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user