| | |
| | | package com.xcong.excoin.quartz.job; |
| | | |
| | | import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService; |
| | | import com.xcong.excoin.modules.coin.service.BlockCoinService; |
| | | import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | /** |
| | | * 链上币种同步任务 |
| | |
| | | |
| | | @Resource |
| | | private BlockCoinService blockCoinService; |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Autowired |
| | | private TrxUsdtUpdateService trxUsdtUpdateService; |
| | | |
| | | @Autowired |
| | | private UsdtUpdateProducer usdtUpdateProducer; |
| | | |
| | | |
| | | public static ConcurrentLinkedQueue<Long> TRC_BLOCK = new ConcurrentLinkedQueue<>(); |
| | | |
| | | /** |
| | | * TRC20_USDT 同步 |
| | | */ |
| | | @Scheduled(cron = "0/2 * * * * ? ") |
| | | // @Async |
| | | public void usdtTc20Update() { |
| | | // 波场3秒出一个块 |
| | | Long blocnNum = TRC_BLOCK.poll(); |
| | | if (blocnNum == null) { |
| | | return; |
| | | } |
| | | usdtUpdateProducer.sendTrc20BlockMsg(blocnNum.toString()); |
| | | redisUtils.set("USDT_TRC20_CURRENT_BLOCK_NUM", blocnNum); |
| | | // try { |
| | | // trxUsdtUpdateService.monitorCoinListener(blocnNum); |
| | | // } catch (RestClientException | HttpException e) { |
| | | // // 此时是连接问题 这个块需要重新扫描 |
| | | // log.info("查询区块超时:" + blocnNum); |
| | | // TRC_BLOCK.add(blocnNum); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0/1 * * * ? ") |
| | | public void usdtTc20UpdateQueue() { |
| | | // 查询最新区块号 |
| | | long getnowblock = trxUsdtUpdateService.getnowblockFromTronScan() - 25; |
| | | // 拿到redis里最新区块 |
| | | Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM"); |
| | | if (trc20BlockNum == null) { |
| | | // 没有则取最新的块 |
| | | trc20BlockNum = getnowblock; |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", getnowblock); |
| | | } |
| | | Long blockNum = Long.valueOf(trc20BlockNum.toString()); |
| | | if (getnowblock <= blockNum) { |
| | | // 如果当前区块比最新已确认区块还大,则不继续执行 |
| | | return; |
| | | } |
| | | // 得到最新区块和当前区块的差值 |
| | | Long diff = getnowblock-blockNum; |
| | | for(long i=1;i<=diff;i++){ |
| | | blockNum++; |
| | | TRC_BLOCK.add(blockNum); |
| | | } |
| | | // 将最新的最大区块放入redis |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", blockNum); |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | blockCoinService.updateBtcUsdt(); |
| | | } |
| | | |
| | | @Scheduled(cron = "0 3/20 * * * ? ") |
| | | // @Scheduled(cron = "0 3/20 * * * ? ") |
| | | public void btcUpdate() { |
| | | blockCoinService.updateBtc(); |
| | | } |
| | | |
| | | @Scheduled(cron = "0 4/20 * * * ? ") |
| | | // @Scheduled(cron = "0 4/20 * * * ? ") |
| | | public void eosUpdate() { |
| | | blockCoinService.updateEos(); |
| | | } |
| | | |
| | | @Scheduled(cron = "0 6/20 * * * ? ") |
| | | // @Scheduled(cron = "0 6/20 * * * ? ") |
| | | public void xrpUpdate() { |
| | | blockCoinService.updateXrp(); |
| | | } |