우편 칼리움 첨부 및 차감 처리

아이템 수량 타입 int > double 변경
This commit is contained in:
2025-02-24 17:47:42 +09:00
parent 1a19b21f9a
commit 01271cbf72
18 changed files with 564 additions and 57 deletions

View File

@@ -1362,7 +1362,7 @@ public class DynamoDBService {
UsersResponse.Item inventory = UsersResponse.Item.builder()
.itemId(CommonUtils.objectToString(item_id))
.itemName(item_nm)
.count(CommonUtils.objectToInteger(attrMap.get("item_stack_count")))
.count(CommonUtils.objectToDouble(attrMap.get("item_stack_count")))
.itemGuid(CommonUtils.objectToString(attrMap.get("item_guid")))
.build();
@@ -1415,7 +1415,7 @@ public class DynamoDBService {
for (Map<String,Object> val : (List<Map<String,Object>>)attrMap.get("item_list")){
UsersResponse.MailItem item = new UsersResponse.MailItem();
item.setItemId(CommonUtils.objectToString(val.get("ItemId")));
item.setCount(CommonUtils.objectToInteger(val.get("Count")));
item.setCount(CommonUtils.objectToDouble(val.get("Count")));
String item_nm = metaDataHandler.getMetaItemNameData(CommonUtils.objectToInteger(val.get("ItemId")));
item.setItemName(metaDataHandler.getTextStringData(item_nm));
itemList.add(item);
@@ -1485,7 +1485,7 @@ public class DynamoDBService {
}
// 유저 조회 - 우편 아이템 삭제
public JSONObject updateMailItem(String type, String guid, String mail_guid, Long itemId, int count, int newCount) {
public JSONObject updateMailItem(String type, String guid, String mail_guid, Long itemId, double count, double newCount) {
try {
Map<String, AttributeValue> item = null;
Map<String, AttributeValue> key = new HashMap<>();
@@ -1871,7 +1871,7 @@ public class DynamoDBService {
UsersResponse.Item item = UsersResponse.Item.builder()
.itemId(item_id)
.itemName(metaDataHandler.getTextStringData(item_name))
.count(CommonUtils.objectToInteger(attrMap2.get("item_stack_count")))
.count(CommonUtils.objectToDouble(attrMap2.get("item_stack_count")))
.itemGuid(CommonUtils.objectToString(attrMap2.get("item_guid")))
.build();
itemList.add(item);

View File

@@ -7,9 +7,11 @@ import com.caliverse.admin.domain.datacomponent.MetaDataHandler;
import com.caliverse.admin.domain.entity.*;
import com.caliverse.admin.domain.request.MailRequest;
import com.caliverse.admin.domain.response.MailResponse;
import com.caliverse.admin.dynamodb.service.DynamodbCaliumService;
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.exception.RestApiException;
import com.caliverse.admin.global.common.utils.CommonUtils;
import com.caliverse.admin.global.common.utils.ExcelUtils;
@@ -51,6 +53,20 @@ public class MailService {
private final ResourceLoader resourceLoader;
private final ScheduleService scheduleService;
private final HistoryService historyService;
private final DynamodbCaliumService dynamodbCaliumService;
public MailResponse getStockCalium(){
double stock_calium = dynamodbCaliumService.getCaliumTotal();
return MailResponse.builder()
.status(CommonCode.SUCCESS.getHttpStatus())
.result(CommonCode.SUCCESS.getResult())
.resultData(MailResponse.ResultData.builder()
.stockCalium(stock_calium)
.build()
)
.build();
}
public MailResponse getList(Map requestParam){
@@ -176,7 +192,7 @@ public class MailService {
guid = getGuid(guid, Mail.USERTYPE.NICKNAME.name());
if(guid == null || mailRequest.getGuid().equals(guid)){
log.error("postMail RECEIVETYPE Single Nickname Find Fail");
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNOMODB_CHECK.getMessage() );
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NICKNAME_CHECK.getMessage() );
}
}else if(mailRequest.getUserType().equals(Mail.USERTYPE.EMAIL)){
guid = getGuid(guid, Mail.USERTYPE.EMAIL.name());
@@ -192,7 +208,7 @@ public class MailService {
else{
mailRequest.setReceiveType(Mail.RECEIVETYPE.MULTIPLE);
if(mailRequest.getFileName() == null){
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.getMessage() ); //Excel 파일을 선택해주세요.
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NOT_EXIT_EXCEL.toString() ); //Excel 파일을 선택해주세요.
}
List<Excel> excelList = excelUtils.getExcelListData(mailRequest.getFileName());
for(Excel excel : excelList){
@@ -200,25 +216,25 @@ public class MailService {
case "GUID" -> {
if (dynamoDBService.isGuidChecked(excel.getUser())) {
log.error("postMail Multi Guid({}) Find Fail", excel.getUser());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.getMessage());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.GUID_CHECK.toString());
}
}
case "NICKNAME" -> {
String user = getGuid(excel.getUser(), Mail.USERTYPE.NICKNAME.name());
if (user == null || user.isEmpty()) {
log.error("postMail Multi Nickname({}) Find Fail", excel.getUser());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.DYNOMODB_CHECK.getMessage());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.NICKNAME_CHECK.toString());
}
}
case "EMAIL" -> {
String user = getGuid(excel.getUser(), Mail.USERTYPE.EMAIL.name());
if (user == null || user.isEmpty()) {
log.error("postMail Multi Email({}) Find Fail", excel.getUser());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.EMAIL_CHECK.getMessage());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.EMAIL_CHECK.toString());
}
}
default ->
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.USERTYPE_CHECK_EXCEL.getMessage()); //Excel 파일을 선택해주세요.
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.USERTYPE_CHECK_EXCEL.toString()); //Excel 파일을 선택해주세요.
}
}
mailRequest.setTarget(mailRequest.getFileName());
@@ -232,26 +248,37 @@ public class MailService {
//아이템 저장
if(mailRequest.getItemList()!= null && !mailRequest.getItemList().isEmpty()){
//칼리움일경우 수량체크
boolean hasCalium = mailRequest.getItemList().stream().anyMatch(item -> item.getItem().equals(CommonConstants.CALIUM_ITEM_CODE));
double caliumSum = 0;
if(hasCalium){
caliumSum = mailRequest.getItemList().stream()
.filter(item -> item.getItem().equals(CommonConstants.CALIUM_ITEM_CODE))
.mapToDouble(Item::getItemCnt)
.sum();
double stockCalium = dynamodbCaliumService.getCaliumTotal();
if(caliumSum > stockCalium){
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_MAIL_ITEM_CALIUM_OVER.toString());
}
}
mailRequest.getItemList().forEach(
item -> {
map.put("goodsId",item.getItem());
map.put("itemCnt",String.valueOf(item.getItemCnt()));
map.put("itemCnt", String.valueOf(item.getItemCnt()));
mailMapper.insertItem(map);
}
);
//재원저장소 칼리움 차감
if(hasCalium){
dynamodbCaliumService.caliumStockDeduction(caliumSum);
}
}
//자원 저장
// if(mailRequest.getResourceList()!= null && mailRequest.getResourceList().size() > 0){
// mailRequest.getResourceList().forEach(
// item -> {
// map.put("goodsId",item.getItem());
// map.put("itemCnt",String.valueOf(item.getItemCnt()));
// mailMapper.insertItem(map);
// }
// );
// }
//메시지 저장
if(mailRequest.getMailList()!= null && mailRequest.getMailList().size() > 0){
if(mailRequest.getMailList()!= null && !mailRequest.getMailList().isEmpty()){
mailRequest.getMailList().forEach(
item -> {
map.put("title",item.getTitle());