package com.xcong.excoin.quartz.job; import com.xcong.excoin.common.enumerates.CoinTypeEnum; import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService; import com.xcong.excoin.modules.coin.service.BlockCoinService; import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao; import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity; import com.xcong.excoin.utils.RedisUtils; import org.apache.commons.collections.CollectionUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; /** * 链上币种同步任务 * * @author wzy * @date 2020-07-02 **/ @Component //@ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") public class BlockCoinUpdateJob { @Resource private BlockCoinService blockCoinService; @Resource private TrxUsdtUpdateService trxUsdtUpdateService; @Resource RedisUtils redisUtils; // 创世区块时间 ,每三秒出一个块 private final static Long TRX_CSQK=1530442002L; public static ConcurrentLinkedQueue TRC_BLOCK = new ConcurrentLinkedQueue<>(); /** * TRC20_USDT 同步 */ @Scheduled(cron = "0/2 * * * * ? ") @Async public void usdtTc20Update() { // 波场3秒出一个块 Long blocnNum = TRC_BLOCK.poll(); if(blocnNum==null){ return; } trxUsdtUpdateService.monitorCoinListener(blocnNum); } @Scheduled(cron = "0/2 * * * * ? ") public void usdtTc20UpdateQueue() { // 当前时间戳 long currentTimeMillis = System.currentTimeMillis()/1000; // 计算当前最新区块 // 波场3秒出一个块 根据创世区块的时间可以计算出当前最新区块号 Long count = (currentTimeMillis-TRX_CSQK)/3; // 减去未确认的区块 long getnowblock =count-25; // 生成块到队列 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