랜드 소유권 변경 처리

This commit is contained in:
2025-03-07 18:31:50 +09:00
parent c5292fa20f
commit 3acb92a579
31 changed files with 981 additions and 144 deletions

View File

@@ -12,6 +12,7 @@ import com.caliverse.admin.domain.request.LandRequest;
import com.caliverse.admin.domain.response.LandResponse;
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.dynamodb.service.DynamodbUserService;
import com.caliverse.admin.global.common.code.CommonCode;
import com.caliverse.admin.global.common.code.ErrorCode;
@@ -19,7 +20,9 @@ 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.global.common.utils.DateUtils;
import com.caliverse.admin.history.service.MysqlHistoryLogService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -34,6 +37,7 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.caliverse.admin.global.common.utils.CommonUtils.convertIsoByDatetime;
import static com.caliverse.admin.global.common.utils.DateUtils.stringToDateTime;
@Service
@RequiredArgsConstructor
@@ -50,6 +54,7 @@ public class LandService {
private final HistoryService historyService;
private final ObjectMapper objectMapper;
private final MysqlHistoryLogService mysqlHistoryLogService;
private final DynamodbService dynamodbService;
public LandResponse getLandInfo(@RequestParam Map<String, String> requestParam){
String searchType = requestParam.getOrDefault("land_type", "ID");
@@ -65,6 +70,7 @@ public class LandService {
List<MetaLandData> landData = metaDataHandler.getMetaLandListData();
List<MetaBuildingData> buildingData = metaDataHandler.getMetaBuildingListData();
List<LandAuction> auctions = landMapper.getLandAuctionList(new HashMap());
List<LandInfo> list = landData.stream()
//필터 전처리(map 처리속도를 최대한 빠르게하기 위해서 먼저 필터 처리할수 있는건 한다)
@@ -87,7 +93,7 @@ public class LandService {
return result;
})
.map(data -> buildLandInfo(data, buildingData))
.map(data -> buildLandInfo(data, buildingData, auctions))
.filter(info -> {
boolean result = true;
@@ -121,40 +127,92 @@ public class LandService {
.build();
}
private LandInfo buildLandInfo(MetaLandData data, List<MetaBuildingData> buildingData){
int landId = data.getLandId();
LandAttrib land = dynamodbLandService.getLandInfo(landId);
String ownerGuid = land == null ? "" : land.getOwnerUserGuid();
String ownerName = data.getEditor().equals(CommonConstants.CALIVERSE_CODE) ? CommonConstants.CALIVERSE_NAME :
ownerGuid.isEmpty() ? "" : dynamodbUserService.getGuidByName(ownerGuid);
String ownerDate = ownerGuid.isEmpty() ? null : dynamodbLandService.getLandOwnerCreateDate(ownerGuid, landId); //랜드 소유 일자
int buildingSocket = buildingData.stream()
.filter(building -> building.getBuildingId().equals(data.getBuildingId()))
.findFirst().get()
.getInstanceSocket();
private LandInfo buildLandInfo(MetaLandData data, List<MetaBuildingData> buildingData, List<LandAuction> auctions){
try {
int landId = data.getLandId();
String editor = data.getEditor();
boolean nonAction = data.isNonAuction();
String parsedDate = null;
if (ownerDate != null && !ownerDate.isEmpty()) {
try {
parsedDate = convertIsoByDatetime(ownerDate);
} catch (DateTimeParseException e) {
log.warn("owner_date parsing fail: " + ownerDate, e);
String ownerGuid = "";
String ownerName = "";
String ownerDate = "";
double ownerPrice = 0;
String category = "";
String status = "";
if(editor.equals(CommonConstants.USER)){
LandAttrib land = dynamodbLandService.getLandInfo(landId);
//랜드 존재
if(land != null){
ownerGuid = land.getOwnerUserGuid();
ownerName = dynamodbUserService.getGuidByName(ownerGuid);
int auctionNumber = dynamodbLandAuctionService.getLandAuctionNumber(landId);
// 경매
if(auctionNumber > 0){
LandAuction auction = auctions.stream()
.filter(row -> row.getLandId().equals(landId) && row.getAuctionSeq().equals(auctionNumber))
.findFirst().orElse(null);
if(auction == null){
log.error("getLandInfo.buildLandInfo auction info error landId: {}, auctionNumber: {}", landId, auctionNumber);
}
LandAuction.AUCTION_STATUS auctionStatus = auction.getStatus();
if(auctionStatus.equals(LandAuction.AUCTION_STATUS.FAIL) || auctionStatus.equals(LandAuction.AUCTION_STATUS.CANCEL)){
status = "";
}else{
status = auctionStatus.toString();
}
ownerPrice = auction.getClosePrice();
ownerDate = stringToDateTime(auction.getCloseEndDt());
}else{
String parsedDate = dynamodbLandService.getLandOwnerCreateDate(ownerGuid, landId);
ownerDate = convertIsoByDatetime(parsedDate);
}
}
}else{
ownerName = CommonConstants.CALIVERSE_NAME;
}
}
return LandInfo.builder()
.id((long)landId)
.landId(landId)
.landName(metaDataHandler.getTextStringData(data.getLandName()))
.landDesc(metaDataHandler.getTextStringData(data.getLandDesc()))
.nonAuction(data.isNonAuction())
.landSize(data.getLandSize())
.landType(data.getLandType())
.socket(buildingSocket)
.ownerUserGuid(ownerGuid)
.ownerUserNickname(ownerName)
.ownerUserCreateDate(parsedDate)
.build();
if(editor.equals(CommonConstants.CALIVERSE_CODE)){
category = CommonConstants.LAND_PUBLIC;
}else{
if(nonAction){
category = CommonConstants.LAND_EVENT;
}else{
category = CommonConstants.LAND_AUCTION;
}
}
boolean isOwned = editor.equals(CommonConstants.USER) && nonAction && ownerGuid.isEmpty();
MetaBuildingData buildingInfo = buildingData.stream()
.filter(building -> building.getBuildingId().equals(data.getBuildingId()))
.findFirst().get();
return LandInfo.builder()
.id((long) landId)
.landId(landId)
.landName(metaDataHandler.getTextStringData(data.getLandName()))
.landDesc(metaDataHandler.getTextStringData(data.getLandDesc()))
.buildingId(data.getBuildingId())
.buildingName(metaDataHandler.getTextStringData(buildingInfo.getBuildingName()))
.nonAuction(nonAction)
.editor(editor)
.status(status)
.isOwned(isOwned)
.category(category)
.landSize(data.getLandSize())
.landType(data.getLandType())
.socket(buildingInfo.getInstanceSocket())
.ownerUserGuid(ownerGuid)
.ownerUserNickname(ownerName)
.ownerUserCreateDate(ownerDate)
.ownerPrice(String.valueOf(ownerPrice))
.build();
}catch(Exception e){
log.error("buildLandInfo", e);
}
return null;
}
// 랜드 메타데이터 정보 조회
@@ -301,17 +359,17 @@ public class LandService {
map.put("id",String.valueOf(auction_id));
//메시지 저장
if(landRequest.getMassageList()!= null && !landRequest.getMassageList().isEmpty()){
landRequest.getMassageList().forEach(
item -> {
map.put("title",item.getTitle());
map.put("content",item.getContent());
map.put("language",item.getLanguage());
landMapper.insertMessage(map);
}
);
}
log.info("AdminToolDB Message Save Complete");
// if(landRequest.getMassageList()!= null && !landRequest.getMassageList().isEmpty()){
// landRequest.getMassageList().forEach(
// item -> {
// map.put("title",item.getTitle());
// map.put("content",item.getContent());
// map.put("language",item.getLanguage());
// landMapper.insertMessage(map);
// }
// );
// }
// log.info("AdminToolDB Message Save Complete");
LandAuction auction_info = landMapper.getLandAuctionDetail(auction_id);
auction_info.setMessageList(landMapper.getMessage(auction_id));
@@ -336,6 +394,61 @@ public class LandService {
.build();
}
@Transactional(transactionManager = "transactionManager")
public LandResponse postLandOwnerChanges(LandRequest landRequest){
String guid = landRequest.getUserGuid();
String nickname = dynamodbUserService.getGuidByName(guid);
if(nickname.isEmpty() || !nickname.equals(landRequest.getUserName())){
return LandResponse.builder()
.status(CommonCode.ERROR.getHttpStatus())
.result(ErrorCode.GUID_CHECK.toString())
.build();
}
landRequest.setCreateBy(CommonUtils.getAdmin().getId());
boolean is_reserve = landRequest.isReserve();
if(!is_reserve){
landRequest.setReservationDt(LocalDateTime.now());
}
int result = landMapper.postLandOwnerChange(landRequest);
try {
log.info("AdminToolDB LandOwnerChanges Save: {}", objectMapper.writeValueAsString(landRequest));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
long id = landRequest.getId();
HashMap<String,Object> map = new HashMap<>();
map.put("id",String.valueOf(id));
LandOwnerChange info = landMapper.getLandOwnerChangeDetail(id);
mysqlHistoryLogService.insertHistoryLog(
HISTORYTYPE.LAND_OWNER_CHANGE_ADD,
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
HISTORYTYPE.LAND_OWNER_CHANGE_ADD.name(),
info,
CommonUtils.getAdmin().getEmail(),
CommonUtils.getClientIp()
);
if(!is_reserve){
dynamodbLandService.ChangesLandOwner(landRequest);
map.put("status", LandOwnerChange.CHANGE_STATUS.FINISH);
updateLandOwnedChangeStatus(map);
}
return LandResponse.builder()
.status(CommonCode.SUCCESS.getHttpStatus())
.result(CommonCode.SUCCESS.getResult())
.resultData(LandResponse.ResultData.builder()
.message(SuccessCode.SAVE.getMessage())
.build())
.build();
}
@Transactional(transactionManager = "transactionManager")
public LandResponse updateLandAuction(Long id, LandRequest landRequest) {
landRequest.setId(id);
@@ -343,7 +456,7 @@ public class LandService {
landRequest.setUpdateDt(LocalDateTime.now());
LandAuction before_info = landMapper.getLandAuctionDetail(id);
before_info.setMessageList(landMapper.getMessage(id));
// before_info.setMessageList(landMapper.getMessage(id));
if(!before_info.getStatus().equals(LandAuction.AUCTION_STATUS.WAIT) && !before_info.getStatus().equals(LandAuction.AUCTION_STATUS.RESV_START)){
return LandResponse.builder()
@@ -359,19 +472,19 @@ public class LandService {
map.put("id", String.valueOf(id));
// message 테이블 데이터 삭제 처리 by mail_id
landMapper.deleteMessage(map);
// 메시지 업데이트
if (landRequest.getMassageList() != null && !landRequest.getMassageList().isEmpty()) {
landRequest.getMassageList().forEach(item -> {
map.put("title", item.getTitle());
map.put("content", item.getContent());
map.put("language", item.getLanguage());
landMapper.insertMessage(map);
});
}
log.info("AdminToolDB Message Update Complete");
// landMapper.deleteMessage(map);
//
// // 메시지 업데이트
// if (landRequest.getMassageList() != null && !landRequest.getMassageList().isEmpty()) {
// landRequest.getMassageList().forEach(item -> {
// map.put("title", item.getTitle());
// map.put("content", item.getContent());
// map.put("language", item.getLanguage());
//
// landMapper.insertMessage(map);
// });
// }
// log.info("AdminToolDB Message Update Complete");
LandAuction after_info = landMapper.getLandAuctionDetail(id);
after_info.setMessageList(landMapper.getMessage(id));
@@ -388,16 +501,39 @@ public class LandService {
dynamodbLandAuctionService.updateLandAuction(landRequest);
//로그 기록
try{
JSONObject jsonObject = new JSONObject();
jsonObject.put("before_info",before_info.toString());
jsonObject.put("after_info",after_info.toString());
// jsonObject.put("dynamoDB_result",land_auction_registry_result);
historyService.setLog(HISTORYTYPE.LAND_AUCTION_UPDATE, jsonObject);
}catch(Exception e){
log.error("history log Save Fail: {}", e.getMessage());
}
return LandResponse.builder()
.resultData(LandResponse.ResultData.builder()
.build())
.status(CommonCode.SUCCESS.getHttpStatus())
.result(CommonCode.SUCCESS.getResult())
.build();
}
@Transactional(transactionManager = "transactionManager")
public LandResponse updateLandOwnerChanges(Long id, LandRequest landRequest) {
landRequest.setId(id);
landRequest.setUpdateBy(CommonUtils.getAdmin().getId());
landRequest.setUpdateDt(LocalDateTime.now());
LandOwnerChange before_info = landMapper.getLandOwnerChangeDetail(id);
int result = landMapper.updateLandOwnerChange(landRequest);
log.info("AdminToolDB LandOwnerChanges Update Complete: {}", landRequest);
LandOwnerChange after_info = landMapper.getLandOwnerChangeDetail(id);
mysqlHistoryLogService.updateHistoryLog(
HISTORYTYPE.LAND_OWNER_CHANGE_UPDATE,
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
HISTORYTYPE.LAND_OWNER_CHANGE_UPDATE.name(),
before_info,
after_info,
CommonUtils.getAdmin().getEmail(),
CommonUtils.getClientIp()
);
dynamodbLandService.ChangesLandOwner(landRequest);
return LandResponse.builder()
.resultData(LandResponse.ResultData.builder()
@@ -488,4 +624,14 @@ public class LandService {
log.error("updateLandAuction LandAuction Update Fail map: {}", map);
}
}
@Transactional(transactionManager = "transactionManager")
public void updateLandOwnedChangeStatus(Map<String,Object> map){
try{
landMapper.updateStatusLandAuction(map);
log.info("updateLandOwnedChangeStatus LandOwned status changed: {}", map.get("status"));
}catch(Exception e){
log.error("updateLandOwnedChangeStatus LandOwned Update Fail map: {}", map);
}
}
}