From e86481b3a32200d83fdcdbca826b72e3776ae5cd Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期六, 12 十月 2024 14:23:55 +0800
Subject: [PATCH] 装机功能 相关 待续

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java |  125 +++++++++++++++++++++++++++--------------
 1 files changed, 83 insertions(+), 42 deletions(-)

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 2a3b853..f044cb7 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
@@ -4,18 +4,19 @@
 import cn.lihu.jh.framework.common.exception.enums.GlobalErrorCodeConstants;
 import cn.lihu.jh.framework.common.util.object.BeanUtils;
 import cn.lihu.jh.module.ecg.controller.admin.room.vo.MonitorInfoVO;
+import cn.lihu.jh.module.ecg.dal.dataobject.checktype.CheckTypeDO;
 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.call.CallMapper;
+import cn.lihu.jh.module.ecg.dal.mysql.checktype.CheckTypeMapper;
 import cn.lihu.jh.module.ecg.dal.mysql.devrent.DevRentMapper;
-import cn.lihu.jh.module.ecg.dal.mysql.queue.queueMapper;
+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.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;
 
@@ -23,6 +24,7 @@
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.lihu.jh.framework.common.pojo.CommonResult.error;
@@ -42,7 +44,7 @@
     private OAuth2TokenApi oAuth2TokenApi;
 
     @Resource
-    private queueMapper queueMapper;
+    private QueueMapper queueMapper;
 
     @Resource
     private RoomMapper roomMapper;
@@ -53,15 +55,22 @@
     @Resource
     private DevRentMapper devRentMapper;
 
+    @Resource
+    private CheckTypeMapper checkTypeMapper;
+
+
     AtomicInteger openingFlag = new AtomicInteger(0);
     AtomicInteger curSeqNum = new AtomicInteger(0);
 
     ConcurrentHashMap<String, BedQueueBO > mapBedVsQueue = new ConcurrentHashMap<>();
 
-    //PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>();
-    Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapCheckTypeVsPriorityQueue = new HashMap();
+    // 瑁呮満宸ヤ綅..涓嶈繘鍏ヤ紭鍏堥槦鍒�
+    Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapCheckTypePriorityQueue = new HashMap();
 
-    Map<Integer, Integer> mapCheckTypeVsReadyMax = null;
+    // 鍩轰簬绫诲瀷鐨�, 瑁呮満鍑嗗鐨勪紭鍏堥槦鍒�
+    // Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapReadyPriorityQueue = new HashMap();
+
+    Map<Integer, CheckTypeDO> mapCheckTypeVsReadyMax = null;
 
     /**
      * 宸插叧闂� 鎴栬�� 鍏抽棴涓紝鍙互寮�閫氬伐浣�
@@ -87,7 +96,7 @@
 
         List<Byte> queueStatusList = new ArrayList<>();
         queueStatusList.add(QueueStatusEnum.READY.getStatus());
-        List<QueueDO> queueDOList = queueMapper.getDoctorQueueByStatus(roomId, bedNo, queueStatusList);
+        List<QueueDO> queueDOList = queueMapper.getBedQueueByStatus(roomId, bedNo, queueStatusList);
 
         RoomDO roomDO = roomMapper.getRoom(roomId, bedNo);
 
@@ -120,7 +129,7 @@
         queueStatusList.add(QueueStatusEnum.READY.getStatus());
         queueStatusList.add(QueueStatusEnum.PASSED.getStatus());
         queueStatusList.add(QueueStatusEnum.RECALLED.getStatus());
-        List<QueueDO>  queueDOList = queueMapper.getDoctorQueueByStatus(roomId, bedNo, queueStatusList);
+        List<QueueDO>  queueDOList = queueMapper.getBedQueueByStatus(roomId, bedNo, queueStatusList);
         if (queueDOList.size() > 0)
             return QUEUE_HAVE_PATIENT;
 
@@ -228,11 +237,12 @@
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
+    // 甯歌 鎴栬�� 棰嗙敤 鏃� 鍖荤敓 鍙栦笅涓�浣嶆偅鑰�
     public ErrorCode nextPatient(Long roomId, String bedNo) {
-        // 浠� DB 鎶� 搴忓彿鏈�灏忕殑 灏辫瘖鍑嗗涓殑浜� 璁剧疆涓哄氨璇婁腑
-        Integer updateNum = queueMapper.updateQueueStatus(roomId, bedNo,
+        // 浠� DB 鎶� 搴忓彿鏈�灏忕殑 [灏辫瘖鍑嗗涓璢 鐨勪汉 璁剧疆涓� [灏辫瘖涓璢 (鎴栭鐢ㄤ腑)
+        Integer updateNum = queueMapper.updateBedQueueStatus(roomId, bedNo,
                 QueueStatusEnum.READY.getStatus(), QueueStatusEnum.ONSTAGE.getStatus());
-        // 璇ュ伐浣� 娌℃湁 灏辫瘖鍑嗗涓� 浜哄憳
+        // 璇ュ伐浣� 娌℃湁 [灏辫瘖鍑嗗涓璢 浜哄憳
         if (null == updateNum || 0 == updateNum) {
             return QUEUE_NOT_READY_PATIENT;
         }
@@ -241,7 +251,26 @@
         BedQueueBO bo = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
         bo.queueNum.getAndDecrement(); // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 hurry-up 涓敼鍙樹簡鍊�
 
-        removePriorityQueue(bo);
+        refreshPriorityQueue(bo);
+        return GlobalErrorCodeConstants.SUCCESS;
+    }
+
+    // 瑁呮満鏃� 鍖荤敓 鍙栦笅涓�浣嶆偅鑰�
+    public ErrorCode nextInstallPatient(Long roomId, String bedNo) {
+        // 浠� DB 鎶� 搴忓彿鏈�灏忕殑 [宸查鐢╙ 鐨勪汉 璁剧疆涓� [瀹夎涓璢
+        Integer updateNum = queueMapper.preemptReceivedPatient(roomId, bedNo,
+                QueueStatusEnum.RECEIVED.getStatus(), QueueStatusEnum.INSTALLING.getStatus());
+        // 璇ュ伐浣� 娌℃湁 [宸查鐢╙ 浜哄憳
+        if (null == updateNum || 0 == updateNum) {
+            return QUEUE_NOT_READY_PATIENT;
+        }
+
+        // 瑁呮満宸ヤ綅 鏃犱紭鍏堥槦鍒�
+        // 浼樺厛闃熷垪涓� 璇ュ伐浣� [宸查鐢╙浜虹殑鏁伴噺 鍑忎竴
+        //BedQueueBO bo = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
+        //bo.queueNum.getAndDecrement(); // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 hurry-up 涓敼鍙樹簡鍊�
+        //refreshPriorityQueue(bo);
+
         return GlobalErrorCodeConstants.SUCCESS;
     }
 
@@ -250,7 +279,7 @@
      * 2. 鏈嶅姟杩愮淮閲嶅惎鏃�
      */
     public ErrorCode bedReload() {
-        mapCheckTypeVsPriorityQueue.clear();
+        mapCheckTypePriorityQueue.clear();
         mapBedVsQueue.clear();
 
         // 娓呴櫎闈炲綋澶╃殑鎺掗槦浜哄憳
@@ -351,7 +380,7 @@
 
     public void hurryupOneCheckType(Integer checkType) {
 
-        PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+        PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypePriorityQueue.get(checkType);
         if (null == priorityQueue)
             return;
 
@@ -368,7 +397,7 @@
                 return;
 
             // 鏌ョ湅 鏄惁鏈夋帓闃熶腑鐨勬偅鑰�
-            Integer updateNum = queueMapper.preemptPatient(
+            Integer updateNum = queueMapper.preemptWaitingPatient(
                     bedQueueBO.getRoomId(),
                     bedQueueBO.getRoomName(),
                     bedQueueBO.getBedNo(),
@@ -400,8 +429,9 @@
         openingFlag.set(flag);
     }
 
-    public void setCheckTypeReadyMax(Map<Integer, Integer> max) {
-        mapCheckTypeVsReadyMax = max;
+    public void initCheckType() {
+        List<CheckTypeDO> checkTypeDOList = checkTypeMapper.simpleCheckTypeList();
+        mapCheckTypeVsReadyMax = checkTypeDOList.stream().collect(Collectors.toMap(CheckTypeDO::getValue, checkType -> checkType));
     }
 
     public BedQueueBO getBedQueueBO(Long roomId, String bedNo) {
@@ -427,7 +457,8 @@
         Integer[] checkTypes = roomDO.getCheckTypes();
         Integer ret = 0;
         for (int i=0; i<checkTypes.length; i++) {
-            Integer tmp = mapCheckTypeVsReadyMax.get(checkTypes[i]);
+            CheckTypeDO checkTypeDO = mapCheckTypeVsReadyMax.get(checkTypes[i]);
+            Integer tmp = checkTypeDO.getReadyNum();
             ret = ret < tmp ? tmp : ret;  //鍙栧ぇ鍊�
         }
         return ret;
@@ -436,7 +467,18 @@
     private void addPriorityQueue(BedQueueBO bedQueueBO) {
         Integer[] checkTypes = bedQueueBO.getCheckTypes();
         Arrays.stream(checkTypes).forEach(checkType -> {
-            PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+            CheckTypeDO checkTypeDO = mapCheckTypeVsReadyMax.get(checkType);
+            // 瑁呮満宸ヤ綅 涓嶈繘 浼樺厛闃熷垪锛屼笉浠庢帓闃熶腑鎺ユ敹浜�
+            if (checkTypeDO.getNeedDevReady() == 1 && bedQueueBO.getOpType() == 2) {
+                return;
+            }
+            
+            PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypePriorityQueue.get(checkType);
+            if (null == priorityQueue) {
+                priorityQueue = new PriorityBlockingQueue<BedQueueBO>();
+                mapCheckTypePriorityQueue.put( checkType, priorityQueue );
+            }
+
             if (!priorityQueue.contains(bedQueueBO)) {
                 priorityQueue.offer(bedQueueBO);
             } else {
@@ -448,7 +490,7 @@
     private void removePriorityQueue(BedQueueBO bedQueueBO) {
         Integer[] checkTypes = bedQueueBO.getCheckTypes();
         Arrays.stream(checkTypes).forEach(checkType -> {
-            PriorityBlockingQueue<BedQueueBO> priorityBlockingQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+            PriorityBlockingQueue<BedQueueBO> priorityBlockingQueue = mapCheckTypePriorityQueue.get(checkType);
             if (null != priorityBlockingQueue)
                 priorityBlockingQueue.remove(bedQueueBO);
         });
@@ -457,7 +499,7 @@
     private void refreshPriorityQueue(BedQueueBO bedQueueBO) {
         Integer[] checkTypes = bedQueueBO.getCheckTypes();
         Arrays.stream(checkTypes).forEach(checkType -> {
-            PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypeVsPriorityQueue.get(checkType);
+            PriorityBlockingQueue<BedQueueBO> priorityQueue = mapCheckTypePriorityQueue.get(checkType);
             priorityQueue.remove(bedQueueBO);
             priorityQueue.offer(bedQueueBO);
         });
@@ -465,55 +507,54 @@
 
     private void roomBedStatistic(MonitorInfoVO monitorInfoVO) {
         Map<Integer, Integer>  mapOpeningCheckBedStatInfo = new HashMap<>();
-        Map<Integer, Integer>  mapOpeningReadyBedStatInfo = new HashMap<>();
+        Map<Integer, Integer>  mapOpeningInstallBedStatInfo = new HashMap<>();
         Map<Integer, Integer>  mapOperatingCheckBedStatInfo = new HashMap<>();
-        Map<Integer, Integer>  mapOperatingReadyBedStatInfo = new HashMap<>();
+        Map<Integer, Integer>  mapOperatingInstallBedStatInfo = new HashMap<>();
         mapCheckTypeVsReadyMax.keySet().forEach( checkType -> {
             mapOpeningCheckBedStatInfo.put(checkType, 0);
-            mapOpeningReadyBedStatInfo.put(checkType, 0);
+            mapOpeningInstallBedStatInfo.put(checkType, 0);
             mapOperatingCheckBedStatInfo.put(checkType, 0);
-            mapOperatingReadyBedStatInfo.put(checkType, 0);
+            mapOperatingInstallBedStatInfo.put(checkType, 0);
         });
 
-        //寮�閫氱殑宸ヤ綅缁熻
+        //寮�閫氱殑 鍜� 杩愯惀涓� 鐨勫伐浣嶇粺璁�
         mapBedVsQueue.values().forEach( bedQueueBO -> {
             Integer[] checkTypes = bedQueueBO.getCheckTypes();
             Arrays.stream(checkTypes).forEach(checkType -> {
-                if (bedQueueBO.opType == 0)
+                if (bedQueueBO.opType == 0 || bedQueueBO.opType == 1)
                     mapOpeningCheckBedStatInfo.put(checkType, mapOpeningCheckBedStatInfo.get(checkType) + 1 );
                 else
-                    mapOpeningReadyBedStatInfo.put(checkType, mapOpeningReadyBedStatInfo.get(checkType) + 1 );
+                    mapOpeningInstallBedStatInfo.put(checkType, mapOpeningInstallBedStatInfo.get(checkType) + 1 );
+
+                if (bedQueueBO.getStatus() == BedStatusEnum.DOCTOR_ON.getStatus()) {
+                    if (bedQueueBO.opType == 0 || bedQueueBO.opType == 1)
+                        mapOperatingCheckBedStatInfo.put(checkType, mapOperatingCheckBedStatInfo.get(checkType) + 1);
+                    else
+                        mapOperatingInstallBedStatInfo.put(checkType, mapOperatingInstallBedStatInfo.get(checkType) + 1);
+                }
             });
         });
 
-        //杩愯惀涓伐浣嶇粺璁�
+        // 鎺ユ敹..鎺掗槦涓偅鑰�..鐨勪紭鍏堥槦鍒�
         HashSet<BedQueueBO> hashSetOperatingBedQueue = new HashSet<>();
-        mapCheckTypeVsPriorityQueue.values().forEach(priorityQueue->{
+        mapCheckTypePriorityQueue.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 );
-            });
-        });
 
         Map<Integer, String> mapCheckTypeBedInfo = new HashMap<>();
         mapCheckTypeVsReadyMax.keySet().forEach( checkType -> {
            String str = mapOpeningCheckBedStatInfo.get(checkType) + " " +
-                        mapOpeningReadyBedStatInfo.get(checkType) + " " +
+                        mapOpeningInstallBedStatInfo.get(checkType) + " " +
                         mapOperatingCheckBedStatInfo.get(checkType) + " " +
-                        mapOperatingReadyBedStatInfo.get(checkType) + " ";
+                        mapOperatingInstallBedStatInfo.get(checkType) + " ";
             mapCheckTypeBedInfo.put( checkType, str);
         });
 
         monitorInfoVO.setCheckTypeBedInfo(mapCheckTypeBedInfo);
         monitorInfoVO.setQueueNum(mapBedVsQueue.size());
-        monitorInfoVO.setActiveQueueNum(hashSetOperatingBedQueue.size());
+        monitorInfoVO.setActiveQueueNum((int) mapBedVsQueue.values().stream().filter(item -> item.getStatus() == BedStatusEnum.DOCTOR_ON.getStatus()).count());
+        monitorInfoVO.setPriorityQueueNum( hashSetOperatingBedQueue.size() );
     }
 
 }

--
Gitblit v1.9.3