zainali5120
2021-02-25 9219e18a9b2fb06b95b5c881b057d3fde7270ca3
src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
@@ -12,6 +12,7 @@
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.modules.platform.entity.PlatformTradeSettingEntity;
import com.xcong.excoin.rabbit.pricequeue.whole.HoldOrderDataModel;
import com.xcong.excoin.rabbit.pricequeue.whole.WholeDataQueue;
import com.xcong.excoin.rabbit.pricequeue.whole.WholePriceDataModel;
@@ -42,6 +43,9 @@
    private MemberDao memberDao;
    @Resource
    private MemberWalletContractDao memberWalletContractDao;
    @Resource
    private CacheSettingUtils cacheSettingUtils;
    /**
     * @param symbol
     * @param price
@@ -283,7 +287,6 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void wholeBomb() {
        Map<String, WholePriceDataModel> dataModelMap = WholeDataQueue.MAP;
        if (CollUtil.isEmpty(dataModelMap)) {
@@ -296,6 +299,8 @@
            if (CollUtil.isNotEmpty(list)) {
                BigDecimal totalProfitOrLoss = BigDecimal.ZERO;
                MemberEntity memberEntity = memberDao.selectById(Long.parseLong(entry.getKey()));
                Map<String, BigDecimal> prices = new HashMap<>();
                for (HoldOrderDataModel holdOrderData : list) {
                    String price = redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderData.getSymbol()));
@@ -311,6 +316,16 @@
                        // (开仓价-最新价)*规格*张数
                        rewardRatio = holdOrderData.getOpeningPrice().subtract(newPrice).multiply(holdOrderData.getSymbolSku()).multiply(new BigDecimal(holdOrderData.getSymbolCntSale()));
                    }
                    if (memberEntity.getIsProfit() == MemberEntity.IS_PROFIT_Y) {
                        PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting();
                        if (rewardRatio.compareTo(BigDecimal.ZERO) > -1) {
                            rewardRatio = rewardRatio.multiply(BigDecimal.ONE.subtract(tradeSettingEntity.getProfitParam()));
                        } else {
//                        rewardRatio = rewardRatio.multiply(BigDecimal.ONE.add(tradeSettingEntity.getProfitParam()));
                        }
                    }
                    holdOrderData.setRewardAmount(rewardRatio);
                    holdOrderData.setClosingPrice(newPrice);
                    totalProfitOrLoss = totalProfitOrLoss.add(rewardRatio).setScale(8, BigDecimal.ROUND_DOWN);
@@ -323,12 +338,20 @@
                    continue;
                }
                dataModelMap.remove(entry.getKey());
                redisUtils.set(AppContants.WHOLE_BOMB_MAP, JSONObject.toJSONString(dataModelMap));
                log.info("全仓爆仓触发:{}", JSONObject.toJSONString(wholePriceData));
                wholePriceData.setPrices(prices);
                contractHoldOrderDao.updateMemberAllHoldOrderClosingStatus(wholePriceData.getMemberId());
                orderProducer.sendWholeBomb(JSONObject.toJSONString(wholePriceData));
                log.info("过来过来");
                synchronized(this) {
                    log.info("爆仓啥的:{}", entry.getKey());
                    boolean b = redisUtils.setNotExist(AppContants.WHOLE_BOMB_PREFIX + entry.getKey(), 1, 5);
                    if (b) {
                        dataModelMap.remove(entry.getKey());
                        wholePriceData.setEquity(wholePriceData.getBalance().add(totalProfitOrLoss));
                        redisUtils.set(AppContants.WHOLE_BOMB_MAP, JSONObject.toJSONString(dataModelMap));
                        log.info("全仓爆仓触发:{}", JSONObject.toJSONString(wholePriceData));
                        wholePriceData.setPrices(prices);
                        contractHoldOrderDao.updateMemberAllHoldOrderClosingStatus(wholePriceData.getMemberId());
                        orderProducer.sendWholeBomb(JSONObject.toJSONString(wholePriceData));
                    }
                }
            }
        }
    }