From cf62910fb3288aa84f81862aa26abb3bb3252ed4 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 03 Jun 2021 11:33:37 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java | 8 +++++---
src/test/java/com/xcong/excoin/OtcTest.java | 8 ++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
index 45596b1..e925174 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
@@ -99,8 +99,9 @@
throw new GlobalException("剩余数量不足");
}
- BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice()).setScale(2,BigDecimal.ROUND_DOWN);;
- if (cny.compareTo(orderAddDto.getCnyAmount()) != 0) {
+ BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice()).setScale(2, BigDecimal.ROUND_DOWN);
+ BigDecimal usdt = orderAddDto.getCnyAmount().divide(entrustOrder.getUnitPrice(), 2, BigDecimal.ROUND_DOWN);
+ if (cny.compareTo(orderAddDto.getCnyAmount()) != 0 && usdt.compareTo(orderAddDto.getUsdtAmount()) != 0) {
throw new GlobalException("数量与金额不符");
}
/**
@@ -201,7 +202,8 @@
}
BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice());
- if (cny.compareTo(orderAddDto.getCnyAmount()) != 0) {
+ BigDecimal usdt = orderAddDto.getCnyAmount().divide(entrustOrder.getUnitPrice(), 2, BigDecimal.ROUND_DOWN);
+ if (cny.compareTo(orderAddDto.getCnyAmount()) != 0 && usdt.compareTo(orderAddDto.getUsdtAmount()) != 0) {
throw new GlobalException("数量与金额不符");
}
diff --git a/src/test/java/com/xcong/excoin/OtcTest.java b/src/test/java/com/xcong/excoin/OtcTest.java
index b288801..c939525 100644
--- a/src/test/java/com/xcong/excoin/OtcTest.java
+++ b/src/test/java/com/xcong/excoin/OtcTest.java
@@ -102,4 +102,12 @@
memberPaymentMethodDao.insert(memberPaymentMethodEntity);
}
}
+
+ @Test
+ public void bigdecimalTest() {
+ BigDecimal one = BigDecimal.valueOf(6.39);
+ BigDecimal two = BigDecimal.valueOf(15.64);
+
+ System.out.println(one.multiply(two));
+ }
}
--
Gitblit v1.9.1