From 6a7f481d975f94984602b15c90904090f30b9b67 Mon Sep 17 00:00:00 2001 From: eight <641137800@qq.com> Date: 星期六, 12 十月 2024 10:15:17 +0800 Subject: [PATCH] 叫号分 领用叫号、安装叫号、常规叫号 --- jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java | 241 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 177 insertions(+), 64 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 15bfd80..6ef229c 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,12 +4,14 @@ 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; @@ -19,12 +21,10 @@ 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; +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; @@ -44,7 +44,7 @@ private OAuth2TokenApi oAuth2TokenApi; @Resource - private queueMapper queueMapper; + private QueueMapper queueMapper; @Resource private RoomMapper roomMapper; @@ -55,13 +55,22 @@ @Resource private DevRentMapper devRentMapper; + @Resource + private CheckTypeMapper checkTypeMapper; + + AtomicInteger openingFlag = new AtomicInteger(0); AtomicInteger curSeqNum = new AtomicInteger(0); - PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>(); ConcurrentHashMap<String, BedQueueBO > mapBedVsQueue = new ConcurrentHashMap<>(); - Map<Integer, Integer> mapCheckTypeVsReadyMax = null; + // 瑁呮満宸ヤ綅..涓嶈繘鍏ヤ紭鍏堥槦鍒� + Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapCheckTypePriorityQueue = new HashMap(); + + // 鍩轰簬绫诲瀷鐨�, 瑁呮満鍑嗗鐨勪紭鍏堥槦鍒� + // Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapReadyPriorityQueue = new HashMap(); + + Map<Integer, CheckTypeDO> mapCheckTypeVsReadyMax = null; /** * 宸插叧闂� 鎴栬�� 鍏抽棴涓紝鍙互寮�閫氬伐浣� @@ -89,7 +98,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 +108,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 +146,7 @@ } mapBedVsQueue.remove(String.format("%09d%s", roomId, bedNo)); - priorityQueue.remove(bedQueueBO); + removePriorityQueue(bedQueueBO); return GlobalErrorCodeConstants.SUCCESS; } @@ -154,7 +167,7 @@ } bedQueueBO.setStatus(BedStatusEnum.PAUSE.getStatus()); - priorityQueue.remove(bedQueueBO); + removePriorityQueue(bedQueueBO); return GlobalErrorCodeConstants.SUCCESS; } @@ -176,13 +189,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 +210,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 +231,7 @@ return ROOM_INVALID_STATUS; } - priorityQueue.remove(bedQueueBO); + removePriorityQueue(bedQueueBO); bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus()); return GlobalErrorCodeConstants.SUCCESS; @@ -248,9 +249,8 @@ // 浼樺厛闃熷垪涓� 璇ュ伐浣� 灏辫瘖鍑嗗涓汉鐨勬暟閲� 鍑忎竴 BedQueueBO bo = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo)); bo.queueNum.getAndDecrement(); // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 hurry-up 涓敼鍙樹簡鍊� - priorityQueue.remove(bo); - priorityQueue.offer(bo); + refreshPriorityQueue(bo); return GlobalErrorCodeConstants.SUCCESS; } @@ -259,7 +259,7 @@ * 2. 鏈嶅姟杩愮淮閲嶅惎鏃� */ public ErrorCode bedReload() { - priorityQueue.clear(); + mapCheckTypePriorityQueue.clear(); mapBedVsQueue.clear(); // 娓呴櫎闈炲綋澶╃殑鎺掗槦浜哄憳 @@ -290,7 +290,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 +315,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 = mapCheckTypePriorityQueue.get(checkType); + if (null == priorityQueue) + return; + while (true) { BedQueueBO bedQueueBO = priorityQueue.peek(); if (null == bedQueueBO) @@ -355,7 +371,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 +383,8 @@ bedQueueBO.getBedNo(), curSeqNum.get() + 1, QueueStatusEnum.WAITING.getStatus(), - QueueStatusEnum.READY.getStatus()); + QueueStatusEnum.READY.getStatus(), + checkType); // 娌℃湁鎶㈠埌鎺掗槦鎮h�� if (null == updateNum || 0 == updateNum) { @@ -380,8 +397,7 @@ bedQueueBO.queueNum.incrementAndGet(); // 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡浼樺厛闃熷垪椤哄簭 - priorityQueue.remove(bedQueueBO); - priorityQueue.offer(bedQueueBO); + refreshPriorityQueue(bedQueueBO); } } @@ -393,8 +409,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) { @@ -404,14 +421,15 @@ public MonitorInfoVO getMonitorInfo() { MonitorInfoVO monitorInfoVO = new MonitorInfoVO(); monitorInfoVO.setOpeningFlag( openingFlag.get() ); - monitorInfoVO.setQueueNum( mapBedVsQueue.size() ); - monitorInfoVO.setActiveQueueNum( priorityQueue.size() ); + roomBedStatistic(monitorInfoVO); + return monitorInfoVO; } public void monitorInfo() { - log.info("map " + mapBedVsQueue.size() + " priority " + priorityQueue.size() - + " opening " + openingFlag.get()); + MonitorInfoVO monitorInfoVO = new MonitorInfoVO(); + roomBedStatistic(monitorInfoVO); + log.info(" opening " + openingFlag.get() + " " + monitorInfoVO.getQueueNum() + " " + monitorInfoVO.getActiveQueueNum() + " " + monitorInfoVO.getCheckTypeBedInfo().toString() ); } private Integer getBedReadyMax(Long roomId, String bedNo) { @@ -419,9 +437,104 @@ 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; } + + private void addPriorityQueue(BedQueueBO bedQueueBO) { + Integer[] checkTypes = bedQueueBO.getCheckTypes(); + Arrays.stream(checkTypes).forEach(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 { + 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 = mapCheckTypePriorityQueue.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 = mapCheckTypePriorityQueue.get(checkType); + priorityQueue.remove(bedQueueBO); + priorityQueue.offer(bedQueueBO); + }); + } + + private void roomBedStatistic(MonitorInfoVO monitorInfoVO) { + Map<Integer, Integer> mapOpeningCheckBedStatInfo = new HashMap<>(); + Map<Integer, Integer> mapOpeningInstallBedStatInfo = new HashMap<>(); + Map<Integer, Integer> mapOperatingCheckBedStatInfo = new HashMap<>(); + Map<Integer, Integer> mapOperatingInstallBedStatInfo = new HashMap<>(); + mapCheckTypeVsReadyMax.keySet().forEach( checkType -> { + mapOpeningCheckBedStatInfo.put(checkType, 0); + mapOpeningInstallBedStatInfo.put(checkType, 0); + mapOperatingCheckBedStatInfo.put(checkType, 0); + mapOperatingInstallBedStatInfo.put(checkType, 0); + }); + + //寮�閫氱殑 鍜� 杩愯惀涓� 鐨勫伐浣嶇粺璁� + mapBedVsQueue.values().forEach( bedQueueBO -> { + Integer[] checkTypes = bedQueueBO.getCheckTypes(); + Arrays.stream(checkTypes).forEach(checkType -> { + if (bedQueueBO.opType == 0 || bedQueueBO.opType == 1) + mapOpeningCheckBedStatInfo.put(checkType, mapOpeningCheckBedStatInfo.get(checkType) + 1 ); + else + 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<>(); + mapCheckTypePriorityQueue.values().forEach(priorityQueue->{ + priorityQueue.stream().forEach(bedQueueBO -> hashSetOperatingBedQueue.add(bedQueueBO)); + }); + + + Map<Integer, String> mapCheckTypeBedInfo = new HashMap<>(); + mapCheckTypeVsReadyMax.keySet().forEach( checkType -> { + String str = mapOpeningCheckBedStatInfo.get(checkType) + " " + + mapOpeningInstallBedStatInfo.get(checkType) + " " + + mapOperatingCheckBedStatInfo.get(checkType) + " " + + mapOperatingInstallBedStatInfo.get(checkType) + " "; + mapCheckTypeBedInfo.put( checkType, str); + }); + + monitorInfoVO.setCheckTypeBedInfo(mapCheckTypeBedInfo); + monitorInfoVO.setQueueNum(mapBedVsQueue.size()); + monitorInfoVO.setActiveQueueNum((int) mapBedVsQueue.values().stream().filter(item -> item.getStatus() == BedStatusEnum.DOCTOR_ON.getStatus()).count()); + monitorInfoVO.setPriorityQueueNum( hashSetOperatingBedQueue.size() ); + } + } -- Gitblit v1.9.3