From cbff0dab05c73b38616d65225b093ac75c639b78 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 08 Sep 2020 10:22:01 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java b/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
index 71dafb0..1f84e53 100644
--- a/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
+++ b/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
@@ -11,10 +11,7 @@
 import com.xcong.excoin.modules.member.entity.MemberEntity;
 import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
 import com.xcong.excoin.rabbit.producer.OrderProducer;
-import com.xcong.excoin.utils.CacheSettingUtils;
-import com.xcong.excoin.utils.CalculateUtil;
-import com.xcong.excoin.utils.RedisUtils;
-import com.xcong.excoin.utils.SpringContextHolder;
+import com.xcong.excoin.utils.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -292,22 +289,29 @@
 
                 if (CollUtil.isNotEmpty(holdOrderEntities)) {
                     BigDecimal totalProfitOrLess = BigDecimal.ZERO;
+                    String currentPrice = null;
                     for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) {
+                        if (symbol.equalsIgnoreCase(holdOrderEntity.getSymbol())) {
+                            currentPrice = price;
+                        } else {
+                            currentPrice = redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()));
+                        }
                         BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol());
-                        BigDecimal profitOrLess = CalculateUtil.calOrderProfitOrLess(holdOrderEntity.getOpeningType(), new BigDecimal(price), holdOrderEntity.getOpeningPrice(), lotNumber, holdOrderEntity.getSymbolCntSale(), memberEntity.getIsProfit());
-
+                        BigDecimal profitOrLess = CalculateUtil.calOrderProfitOrLess(holdOrderEntity.getOpeningType(), new BigDecimal(currentPrice), holdOrderEntity.getOpeningPrice(), lotNumber, holdOrderEntity.getSymbolCntSale(), memberEntity.getIsProfit());
                         totalProfitOrLess = totalProfitOrLess.add(profitOrLess);
                     }
-
                     MemberWalletContractEntity wallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, CoinTypeEnum.USDT.name());
 
-                    BigDecimal sub = wallet.getTotalBalance().subtract(totalProfitOrLess);
+                    BigDecimal sub = wallet.getTotalBalance().add(totalProfitOrLess);
+                    log.info("sub : {}, memberId : {}", sub, memberId);
                     if (sub.compareTo(BigDecimal.ZERO) <= 0) {
                         List<OrderModel> list = new ArrayList<>();
                         OrderModel orderModel = new OrderModel(null, 0, price, symbol, memberId);
                         list.add(orderModel);
                         String content = JSONObject.toJSONString(list);
-//                        orderProducer.sendWholeBomb(content);
+                        orderProducer.sendWholeBomb(content);
+
+                        contractHoldOrderDao.updateMemberAllHoldOrderClosingStatus(memberId);
                     }
                 }
             }

--
Gitblit v1.9.1