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);
|
}
|
}
|
|
}
|
}
|