Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 金额转分,程序上进行最大值判定,避免业务方无感知造成金额不可控问题 #106

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -613,4 +620,4 @@ public static <V> boolean isEmpty(Collection<V> collection) {
}


}
}