| | |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import cn.lihu.jh.module.ecg.controller.admin.queue.vo.*; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.queue.queueDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO; |
| | | import cn.lihu.jh.framework.common.pojo.PageResult; |
| | | import cn.lihu.jh.framework.common.pojo.PageParam; |
| | | import cn.lihu.jh.framework.common.util.object.BeanUtils; |
| | | |
| | | 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.*; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class queueServiceImpl implements queueService { |
| | | 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) { |
| | | public Integer createqueue(QueueSaveReqVO createReqVO) { |
| | | // 插入 |
| | | queueDO queue = BeanUtils.toBean(createReqVO, queueDO.class); |
| | | QueueDO queue = BeanUtils.toBean(createReqVO, QueueDO.class); |
| | | queueMapper.insert(queue); |
| | | // 返回 |
| | | return queue.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updatequeue(queueSaveReqVO updateReqVO) { |
| | | public void updatequeue(QueueSaveReqVO updateReqVO) { |
| | | // 校验存在 |
| | | validatequeueExists(updateReqVO.getId()); |
| | | // 更新 |
| | | queueDO updateObj = BeanUtils.toBean(updateReqVO, queueDO.class); |
| | | QueueDO updateObj = BeanUtils.toBean(updateReqVO, QueueDO.class); |
| | | queueMapper.updateById(updateObj); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public queueDO getqueue(Integer id) { |
| | | public QueueDO getqueue(Integer id) { |
| | | return queueMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<queueDO> getqueuePage(queuePageReqVO pageReqVO) { |
| | | public PageResult<QueueDO> getqueuePage(QueuePageReqVO pageReqVO) { |
| | | return queueMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | } |
| | | @Override |
| | | public List<QueueStatisticDO> queueStatistics(List<Byte> statusList) { |
| | | 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(); |
| | | } |
| | | } |
| | | |