Pu Zhibing
昨天 98b09eae533537dc9a5277aa6374bd7d35cfe5c4
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
package com.ruoyi.chargingPile.util;
 
 
import com.ruoyi.chargingPile.service.TChargingPileService;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
 
/**
 * 定时任务工具类
 */
@Component
public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
    
    @Resource
    private TChargingPileService chargingPileService;
    
    private Integer port = null;
    
    
    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        port = event.getWebServer().getPort();
        System.out.println("端口号:" + port);
    }
 
    /**
     * 每隔1分钟去处理的定时任务
     */
    @Scheduled(fixedRate = 60000)
    public void taskMinute(){
        if(null != port && port == 5300){
            chargingPileService.updateStatus();
        }
    }
    
    
}