| | |
| | | import cn.lihu.jh.module.ecg.service.room.RoomService; |
| | | import cn.lihu.jh.module.infra.api.config.ConfigApi; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.TaskScheduler; |
| | | import org.springframework.scheduling.config.CronTask; |
| | | import org.springframework.scheduling.config.ScheduledTask; |
| | | import org.springframework.scheduling.config.ScheduledTaskRegistrar; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalTime; |
| | | import java.util.List; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | |
| | | import static cn.lihu.jh.module.ecg.Constants.ECG_OPENING_TIME_KEY; |
| | | import static cn.lihu.jh.module.ecg.Constants.ECG_ROOM_RESET_TIME_KEY; |
| | |
| | | @Resource |
| | | private QueueService queueService; |
| | | |
| | | ScheduledTask startBizTask = null; |
| | | ScheduledTask closeBizTask = null; |
| | | ScheduledTask resetRoomTask = null; |
| | | |
| | | @Override |
| | | public void resetScheduler() { |
| | | ScheduledTaskRegistrar taskRegistrar = DynamicSchedulingConfig.static_scheduledTaskRegistrar; |
| | | List<CronTask> cronTaskList = taskRegistrar.getCronTaskList(); |
| | | cronTaskList.forEach(cronTaskList::remove); |
| | | |
| | | if (null != startBizTask) startBizTask.cancel(); |
| | | if (null != closeBizTask) closeBizTask.cancel(); |
| | | if (null != resetRoomTask) resetRoomTask.cancel(); |
| | | |
| | | String strOpenCloseTime = configApi.getConfigValueByKey(ECG_OPENING_TIME_KEY); |
| | | List<LocalTime> list = Utils.parseOpeningTime(strOpenCloseTime); |
| | |
| | | LocalTime roomResetTime = Utils.parseTime(strRoomResetTime); |
| | | String roomResetCronExpression = String.format("0 %d %d * * ?", roomResetTime.getMinute(), roomResetTime.getHour()); |
| | | |
| | | taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | startBizTask = taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | System.out.println("Opening Task executed at: " + System.currentTimeMillis()); |
| | | queueService.startBiz(); |
| | | }, openCronExpression)); |
| | | |
| | | taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | closeBizTask = taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | System.out.println("Close Task executed at: " + System.currentTimeMillis()); |
| | | queueService.closeBiz(); |
| | | }, closeCronExpression)); |
| | | |
| | | taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | resetRoomTask = taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | System.out.println("Room Reset Task executed at: " + System.currentTimeMillis()); |
| | | roomService.resetRoom(); |
| | | }, roomResetCronExpression)); |