From 8318f10556a4b0e093fbbb4055c5646bcb49e2ba Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 26 Jan 2021 11:45:40 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java | 67 ++++++++++++++++++++++++++++++++-
1 files changed, 64 insertions(+), 3 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 e04f7e5..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,16 +1,26 @@
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;
+import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
+import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
+import com.xcong.excoin.modules.member.dao.MemberDao;
+import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
+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.RedisUtils;
+import com.xcong.excoin.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
+import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
@@ -22,7 +32,12 @@
OrderProducer orderProducer;
@Resource
private RedisUtils redisUtils;
-
+ @Resource
+ private ContractHoldOrderDao contractHoldOrderDao;
+ @Resource
+ private MemberDao memberDao;
+ @Resource
+ private MemberWalletContractDao memberWalletContractDao;
/**
* @param symbol
* @param price
@@ -78,7 +93,7 @@
}
private void addExecType(OrderModel model) {
- List<Object> orderTypes = redisUtils.lGet(AppContants.RABBIT_TYPE + model.getOrderId(), 0 , -1);
+ List<Object> orderTypes = redisUtils.lGet(AppContants.RABBIT_TYPE + model.getOrderId(), 0, -1);
if (CollUtil.isNotEmpty(orderTypes)) {
orderTypes.add(model.getType());
} else {
@@ -264,4 +279,50 @@
}
}
+
+ public void wholeBomb(String symbol, String price) {
+ List<Long> memberIds = contractHoldOrderDao.selectMemberHasWholeOrder();
+ CacheSettingUtils cacheSettingUtils = SpringContextHolder.getBean(CacheSettingUtils.class);
+
+ if (CollUtil.isNotEmpty(memberIds)) {
+ for (Long memberId : memberIds) {
+ List<ContractHoldOrderEntity> holdOrderEntities = contractHoldOrderDao.selectHoldOrderListByMemberId(memberId);
+ MemberEntity memberEntity = memberDao.selectById(memberId);
+
+ if (CollUtil.isNotEmpty(holdOrderEntities)) {
+ BigDecimal totalProfitOrLess = BigDecimal.ZERO;
+ Map<String, Object> priceMap = new HashMap<>();
+ for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) {
+ 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().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);
+
+ 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