diff --git a/src/main/java/itn/let/mjo/msgdata/service/impl/MjonMsgDataServiceImpl.java b/src/main/java/itn/let/mjo/msgdata/service/impl/MjonMsgDataServiceImpl.java index 63db111d..b2dcab5c 100644 --- a/src/main/java/itn/let/mjo/msgdata/service/impl/MjonMsgDataServiceImpl.java +++ b/src/main/java/itn/let/mjo/msgdata/service/impl/MjonMsgDataServiceImpl.java @@ -4111,7 +4111,10 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M return statusResponse; } - if (!isCashSufficient(mjonMsgVO)) { + /* + * @ 금액체크 + * */ + if (!isCashSufficient(mjonMsgVO, mjonMsgSendVOList)) { log.error("Insufficient balance for message sending."); return new StatusResponse(HttpStatus.BAD_REQUEST, "문자 발송에 필요한 보유 잔액이 부족 합니다."); } @@ -4476,7 +4479,7 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M * * return statusResponse; } */ - +/* private Map fncSendMsgRtnMap(MjonMsgVO mjonMsgVO) throws Exception { Map returnMap = new HashMap(); @@ -4525,7 +4528,7 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M returnMap.put("resultBlockSts", Integer.toString(resultBlockSts)); return returnMap; - } + }*/ private void handleSpamMsg(MjonMsgVO mjonMsgVO) { 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 mjonMsgSendVOList) throws Exception { + + String userMoney = priceAndPoint.getBefCash(mjonMsgVO.getUserId()); // 쉼표 제거 userMoney = userMoney.replace(",", ""); - String totalPrice = mjonMsgVO.getTotPrice(); - // 쉼표 제거 - totalPrice = totalPrice.replace(",", ""); - + // 사용자 보유 금액 BigDecimal 변환 (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()); -// BigDecimal befCash = new BigDecimal(userMoney).setScale(2, RoundingMode.HALF_EVEN); -// BigDecimal totMsgPrice = new BigDecimal(mjonMsgVO.getTotPrice()).setScale(2, RoundingMode.HALF_EVEN); + // 총 메시지 금액 계산 (HALF_EVEN 적용) + BigDecimal totalEachPrice = mjonMsgSendVOList.stream() + .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 * - */ public StatusResponse fncSendMsg(MjonMsgVO mjonMsgVO) throws Exception { log.info(" :: fncSendMsg :: "); @@ -4839,6 +4842,7 @@ public class MjonMsgDataServiceImpl extends EgovAbstractServiceImpl implements M log.info("Message sending process completed."); return new StatusResponse(HttpStatus.OK, "문자 전송이 완료되었습니다.", getReturnMap(resultSts, resultBlockSts)); } + */ /** * @param mjonMsgVO