From 6a615efb2051fee8aa119ffc9e6fa0c991c7758c Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 22 Jan 2021 17:25:59 +0800
Subject: [PATCH] 20210122
---
src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java | 32 ++++++++++++++++++++++----------
1 files changed, 22 insertions(+), 10 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..ed20d89 100644
--- a/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
+++ b/src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
@@ -1,6 +1,8 @@
package com.xcong.excoin.rabbit.pricequeue;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
@@ -11,10 +13,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 +291,35 @@
if (CollUtil.isNotEmpty(holdOrderEntities)) {
BigDecimal totalProfitOrLess = BigDecimal.ZERO;
+ Map<String, Object> priceMap = new HashMap<>();
for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) {
- BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol());
- BigDecimal profitOrLess = CalculateUtil.calOrderProfitOrLess(holdOrderEntity.getOpeningType(), new BigDecimal(price), holdOrderEntity.getOpeningPrice(), lotNumber, holdOrderEntity.getSymbolCntSale(), memberEntity.getIsProfit());
+ String currentPrice = redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()));
+ priceMap.put(holdOrderEntity.getSymbol(), currentPrice);
+ BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol());
+ 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);
- if (sub.compareTo(BigDecimal.ZERO) <= 0) {
+ BigDecimal sub = wallet.getTotalBalance().add(totalProfitOrLess);
+ BigDecimal target = wallet.getTotalBalance().multiply(BigDecimal.valueOf(0.01));
+// log.info("sub : {}, target : {}", sub, target);
+ if (sub.compareTo(target) <= 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);
+
+ String key = AppContants.WHOLE_BOMB_PREFIX + memberId;
+ Map<Object, Object> value = redisUtils.hmget(key);
+ if (MapUtil.isEmpty(value)) {
+ log.info("priceMap -- {}", priceMap);
+ orderProducer.sendWholeBomb(content);
+ contractHoldOrderDao.updateMemberAllHoldOrderClosingStatus(memberId);
+
+ redisUtils.hmset(key, priceMap);
+ }
}
}
}
--
Gitblit v1.9.1