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