xiaoyong931011
2021-01-15 292a4634d9c52ce193eca9de356d65960bdc35f4
src/main/java/com/xcong/excoin/modules/blackchain/service/Impl/BlockSeriveImpl.java
@@ -6,7 +6,10 @@
import javax.annotation.Resource;
import com.xcong.excoin.modules.blackchain.service.*;
import com.xcong.excoin.modules.coin.dao.TrcAddressDao;
import com.xcong.excoin.modules.coin.entity.TrcAddressEntity;
import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer;
import com.xcong.excoin.utils.TRC20ApiUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -30,6 +33,8 @@
    MemberDao memberDao;
    @Resource
    MemberCoinAddressDao memberMapper;
    @Resource
    private TrcAddressDao trcAddressDao;
    @Resource
    private UsdtUpdateProducer usdtUpdateProducer;
@@ -50,6 +55,33 @@
            if ("USDT".equals(symbol)) {
                memberCoinAddress = memberMapper.selectBlockAddressWithTag(Long.parseLong(mId), symbol, lable);
                TrcAddressEntity srcAddressEntity = trcAddressDao.selectSrcAddressByMemberId(member.getId());
                if (srcAddressEntity != null) {
                    map.put("trc20_address", srcAddressEntity.getAddress());
                    map.put("trc20_label", "TRC20");
                } else {
                    // 分布式redis锁
                    for (;;) {
                        boolean flag = redisUtil.setNotExist("LOCK_TRC20", 1, 5);
                        log.info("是否存在:{}", flag);
                        if (!flag) {
                            continue;
                        }
                        TrcAddressEntity address = trcAddressDao.selectOneSrcAddressUnUse();
                        address.setMemberId(member.getId());
                        address.setIsUse(1);
                        address.setSystemFlag(1);
                        TRC20ApiUtils.createWallet(member.getId(), member.getInviteId(), "USDT", address.getAddress());
                        trcAddressDao.updateById(address);
                        map.put("trc20_address", address.getAddress());
                        map.put("trc20_label", "TRC20");
                        break;
                    }
                }
            } else {
                memberCoinAddress = memberMapper.selectBlockAddress(Long.parseLong(mId), symbol);
            }