zainali5120
2020-07-16 c119feb821bdb1e6ef407f55056173f752c01c32
src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java
@@ -5,7 +5,9 @@
import cn.hutool.core.date.DateUtil;
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.coin.service.BlockCoinService;
@@ -18,10 +20,14 @@
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.utils.LogRecordUtils;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.ThreadPoolUtils;
import com.xcong.excoin.utils.dingtalk.DingTalkUtils;
import com.xcong.excoin.utils.mail.SmsSend;
import com.xcong.excoin.utils.mail.Sms106Send;
import com.xcong.excoin.utils.mail.SubMailSend;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -47,6 +53,11 @@
    private MemberCoinChargeDao memberCoinChargeDao;
    @Resource
    private MemberWalletCoinDao memberWalletCoinDao;
    @Resource
    private RedisUtils redisUtils;
    private final static String EOS_SEQ_KEY="eos_seq_key";
    @Transactional(rollbackFor = Exception.class)
    @Override
@@ -92,7 +103,9 @@
                        MemberEntity member = memberDao.selectById(memberId);
                        if (StrUtil.isNotBlank(member.getPhone())) {
                            String amount = newBalance.toPlainString() + "USDT-ERC20";
                            SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo);
                            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);
                        }
                    }
                }
@@ -141,7 +154,9 @@
                        MemberEntity member = memberDao.selectById(memberId);
                        if (StrUtil.isNotBlank(member.getPhone())) {
                            String amount = newBalance.toPlainString() + "ETH";
                            SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo);
                            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);
                        }
                    }
                }
@@ -186,7 +201,9 @@
                        MemberEntity member = memberDao.selectById(memberId);
                        if (StrUtil.isNotBlank(member.getPhone())) {
                            String amount = newBalance.toPlainString() + "USDT-OMNI";
                            SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo);
                            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);
                        }
                    }
                }
@@ -233,7 +250,9 @@
                        MemberEntity member = memberDao.selectById(memberId);
                        if (StrUtil.isNotBlank(member.getPhone())) {
                            String amount = newBalance.toPlainString() + "BTC";
                            SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo);
                            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);
                        }
                    }
                }
@@ -241,6 +260,62 @@
        }
    }
    @Override
    public void updateEos() {
        // 获取上次读取的序号
        int pos= 0;
        //每次获取的条数
        int offset = 10;
        String eosSeq = redisUtils.getString(EOS_SEQ_KEY);
        if(StringUtils.isNotBlank(eosSeq)){
            pos = Integer.valueOf(eosSeq);
        }
        // 记录最大的seq
        int seq = pos;
        List<EosResult> actions = EosService.getActions(pos, offset);
        if(CollectionUtils.isNotEmpty(actions)){
            for(EosResult eosResult:actions){
                String to = eosResult.getTo();
                Integer accountActionSeq = eosResult.getAccountActionSeq();
                if(accountActionSeq>seq){
                    seq = accountActionSeq;
                }
                if(!EosService.ACCOUNT.equals(to)){
                    // 判断是否是收款
                    continue;
                }
                // 处理收款
                String quantity = eosResult.getQuantity();
                String memo = eosResult.getMemo();
                if(StringUtils.isBlank(memo)){
                    // 没有标记的跳过
                    continue;
                }
                if(StringUtils.isNotBlank(quantity)){
                    // 转账额
                    String amountStr = quantity.split("")[0];
                    List<MemberCoinAddressEntity> memberCoinAddress = memberCoinAddressDao.selectAllBlockAddressBySymbolAndTag(CoinTypeEnum.EOS.name(), memo);
                    if(CollectionUtils.isNotEmpty(memberCoinAddress)){
                        MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddress.get(0);
                        // 用户ID
                        Long memberId = memberCoinAddressEntity.getMemberId();
                        MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.EOS.name());
                        if(memberCoinAddressEntity!=null){
                            memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(),new BigDecimal(amountStr),BigDecimal.ZERO,0);
                            // 添加冲币记录
                            insertCoinCharge(EosService.ACCOUNT,memberId,new BigDecimal(amountStr),CoinTypeEnum.EOS.name(),memo,BigDecimal.ZERO);
                        }
                    }
                }
            }
        }
        // 最后更新seq 即下次查询的起始位置 在本次最大的基础上加一
        if(seq>0 && seq>pos){
            redisUtils.set(EOS_SEQ_KEY,seq+1);
        }
    }
    private String generateNo() {
        // 生成订单号
        Long timestamp = System.currentTimeMillis();