| | |
| | | package cn.lihu.jh.module.ecg.service.queue; |
| | | |
| | | import java.time.LocalTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import javax.annotation.Resource; |
| | | |
| | | import cn.lihu.jh.module.ecg.Utils; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO; |
| | | import cn.lihu.jh.module.ecg.service.room.RoomService; |
| | | import org.springframework.scheduling.config.CronTask; |
| | | import org.springframework.scheduling.config.ScheduledTask; |
| | | import org.springframework.scheduling.config.ScheduledTaskRegistrar; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | |
| | | import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.lihu.jh.framework.common.pojo.CommonResult.error; |
| | | import static cn.lihu.jh.framework.common.pojo.CommonResult.success; |
| | | 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; |
| | | import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private ConfigApi configApi; |
| | | |
| | | @Resource |
| | | private ScheduledTaskRegistrar taskRegistrar; |
| | | |
| | | @Resource |
| | | private QueueService queueService; |
| | | |
| | | @Resource |
| | | private RoomService roomService; |
| | | |
| | | |
| | | @Resource |
| | | private queueMapper queueMapper; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void resetScheduler() { |
| | | Set<ScheduledTask> taskList = taskRegistrar.getScheduledTasks(); |
| | | taskList.forEach((task)->task.cancel()); |
| | | |
| | | String strOpenCloseTime = configApi.getConfigValueByKey(ECG_OPENING_TIME_KEY); |
| | | List<LocalTime> list = Utils.parseOpeningTime(strOpenCloseTime); |
| | | LocalTime openingTime = list.get(0); |
| | | LocalTime closeTime = list.get(1); |
| | | 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.scheduleCronTask(new CronTask(() -> { |
| | | System.out.println("Opening Task executed at: " + System.currentTimeMillis()); |
| | | queueService.startBiz(); |
| | | }, openCronExpression)); |
| | | |
| | | taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | System.out.println("Close Task executed at: " + System.currentTimeMillis()); |
| | | queueService.closeBiz(); |
| | | }, closeCronExpression)); |
| | | |
| | | taskRegistrar.scheduleCronTask(new CronTask(() -> { |
| | | System.out.println("Room Reset Task executed at: " + System.currentTimeMillis()); |
| | | roomService.resetRoom(); |
| | | }, roomResetCronExpression)); |
| | | } |
| | | |
| | | @Override |
| | | public Integer recallPatient(Long roomId, String bedNo, String patId) { |
| | | Integer updateNum = queueMapper.recallPassedPatient(roomId, bedNo, patId, |
| | | QueueStatusEnum.PASSED.getStatus(), QueueStatusEnum.PASSED_RETURN.getStatus()); |