From 20d1b6b5d9955faeed1689d656e1f6bab0097d1e Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期四, 10 十月 2024 15:08:30 +0800
Subject: [PATCH] 根据检查类型 安排医生工位 step 1

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomPageReqVO.java     |    3 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java                   |    2 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/MonitorInfoVO.java     |    2 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorNextPatientCallable.java |    2 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java                |    8 +
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java      |  202 ++++++++++++++++++++++++++++-----------
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomSaveReqVO.java     |    3 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceImpl.java             |   21 +++-
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java                  |    5 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueService.java                 |    4 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomRespVO.java        |    4 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomDO.java                 |    2 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorResumeCallable.java      |    2 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java              |    2 
 14 files changed, 191 insertions(+), 71 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/MonitorInfoVO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/MonitorInfoVO.java
index b2027b4..d244fc7 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/MonitorInfoVO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/MonitorInfoVO.java
@@ -7,4 +7,6 @@
     private Integer queueNum;
     private Integer activeQueueNum;
     private Integer openingFlag;
+    private String  openingInfo;
+    private String  operatingInfo;
 }
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomPageReqVO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomPageReqVO.java
index 14691f3..583ffa7 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomPageReqVO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomPageReqVO.java
@@ -31,6 +31,9 @@
     @Schema(description = "妫�鏌ョ被鍨�")
     private Integer[] checkTypes;
 
+    @Schema(description = "鎿嶄綔绫诲瀷")
+    private Integer opType;
+
     @Schema(description = "寮�璇婄姸鎬�")
     private Integer status;
 
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomRespVO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomRespVO.java
index dacce50..07e4214 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomRespVO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomRespVO.java
@@ -36,6 +36,10 @@
     @ExcelProperty("妫�鏌ョ被鍨�")
     private Integer[] checkTypes;
 
+    @Schema(description = "鎿嶄綔绫诲瀷")
+    @ExcelProperty("鎿嶄綔绫诲瀷")
+    private Integer opType;
+
     @Schema(description = "寮�璇婄姸鎬�", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("寮�璇婄姸鎬�")
     private Integer status;
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomSaveReqVO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomSaveReqVO.java
index 5f372c0..71ba7b4 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomSaveReqVO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomSaveReqVO.java
@@ -39,4 +39,7 @@
 
     @Schema(description = "妫�鏌ョ被鍨�")
     private Integer[] checkTypes;
+
+    @Schema(description = "鎿嶄綔绫诲瀷")
+    private Integer opType;
 }
\ No newline at end of file
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomDO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomDO.java
index c49e936..446d754 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomDO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomDO.java
@@ -63,4 +63,6 @@
 
     @TableField(typeHandler = JacksonTypeHandler.class)
     private Integer[] checkTypes;
+
+    private Integer opType;
 }
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java
index 0f917c6..3daeeed 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java
@@ -39,6 +39,9 @@
     @Select("SELECT max(seq_num) FROM lihu.queue")
     Integer getMaxSeqNum();
 
+    @Select("SELECT * FROM lihu.queue where pat_id = #{patId}")
+    QueueDO getQueueByPatId(@Param("patId")String patId);
+
     @Select("<script>" +
             "SELECT * FROM lihu.queue " +
             "where room_id = #{roomId} and status in (" +
@@ -112,9 +115,10 @@
     @Update("update lihu.queue set status = #{newStatus}, room_id = #{roomId}, room_name = #{roomName}, \n" +
             " bed_no = #{bedNo}, seq_num = #{seqNum} where id = \n" +
             "  (select a.id from \n" +
-            "    (select id from lihu.queue where status = #{curStatus} order by jump_flag desc, book_timeslot, create_time limit 1) a)")
+            "    (select id from lihu.queue where status = #{curStatus} and book_check_type= #{checkType} order by jump_flag desc, book_timeslot, create_time limit 1) a)")
     Integer preemptPatient(@Param("roomId")Long roomId, @Param("roomName")String roomName, @Param("bedNo")String bedNo,
-                           @Param("seqNum")Integer seqNum, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus);
+                           @Param("seqNum")Integer seqNum, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus,
+                           @Param("checkType")Integer checkType);
 
     @Update("update lihu.queue set status = #{newStatus}, seq_num = #{seqNum}, passed = 1 " +
             " where id = " +
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java
index acf2165..f352a2f 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java
@@ -41,13 +41,16 @@
     List<RoomStatisticsDO> roomStatistic();
 
     @Select("<script> " +
-            "SELECT id, room_id, room_name, bed_no, status, doc_id, doc_name FROM lihu.clinic_room " +
+            "SELECT * FROM lihu.clinic_room " +
             "where status in ( " +
                     " <foreach collection='curStatusList' separator=',' item='curStatus'>" +
                     "  #{curStatus.status} " +
                     " </foreach> )" +
             " and deleted = 0;" +
             "</script>")
+    @Results({
+            @Result(property = "checkTypes", column = "check_types", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+    })
     List<RoomDO> simpleRoomList(@Param("curStatusList") List<BedStatusEnum> curStatusList);
 
     @Select("SELECT * FROM lihu.clinic_room where room_id=#{roomId} and bed_no=#{bedNo}")
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorNextPatientCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorNextPatientCallable.java
index ab983a4..18db62b 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorNextPatientCallable.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorNextPatientCallable.java
@@ -22,7 +22,7 @@
     public ErrorCode call() throws Exception {
         ErrorCode ec = queueService.nextPatient(roomId, bedNo);
         if (GlobalErrorCodeConstants.SUCCESS.equals(ec)) {
-            queueService.hurryup();
+            queueService.hurryupOneBed(roomId, bedNo);
         }
 
         queueService.monitorInfo();
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorResumeCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorResumeCallable.java
index 8cafece..8d5198b 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorResumeCallable.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorResumeCallable.java
@@ -26,7 +26,7 @@
     public ErrorCode call() throws Exception {
         ErrorCode ec = queueService.bedDoctorResume(roomId, bedNo, docId, docName);
         if (GlobalErrorCodeConstants.SUCCESS.equals(ec)) {
-            queueService.hurryup();
+            queueService.hurryupOneBed(roomId, bedNo);
         }
 
         queueService.monitorInfo();
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java
index 4b2a2ed..d299f27 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java
@@ -24,7 +24,7 @@
     public ErrorCode call() throws Exception {
         ErrorCode ec = queueService.bedOpen(roomId, roomName, bedNo);
         if (GlobalErrorCodeConstants.SUCCESS.equals(ec)) {
-            queueService.hurryup();
+            queueService.hurryupOneBed(roomId, bedNo);
         }
 
         queueService.monitorInfo();
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java
index 011c81b..7431881 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java
@@ -13,6 +13,8 @@
     AtomicInteger queueNum = new AtomicInteger(0);
     Integer maxQueueNum;
     Integer status;
+    Integer[] checkTypes;
+    Integer opType;
 
     @Override
     public int compareTo(@NotNull BedQueueBO o) {
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueService.java
index d0e9913..ec540b2 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueService.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueService.java
@@ -50,7 +50,9 @@
     /**
      *
      */
-    void startHurryUp();
+    void startHurryUpOneBed(Long roomId, String bedNo);
+    void startHurryUpOneCheckType(Integer checkType);
+
     void startBedReload();
     void startResetRoom(Boolean needCloseBed);
     MonitorInfoVO getMonitorInfo();
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceImpl.java
index f9bd92d..bc007a9 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceImpl.java
@@ -218,9 +218,16 @@
     }
 
     @Override
-    public void startHurryUp() {
+    public void startHurryUpOneBed(Long roomId, String bedNo) {
         singleThreadExecutor.execute( () -> {
-            queueServiceTxFunctions.hurryup();
+            queueServiceTxFunctions.hurryupOneBed(roomId, bedNo);
+        });
+    }
+
+    @Override
+    public void startHurryUpOneCheckType(Integer checkType) {
+        singleThreadExecutor.execute( () -> {
+            queueServiceTxFunctions.hurryupOneCheckType( checkType );
         });
     }
 
@@ -228,7 +235,7 @@
     public void startBedReload() {
         singleThreadExecutor.execute( () -> {
             queueServiceTxFunctions.bedReload();
-            queueServiceTxFunctions.hurryup();
+            queueServiceTxFunctions.hurryupAllBed();
             queueServiceTxFunctions.monitorInfo();
         });
     }
@@ -296,7 +303,7 @@
         devRent.setState( DevRentStateEnum.FREE.getState() );
         devRentMapper.insert(devRent);
 
-        startHurryUp();
+        startHurryUpOneCheckType(Integer.valueOf(queue.getBookCheckType()));
     }
 
     public void finishNextPatient(Long roomId, String bedNo) {
@@ -362,14 +369,16 @@
     public Integer recallPatient(Long roomId, String bedNo, String patId) {
         Integer updateNum = queueMapper.recallPassedPatient(roomId, bedNo, patId,
                 QueueStatusEnum.PASSED.getStatus(), QueueStatusEnum.RECALLED.getStatus());
-        startHurryUp();
+        startHurryUpOneBed(roomId, bedNo);
         return updateNum;
     }
 
     @Override
     public Integer patientJump(String patId, Byte jumped) {
         Integer updateNum = queueMapper.queueJump(patId, QueueStatusEnum.WAITING.getStatus(), jumped);
-        startHurryUp();
+
+        QueueDO queueDO = queueMapper.getQueueByPatId(patId);
+        startHurryUpOneCheckType(Integer.valueOf(queueDO.getBookCheckType()));
         return updateNum;
     }
 
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java
index 15bfd80..2c13a09 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java
@@ -15,14 +15,12 @@
 import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
 import cn.lihu.jh.module.system.api.oauth2.OAuth2TokenApi;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Component;
 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.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -58,8 +56,10 @@
     AtomicInteger openingFlag = new AtomicInteger(0);
     AtomicInteger curSeqNum = new AtomicInteger(0);
 
-    PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>();
     ConcurrentHashMap<String, BedQueueBO > mapBedVsQueue = new ConcurrentHashMap<>();
+
+    //PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>();
+    Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapCheckTypeVsPriorityQueue = new HashMap();
 
     Map<Integer, Integer> mapCheckTypeVsReadyMax = null;
 
@@ -89,7 +89,9 @@
         queueStatusList.add(QueueStatusEnum.READY.getStatus());
         List<QueueDO> queueDOList = queueMapper.getDoctorQueueByStatus(roomId, bedNo, queueStatusList);
 
-        // 鏂板宸ヤ綅 浼樺厛闃熷垪
+        RoomDO roomDO = roomMapper.getRoom(roomId, bedNo);
+
+        // 鏂板..宸ヤ綅闃熷垪
         BedQueueBO bedQueueBO = new BedQueueBO();
         bedQueueBO.setRoomId(roomId);
         bedQueueBO.setRoomName(roomName);
@@ -97,6 +99,8 @@
         bedQueueBO.setMaxQueueNum(getBedReadyMax(roomId, bedNo));
         bedQueueBO.setQueueNum(new AtomicInteger(queueDOList.size()));
         bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus());
+        bedQueueBO.setCheckTypes( roomDO.getCheckTypes() );
+        bedQueueBO.setOpType( roomDO.getOpType() );
         mapBedVsQueue.put(String.format("%09d%s", roomId, bedNo), bedQueueBO);
 
         return GlobalErrorCodeConstants.SUCCESS;
@@ -133,7 +137,7 @@
         }
 
         mapBedVsQueue.remove(String.format("%09d%s", roomId, bedNo));
-        priorityQueue.remove(bedQueueBO);
+        removePriorityQueue(bedQueueBO);
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
@@ -154,7 +158,7 @@
         }
 
         bedQueueBO.setStatus(BedStatusEnum.PAUSE.getStatus());
-        priorityQueue.remove(bedQueueBO);
+        removePriorityQueue(bedQueueBO);
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
@@ -176,13 +180,7 @@
         }
 
         bedQueueBO.setStatus(BedStatusEnum.DOCTOR_ON.getStatus());
-        if (!priorityQueue.contains(bedQueueBO)) {
-            priorityQueue.offer(bedQueueBO);
-        } else {
-            log.error("bedDoctorResume priorityQueue still exist!. " + roomId + " " + bedNo);
-            return ECG_INNER_ERROR;
-        }
-
+        addPriorityQueue(bedQueueBO);
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
@@ -203,13 +201,7 @@
         }
 
         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;
-        }
-
+        addPriorityQueue(bedQueueBO);
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
@@ -230,7 +222,7 @@
             return ROOM_INVALID_STATUS;
         }
 
-        priorityQueue.remove(bedQueueBO);
+        removePriorityQueue(bedQueueBO);
 
         bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus());
         return GlobalErrorCodeConstants.SUCCESS;
@@ -248,9 +240,8 @@
         // 浼樺厛闃熷垪涓� 璇ュ伐浣� 灏辫瘖鍑嗗涓汉鐨勬暟閲� 鍑忎竴
         BedQueueBO bo = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
         bo.queueNum.getAndDecrement(); // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 hurry-up 涓敼鍙樹簡鍊�
-        priorityQueue.remove(bo);
-        priorityQueue.offer(bo);
 
+        removePriorityQueue(bo);
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
@@ -259,7 +250,7 @@
      * 2. 鏈嶅姟杩愮淮閲嶅惎鏃�
      */
     public ErrorCode bedReload() {
-        priorityQueue.clear();
+        mapCheckTypeVsPriorityQueue.clear();
         mapBedVsQueue.clear();
 
         // 娓呴櫎闈炲綋澶╃殑鎺掗槦浜哄憳
@@ -290,7 +281,7 @@
             item.queueNum.set( queueNum );
             mapBedVsQueue.put(String.format("%09d%s", item.roomId, item.bedNo), item);
             if (BedStatusEnum.DOCTOR_ON.getStatus() == item.getStatus()) {
-                priorityQueue.offer(item);
+                addPriorityQueue(item);
             }
         });
 
@@ -315,39 +306,55 @@
         }
     }
 
-    /**
-     * 鎶婂尰鐢熷�欒瘖鐨勯槦鍒楀婊�
-     */
-    public void hurryup() {
+    public void hurryupAllBed() {
         if (0 == openingFlag.get())
             return;
 
+        mapBedVsQueue.values().forEach(bedQueueBO -> hurryupOneBed(bedQueueBO.roomId, bedQueueBO.bedNo));
+    }
+
+    /**
+     * 鎶婂尰鐢熷�欒瘖鐨勯槦鍒楀婊�
+     */
+    public void hurryupOneBed(Long roomId, String bedNo) {
+        if (0 == openingFlag.get())
+            return;
+
+        BedQueueBO bedQueueBO = getBedQueueBO(roomId, bedNo);
+
         // 澶勭悊 杩囧彿-鍥炴潵 鐨勪汉
-        for (BedQueueBO bedQueueBO : mapBedVsQueue.values()) {
-            while (bedQueueBO.queueNum.get() < bedQueueBO.maxQueueNum) {
-                // 鏌ョ湅 褰撳墠宸ヤ綅 鏄惁鏈夎繃鍙�-鍥炴潵鐨勬偅鑰�
-                Integer updateNum = queueMapper.queueRecalledPatient(
-                        bedQueueBO.getRoomId(),
-                        bedQueueBO.getRoomName(),
-                        bedQueueBO.getBedNo(),
-                        curSeqNum.get() + 1,
-                        QueueStatusEnum.RECALLED.getStatus(),
-                        QueueStatusEnum.READY.getStatus());
-                if (null == updateNum || 0 == updateNum)
-                    break;
+        while (bedQueueBO.queueNum.get() < bedQueueBO.maxQueueNum) {
+            // 鏌ョ湅 褰撳墠宸ヤ綅 鏄惁鏈夎繃鍙�-鍥炴潵鐨勬偅鑰�
+            Integer updateNum = queueMapper.queueRecalledPatient(
+                    bedQueueBO.getRoomId(),
+                    bedQueueBO.getRoomName(),
+                    bedQueueBO.getBedNo(),
+                    curSeqNum.get() + 1,
+                    QueueStatusEnum.RECALLED.getStatus(),
+                    QueueStatusEnum.READY.getStatus());
+            if (null == updateNum || 0 == updateNum)
+                break;
 
-                curSeqNum.getAndIncrement();
+            curSeqNum.getAndIncrement();
 
-                // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡鍊�
-                bedQueueBO.queueNum.incrementAndGet();
+            // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡鍊�
+            bedQueueBO.queueNum.incrementAndGet();
 
-                // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡浼樺厛闃熷垪椤哄簭
-                priorityQueue.remove(bedQueueBO);
-                priorityQueue.offer(bedQueueBO);
-            }
+            // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡浼樺厛闃熷垪椤哄簭
+            refreshPriorityQueue(bedQueueBO);
         }
 
         // 澶勭悊 鎺掗槦涓� 鎮h��
+        Integer[] checkTypes = bedQueueBO.getCheckTypes();
+        Arrays.stream(checkTypes).forEach(checkType -> hurryupOneCheckType(checkType));
+    }
+
+    public void hurryupOneCheckType(Integer checkType) {
+
+        PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+        if (null == priorityQueue)
+            return;
+
         while (true) {
             BedQueueBO bedQueueBO = priorityQueue.peek();
             if (null == bedQueueBO)
@@ -355,7 +362,7 @@
 
             int curQueueNum = bedQueueBO.queueNum.get();
             if (curQueueNum > bedQueueBO.maxQueueNum)
-                throw new RuntimeException("hurryup: exceed max queue number!");
+                throw new RuntimeException("hurryupOneCheckType: exceed max queue number!");
 
             if (curQueueNum == bedQueueBO.maxQueueNum)
                 return;
@@ -367,7 +374,8 @@
                     bedQueueBO.getBedNo(),
                     curSeqNum.get() + 1,
                     QueueStatusEnum.WAITING.getStatus(),
-                    QueueStatusEnum.READY.getStatus());
+                    QueueStatusEnum.READY.getStatus(),
+                    checkType);
 
             // 娌℃湁鎶㈠埌鎺掗槦鎮h��
             if (null == updateNum || 0 == updateNum) {
@@ -380,8 +388,7 @@
             bedQueueBO.queueNum.incrementAndGet();
 
             // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡浼樺厛闃熷垪椤哄簭
-            priorityQueue.remove(bedQueueBO);
-            priorityQueue.offer(bedQueueBO);
+            refreshPriorityQueue(bedQueueBO);
         }
     }
 
@@ -404,14 +411,16 @@
     public MonitorInfoVO getMonitorInfo() {
         MonitorInfoVO monitorInfoVO = new MonitorInfoVO();
         monitorInfoVO.setOpeningFlag( openingFlag.get() );
-        monitorInfoVO.setQueueNum( mapBedVsQueue.size() );
-        monitorInfoVO.setActiveQueueNum( priorityQueue.size() );
+        String[] arrStatInfo = roomBedStatistic();
+        monitorInfoVO.setOpeningInfo(arrStatInfo[0]);
+        monitorInfoVO.setOperatingInfo(arrStatInfo[1]);
+
         return monitorInfoVO;
     }
 
     public void monitorInfo() {
-        log.info("map " + mapBedVsQueue.size() + " priority " + priorityQueue.size()
-                + " opening " + openingFlag.get());
+        String[] arrStatInfo = roomBedStatistic();
+        log.info(" opening " + openingFlag.get() + " openingInfo " + arrStatInfo[0] + " operatingInfo " + arrStatInfo[1] );
     }
 
     private Integer getBedReadyMax(Long roomId, String bedNo) {
@@ -424,4 +433,81 @@
         }
         return ret;
     }
+
+    private void addPriorityQueue(BedQueueBO bedQueueBO) {
+        Integer[] checkTypes = bedQueueBO.getCheckTypes();
+        Arrays.stream(checkTypes).forEach(checkType -> {
+            PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+            if (!priorityQueue.contains(bedQueueBO)) {
+                priorityQueue.offer(bedQueueBO);
+            } else {
+                log.error("bedDoctorResume priorityQueue still exist!. " + bedQueueBO.getRoomId() + " " + bedQueueBO.getBedNo());
+            }
+        });
+    }
+
+    private void removePriorityQueue(BedQueueBO bedQueueBO) {
+        Integer[] checkTypes = bedQueueBO.getCheckTypes();
+        Arrays.stream(checkTypes).forEach(checkType -> {
+            PriorityBlockingQueue<BedQueueBO> priorityBlockingQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+            if (null != priorityBlockingQueue)
+                priorityBlockingQueue.remove(bedQueueBO);
+        });
+    }
+
+    private void refreshPriorityQueue(BedQueueBO bedQueueBO) {
+        Integer[] checkTypes = bedQueueBO.getCheckTypes();
+        Arrays.stream(checkTypes).forEach(checkType -> {
+            PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+            priorityQueue.remove(bedQueueBO);
+            priorityQueue.offer(bedQueueBO);
+        });
+    }
+
+    private String[]  roomBedStatistic() {
+        Map<Integer, Integer>  mapOpeningCheckBedStatInfo = new HashMap<>();
+        Map<Integer, Integer>  mapOpeningReadyBedStatInfo = new HashMap<>();
+        Map<Integer, Integer>  mapOperatingCheckBedStatInfo = new HashMap<>();
+        Map<Integer, Integer>  mapOperatingReadyBedStatInfo = new HashMap<>();
+        mapCheckTypeVsReadyMax.keySet().forEach( checkType -> {
+            mapOpeningCheckBedStatInfo.put(checkType, 0);
+            mapOpeningReadyBedStatInfo.put(checkType, 0);
+            mapOperatingCheckBedStatInfo.put(checkType, 0);
+            mapOperatingReadyBedStatInfo.put(checkType, 0);
+        });
+
+        //寮�閫氱殑宸ヤ綅缁熻
+        mapBedVsQueue.values().forEach( bedQueueBO -> {
+            Integer[] checkTypes = bedQueueBO.getCheckTypes();
+            Arrays.stream(checkTypes).forEach(checkType -> {
+                if (bedQueueBO.opType == 0)
+                    mapOpeningCheckBedStatInfo.put(checkType, mapOpeningCheckBedStatInfo.get(checkType) + 1 );
+                else
+                    mapOpeningReadyBedStatInfo.put(checkType, mapOpeningReadyBedStatInfo.get(checkType) + 1 );
+            });
+        });
+
+        String openingBedInfo = "鎬绘暟锛�" + mapBedVsQueue.size() + "  妫�鏌ュ伐浣嶆暟: " + mapOpeningCheckBedStatInfo.toString() + "  棰嗙敤宸ヤ綅鏁�: " + mapOpeningReadyBedStatInfo.toString();
+
+        //杩愯惀涓伐浣嶇粺璁�
+        HashSet<BedQueueBO> hashSetOperatingBedQueue = new HashSet<>();
+        mapCheckTypeVsPriorityQueue.values().forEach(priorityQueue->{
+            priorityQueue.stream().forEach(bedQueueBO -> hashSetOperatingBedQueue.add(bedQueueBO));
+        });
+
+        hashSetOperatingBedQueue.stream().forEach( bedQueueBO -> {
+            Integer[] checkTypes = bedQueueBO.getCheckTypes();
+            Arrays.stream(checkTypes).forEach(checkType -> {
+                if (bedQueueBO.opType == 0)
+                    mapOperatingCheckBedStatInfo.put(checkType, mapOperatingCheckBedStatInfo.get(checkType) + 1 );
+                else
+                    mapOperatingReadyBedStatInfo.put(checkType, mapOperatingReadyBedStatInfo.get(checkType) + 1 );
+            });
+        });
+
+        String operatingBedInfo = "鎬绘暟锛�" + hashSetOperatingBedQueue.size() + "  妫�鏌ュ伐浣嶆暟: " + mapOperatingCheckBedStatInfo.toString() + "  棰嗙敤宸ヤ綅鏁�: " + mapOperatingReadyBedStatInfo.toString();
+
+        return new String[]{openingBedInfo, operatingBedInfo};
+    }
+
 }

--
Gitblit v1.9.3