문자 금액 체크 수정

This commit is contained in:
hehihoho3@gmail.com 2025-02-04 17:53:51 +09:00
parent 726a803e3e
commit 2ef4731e34

View File

@ -4111,7 +4111,10 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M
return statusResponse; return statusResponse;
} }
if (!isCashSufficient(mjonMsgVO)) { /*
* @ 금액체크
* */
if (!isCashSufficient(mjonMsgVO, mjonMsgSendVOList)) {
log.error("Insufficient balance for message sending."); log.error("Insufficient balance for message sending.");
return new StatusResponse(HttpStatus.BAD_REQUEST, "문자 발송에 필요한 보유 잔액이 부족 합니다."); return new StatusResponse(HttpStatus.BAD_REQUEST, "문자 발송에 필요한 보유 잔액이 부족 합니다.");
} }
@ -4476,7 +4479,7 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M
* *
* return statusResponse; } * return statusResponse; }
*/ */
/*
private Map<String, String> fncSendMsgRtnMap(MjonMsgVO mjonMsgVO) throws Exception { private Map<String, String> fncSendMsgRtnMap(MjonMsgVO mjonMsgVO) throws Exception {
Map<String, String> returnMap = new HashMap<String, String>(); Map<String, String> returnMap = new HashMap<String, String>();
@ -4525,7 +4528,7 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M
returnMap.put("resultBlockSts", Integer.toString(resultBlockSts)); returnMap.put("resultBlockSts", Integer.toString(resultBlockSts));
return returnMap; return returnMap;
} }*/
private void handleSpamMsg(MjonMsgVO mjonMsgVO) { private void handleSpamMsg(MjonMsgVO mjonMsgVO) {
try { try {
@ -4617,23 +4620,24 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M
} }
// 보유 금액이 충분한지 확인하는 메서드 // 보유 금액이 충분한지 확인하는 메서드
private boolean isCashSufficient(MjonMsgVO mjonMsgVO) throws Exception { private boolean isCashSufficient(MjonMsgVO mjonMsgVO, List<MjonMsgSendVO> mjonMsgSendVOList) throws Exception {
String userMoney = priceAndPoint.getBefCash(mjonMsgVO.getUserId()); String userMoney = priceAndPoint.getBefCash(mjonMsgVO.getUserId());
// 쉼표 제거 // 쉼표 제거
userMoney = userMoney.replace(",", ""); userMoney = userMoney.replace(",", "");
String totalPrice = mjonMsgVO.getTotPrice(); // 사용자 보유 금액 BigDecimal 변환 (HALF_EVEN 적용)
// 쉼표 제거
totalPrice = totalPrice.replace(",", "");
BigDecimal befCash = new BigDecimal(userMoney).setScale(2, RoundingMode.HALF_EVEN); BigDecimal befCash = new BigDecimal(userMoney).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal totMsgPrice = new BigDecimal(totalPrice).setScale(2, RoundingMode.HALF_EVEN);
// String userMoney = priceAndPoint.getBefCash(mjonMsgVO.getUserId()); // 메시지 금액 계산 (HALF_EVEN 적용)
// BigDecimal befCash = new BigDecimal(userMoney).setScale(2, RoundingMode.HALF_EVEN); BigDecimal totalEachPrice = mjonMsgSendVOList.stream()
// BigDecimal totMsgPrice = new BigDecimal(mjonMsgVO.getTotPrice()).setScale(2, RoundingMode.HALF_EVEN); .map(msg -> new BigDecimal(String.valueOf(msg.getEachPrice()))) // 변환 오류 방지
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_EVEN); // 일관성 유지
return befCash.compareTo(totMsgPrice) >= 0; // 비교 수행
return befCash.compareTo(totalEachPrice) >= 0;
} }
/** /**
@ -4788,7 +4792,6 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M
* *
* @throws Exception * @throws Exception
* *
*/
public StatusResponse fncSendMsg(MjonMsgVO mjonMsgVO) throws Exception { public StatusResponse fncSendMsg(MjonMsgVO mjonMsgVO) throws Exception {
log.info(" :: fncSendMsg :: "); log.info(" :: fncSendMsg :: ");
@ -4839,6 +4842,7 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M
log.info("Message sending process completed."); log.info("Message sending process completed.");
return new StatusResponse(HttpStatus.OK, "문자 전송이 완료되었습니다.", getReturnMap(resultSts, resultBlockSts)); return new StatusResponse(HttpStatus.OK, "문자 전송이 완료되었습니다.", getReturnMap(resultSts, resultBlockSts));
} }
*/
/** /**
* @param mjonMsgVO * @param mjonMsgVO