| | |
| | | |
| | | import cn.lihu.jh.framework.common.exception.ErrorCode; |
| | | import cn.lihu.jh.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import cn.lihu.jh.framework.common.pojo.CommonResult; |
| | | import cn.lihu.jh.framework.common.pojo.PageResult; |
| | | import cn.lihu.jh.framework.common.util.object.BeanUtils; |
| | | import cn.lihu.jh.module.ecg.controller.admin.queue.vo.PatientStatisticVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueuePageReqVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueueSaveReqVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.room.vo.MonitorInfoVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomRespVO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.queue.BedQueueStatisticDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO; |
| | | 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.mysql.queue.queueMapper; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.room.RoomMapper; |
| | | import cn.lihu.jh.module.ecg.enums.BedStatusEnum; |
| | | import cn.lihu.jh.module.ecg.enums.DevRentStateEnum; |
| | | import cn.lihu.jh.module.ecg.enums.QueueStatusEnum; |
| | | import cn.lihu.jh.module.system.api.oauth2.OAuth2TokenApi; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.concurrent.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | 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.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | |
| | | PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>(); |
| | | ConcurrentHashMap<String, BedQueueBO > mapBedVsQueue = new ConcurrentHashMap<>(); |
| | | |
| | | Integer queueReadyMax = 0; |
| | | Map<Integer, Integer> mapCheckTypeVsReadyMax = null; |
| | | |
| | | /** |
| | | * 已关闭 或者 关闭中,可以开通工位 |
| | |
| | | bedQueueBO.setRoomId(roomId); |
| | | bedQueueBO.setRoomName(roomName); |
| | | bedQueueBO.setBedNo(bedNo); |
| | | bedQueueBO.setMaxQueueNum(queueReadyMax); |
| | | bedQueueBO.setMaxQueueNum(getBedReadyMax(roomId, bedNo)); |
| | | bedQueueBO.setQueueNum(new AtomicInteger(queueDOList.size())); |
| | | bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus()); |
| | | priorityQueue.offer(bedQueueBO); |
| | | mapBedVsQueue.put(String.format("%09d%s", roomId, bedNo), bedQueueBO); |
| | | |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | |
| | | } |
| | | |
| | | bedQueueBO.setStatus(BedStatusEnum.DOCTOR_ON.getStatus()); |
| | | if (!priorityQueue.contains(bedQueueBO)) { |
| | | priorityQueue.offer(bedQueueBO); |
| | | } else { |
| | | log.error("bedDoctorOn priorityQueue still exist!. " + roomId + " " + bedNo); |
| | | return ECG_INNER_ERROR; |
| | | } |
| | | |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | | // 如果是在 PAUSE 状态离座的,需要重新加回 优先队列 |
| | | if (bedQueueBO.getStatus().equals(BedStatusEnum.PAUSE.getStatus())) { |
| | | if (!priorityQueue.contains(bedQueueBO)) { |
| | | priorityQueue.offer(bedQueueBO); |
| | | } else { |
| | | log.error("bedDoctorResume priorityQueue still exist!. " + roomId + " " + bedNo); |
| | | return ECG_INNER_ERROR; |
| | | } |
| | | } |
| | | priorityQueue.remove(bedQueueBO); |
| | | |
| | | bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus()); |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | |
| | | List<QueueStatisticDO> queueStatisticDOList = queueMapper.queueStatistic(queueStatusList); |
| | | |
| | | bedQueueBOList.forEach(item -> { |
| | | item.maxQueueNum = queueReadyMax; |
| | | item.maxQueueNum = getBedReadyMax(item.roomId, item.bedNo); |
| | | Optional<QueueStatisticDO> queueStatisticDOOptional = queueStatisticDOList.stream().filter(it->it.getRoomId()==item.roomId && it.getBedNo().equals(item.getBedNo())).findFirst(); |
| | | int queueNum = queueStatisticDOOptional.isPresent() ? queueStatisticDOOptional.get().getTotalInStatus() : 0; |
| | | if ( queueReadyMax < queueNum ) |
| | | if ( item.maxQueueNum < queueNum ) |
| | | throw new RuntimeException("init: exceed max queue number!"); |
| | | |
| | | item.queueNum.set( queueNum ); |
| | | mapBedVsQueue.put(String.format("%09d%s", item.roomId, item.bedNo), item); |
| | | if (BedStatusEnum.PAUSE.getStatus() != item.getStatus()) { |
| | | if (BedStatusEnum.DOCTOR_ON.getStatus() == item.getStatus()) { |
| | | priorityQueue.offer(item); |
| | | } |
| | | }); |
| | |
| | | openingFlag.set(flag); |
| | | } |
| | | |
| | | public void setQueueReadyMax(Integer max) { |
| | | queueReadyMax = max; |
| | | public void setCheckTypeReadyMax(Map<Integer, Integer> max) { |
| | | mapCheckTypeVsReadyMax = max; |
| | | } |
| | | |
| | | public BedQueueBO getBedQueueBO(Long roomId, String bedNo) { |
| | |
| | | + " opening " + openingFlag.get()); |
| | | } |
| | | |
| | | private Integer getBedReadyMax(Long roomId, String bedNo) { |
| | | RoomDO roomDO = roomMapper.getRoom(roomId, bedNo); |
| | | Integer[] checkTypes = roomDO.getCheckTypes(); |
| | | Integer ret = 0; |
| | | for (int i=0; i<checkTypes.length; i++) { |
| | | Integer tmp = mapCheckTypeVsReadyMax.get(checkTypes[i]); |
| | | ret = ret < tmp ? tmp : ret; //取大值 |
| | | } |
| | | return ret; |
| | | } |
| | | } |