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

---
 src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 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 b82aa7a..f82fc86 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
@@ -92,7 +92,7 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void addFollowerOrder(Long id) throws InterruptedException {
+    public void addFollowerOrder(Long id) {
         log.info("进入跟单处理逻辑 : {}", id);
         // 查询交易员订单
         ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectById(id);
@@ -124,19 +124,24 @@
             List<Object> hasExist = new ArrayList<>();
             for (FollowFollowerSettingEntity followerSetting : followerSettings) {
                 // 加redis锁,同一个用户不能同时触发两个跟单任务,否则会出现金额问题
-                while(true) {
-                    List<Object> followerMemberId =  redisUtils.lGet(AppContants.MEMBER_HAS_FOLLOW, 0, -1);
-                    log.info("#跟单用户任务已存在:{}, 当前:{}#", followerMemberId, followerSetting.getMemberId());
-                    log.info("#------->{}#", followerMemberId.contains(followerSetting.getMemberId().intValue()));
-                    if (CollUtil.isEmpty(followerMemberId) || !followerMemberId.contains(followerSetting.getMemberId().intValue())) {
+                while (true) {
+                    boolean flag = redisUtils.setNotExist(AppContants.MEMBER_HAS_FOLLOW + "_" + followerSetting.getMemberId(), "1", 1);
+//                    List<Object> followerMemberId = redisUtils.lGet(AppContants.MEMBER_HAS_FOLLOW, 0, -1);
+//                    log.info("#跟单用户任务已存在:{}, 当前:{}#", followerMemberId, followerSetting.getMemberId());
+//                    log.info("#------->{}#", followerMemberId.contains(followerSetting.getMemberId().intValue()));
+//                    if (CollUtil.isEmpty(followerMemberId) || !followerMemberId.contains(followerSetting.getMemberId().intValue())) {
+//                        log.info("跳出");
+//                        hasExist.add(followerSetting.getMemberId());
+//                        redisUtils.lSet(AppContants.MEMBER_HAS_FOLLOW, hasExist);
+//                        break;
+//                    }
+
+                    if (flag) {
                         log.info("跳出");
-                        hasExist.add(followerSetting.getMemberId());
-                        redisUtils.lSet(AppContants.MEMBER_HAS_FOLLOW, hasExist);
                         break;
                     }
-
                     try {
-                        Thread.sleep(1000);
+                        Thread.sleep(500);
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     }
@@ -198,6 +203,7 @@
 
                 // 预付款
                 BigDecimal prePaymentAmount = bondAmount.add(openFeePrice).add(openFeePrice);
+                log.info("可用的余额:{}, {}", prePaymentAmount, walletContract.getAvailableBalance());
                 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()));
@@ -261,8 +267,9 @@
                         LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.OPEN_ORDER_TITLE, StrUtil.format(NoticeConstant.OPEN_ORDER_CONTENT, holdOrderEntity.getSymbol() + "开空", openPrice.setScale(2, BigDecimal.ROUND_HALF_UP).toString(), followTraderInfoEntity.getNickname()));
                     }
                 }
+                redisUtils.del(AppContants.MEMBER_HAS_FOLLOW + "_" + followerSetting.getMemberId());
             }
-            redisUtils.del(AppContants.MEMBER_HAS_FOLLOW);
+//            redisUtils.del(AppContants.MEMBER_HAS_FOLLOW);
         }
     }
 

--
Gitblit v1.9.1