|
@@ -5,6 +5,7 @@
|
|
|
|
|
|
package ieven.server.webapp.util;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.ArrayList;
|
|
@@ -66,4 +67,29 @@ public class Common {
|
|
|
|
|
|
return sb.toString();
|
|
|
}
|
|
|
+
|
|
|
+ public static BigDecimal addMoney(BigDecimal oMoney, Object money) {
|
|
|
+ try {
|
|
|
+ if (money == null) {
|
|
|
+ return oMoney.add(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试将 money 转换为 Number 类型
|
|
|
+ if (money instanceof Number) {
|
|
|
+ return oMoney.add(new BigDecimal(((Number) money).doubleValue()));
|
|
|
+ } else if (money instanceof String) {
|
|
|
+ String str = (String) money;
|
|
|
+ if (str.isEmpty()) {
|
|
|
+ return oMoney.add(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ // 尝试解析字符串
|
|
|
+ return oMoney.add(new BigDecimal(str));
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 如果无法转换或解析,返回 0
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ // 如果 money 是其他类型,默认返回 0
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
}
|