| | |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import javax.annotation.Resource; |
| | | |
| | | import cn.lihu.jh.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import cn.lihu.jh.module.ecg.Utils; |
| | | import cn.lihu.jh.module.ecg.config.DynamicSchedulingConfig; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO; |
| | |
| | | import cn.lihu.jh.framework.common.util.object.BeanUtils; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.queue.queueMapper; |
| | | |
| | | import static cn.lihu.jh.framework.common.exception.enums.GlobalErrorCodeConstants.SUCCESS; |
| | | 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; |
| | |
| | | public ErrorCode bedOpen(Long roomId, String bedNo) { |
| | | BedQueueBO bedQueueBO2 = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo)); |
| | | if (null != bedQueueBO2) { |
| | | log.error("bedOpen mapBedVsQueue has existed" + roomId + " " + bedNo); |
| | | log.error("bedOpen mapBedVsQueue has existed. " + roomId + " " + bedNo); |
| | | return QUEUE_BED_EXIST; |
| | | } |
| | | |
| | |
| | | statusList.add(BedStatusEnum.CLOSED); |
| | | Integer updateNum = roomMapper.setBedOpeningClosed(roomId, bedNo, BedStatusEnum.OPENING, statusList); |
| | | if ( null==updateNum || 0 == updateNum ) { |
| | | log.error("bedOpen DB invalid status " + roomId + " " + bedNo); |
| | | log.error("bedOpen DB invalid status. " + roomId + " " + bedNo); |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | |
| | | bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus()); |
| | | priorityQueue.offer(bedQueueBO); |
| | | mapBedVsQueue.put(String.format("%09d%s", roomId, bedNo), bedQueueBO); |
| | | return SUCCESS; |
| | | |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | | public ErrorCode bedClose(Long roomId, String bedNo) { |
| | | BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo)); |
| | | if (null == bedQueueBO) { |
| | | log.error("bedClose mapBedVsQueue DONOT existed" + roomId + " " + bedNo); |
| | | log.error("bedClose mapBedVsQueue DONOT existed. " + roomId + " " + bedNo); |
| | | return QUEUE_BED_NOT_EXIST; |
| | | } |
| | | |
| | |
| | | Integer updateNum = roomMapper.setBedOpeningClosed(roomId, bedNo, |
| | | BedStatusEnum.CLOSED, statusList); |
| | | if ( null==updateNum || 0 == updateNum ) { |
| | | log.error("bedClose DB invalid status " + roomId + " " + bedNo); |
| | | log.error("bedClose DB invalid status. " + roomId + " " + bedNo); |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | | mapBedVsQueue.remove(String.format("%09d%s", roomId, bedNo)); |
| | | priorityQueue.remove(bedQueueBO); |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | | public CommonResult<RoomRespVO> getRoom(Long roomId, String bedNo, Long docId) { |
| | | BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo)); |
| | | if (null == bedQueueBO) { |
| | | log.error("getRoom mapBedVsQueue DONOT existed" + roomId + " " + bedNo); |
| | | return error(QUEUE_BED_NOT_EXIST); |
| | | } |
| | | |
| | | RoomDO roomDO = roomMapper.getRoom(roomId, bedNo, docId); |
| | | if (null == roomDO) { |
| | | return error(ROOM_NOT_SIT); |
| | | } |
| | | |
| | | BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo)); |
| | | if (null == bedQueueBO) { |
| | | log.error("getRoom mapBedVsQueue DONOT existed. " + roomId + " " + bedNo); |
| | | return error(QUEUE_BED_NOT_EXIST); |
| | | } |
| | | |
| | | RoomRespVO roomRespVO = BeanUtils.toBean(roomDO, RoomRespVO.class); |
| | |
| | | public ErrorCode bedDoctorPause(Long roomId, String bedNo, Long docId, String docName) { |
| | | BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo)); |
| | | if (null == bedQueueBO) { |
| | | log.error("bedDoctorPause mapBedVsQueue DONOT existed" + roomId + " " + bedNo); |
| | | log.error("bedDoctorPause mapBedVsQueue DONOT existed. " + roomId + " " + bedNo); |
| | | return QUEUE_BED_NOT_EXIST; |
| | | } |
| | | |
| | |
| | | statusList.add(BedStatusEnum.DOCTOR_ON); |
| | | Integer updateNum = roomMapper.setBedDoctorStatus(roomId, bedNo, docId, BedStatusEnum.PAUSE, statusList); |
| | | if ( null==updateNum || 0 == updateNum ) { |
| | | log.error("bedDoctorPause DB invalid status " + roomId + " " + bedNo); |
| | | log.error("bedDoctorPause DB invalid status. " + roomId + " " + bedNo); |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | | bedQueueBO.setStatus(BedStatusEnum.PAUSE.getStatus()); |
| | | priorityQueue.remove(bedQueueBO); |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | |
| | | Integer updateNum = roomMapper.setBedDoctorStatus(roomId, bedNo, docId, |
| | | BedStatusEnum.DOCTOR_ON, statusList); |
| | | if ( null==updateNum || 0 == updateNum ) { |
| | | log.error("bedDoctorResume DB invalid status " + roomId + " " + bedNo); |
| | | log.error("bedDoctorResume DB invalid status. " + roomId + " " + bedNo); |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | |
| | | return ECG_INNER_ERROR; |
| | | } |
| | | |
| | | hurryup(); |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | |
| | | statusList.add(BedStatusEnum.OPENING); |
| | | Integer updateNum = roomMapper.setBedDoctorOn(roomId, bedNo, docId, docName, BedStatusEnum.DOCTOR_ON, statusList); |
| | | if ( null==updateNum || 0 == updateNum ) { |
| | | log.error("bedDoctorOn DB invalid status " + roomId + " " + bedNo); |
| | | log.error("bedDoctorOn DB invalid status. " + roomId + " " + bedNo); |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | | bedQueueBO.setStatus(BedStatusEnum.DOCTOR_ON.getStatus()); |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | |
| | | statusList.add(BedStatusEnum.DOCTOR_ON); |
| | | Integer updateNum = roomMapper.setBedDoctorOff(roomId, bedNo, docId, BedStatusEnum.OPENING, statusList); |
| | | if ( null==updateNum || 0 == updateNum ) { |
| | | log.error("bedDoctorOff DB invalid status " + roomId + " " + bedNo); |
| | | log.error("bedDoctorOff DB invalid status. " + roomId + " " + bedNo); |
| | | return ROOM_INVALID_STATUS; |
| | | } |
| | | |
| | | bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus()); |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | private void validatequeueExists(Integer id) { |
| | |
| | | Integer num = queueMapper.getMaxSeqNum(); |
| | | curSeqNum = new AtomicInteger(null == num ? 0 : num); |
| | | |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | /** |
| | |
| | | public void hurryup() { |
| | | if (0 == openingFlag.get()) |
| | | return; |
| | | |
| | | // TODO |
| | | if (mapBedVsQueue.size() != priorityQueue.size()) { |
| | | log.error("map " + mapBedVsQueue.size() + " priority " + priorityQueue.size()); |
| | | } |
| | | |
| | | // 处理 过号-回来 的人 |
| | | for (BedQueueBO bedQueueBO : mapBedVsQueue.values()) { |
| | |
| | | priorityQueue.remove(bo); |
| | | priorityQueue.offer(bo); |
| | | |
| | | hurryup(); |
| | | return SUCCESS; |
| | | return GlobalErrorCodeConstants.SUCCESS; |
| | | } |
| | | |
| | | public void finishNextPatient(Long roomId, String bedNo) { |
| | |
| | | return updateNum; |
| | | } |
| | | |
| | | @Override |
| | | public void monitorInfo() { |
| | | log.info("map " + mapBedVsQueue.size() + " priority " + priorityQueue.size() |
| | | + " opening " + openingFlag.get()); |
| | | } |
| | | |
| | | private void startHurryUp() { |
| | | singleThreadExecutor.execute( () -> { |
| | | hurryup(); |