| | |
| | | |
| | | import cn.lihu.jh.module.ecg.Utils; |
| | | import cn.lihu.jh.module.ecg.service.queue.QueueService; |
| | | import cn.lihu.jh.module.ecg.service.room.RoomService; |
| | | import cn.lihu.jh.module.infra.api.config.ConfigApi; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | |
| | | import java.util.concurrent.Executors; |
| | | |
| | | 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; |
| | | |
| | | @Configuration |
| | | @EnableScheduling |
| | |
| | | |
| | | @Resource |
| | | private QueueService queueService; |
| | | |
| | | @Resource |
| | | private RoomService roomService; |
| | | |
| | | @Override |
| | | public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { |
| | |
| | | String openCronExpression = String.format("0 %d %d * * ?", openingTime.getMinute(), openingTime.getHour()); |
| | | String closeCronExpression = String.format("0 %d %d * * ?", closeTime.getMinute(), closeTime.getHour()); |
| | | |
| | | String strRoomResetTime = configApi.getConfigValueByKey(ECG_ROOM_RESET_TIME_KEY); |
| | | LocalTime roomResetTime = Utils.parseTime(strRoomResetTime); |
| | | String roomResetCronExpression = String.format("0 %d %d * * ?", roomResetTime.getMinute(), roomResetTime.getHour()); |
| | | |
| | | taskRegistrar.addCronTask(() -> { |
| | | System.out.println("Opening Task executed at: " + System.currentTimeMillis()); |
| | | queueService.startBiz(); |
| | |
| | | System.out.println("Close Task executed at: " + System.currentTimeMillis()); |
| | | queueService.closeBiz(); |
| | | }, closeCronExpression); |
| | | |
| | | taskRegistrar.addCronTask(() -> { |
| | | System.out.println("Room Reset Task executed at: " + System.currentTimeMillis()); |
| | | roomService.resetRoom(); |
| | | }, roomResetCronExpression); |
| | | } |
| | | |
| | | } |