예전 dynamodb 방식 정리
This commit is contained in:
@@ -1664,122 +1664,6 @@ public class DynamoDBService {
|
||||
return resTatto;
|
||||
}
|
||||
|
||||
public String insertSystemMail(int id, ArrayNode titleList, ArrayNode textList, ArrayNode senderList, LocalDateTime start_dt, LocalDateTime end_dt, ArrayNode itemList) {
|
||||
try {
|
||||
|
||||
// Attrib에 저장할 JSON 생성
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode infoNode = objectMapper.createObjectNode();
|
||||
infoNode.put("attrib_type", DynamoDBConstants.ATTRIB_SYSTEMMAIL);
|
||||
infoNode.put("mail_id", id);
|
||||
infoNode.set("sender_nickname", senderList);
|
||||
infoNode.set("title", titleList);
|
||||
infoNode.set("text", textList);
|
||||
infoNode.put("start_time", CommonUtils.convertUTCDate(start_dt));
|
||||
infoNode.put("end_time", CommonUtils.convertUTCDate(end_dt));
|
||||
infoNode.set("item_list", itemList);
|
||||
|
||||
String infoJson = infoNode.toString();
|
||||
log.info("insertSystemMail SystemMetaMailAttrib: {}", infoJson);
|
||||
|
||||
// 추가 데이터
|
||||
Map<String, AttributeValue> itemValues = new HashMap<>();
|
||||
itemValues.put("PK", AttributeValue.builder().s(DynamoDBConstants.PK_KEY_SYSTEM_MAIL).build());
|
||||
itemValues.put("SK", AttributeValue.builder().s(String.valueOf(id)).build());
|
||||
itemValues.put("CreatedDateTime", AttributeValue.builder().s(CommonUtils.convertUTCDate(LocalDateTime.now())).build());
|
||||
itemValues.put("DeletedDateTime", AttributeValue.builder().s(DynamoDBConstants.MIN_DATE).build());
|
||||
itemValues.put("DocType", AttributeValue.builder().s(DynamoDBConstants.DOC_SYSTEMMAIL).build());
|
||||
itemValues.put("SystemMetaMailAttrib", AttributeValue.builder().s(infoJson).build());
|
||||
itemValues.put("RestoredDateTime", AttributeValue.builder().s(DynamoDBConstants.MIN_DATE).build());
|
||||
itemValues.put("UpdatedDateTime", AttributeValue.builder().s(CommonUtils.convertUTCDate(LocalDateTime.now())).build());
|
||||
|
||||
PutItemRequest putRequest = PutItemRequest.builder()
|
||||
.tableName(metaTable)
|
||||
.item(itemValues)
|
||||
.build();
|
||||
|
||||
dynamoDbClient.putItem(putRequest);
|
||||
|
||||
return itemValues.toString();
|
||||
} catch (Exception e) {
|
||||
log.error("insertSystemMail: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String deleteSystemMail(String id) {
|
||||
Map<String, AttributeValue> itemAttributes = new HashMap<>();
|
||||
itemAttributes.put("PK", AttributeValue.builder().s(DynamoDBConstants.PK_KEY_SYSTEM_MAIL).build());
|
||||
itemAttributes.put("SK", AttributeValue.builder().s(id).build());
|
||||
try {
|
||||
Map<String, AttributeValue> item = getItem(DynamoDBConstants.PK_KEY_SYSTEM_MAIL, id);
|
||||
|
||||
DeleteItemRequest request = DeleteItemRequest.builder()
|
||||
.tableName(metaTable)
|
||||
.key(itemAttributes)
|
||||
.build();
|
||||
|
||||
DeleteItemResponse response = dynamoDbClient.deleteItem(request);
|
||||
|
||||
if(response.sdkHttpResponse().isSuccessful())
|
||||
return item.toString();
|
||||
|
||||
return "";
|
||||
}catch (ConditionalCheckFailedException e) {
|
||||
log.error("deleteSystemMail Conditional check failed: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}catch(Exception e){
|
||||
log.error("deleteSystemMail: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String updateSystemMail(String id, ArrayNode titleList, ArrayNode textList, LocalDateTime start_dt, LocalDateTime end_dt, ArrayNode itemList) {
|
||||
try{
|
||||
|
||||
Map<String, AttributeValue> item = getItem(DynamoDBConstants.PK_KEY_SYSTEM_MAIL, id);
|
||||
|
||||
String InfoJson = item.get("SystemMetaMailAttrib").s();
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode infoNode = objectMapper.readTree(InfoJson);
|
||||
|
||||
((ObjectNode) infoNode).set("title", titleList);
|
||||
((ObjectNode) infoNode).set("text", textList);
|
||||
((ObjectNode) infoNode).put("start_time", CommonUtils.convertUTCDate(start_dt));
|
||||
((ObjectNode) infoNode).put("end_time", CommonUtils.convertUTCDate(end_dt));
|
||||
((ObjectNode) infoNode).set("item_list", itemList);
|
||||
|
||||
String updatedInfoJson = infoNode.toString();
|
||||
|
||||
Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
|
||||
expressionAttributeValues.put(":newAttrib", AttributeValue.builder().s(updatedInfoJson).build());
|
||||
|
||||
String updateExpression = "SET SystemMetaMailAttrib = :newAttrib";
|
||||
|
||||
UpdateItemRequest updateRequest = UpdateItemRequest.builder()
|
||||
.tableName(metaTable)
|
||||
.key(Map.of(
|
||||
"PK", AttributeValue.builder().s(DynamoDBConstants.PK_KEY_SYSTEM_MAIL).build(),
|
||||
"SK", AttributeValue.builder().s(id).build()))
|
||||
.updateExpression(updateExpression)
|
||||
.expressionAttributeValues(expressionAttributeValues)
|
||||
.returnValues(ReturnValue.ALL_NEW) // 업데이트 후의 값을 반환하려면 지정
|
||||
.build();
|
||||
|
||||
|
||||
dynamoDbClient.updateItem(updateRequest);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data(before)", InfoJson);
|
||||
jsonObject.put("data(after)", updatedInfoJson);
|
||||
return jsonObject.toString();
|
||||
}catch(Exception e){
|
||||
log.error("updateSystemMail: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
// 친구 목록
|
||||
public List<UsersResponse.Friend> getFriendList(String guid){
|
||||
List<UsersResponse.Friend> resList = new ArrayList<>();
|
||||
@@ -1885,454 +1769,4 @@ public class DynamoDBService {
|
||||
}
|
||||
return myhome;
|
||||
}
|
||||
|
||||
// 칼리움 수량
|
||||
public float getCaliumTotal(){
|
||||
try {
|
||||
float total = 0;
|
||||
Map<String, AttributeValue> response = getItem(DynamoDBConstants.PK_KEY_CALIUM, "empty");
|
||||
|
||||
AttributeValue attributeValue = response.get(DynamoDBConstants.ATTRIB_CALIUM);
|
||||
|
||||
if (attributeValue != null) {
|
||||
Map<String, AttributeValue> attrib = attributeValue.m();
|
||||
Map<String, AttributeValue> storageMap = attrib.get("calium_operator_storage").m();
|
||||
|
||||
total = Float.parseFloat(storageMap.get("operator_total_calium").n());
|
||||
}
|
||||
log.info("getCaliumTotal calium total: {}", total);
|
||||
return total;
|
||||
}catch (Exception e){
|
||||
log.error("getCaliumTotal: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String updateCaliumTotal(float caliumCnt) {
|
||||
try{
|
||||
Map<String, AttributeValue> item = getItem(DynamoDBConstants.PK_KEY_CALIUM, "empty");
|
||||
|
||||
String InfoJson = item.get(DynamoDBConstants.ATTRIB_CALIUM).m().toString();
|
||||
|
||||
float currentTotal = Float.parseFloat(item.get(DynamoDBConstants.ATTRIB_CALIUM).m().get("calium_operator_storage").m().get("operator_total_calium").n());
|
||||
float sumTotal = currentTotal + caliumCnt;
|
||||
log.info("updateCaliumTotal currentTotal: {}, newCaliumCnt: {}", currentTotal, caliumCnt);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS");
|
||||
String nowDateTime = LocalDateTime.now().format(formatter);
|
||||
|
||||
try {
|
||||
String updateExpression = "SET " + DynamoDBConstants.ATTRIB_CALIUM + ".calium_operator_storage.operator_total_calium = :newCalium, "
|
||||
+ DynamoDBConstants.ATTRIB_CALIUM + ".calium_operator_storage.operator_calium_fill_up_date = :newDate, "
|
||||
+ "UpdatedDateTime = :newDate";
|
||||
log.info("updateCaliumTotal update Query: {}", updateExpression);
|
||||
|
||||
Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
|
||||
expressionAttributeValues.put(":newCalium",
|
||||
AttributeValue.builder().n(String.valueOf(sumTotal)).build());
|
||||
expressionAttributeValues.put(":newDate",
|
||||
AttributeValue.builder().s(nowDateTime).build());
|
||||
|
||||
UpdateItemRequest updateRequest = UpdateItemRequest.builder()
|
||||
.tableName(metaTable)
|
||||
.key(Map.of(
|
||||
"PK", AttributeValue.builder().s(DynamoDBConstants.PK_KEY_CALIUM).build(),
|
||||
"SK", AttributeValue.builder().s("empty").build()))
|
||||
.updateExpression(updateExpression)
|
||||
.expressionAttributeValues(expressionAttributeValues)
|
||||
.returnValues(ReturnValue.ALL_NEW) // 업데이트 후의 값을 반환하려면 지정
|
||||
.build();
|
||||
|
||||
UpdateItemResponse updateResponse = dynamoDbClient.updateItem(updateRequest);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data(before)", InfoJson);
|
||||
jsonObject.put("data(after)", updateResponse.attributes().get(DynamoDBConstants.ATTRIB_CALIUM).m().toString());
|
||||
return jsonObject.toString();
|
||||
}catch(Exception e){
|
||||
log.error("updateCaliumTotal Error occurred during update. Rolling back to original value: {}", e.getMessage());
|
||||
|
||||
String updateExpression = "SET " + DynamoDBConstants.ATTRIB_CALIUM + ".calium_operator_storage.operator_total_calium = :oldAttrib";
|
||||
|
||||
Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
|
||||
expressionAttributeValues.put(":oldAttrib",
|
||||
AttributeValue.builder().n(String.valueOf(currentTotal)).build()); // 여기서 20은 새로운 값입니다
|
||||
|
||||
UpdateItemRequest updateRequest = UpdateItemRequest.builder()
|
||||
.tableName(metaTable)
|
||||
.key(Map.of(
|
||||
"PK", AttributeValue.builder().s(DynamoDBConstants.PK_KEY_CALIUM).build(),
|
||||
"SK", AttributeValue.builder().s("empty").build()))
|
||||
.updateExpression(updateExpression)
|
||||
.expressionAttributeValues(expressionAttributeValues)
|
||||
.returnValues(ReturnValue.ALL_NEW) // 업데이트 후의 값을 반환하려면 지정
|
||||
.build();
|
||||
|
||||
try{
|
||||
UpdateItemResponse updateResponse = dynamoDbClient.updateItem(updateRequest);
|
||||
}catch(Exception rollbackError){
|
||||
log.error("updateCaliumTotal Failed to rollback: {}", rollbackError.getMessage());
|
||||
throw rollbackError;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}catch(Exception e){
|
||||
log.error("updateCaliumTotal: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
// public String insertLandAuction(LandRequest landRequest) {
|
||||
// try {
|
||||
// LocalDateTime nowDate = LocalDateTime.now();
|
||||
//
|
||||
// // LandAuctionRegistryAttrib 객체 생성
|
||||
// LandAuctionRegistryAttrib attrib = new LandAuctionRegistryAttrib();
|
||||
// attrib.setLandMetaId(landRequest.getLandId());
|
||||
// attrib.setAuctionNumber(landRequest.getAuctionSeq());
|
||||
// attrib.setAuctionReservationNoticeStartTime(CommonUtils.convertUTCDate(landRequest.getResvStartDt()));
|
||||
// attrib.setBidCurrencyType(landRequest.getCurrencyType());
|
||||
// attrib.setAuctionStartTime(CommonUtils.convertUTCDate(landRequest.getAuctionStartDt()));
|
||||
// attrib.setAuctionEndTime(CommonUtils.convertUTCDate(landRequest.getAuctionEndDt()));
|
||||
// attrib.setBidStartPrice(landRequest.getStartPrice());
|
||||
// attrib.setIsCancelAuction(CommonConstants.FALSE);
|
||||
// attrib.setAuctionState(CommonConstants.NONE);
|
||||
// attrib.setAuctionResult(CommonConstants.NONE);
|
||||
// attrib.setRegisteredVersionTime(CommonUtils.convertUTCDate(nowDate));
|
||||
// attrib.setProcessVersionTime(DynamoDBConstants.MIN_DATE);
|
||||
//
|
||||
// // LandAuctionRegistry 객체 생성
|
||||
// LandAuctionRegistryDoc registry = new LandAuctionRegistryDoc();
|
||||
// registry.setPK(DynamoDBConstants.PK_KEY_LANDAUCTION);
|
||||
// registry.setSK(String.format("%s#%s", landRequest.getLandId(), landRequest.getAuctionSeq()));
|
||||
// registry.setDocType(DynamoDBConstants.DOC_LANDAUCTION);
|
||||
// registry.setAttribValue(attrib);
|
||||
// registry.setCreatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
// registry.setUpdatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
// registry.setDeletedDateTime(DynamoDBConstants.MIN_DATE);
|
||||
// registry.setRestoredDateTime(DynamoDBConstants.MIN_DATE);
|
||||
//
|
||||
// TableSchema<LandAuctionRegistryDoc> schema = TableSchema.fromBean(LandAuctionRegistryDoc.class);
|
||||
//
|
||||
// DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
//
|
||||
// table.putItem(registry);
|
||||
//
|
||||
// return registry.toString();
|
||||
//
|
||||
// } catch (DynamoDbException e) {
|
||||
// log.error("insertLandAuction Failed to insert new item: {}", e.getMessage());
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
// ErrorCode.DYNAMODB_INSERT_ERROR.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// log.error("insertLandAuction Error: {}", e.getMessage());
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
// ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
@DynamoDBTransaction
|
||||
public JSONObject insertLandAuctionRegistryWithActivity(LandRequest landRequest) {
|
||||
String registry_result = insertLandAuction(landRequest);
|
||||
String activity_result = upsertLandAuctionActive(landRequest);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("land_auction_registry_result", registry_result);
|
||||
jsonObject.put("land_auction_active_result", activity_result);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public String insertLandAuction(LandRequest landRequest) {
|
||||
LocalDateTime nowDate = LocalDateTime.now();
|
||||
|
||||
// LandAuctionRegistryAttrib 객체 생성
|
||||
LandAuctionRegistryAttrib attrib = new LandAuctionRegistryAttrib();
|
||||
attrib.setLandMetaId(landRequest.getLandId());
|
||||
attrib.setAuctionNumber(landRequest.getAuctionSeq());
|
||||
attrib.setAuctionReservationNoticeStartTime(CommonUtils.convertUTCDate(landRequest.getResvStartDt()));
|
||||
attrib.setBidCurrencyType(landRequest.getCurrencyType());
|
||||
attrib.setAuctionStartTime(CommonUtils.convertUTCDate(landRequest.getAuctionStartDt()));
|
||||
attrib.setAuctionEndTime(CommonUtils.convertUTCDate(landRequest.getAuctionEndDt()));
|
||||
attrib.setBidStartPrice(landRequest.getStartPrice());
|
||||
attrib.setIsCancelAuction(CommonConstants.FALSE);
|
||||
attrib.setAuctionState(CommonConstants.NONE);
|
||||
attrib.setAuctionResult(CommonConstants.NONE);
|
||||
attrib.setRegisteredVersionTime(CommonUtils.convertUTCDate(nowDate));
|
||||
attrib.setProcessVersionTime(DynamoDBConstants.MIN_DATE);
|
||||
|
||||
// LandAuctionRegistry 객체 생성
|
||||
LandAuctionRegistryDoc registry = new LandAuctionRegistryDoc();
|
||||
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);
|
||||
registry.setCreatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
registry.setUpdatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
registry.setDeletedDateTime(DynamoDBConstants.MIN_DATE);
|
||||
registry.setRestoredDateTime(DynamoDBConstants.MIN_DATE);
|
||||
|
||||
DynamoDBOperations.addPutItem(registry, LandAuctionRegistryDoc.class);
|
||||
|
||||
return registry.toString();
|
||||
}
|
||||
|
||||
public String updateLandAuction(LandRequest landRequest) {
|
||||
try {
|
||||
TableSchema<LandAuctionRegistryDoc> schema = TableSchema.fromBean(LandAuctionRegistryDoc.class);
|
||||
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", landRequest.getLandId(), landRequest.getAuctionSeq()))
|
||||
.build();
|
||||
|
||||
LandAuctionRegistryDoc existingRegistry = table.getItem(key);
|
||||
if (existingRegistry == null) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
|
||||
LandAuctionRegistryAttrib before = existingRegistry.getAttribValue();
|
||||
|
||||
// JSON을 객체로 변환하여 업데이트
|
||||
LandAuctionRegistryAttrib attrib = before;
|
||||
attrib.setAuctionReservationNoticeStartTime(CommonUtils.convertUTCDate(landRequest.getResvStartDt()));
|
||||
attrib.setAuctionStartTime(CommonUtils.convertUTCDate(landRequest.getAuctionStartDt()));
|
||||
attrib.setAuctionEndTime(CommonUtils.convertUTCDate(landRequest.getAuctionEndDt()));
|
||||
attrib.setBidStartPrice(landRequest.getStartPrice());
|
||||
attrib.setRegisteredVersionTime(CommonUtils.convertUTCDate(LocalDateTime.now()));
|
||||
|
||||
// Registry 업데이트
|
||||
existingRegistry.setAttribValue(attrib);
|
||||
existingRegistry.setUpdatedDateTime(CommonUtils.convertUTCDate(LocalDateTime.now()));
|
||||
|
||||
table.updateItem(existingRegistry);
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("data(before)", mapper.writeValueAsString(before));
|
||||
response.put("data(after)", mapper.writeValueAsString(attrib));
|
||||
return response.toString();
|
||||
|
||||
} catch (DynamoDbException e) {
|
||||
log.error("updateLandAuction Failed to update existing item: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.DYNAMODB_UPDATE_ERROR.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("updateLandAuction Error: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String cancelLandAuction(LandAuction auctionInfo) {
|
||||
try {
|
||||
TableSchema<LandAuctionRegistryDoc> schema = TableSchema.fromBean(LandAuctionRegistryDoc.class);
|
||||
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable, schema);
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", auctionInfo.getLandId(), auctionInfo.getAuctionSeq()))
|
||||
.build();
|
||||
|
||||
LandAuctionRegistryDoc existingRegistry = table.getItem(key);
|
||||
if (existingRegistry == null) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
|
||||
LandAuctionRegistryAttrib before = existingRegistry.getAttribValue();
|
||||
|
||||
// JSON을 객체로 변환하여 업데이트
|
||||
LandAuctionRegistryAttrib attrib = before;
|
||||
attrib.setIsCancelAuction(CommonConstants.TRUE);
|
||||
attrib.setAuctionResult(ELandAuctionResult.CANCELED.getName());
|
||||
attrib.setRegisteredVersionTime(CommonUtils.convertUTCDate(LocalDateTime.now()));
|
||||
|
||||
// Registry 업데이트
|
||||
existingRegistry.setAttribValue(attrib);
|
||||
existingRegistry.setUpdatedDateTime(CommonUtils.convertUTCDate(LocalDateTime.now()));
|
||||
|
||||
table.updateItem(existingRegistry);
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("data(before)", mapper.writeValueAsString(before));
|
||||
response.put("data(after)", mapper.writeValueAsString(attrib));
|
||||
return response.toString();
|
||||
|
||||
} catch (DynamoDbException e) {
|
||||
log.error("cancelLandAuction Failed to update existing item: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.DYNAMODB_UPDATE_ERROR.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("cancelLandAuction Error: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String upsertLandAuctionActive(LandRequest landRequest){
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_ACTIVE)
|
||||
.sortValue(landRequest.getLandId().toString())
|
||||
.build();
|
||||
|
||||
LandAuctionActivityDoc item = DynamoDBOperations.getItem(key, LandAuctionActivityDoc.class);
|
||||
|
||||
String resultJson;
|
||||
|
||||
if (item == null) {
|
||||
resultJson = insertLandAuctionActive(landRequest);
|
||||
}else{
|
||||
resultJson = updateLandAuctionActive(landRequest, item);
|
||||
}
|
||||
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
public String insertLandAuctionActive(LandRequest landRequest){
|
||||
LocalDateTime nowDate = LocalDateTime.now();
|
||||
|
||||
LandAuctionActivityAttrib attrib = new LandAuctionActivityAttrib();
|
||||
attrib.setLandMetaId(landRequest.getLandId());
|
||||
attrib.setAuctionNumber(landRequest.getAuctionSeq());
|
||||
|
||||
LandAuctionActivityDoc activityDoc = new LandAuctionActivityDoc();
|
||||
activityDoc.setPK(DynamoDBConstants.PK_KEY_LAND_AUCTION_ACTIVE);
|
||||
activityDoc.setSK(landRequest.getLandId().toString());
|
||||
activityDoc.setDocType(DynamoDBConstants.DOC_LANDAUCTION_ACTIVE);
|
||||
activityDoc.setAttribValue(attrib);
|
||||
activityDoc.setCreatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
activityDoc.setUpdatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
|
||||
DynamoDBOperations.addPutItem(activityDoc, LandAuctionActivityDoc.class);
|
||||
|
||||
try {
|
||||
return mapper.writeValueAsString(activityDoc.getAttribValue());
|
||||
}catch(JsonProcessingException e){
|
||||
log.error("insertLandAuctionActive JsonProcessingException: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_JSON_PARSE_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String updateLandAuctionActive(LandRequest landRequest, LandAuctionActivityDoc existingDoc){
|
||||
LandAuctionActivityAttrib attrib = existingDoc.getAttribValue();
|
||||
attrib.setAuctionNumber(landRequest.getAuctionSeq());
|
||||
|
||||
existingDoc.setAttribValue(attrib);
|
||||
existingDoc.setUpdatedDateTime(CommonUtils.convertUTCDate(LocalDateTime.now()));
|
||||
|
||||
DynamoDBOperations.addUpdateItem(existingDoc, LandAuctionActivityDoc.class);
|
||||
|
||||
try {
|
||||
return mapper.writeValueAsString(existingDoc.getAttribValue());
|
||||
}catch(JsonProcessingException e){
|
||||
log.error("updateLandAuctionActive JsonProcessingException: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_JSON_PARSE_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// public String insertLandAuctionActive(LandRequest landRequest) {
|
||||
// try {
|
||||
// TableSchema<LandAuctionActivityDoc> schema = TableSchema.fromBean(LandAuctionActivityDoc.class);
|
||||
//
|
||||
// DynamoDbTable<LandAuctionActivityDoc> table = enhancedClient.table(metaTable, schema);
|
||||
// LocalDateTime nowDate = LocalDateTime.now();
|
||||
//
|
||||
// Key key = Key.builder()
|
||||
// .partitionValue(DynamoDBConstants.PK_KEY_LANDAUCTION_ACTIVE)
|
||||
// .sortValue(landRequest.getLandId().toString())
|
||||
// .build();
|
||||
//
|
||||
// LandAuctionActivityDoc activity = table.getItem(key);
|
||||
// String resultJson;
|
||||
//
|
||||
// if (activity == null) {
|
||||
// // 새로운 데이터 생성
|
||||
// LandAuctionActivityAttrib attrib = new LandAuctionActivityAttrib();
|
||||
// attrib.setLandMetaId(landRequest.getLandId());
|
||||
// attrib.setAuctionNumber(landRequest.getAuctionSeq());
|
||||
//
|
||||
// activity = new LandAuctionActivityDoc();
|
||||
// activity.setPK(DynamoDBConstants.PK_KEY_LANDAUCTION_ACTIVE);
|
||||
// activity.setSK(landRequest.getLandId().toString());
|
||||
// activity.setDocType(DynamoDBConstants.DOC_LANDAUCTION_ACTIVE);
|
||||
// activity.setAttribValue(attrib);
|
||||
// activity.setCreatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
// activity.setUpdatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
//// activity.setDeletedDateTime(DynamoDBConstants.MIN_DATE);
|
||||
//// activity.setRestoredDateTime(DynamoDBConstants.MIN_DATE);
|
||||
//
|
||||
// table.putItem(activity);
|
||||
// resultJson = mapper.writeValueAsString(attrib);
|
||||
//
|
||||
// } else {
|
||||
// // 기존 데이터 업데이트
|
||||
// LandAuctionActivityAttrib attrib = activity.getAttribValue();
|
||||
// attrib.setAuctionNumber(landRequest.getAuctionSeq());
|
||||
//
|
||||
// activity.setAttribValue(attrib);
|
||||
// activity.setUpdatedDateTime(CommonUtils.convertUTCDate(nowDate));
|
||||
//
|
||||
// table.updateItem(activity);
|
||||
// resultJson = mapper.writeValueAsString(attrib);
|
||||
// }
|
||||
//
|
||||
// return resultJson;
|
||||
//
|
||||
// } catch (DynamoDbException e) {
|
||||
// log.error("insertLandAuctionActive DB operation failed: {}", e.getMessage());
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
// ErrorCode.DYNAMODB_INSERT_ERROR.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// log.error("insertLandAuctionActive Fail: {}", e.getMessage());
|
||||
// throw new RestApiException(CommonCode.ERROR.getHttpStatus(),
|
||||
// ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
public LandAuctionRegistryAttrib getLandAuctionRegistry(Integer land_id, Integer auction_seq){
|
||||
try {
|
||||
DynamoDbTable<LandAuctionRegistryDoc> table = enhancedClient.table(metaTable,
|
||||
TableSchema.fromBean(LandAuctionRegistryDoc.class));
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_REGISTRY)
|
||||
.sortValue(String.format("%s#%s", land_id, auction_seq))
|
||||
.build();
|
||||
|
||||
LandAuctionRegistryDoc registry = table.getItem(key);
|
||||
if (registry == null) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
|
||||
return registry.getAttribValue();
|
||||
}catch (Exception e){
|
||||
log.error("getLandAuctionRegistry: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public LandAuctionHighestBidUserAttrib getLandAuctionHighestUser(Integer land_id, Integer auction_seq){
|
||||
try {
|
||||
DynamoDbTable<LandAuctionHighestBidUserDoc> table = enhancedClient.table(metaTable,
|
||||
TableSchema.fromBean(LandAuctionHighestBidUserDoc.class));
|
||||
|
||||
Key key = Key.builder()
|
||||
.partitionValue(DynamoDBConstants.PK_KEY_LAND_AUCTION_HIGHEST_USER)
|
||||
.sortValue(String.format("%s#%s", land_id, auction_seq))
|
||||
.build();
|
||||
|
||||
LandAuctionHighestBidUserDoc highestBidUser = table.getItem(key);
|
||||
if (highestBidUser == null) {
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
|
||||
return highestBidUser.getAttribValue();
|
||||
}catch (Exception e){
|
||||
log.error("getLandAuctionHighestUser: {}", e.getMessage());
|
||||
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNAMODB_CONNECTION_ERROR.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,23 +358,6 @@ public class EventService {
|
||||
.build();
|
||||
}
|
||||
|
||||
public void insertSystemMail(Event event, ArrayNode mailTitleArray, ArrayNode mailTextArray, ArrayNode mailSenderArray, ArrayNode mailItemArray){
|
||||
String dynamoResult = dynamoDBService.insertSystemMail(
|
||||
event.getId().intValue(),
|
||||
mailTitleArray,
|
||||
mailTextArray,
|
||||
mailSenderArray,
|
||||
event.getStartDt(),
|
||||
event.getEndDt(),
|
||||
mailItemArray
|
||||
);
|
||||
|
||||
eventMapper.updateAddFlag(event.getId());
|
||||
|
||||
historyService.setScheduleLog(HISTORYTYPE.EVENT_ADD, dynamoResult);
|
||||
log.info("insertSystemMail Save Complete: {}", dynamoResult);
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void insertSystemMail(Event event){
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user