| | |
| | | package cn.lihu.jh.module.ecg.service.queue; |
| | | |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueStatisticDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomStatisticsDO; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.room.RoomMapper; |
| | | import cn.lihu.jh.module.ecg.enums.QueueStatusEnum; |
| | | import lombok.Data; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | |
| | | |
| | | import cn.lihu.jh.module.ecg.dal.mysql.queue.queueMapper; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.PriorityQueue; |
| | | |
| | | import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; |
| | |
| | | @Validated |
| | | public class QueueServiceImpl implements QueueService { |
| | | |
| | | final static Integer MAX_QUEUE_NUM = 2; |
| | | |
| | | Integer curSeqNum = 0; |
| | | |
| | | PriorityQueue<BedQueueBO> priorityQueue = new PriorityQueue<>(); |
| | | |
| | | @Resource |
| | | private queueMapper queueMapper; |
| | | |
| | | @Resource |
| | | private RoomMapper roomMapper; |
| | | |
| | | @Override |
| | | public Integer createqueue(QueueSaveReqVO createReqVO) { |
| | |
| | | return queueMapper.queueStatistic(statusList); |
| | | } |
| | | |
| | | } |
| | | @Override |
| | | public void queue(QueueSaveReqVO queueSaveReqVO) { |
| | | BedQueueBO bedQueueBO = priorityQueue.peek(); |
| | | if (bedQueueBO.queueNum == bedQueueBO.maxQueueNum) { |
| | | queueSaveReqVO.setStatus(QueueStatusEnum.WAITING.getStatus()); //排队中 |
| | | } else if (bedQueueBO.queueNum < bedQueueBO.maxQueueNum) { |
| | | queueSaveReqVO.setStatus(QueueStatusEnum.READY.getStatus()); //候诊准备中 |
| | | queueSaveReqVO.setRoomNum(bedQueueBO.getRoomName()); |
| | | queueSaveReqVO.setBedNum(bedQueueBO.getBedNo()); |
| | | queueSaveReqVO.setSeqNum(curSeqNum++); |
| | | QueueDO queue = BeanUtils.toBean(queueSaveReqVO, QueueDO.class); |
| | | queueMapper.insert(queue); // queue.getId(); |
| | | |
| | | bedQueueBO.queueNum++; |
| | | } |
| | | } |
| | | |
| | | @PostConstruct |
| | | private void initQueue() { |
| | | List<RoomDO> roomDOList = roomMapper.simpleRoomList(); |
| | | List<BedQueueBO> bedQueueBOList = roomDOList.stream().map(item -> BeanUtils.toBean(item, BedQueueBO.class)).toList(); |
| | | |
| | | bedQueueBOList.forEach(item -> { |
| | | item.maxQueueNum = MAX_QUEUE_NUM; |
| | | item.queueNum = 0; |
| | | priorityQueue.add(item); |
| | | }); |
| | | |
| | | curSeqNum = queueMapper.getMaxSeqNum(); |
| | | } |
| | | } |
| | | |