KKSU
2025-03-18 664184af3e070dee665ee736caffa0297804975f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cc.mrbird.febs.mall.chain.ercCoin.quartz;
 
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.mall.chain.ercCoin.ChainEnum;
import cc.mrbird.febs.mall.chain.ercCoin.ChainService;
import lombok.extern.slf4j.Slf4j;
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 java.math.BigInteger;
 
@Slf4j
@Component
@ConditionalOnProperty(prefix = "chain", name = "bsc", havingValue = "true")
public class ChainSDMListenerJob{
 
    @Autowired
    private RedisUtils redisUtils;
 
    @Scheduled(cron = "0 0/5 * * * ? ")
    public void chainBlockUpdate() {
        BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_USDT.name()).blockNumber();
 
        redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM, blockNumber);
    }
 
    @Scheduled(cron = "0/2 * * * * ? ")
    public void chainIncrementBlock() {
        Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM);
        BigInteger newestBlock;
        if (newestBlockObj == null) {
            newestBlock = ChainService.getInstance(ChainEnum.BSC_USDT.name()).blockNumber();
        } else {
            newestBlock = (BigInteger) newestBlockObj;
        }
 
        Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM);
        BigInteger toIncrement;
        if (incrementObj == null) {
            toIncrement = newestBlock;
        } else {
            BigInteger incrementBlock = (BigInteger) incrementObj;
 
            // 最新区块小于增加区块
            if (newestBlock.compareTo(incrementBlock) <= 0) {
                return;
            }
            toIncrement = incrementBlock.add(BigInteger.ONE);
        }
 
        redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, toIncrement);
    }
 
}