From d61072f997839b4564ce35132d5902a1b6f7d54f Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 03 Aug 2020 17:39:10 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java | 89 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 84 insertions(+), 5 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 1bb919e..a0ef93b 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
@@ -6,10 +6,10 @@
import cn.hutool.core.util.StrUtil;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.modules.blackchain.model.EosResult;
-import com.xcong.excoin.modules.blackchain.service.BtcService;
-import com.xcong.excoin.modules.blackchain.service.EosService;
-import com.xcong.excoin.modules.blackchain.service.EthService;
-import com.xcong.excoin.modules.blackchain.service.UsdtService;
+import com.xcong.excoin.modules.blackchain.model.XrpTransResult;
+import com.xcong.excoin.modules.blackchain.model.XrpTransactions;
+import com.xcong.excoin.modules.blackchain.model.XrpTx;
+import com.xcong.excoin.modules.blackchain.service.*;
import com.xcong.excoin.modules.coin.service.BlockCoinService;
import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao;
import com.xcong.excoin.modules.member.dao.MemberCoinChargeDao;
@@ -26,6 +26,7 @@
import com.xcong.excoin.utils.mail.Sms106Send;
import com.xcong.excoin.utils.mail.SubMailSend;
import lombok.extern.slf4j.Slf4j;
+import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -34,6 +35,8 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@@ -58,6 +61,8 @@
private RedisUtils redisUtils;
private final static String EOS_SEQ_KEY="eos_seq_key";
+
+ private final static String xrp_update_key = "xrp_update_key";
@Transactional(rollbackFor = Exception.class)
@Override
@@ -123,7 +128,7 @@
Long memberId = coinAddressEntity.getMemberId();
BigDecimal balance = EthService.getEthBlance(address);
- if (balance != null && new BigDecimal("0.008").compareTo(balance) < 0) {
+ if (balance != null && new BigDecimal("0.01").compareTo(balance) < 0) {
MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.ETH.name());
if (walletCoin == null) {
@@ -327,6 +332,80 @@
}
}
+ public void updateXrp() {
+ // 首先去查redis上的上次同步时间
+ Object lastUpdateTime = redisUtils.get(xrp_update_key);
+ SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss");
+ Date start =null;
+ if(lastUpdateTime==null) {
+ // 没有 说明是第一次同步 此时从第一天开始同步2020 0716开始
+ try {
+ start = format.parse("2020-07-16 12:00:00");
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }else {
+ // 有上次时间
+ try {
+ start = format.parse(lastUpdateTime.toString());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // 去查询上次同步时间后的所有记录
+ XrpTransResult result = XrpService.getTransactions(start);
+ // 写入本次更新时间
+ String updateTime = format.format(new Date());
+ redisUtils.set(xrp_update_key, updateTime);
+ // 判断有无
+ List<XrpTransactions> list = result.getTransactions();
+ if(CollectionUtils.isNotEmpty(list)) {
+ // 不为空 说明有转入记录
+ for(XrpTransactions item:list) {
+ XrpTx data = item.getTx();
+ Integer amountOld = data.getAmount();
+ // 除以1000000
+ BigDecimal amount = new BigDecimal(amountOld).divide(new BigDecimal(1000000));
+ Integer memoInt = data.getDestinationTag();
+ // 没有标签直接返回
+ if(memoInt==null){
+ continue;
+ }
+ String memo = memoInt.toString();
+ String destination = data.getDestination();
+ // 判断收款人是不是系统账号
+ if(!XrpService.ACCOUNT.equals(destination)){
+ continue;
+ }
+ List<MemberCoinAddressEntity> memberCoinAddress = memberCoinAddressDao.selectAllBlockAddressBySymbolAndTag(CoinTypeEnum.XRP.name(), memo);
+ if(CollectionUtils.isNotEmpty(memberCoinAddress)){
+ MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddress.get(0);
+ // 用户ID
+ Long memberId = memberCoinAddressEntity.getMemberId();
+ MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XRP.name());
+ if(memberCoinAddressEntity!=null){
+ memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(),amount,BigDecimal.ZERO,0);
+ // 添加冲币记录
+ String orderNo = insertCoinCharge(XrpService.ACCOUNT,memberId,amount,CoinTypeEnum.XRP.name(),memo,BigDecimal.ZERO);
+ LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.XRP.name(), 1, 1);
+
+ ThreadPoolUtils.sendDingTalk(5);
+ MemberEntity member = memberDao.selectById(memberId);
+ if (StrUtil.isNotBlank(member.getPhone())) {
+ //String amountEos = amount + "XRP";
+ Sms106Send.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo);
+ } else {
+ SubMailSend.sendRechargeMail(member.getEmail(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo);
+ }
+ }
+ }
+
+ }
+ }
+
+ }
+
private String generateNo() {
// 生成订单号
Long timestamp = System.currentTimeMillis();
--
Gitblit v1.9.1