From 88c4fdfeaea7640ade57e391e0587b3491da60e5 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Mon, 06 Jul 2020 11:30:55 +0800 Subject: [PATCH] modify --- src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java | 76 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 76 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java index 1e02af0..5ed9ee2 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.xcong.excoin.common.enumerates.CoinTypeEnum; +import com.xcong.excoin.modules.blackchain.service.BtcService; import com.xcong.excoin.modules.blackchain.service.EthService; +import com.xcong.excoin.modules.blackchain.service.UsdtService; import com.xcong.excoin.modules.coin.service.BlockCoinService; import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao; import com.xcong.excoin.modules.member.dao.MemberCoinChargeDao; @@ -84,6 +86,7 @@ } } + @Transactional(rollbackFor = Exception.class) @Override public void updateEth() { List<MemberCoinAddressEntity> list = memberCoinAddressDao.selectAllBlockAddressBySymbol(CoinTypeEnum.ETH.name()); @@ -126,14 +129,87 @@ } } + @Transactional(rollbackFor = Exception.class) @Override public void updateBtcUsdt() { + List<MemberCoinAddressEntity> list = memberCoinAddressDao.selectAllBlockAddressBySymbolAndTag(CoinTypeEnum.USDT.name(), "OMNI"); + if (CollUtil.isNotEmpty(list)) { + UsdtService usdtService = UsdtService.getInstance(); + for (MemberCoinAddressEntity coinAddressEntity : list) { + String address = coinAddressEntity.getAddress(); + Long memberId = coinAddressEntity.getMemberId(); + + BigDecimal balance = usdtService.getBalance(address); + if (balance != null && balance.compareTo(new BigDecimal("0.1")) > 0) { + MemberCoinChargeEntity memberCoinChargeEntity = memberCoinChargeDao.selectNewestChargeRecord(memberId, CoinTypeEnum.USDT.name(), "OMNI"); + BigDecimal early = BigDecimal.ZERO; + if (memberCoinChargeEntity != null) { + BigDecimal lastAmount = memberCoinChargeEntity.getLastAmount(); + if (lastAmount != null) { + early = lastAmount; + } + } + + MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); + if (walletCoin == null) { + continue; + } + + if (balance.compareTo(early) > 0) { + BigDecimal newBalance = balance.subtract(early); + + memberWalletCoinDao.updateBlockBalance(memberId, newBalance, balance, 0); + insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance); + + // TODO 钉钉消息, 短信提醒 + } + } + } + } } + @Transactional(rollbackFor = Exception.class) @Override public void updateBtc() { + List<MemberCoinAddressEntity> list = memberCoinAddressDao.selectAllBlockAddressBySymbol(CoinTypeEnum.BTC.name()); + if (CollUtil.isNotEmpty(list)) { + BtcService btcService = BtcService.getInstance(); + for (MemberCoinAddressEntity coinAddressEntity : list) { + String address = coinAddressEntity.getAddress(); + Long memberId = coinAddressEntity.getMemberId(); + BigDecimal balance = btcService.getBalance(address); + + if (balance != null && balance.compareTo(new BigDecimal("0.00012")) > 0) { + MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.BTC.name()); + if (walletCoin == null) { + continue; + } + + BigDecimal early = BigDecimal.ZERO; + MemberCoinChargeEntity coinCharge = memberCoinChargeDao.selectNewestChargeRecord(memberId, CoinTypeEnum.BTC.name(), null); + if (coinCharge != null) { + BigDecimal lastAmount = coinCharge.getLastAmount(); + if (lastAmount != null) { + early = lastAmount; + } + } + + if (balance.compareTo(early) > 0) { + log.info("#btc同步:{}, {}, {}#", memberId, balance, early); + BigDecimal newBalance = balance.subtract(early); + memberWalletCoinDao.updateBlockBalance(memberId, newBalance, balance, 0); + + insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance); + LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.BTC.name(), 1, 1); + + // TODO 钉钉提醒, 短信提醒 + + } + } + } + } } private String generateNo() { -- Gitblit v1.9.1