From 25aec7899b8ab3d483bbfd6d7580c6966318ee7f Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 01 Jun 2021 11:19:31 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 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 2ed558d..38de88b 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
@@ -32,6 +32,7 @@
 import com.xcong.excoin.modules.otc.vo.BuyOrderDetailVo;
 import com.xcong.excoin.modules.otc.vo.OrderListVo;
 import com.xcong.excoin.modules.otc.vo.SaleOrderDetailVo;
+import com.xcong.excoin.rabbit.producer.OtcProducter;
 import com.xcong.excoin.utils.RedisUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -57,12 +58,15 @@
     private final OtcBlackListDao otcBlackListDao;
     private final OtcSettingDao otcSettingDao;
     private final RedisUtils redisUtils;
+    private final OtcProducter otcProducter;
 
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Result buyOrder(OtcOrderAddDto orderAddDto) {
         MemberEntity member = LoginUserUtils.getAppLoginUser();
+
+//        MemberEntity member = memberDao.selectById(445L);
         OtcEntrustOrder entrustOrder = otcEntrustOrderDao.selectById(orderAddDto.getId());
         if (entrustOrder == null) {
             throw new GlobalException("委托单不存在");
@@ -95,7 +99,7 @@
             throw new GlobalException("剩余数量不足");
         }
 
-        BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice());
+        BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice()).setScale(2,BigDecimal.ROUND_DOWN);;
         if (cny.compareTo(orderAddDto.getCnyAmount()) != 0) {
             throw new GlobalException("数量与金额不符");
         }
@@ -107,7 +111,7 @@
         objectQueryWrapper.lt("status",OtcOrder.STATUS_PAY);
         List<OtcOrder> otcOrders = this.baseMapper.selectList(objectQueryWrapper);
         if(CollUtil.isNotEmpty(otcOrders)){
-            if(otcOrders.size() > 3){
+            if(otcOrders.size() >= 3){
                 throw new GlobalException("最多可同时有三个待付款订单");
             }
         }
@@ -313,6 +317,7 @@
         memberWalletCoinDao.reduceFrozenBalance(saleWallet.getId(), buyOrder.getCoinAmount());
 
         this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_FINISH, null, otcOrder.getOrderNo());
+        otcProducter.sendMarketBussinessMsg(otcOrder.getEntrustOrderId(), OtcOrder.STATUS_FINISH);
     }
 
     @Override
@@ -462,6 +467,8 @@
 
         otcEntrustOrderDao.updateRemainAmount(otcOrder.getEntrustOrderId(), otcOrder.getCoinAmount());
         this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_CANCEL, null, otcOrder.getOrderNo());
+
+        otcProducter.sendMarketBussinessMsg(otcOrder.getEntrustOrderId(), OtcOrder.STATUS_CANCEL);
     }
 
     @Override

--
Gitblit v1.9.1