liding
3 天以前 7f9e375391e30fd3c367cb5a080a609a6e25e524
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
58
59
60
61
62
package com.zbkj.admin.task.vehicle;
 
import com.zbkj.admin.service.EbVehicleInfoService;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
 
@Component
@Configuration //读取配置
@EnableScheduling // 2.开启定时任务
public class VehicleCallNumberTask {
 
    public static final Logger logger = LoggerFactory.getLogger(VehicleCallNumberTask.class);
 
    private static final String SIXTY_MINUTE = "PT1M";
    private static final String THREE_MINUTE = "PT1M";
 
 
    @Autowired
    private EbVehicleInfoService ebVehicleInfoService;
 
    @Scheduled(fixedDelay = 1000 * 60L)
    @SchedulerLock(name = "VehicleCallNumberTask", lockAtMostFor = SIXTY_MINUTE, lockAtLeastFor = THREE_MINUTE)
    public void pushNews() {
        logger.info("---VehicleCallNumberTask task--- Execution Time - {}", new Date());
        try {
            ebVehicleInfoService.autoCallNumber();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    @Scheduled(fixedDelay = 1000 * 60L)
    @SchedulerLock(name = "VehiclePassNumberTask", lockAtMostFor = SIXTY_MINUTE, lockAtLeastFor = THREE_MINUTE)
    public void passNumber() {
        logger.info("---VehiclePassNumberTask task--- Execution Time - {}", new Date());
        try {
            ebVehicleInfoService.autoPassNumber();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    //每小时运行一次
    @Scheduled(cron = "0 0 * * * *")
    @SchedulerLock(name = "AutoUpdateScreen",lockAtMostFor = SIXTY_MINUTE,lockAtLeastFor = THREE_MINUTE)
    public void autoUpdateScreen() {
        logger.info("---AutoUpdateScreen task--- Execution Time - {}", new Date());
        try {
            ebVehicleInfoService.autoUpdateScreen();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}