From ceada8262db96a725c0898d6f8a3b73fc8e7ccc0 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 02 Apr 2021 17:14:37 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java b/src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java
index f82fc86..f218e29 100644
--- a/src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java
@@ -40,6 +40,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
@@ -91,7 +92,7 @@
     private RedisUtils redisUtils;
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
+    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
     public void addFollowerOrder(Long id) {
         log.info("进入跟单处理逻辑 : {}", id);
         // 查询交易员订单
@@ -125,7 +126,7 @@
             for (FollowFollowerSettingEntity followerSetting : followerSettings) {
                 // 加redis锁,同一个用户不能同时触发两个跟单任务,否则会出现金额问题
                 while (true) {
-                    boolean flag = redisUtils.setNotExist(AppContants.MEMBER_HAS_FOLLOW + "_" + followerSetting.getMemberId(), "1", 1);
+                    boolean flag = redisUtils.setNotExist(AppContants.MEMBER_HAS_FOLLOW + "_" + followerSetting.getMemberId(), "1", 5);
 //                    List<Object> followerMemberId = redisUtils.lGet(AppContants.MEMBER_HAS_FOLLOW, 0, -1);
 //                    log.info("#跟单用户任务已存在:{}, 当前:{}#", followerMemberId, followerSetting.getMemberId());
 //                    log.info("#------->{}#", followerMemberId.contains(followerSetting.getMemberId().intValue()));
@@ -210,6 +211,34 @@
                     continue;
                 }
 
+                boolean flag = false;
+                while(true) {
+                    MemberWalletContractEntity updateEntity = new MemberWalletContractEntity();
+                    updateEntity.setAvailableBalance(prePaymentAmount.negate());
+                    updateEntity.setTotalBalance(openFeePrice.negate());
+                    updateEntity.setId(walletContract.getId());
+                    updateEntity.setVersion(walletContract.getVersion());
+                    log.info("==={}, {}===", walletContract.getAvailableBalance(), walletContract.getVersion());
+                    int i = memberWalletContractDao.updateWalletContractWithVersion(updateEntity);
+                    if (i > 0) {
+                        break;
+                    }
+
+                    walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(followerSetting.getMemberId(), CoinTypeEnum.USDT.name());
+                    if (prePaymentAmount.compareTo(walletContract.getAvailableBalance()) > -1) {
+                        log.info("可用金额不足");
+                        LogRecordUtils.insertFollowerNotice(followerSetting.getMemberId(), NoticeConstant.MONEY_NOT_ENOUGH_TITLE, StrUtil.format(NoticeConstant.MONEY_NOT_ENOUGH_CONTENT, followTraderInfoEntity.getNickname()));
+                        flag = true;
+                        break;
+                    }
+
+                    log.info("---{}, {}--", walletContract.getAvailableBalance(), walletContract.getVersion());
+                }
+
+                if (flag) {
+                    continue;
+                }
+
                 MemberEntity memberEntity = memberDao.selectById(followerSetting.getMemberId());
                 // 强平价
                 BigDecimal forceClosingPrice = CalculateUtil.getForceSetPrice(bondAmount, openPrice, symbolCnt, lotNumber, holdOrderEntity.getOpeningType(), memberEntity);
@@ -240,7 +269,7 @@
                 contractHoldOrderDao.insert(followHoldOrder);
                 int i = contractOrderDao.insert(contractOrderEntity);
                 if (i > 0) {
-                    memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId());
+//                    memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId());
 
                     FollowFollowerOrderRelationEntity relationEntity = new FollowFollowerOrderRelationEntity();
                     relationEntity.setIsShow(FollowFollowerOrderRelationEntity.IS_SHOW_Y);

--
Gitblit v1.9.1