From fe0371840d353ce8b39e3811a9d87108cfd84253 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 02 Apr 2021 15:52:26 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java | 70 ++++++++++++++++++++++++++++++----
1 files changed, 61 insertions(+), 9 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 db40238..90a595e 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
@@ -6,6 +6,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum;
@@ -35,10 +36,7 @@
import com.xcong.excoin.rabbit.pricequeue.OrderModel;
import com.xcong.excoin.rabbit.producer.FollowProducer;
import com.xcong.excoin.rabbit.producer.OrderProducer;
-import com.xcong.excoin.utils.CacheSettingUtils;
-import com.xcong.excoin.utils.CalculateUtil;
-import com.xcong.excoin.utils.LogRecordUtils;
-import com.xcong.excoin.utils.ThreadPoolUtils;
+import com.xcong.excoin.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -89,7 +87,8 @@
private FollowProducer followProducer;
@Autowired
private FollowTraderProfitDetailDao followTraderProfitDetailDao;
-
+ @Resource
+ private RedisUtils redisUtils;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -122,9 +121,33 @@
BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol());
Long tradeMemberId = holdOrderEntity.getMemberId();
if (CollUtil.isNotEmpty(followerSettings)) {
+ List<Object> hasExist = new ArrayList<>();
for (FollowFollowerSettingEntity followerSetting : followerSettings) {
+ // 加redis锁,同一个用户不能同时触发两个跟单任务,否则会出现金额问题
+ while (true) {
+ 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()));
+// 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("跳出");
+ break;
+ }
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ //更新更新消息提醒的状态
MemberSettingEntity memberSettingEntity = memberSettingDao.selectMemberSettingByMemberId(followerSetting.getMemberId());
if(ObjectUtil.isNotEmpty(memberSettingEntity)){
Long memberId = memberSettingEntity.getMemberId();
@@ -180,9 +203,36 @@
// 预付款
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()));
+ continue;
+ }
+
+ boolean flag = false;
+ while(true) {
+ log.info("----循环更新----");
+ MemberWalletContractEntity updateEntity = new MemberWalletContractEntity();
+ updateEntity.setAvailableBalance(prePaymentAmount.negate());
+ updateEntity.setTotalBalance(openFeePrice.negate());
+ updateEntity.setId(walletContract.getId());
+ updateEntity.setVersion(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;
+ }
+ }
+
+ if (flag) {
continue;
}
@@ -216,7 +266,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);
@@ -243,7 +293,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);
}
}
@@ -302,8 +354,8 @@
LogRecordUtils.insertMemberAccountMoneyChange(
traderMemberId,
StrUtil.format(NoticeConstant.RETURN_MONEY_CONTENT_MAMC,
- orderNoTrader.substring(8),
- symbol),
+ symbol,
+ orderNoTrader.substring(8)),
totalAmount,
MemberWalletCoinEnum.WALLETCOINCODE.getValue(),
MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER,
--
Gitblit v1.9.1