우편 칼리움 첨부 및 차감 처리
아이템 수량 타입 int > double 변경
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user