데이터 초기화 API 추가 및 처리
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.domain.dao.admin.DataMapper;
|
||||
import com.caliverse.admin.domain.dao.admin.LandMapper;
|
||||
import com.caliverse.admin.domain.entity.*;
|
||||
import com.caliverse.admin.domain.request.AuthenticateRequest;
|
||||
import com.caliverse.admin.domain.request.LogGenericRequest;
|
||||
import com.caliverse.admin.domain.response.DataResponse;
|
||||
import com.caliverse.admin.dynamodb.service.DynamodbDataService;
|
||||
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.MysqlConstants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.component.transaction.TransactionIdManager;
|
||||
import com.caliverse.admin.history.domain.DynamodbDataInitializeHistory;
|
||||
import com.caliverse.admin.history.service.DataInitializeHistoryService;
|
||||
import com.caliverse.admin.history.service.MysqlHistoryLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.mongodb.UncategorizedMongoDbException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DataService {
|
||||
|
||||
private final DynamodbDataService dynamodbDataService;
|
||||
private final MysqlHistoryLogService mysqlHistoryLogService;
|
||||
private final LandMapper landMapper;
|
||||
private final DataMapper dataMapper;
|
||||
private final DataInitializeHistoryService dataInitializeHistoryService;
|
||||
private final TransactionIdManager transactionIdManager;
|
||||
|
||||
public DataResponse initHistoryList(LogGenericRequest logGenericRequest){
|
||||
|
||||
LocalDateTime startDt = logGenericRequest.getStartDt().plusHours(9);
|
||||
LocalDateTime endDt = logGenericRequest.getEndDt().plusHours(9).plusDays(1);
|
||||
|
||||
logGenericRequest.setStartDt(startDt);
|
||||
logGenericRequest.setEndDt(endDt);
|
||||
|
||||
List<DynamodbDataInitializeHistory> logList = new ArrayList<>();
|
||||
try{
|
||||
logList = dataInitializeHistoryService.loadHistoryData(logGenericRequest, DynamodbDataInitializeHistory.class);
|
||||
}catch(UncategorizedMongoDbException e){
|
||||
if (e.getMessage().contains("Sort exceeded memory limit")) {
|
||||
log.error("MongoDB Query memory limit error: {}", e.getMessage());
|
||||
return DataResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_LOG_MEMORY_LIMIT.toString())
|
||||
.build();
|
||||
} else {
|
||||
log.error("MongoDB Query error", e);
|
||||
return DataResponse.builder()
|
||||
.status(CommonCode.ERROR.getHttpStatus())
|
||||
.result(ErrorCode.ERROR_MONGODB_QUERY.toString())
|
||||
.build();
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("dataInitialize error", e);
|
||||
}
|
||||
|
||||
return DataResponse.builder()
|
||||
.resultData(DataResponse.ResultData.builder()
|
||||
.dataInitList(logList)
|
||||
.build())
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public DataResponse initData(AuthenticateRequest authenticateRequest){
|
||||
EInitDataType dataType = authenticateRequest.getInitDataType();
|
||||
log.info("initData email: {}, initDataType: {}", CommonUtils.getAdmin().getEmail(), dataType);
|
||||
|
||||
dataMapper.postDataInit(dataType, CommonUtils.getAdmin().getId());
|
||||
|
||||
// switch(dataType){
|
||||
// case LandAuction -> {
|
||||
// int result = initLandAuction();
|
||||
// if(result == 0){
|
||||
// return DataResponse.builder()
|
||||
// .status(CommonCode.ERROR.getHttpStatus())
|
||||
// .result(ErrorCode.ERROR_DATA_INIT.toString())
|
||||
// .build();
|
||||
// }
|
||||
// }
|
||||
// case LandOwned -> {
|
||||
// int result = initLandOwned();
|
||||
// if(result == 0){
|
||||
// return DataResponse.builder()
|
||||
// .status(CommonCode.ERROR.getHttpStatus())
|
||||
// .result(ErrorCode.ERROR_DATA_INIT.toString())
|
||||
// .build();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// dynamodbDataService.InitDataLandOwned();
|
||||
|
||||
return DataResponse.builder()
|
||||
.status(CommonCode.SUCCESS.getHttpStatus())
|
||||
.result(CommonCode.SUCCESS.getResult())
|
||||
.resultData(DataResponse.ResultData.builder()
|
||||
.message(SuccessCode.SAVE.getMessage())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void initLandAuction(LandAuction landAuction){
|
||||
try {
|
||||
long auctionId = landAuction.getId();
|
||||
int result = landMapper.initLandAuction(auctionId);
|
||||
|
||||
List<Message> message = landMapper.getMessage(auctionId);
|
||||
Map map = new HashMap();
|
||||
map.put("id", landAuction.getId());
|
||||
landMapper.deleteMessage(map);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE.name(),
|
||||
landAuction,
|
||||
CommonUtils.getAdmin() == null ? "" : CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp() == null ? "" : CommonUtils.getClientIp()
|
||||
);
|
||||
if (!message.isEmpty()) {
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE,
|
||||
MysqlConstants.TABLE_NAME_MESSAGE,
|
||||
HISTORYTYPE.LAND_AUCTION_INITIALIZE.name(),
|
||||
message,
|
||||
CommonUtils.getAdmin() == null ? "" : CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp() == null ? "" : CommonUtils.getClientIp()
|
||||
);
|
||||
}
|
||||
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandAuction,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
true,
|
||||
"",
|
||||
landAuction
|
||||
);
|
||||
|
||||
}catch(Exception e){
|
||||
log.error("InitLandAuction Delete Error: {}", e.getMessage());
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandAuction,
|
||||
MysqlConstants.TABLE_NAME_LAND_AUCTION,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
false,
|
||||
e.getMessage(),
|
||||
landAuction
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void initLandOwned(LandOwnerChange landOwnerChange){
|
||||
try {
|
||||
long id = landOwnerChange.getId();
|
||||
landMapper.initLandOwnedChanges(id);
|
||||
|
||||
mysqlHistoryLogService.deleteHistoryLog(
|
||||
HISTORYTYPE.LAND_OWNED_INITIALIZE,
|
||||
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
|
||||
HISTORYTYPE.LAND_OWNED_INITIALIZE.name(),
|
||||
landOwnerChange,
|
||||
CommonUtils.getAdmin() == null ? "" : CommonUtils.getAdmin().getEmail(),
|
||||
CommonUtils.getClientIp() == null ? "" : CommonUtils.getClientIp()
|
||||
);
|
||||
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandOwned,
|
||||
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
true,
|
||||
"",
|
||||
landOwnerChange
|
||||
);
|
||||
}catch(Exception e){
|
||||
log.error("initLandOwned Delete Error: {}", e.getMessage());
|
||||
dataInitializeHistoryService.mysqlDataInitHistory(
|
||||
EInitDataType.LandOwned,
|
||||
MysqlConstants.TABLE_NAME_LAND_OWNER_CHANGE,
|
||||
transactionIdManager.getCurrentTransactionId(),
|
||||
false,
|
||||
e.getMessage(),
|
||||
landOwnerChange
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public List<DataInit> getScheduleDataInitList(){
|
||||
return dataMapper.getDataInit();
|
||||
}
|
||||
|
||||
public void updateStatus(long id, DataInit.DATA_INIT_STATUS status){
|
||||
dataMapper.updateStatus(id, status.toString());
|
||||
}
|
||||
}
|
||||
@@ -2062,7 +2062,7 @@ public class DynamoDBService {
|
||||
|
||||
// LandAuctionRegistry 객체 생성
|
||||
LandAuctionRegistryDoc registry = new LandAuctionRegistryDoc();
|
||||
registry.setPK(DynamoDBConstants.PK_KEY_LAND_AUCTION);
|
||||
registry.setPK(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY);
|
||||
registry.setSK(String.format("%s#%s", landRequest.getLandId(), landRequest.getAuctionSeq()));
|
||||
registry.setDocType(DynamoDBConstants.DOC_LANDAUCTION);
|
||||
registry.setAttribValue(attrib);
|
||||
@@ -2083,7 +2083,7 @@ public class DynamoDBService {
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION)
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", landRequest.getLandId(), landRequest.getAuctionSeq()))
|
||||
.build();
|
||||
|
||||
@@ -2132,7 +2132,7 @@ public class DynamoDBService {
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION)
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", auctionInfo.getLandId(), auctionInfo.getAuctionSeq()))
|
||||
.build();
|
||||
|
||||
@@ -2298,7 +2298,7 @@ public class DynamoDBService {
|
||||
TableSchema.fromBean(LandAuctionRegistryDoc.class));
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION)
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", land_id, auction_seq))
|
||||
.build();
|
||||
|
||||
|
||||
@@ -711,6 +711,14 @@ public class LandService {
|
||||
return landMapper.getScheduleLandOwnedChangeList();
|
||||
}
|
||||
|
||||
public List<LandAuction> getAllLandAuctionList(){
|
||||
return landMapper.getAllLandAuction();
|
||||
}
|
||||
|
||||
public List<LandOwnerChange> getAllLandOwnerChangesList(){
|
||||
return landMapper.getAllLandOwnedChanges();
|
||||
}
|
||||
|
||||
public LandAuctionRegistryAttrib getLandAuctionRegistryAttrib(Integer land_id, Integer auction_seq){
|
||||
return dynamodbLandAuctionService.getLandAuctionRegistry(land_id, auction_seq);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user