eight
2024-08-27 dde48b28846af614af49d9e569d12dd69ec910a9
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
@@ -1,10 +1,12 @@
package cn.lihu.jh.module.ecg.service.queue;
import cn.lihu.jh.framework.common.exception.ErrorCode;
import cn.lihu.jh.module.ecg.dal.dataobject.queue.BedQueueStatisticDO;
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.room.RoomMapper;
import cn.lihu.jh.module.ecg.enums.BedStatusEnum;
import cn.lihu.jh.module.ecg.enums.ErrorCodeConstants;
import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -22,6 +24,7 @@
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
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.module.ecg.enums.ErrorCodeConstants.*;
@@ -77,11 +80,11 @@
    }
    @Override
    public Integer startBedOpen(Long roomId, String bedNo) {
        Future<Integer> future = singleThreadExecutor.submit( new BedOpenCallable(this, roomId, bedNo));
    public ErrorCode startBedOpen(Long roomId, String bedNo) {
        Future<ErrorCode> future = singleThreadExecutor.submit( new BedOpenCallable(this, roomId, bedNo));
        try {
            Integer ret = future.get();
            ErrorCode ret = future.get();
            return ret;
        } catch (InterruptedException e) {
            e.printStackTrace();
@@ -89,15 +92,15 @@
            e.printStackTrace();
        }
        return 100;
        return ECG_INNER_ERROR;
    }
    @Override
    public Integer startBedClose(Long roomId, String bedNo) {
        Future<Integer> future = singleThreadExecutor.submit( new BedCloseCallable(this, roomId, bedNo));
    public ErrorCode startBedClose(Long roomId, String bedNo) {
        Future<ErrorCode> future = singleThreadExecutor.submit( new BedCloseCallable(this, roomId, bedNo));
        try {
            Integer ret = future.get();
            ErrorCode ret = future.get();
            return ret;
        } catch (InterruptedException e) {
            e.printStackTrace();
@@ -105,17 +108,17 @@
            e.printStackTrace();
        }
        return 100;
        return ECG_INNER_ERROR;
    }
    @Override
    public Integer startBedDoctorPause(Long roomId, String bedNo, Long docId, String docName) {
        Future<Integer> future = singleThreadExecutor.submit(
    public ErrorCode startBedDoctorPause(Long roomId, String bedNo, Long docId, String docName) {
        Future<ErrorCode> future = singleThreadExecutor.submit(
            new BedDoctorPauseCallable(this, roomId, bedNo, docId, docName)
        );
        try {
            Integer ret = future.get();
            ErrorCode ret = future.get();
            return ret;
        } catch (InterruptedException e) {
            e.printStackTrace();
@@ -123,17 +126,17 @@
            e.printStackTrace();
        }
        return 100;
        return ECG_INNER_ERROR;
    }
    @Override
    public Integer startBedDoctorOn(Long roomId, String bedNo, Long docId, String docName) {
        Future<Integer> future = singleThreadExecutor.submit(
    public ErrorCode startBedDoctorOn(Long roomId, String bedNo, Long docId, String docName) {
        Future<ErrorCode> future = singleThreadExecutor.submit(
            new BedDoctorOnCallable(this, roomId, bedNo, docId, docName)
        );
        try {
            Integer ret = future.get();
            ErrorCode ret = future.get();
            return ret;
        } catch (InterruptedException e) {
            e.printStackTrace();
@@ -141,17 +144,17 @@
            e.printStackTrace();
        }
        return 100;
        return ECG_INNER_ERROR;
    }
    @Override
    public Integer startBedDoctorOff(Long roomId, String bedNo, Long docId, String docName) {
        Future<Integer> future = singleThreadExecutor.submit(
    public ErrorCode startBedDoctorOff(Long roomId, String bedNo, Long docId, String docName) {
        Future<ErrorCode> future = singleThreadExecutor.submit(
            new BedDoctorOffCallable(this, roomId, bedNo, docId, docName)
        );
        try {
            Integer ret = future.get();
            ErrorCode ret = future.get();
            return ret;
        } catch (InterruptedException e) {
            e.printStackTrace();
@@ -159,7 +162,7 @@
            e.printStackTrace();
        }
        return 100;
        return ECG_INNER_ERROR;
    }
@@ -170,7 +173,7 @@
     * @return
     */
    @Override
    public Integer bedOpen(Long roomId, String bedNo) {
    public ErrorCode bedOpen(Long roomId, String bedNo) {
        // DB update
        List statusList = new ArrayList<BedStatusEnum>();
        statusList.add(BedStatusEnum.CLOSED);
@@ -178,7 +181,7 @@
        Integer updateNum = roomMapper.setBedStatus(roomId, bedNo,
                BedStatusEnum.OPENING, statusList);
        if ( null==updateNum || 0 == updateNum )
            return 310;
            return ROOM_INVALID_STATUS;
        List<Byte> queueStatusList = new ArrayList<>();
        queueStatusList.add(QueueStatusEnum.READY.getStatus());
@@ -192,14 +195,14 @@
        bedQueueBO.setQueueNum(new AtomicInteger(queueDOList.size()));
        priorityQueue.offer(bedQueueBO);
        mapBedVsQueue.put(String.format("%09d%s", roomId, bedNo), bedQueueBO);
        return 0;
        return SUCCESS;
    }
    @Override
    public Integer bedClose(Long roomId, String bedNo) {
    public ErrorCode bedClose(Long roomId, String bedNo) {
        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
        if (null == bedQueueBO)
            return 320;
            return QUEUE_BED_ABNORMAL;
        // DB update
        List statusList = new ArrayList<BedStatusEnum>();
@@ -209,16 +212,16 @@
        Integer updateNum = roomMapper.setBedStatus(roomId, bedNo,
                BedStatusEnum.CLOSING, statusList);
        if ( null==updateNum || 0 == updateNum )
            return 321;
            return ROOM_INVALID_STATUS;
        return 0;
        return SUCCESS;
    }
    @Override
    public Integer bedDoctorPause(Long roomId, String bedNo, Long docId, String docName) {
    public ErrorCode bedDoctorPause(Long roomId, String bedNo, Long docId, String docName) {
        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
        if (null == bedQueueBO)
            return 320;
            return QUEUE_BED_ABNORMAL;
        // DB update
        List statusList = new ArrayList<BedStatusEnum>();
@@ -226,16 +229,16 @@
        Integer updateNum = roomMapper.setBedDoctorPause(roomId, bedNo, docId, docName,
                BedStatusEnum.PAUSE, statusList);
        if ( null==updateNum || 0 == updateNum )
            return 331;
            return ROOM_INVALID_STATUS;
        return 0;
        return SUCCESS;
    }
    @Override
    public Integer bedDoctorOn(Long roomId, String bedNo, Long docId, String docName) {
    public ErrorCode bedDoctorOn(Long roomId, String bedNo, Long docId, String docName) {
        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
        if (null == bedQueueBO)
            return 320;
            return QUEUE_BED_ABNORMAL;
        // DB update
        List statusList = new ArrayList<BedStatusEnum>();
@@ -243,16 +246,16 @@
        Integer updateNum = roomMapper.setBedDoctorOn(roomId, bedNo, docId, docName,
                BedStatusEnum.DOCTOR_ON, statusList);
        if ( null==updateNum || 0 == updateNum )
            return 341;
            return ROOM_INVALID_STATUS;
        return 0;
        return SUCCESS;
    }
    @Override
    public Integer bedDoctorOff(Long roomId, String bedNo, Long docId, String docName) {
    public ErrorCode bedDoctorOff(Long roomId, String bedNo, Long docId, String docName) {
        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
        if (null == bedQueueBO)
            return 320;
            return QUEUE_BED_ABNORMAL;
        // DB update
        List statusList = new ArrayList<BedStatusEnum>();
@@ -260,9 +263,9 @@
        Integer updateNum = roomMapper.setBedDoctorOff(roomId, bedNo, docId, docName,
                BedStatusEnum.OPENING, statusList);
        if ( null==updateNum || 0 == updateNum )
            return 351;
            return ROOM_INVALID_STATUS;
        return 0;
        return SUCCESS;
    }
    private void validatequeueExists(Integer id) {