From b28e9c58f084b152e15e85a6925a3b80f9d7c31b Mon Sep 17 00:00:00 2001 From: snowball Date: Sun, 21 Apr 2024 13:56:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=91=E9=A2=9D=E8=BD=AC=E5=88=86?= =?UTF-8?q?=EF=BC=8C=E7=A8=8B=E5=BA=8F=E4=B8=8A=E8=BF=9B=E8=A1=8C=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=80=BC=E5=88=A4=E5=AE=9A=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=96=B9=E6=97=A0=E6=84=9F=E7=9F=A5=E9=80=A0?= =?UTF-8?q?=E6=88=90=E9=87=91=E9=A2=9D=E4=B8=8D=E5=8F=AF=E6=8E=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/egzosn/pay/common/util/Util.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java b/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java index 53b9ae5a..f730aa9b 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java @@ -1,7 +1,10 @@ package com.egzosn.pay.common.util; +import com.egzosn.pay.common.bean.result.PayException; +import com.egzosn.pay.common.exception.PayErrorException; import java.math.BigDecimal; import java.math.BigInteger; +import java.math.RoundingMode; import java.util.Collection; import java.util.Map; @@ -590,7 +593,11 @@ public static byte[] subByte(byte[] input, int startIndex, int length) { * @return 分的金额 */ public static int conversionCentAmount(BigDecimal amount) { - return amount.multiply(HUNDRED).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); + final BigDecimal decimal = amount.multiply(HUNDRED).setScale(0, RoundingMode.HALF_UP); + if (decimal.longValue() > (long) Integer.MAX_VALUE) { + throw new PayErrorException(new PayException("illegal parameter", "订单金额过大")); + } + return decimal.intValue(); } /** @@ -613,4 +620,4 @@ public static boolean isEmpty(Collection collection) { } -} \ No newline at end of file +}