sgj
8 天以前 71fe4f1f6a75c86640a726b9c230e8aaae2a28e7
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
package com.fzzy.igds.timer;
 
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.domain.GatewaySer;
import com.fzzy.igds.service.GatewaySerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @Description  定时核验网关是否在线并更新
 * @Author CZT
 * @Date 2026/1/30 9:47
 */
@Slf4j
@Component
public class GatewayScheduled {
 
    @Resource
    private GatewaySerService gatewaySerService;
 
    /**
     * 每15分执行一次
     */
    @Scheduled(cron = "0 0/15 * * * ?")
    public void timer() {
 
        //获取缓存中所有网关
        List<GatewaySer> list = gatewaySerService.getCacheSer(null);
        if(null == list || list.isEmpty()){
            log.error("------------获取网关信息为空,不校验是否离线------------");
            return;
        }
 
        Date cur = new Date();
        Date update;
        long min = 0;
        for (GatewaySer gatewaySer : list) {
            update = gatewaySer.getUpdateTime();
            //计算分钟差
            min = (cur.getTime() - update.getTime())/(60*1000);
 
            if(min > 15){
                //设置网关离线
                gatewaySerService.updateStatus(gatewaySer, Constant.YN_N, false);
            }
        }
 
    }
}