eight
2024-11-11 c48f179be89343dc1620bfa147433bfe87d9bed3
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java
@@ -30,7 +30,6 @@
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.module.ecg.Constants.*;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
/**
@@ -243,6 +242,7 @@
        return GlobalErrorCodeConstants.SUCCESS;
    }
    /* 2024.11.11
    // 常规 或者 领用 时 医生 取下一位患者
    public ErrorCode nextPatient(Long roomId, String bedNo) {
        // 从 DB 把该工位.序号最小的 [就诊准备中] 的人 设置为 [就诊中] (或领用中)
@@ -251,6 +251,39 @@
        // 该工位 没有 [就诊准备中] 人员
        if (null == updateNum || 0 == updateNum) {
            return QUEUE_NOT_READY_PATIENT;
        }
        // 优先队列中 该工位 就诊准备中人的数量 减一
        BedQueueBO bo = mapBedVsQueue.get( Utils.formatRoomBed( roomId, bedNo ) );
        bo.queueNum.getAndDecrement(); // 可能已经【并发的】在 hurry-up 中改变了值
        refreshPriorityQueue(bo);
        return GlobalErrorCodeConstants.SUCCESS;
    }
    */
    // 常规 或者 领用 时 医生 取下一位患者
    public ErrorCode nextPatient(Long roomId, String bedNo) {
        QueueDO firstReadyQueueItem = queueMapper.getFirstItemByBedAndStatus(roomId, bedNo, QueueStatusEnum.READY.getStatus());
        // 该工位 没有 [就诊准备中] 人员
        if (null == firstReadyQueueItem) {
            return QUEUE_NOT_READY_PATIENT;
        }
        // QueueStatusEnum.READY  =>  QueueStatusEnum.ONSTAGE
        firstReadyQueueItem.setStatus(QueueStatusEnum.ONSTAGE.getStatus());
        queueMapper.updateById( firstReadyQueueItem );
        // 检查项目.亲和性 处理逻辑
        CheckTypeDO checkTypeDO = getCheckTypeItem( firstReadyQueueItem.getBookCheckType() );
        if (checkTypeDO.getAffinityCheckTypes().length > 0) {
            List<QueueDO> affinityItems = queueMapper.getCurPatGivenCheckTypesAndStatus(firstReadyQueueItem.getPatId(), checkTypeDO.getAffinityCheckTypes(), QueueStatusEnum.AFFINITY_WAITING.getStatus());
            if (!affinityItems.isEmpty()) {
                QueueDO tmpQueueDO = affinityItems.get(0);
                tmpQueueDO.setStatus( QueueStatusEnum.READY.getStatus() );
                queueMapper.updateById( tmpQueueDO );
                return GlobalErrorCodeConstants.SUCCESS;   // 准备中 数量没有变化,故直接返回
            }
        }
        // 优先队列中 该工位 就诊准备中人的数量 减一
@@ -418,6 +451,23 @@
                return;
            }
            // 抢到排队患者后,处理 检查项目.亲和性 逻辑
            QueueDO queueDO = queueMapper.getQueueItemBySeqNum(curSeqNum.get() + 1);
            CheckTypeDO checkTypeDO = getCheckTypeItem( queueDO.getBookCheckType() );
            if ( checkTypeDO.getAffinityCheckTypes().length > 0) {
                List<QueueDO> affinityItems = queueMapper.getCurPatGivenCheckTypesAndStatus(queueDO.getPatId(),
                        checkTypeDO.getAffinityCheckTypes(), QueueStatusEnum.WAITING.getStatus());
                for (int i = 0; i < affinityItems.size(); i++) {
                    QueueDO queueItem = affinityItems.get(i);
                    queueItem.setStatus(QueueStatusEnum.AFFINITY_WAITING.getStatus()); //改变 排队状态
                    queueItem.setRoomId(queueItem.getRoomId());
                    queueItem.setRoomName(queueItem.getRoomName());
                    queueItem.setBedNo(queueItem.getBedNo());
                    queueItem.setSeqNum(curSeqNum.get() + 1);  // 使用同一个 内部序号
                    queueMapper.updateById(queueItem);
                }
            }
            curSeqNum.getAndIncrement();
            // 可能已经【并发的】在 nextPatient 中改变了值
@@ -441,6 +491,10 @@
        mapCheckTypeVsReadyMax = checkTypeDOList.stream().collect(Collectors.toMap(CheckTypeDO::getValue, checkType -> checkType));
    }
    public CheckTypeDO getCheckTypeItem(Integer checkType) {
        return mapCheckTypeVsReadyMax.get( checkType );
    }
    public BedQueueBO getBedQueueBO(Long roomId, String bedNo) {
        return mapBedVsQueue.get( Utils.formatRoomBed(roomId, bedNo) );
    }
@@ -457,13 +511,6 @@
        MonitorInfoVO monitorInfoVO = new MonitorInfoVO();
        roomBedStatistic(monitorInfoVO);
        log.info(" opening " + openingFlag.get() + " " + monitorInfoVO.getQueueNum() + " " + monitorInfoVO.getActiveQueueNum() + " " + monitorInfoVO.getCheckTypeBedInfo().toString() );
    }
    public void resetQueueSequenceTable() {
        String strBookTimeslotLength = configApi.getConfigValueByKey(BOOK_TIMESLOT_LENGTH);
        String strBookTimeslotList = configApi.getConfigValueByKey(BOOK_TIMESLOT_LIST);
    }
    private Integer getBedReadyMax(Long roomId, String bedNo) {