From 05466007a40b6a22d68ef47b784fb3738760d18b Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期四, 10 十月 2024 16:36:15 +0800
Subject: [PATCH] 工位状态 动态查看
---
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/QueueServiceTxFunctions.java | 245 +++++++++++++++++++++++++++++++++---------------
1 files changed, 168 insertions(+), 77 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 93ed504..2a3b853 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
@@ -2,16 +2,8 @@
import cn.lihu.jh.framework.common.exception.ErrorCode;
import cn.lihu.jh.framework.common.exception.enums.GlobalErrorCodeConstants;
-import cn.lihu.jh.framework.common.pojo.CommonResult;
-import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.framework.common.util.object.BeanUtils;
-import cn.lihu.jh.module.ecg.controller.admin.queue.vo.PatientStatisticVO;
-import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueuePageReqVO;
-import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueueSaveReqVO;
import cn.lihu.jh.module.ecg.controller.admin.room.vo.MonitorInfoVO;
-import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomRespVO;
-import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO;
-import cn.lihu.jh.module.ecg.dal.dataobject.queue.BedQueueStatisticDO;
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;
@@ -20,25 +12,20 @@
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.DevRentStateEnum;
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.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
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.framework.common.pojo.CommonResult.success;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
/**
@@ -69,10 +56,12 @@
AtomicInteger openingFlag = new AtomicInteger(0);
AtomicInteger curSeqNum = new AtomicInteger(0);
- PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>();
ConcurrentHashMap<String, BedQueueBO > mapBedVsQueue = new ConcurrentHashMap<>();
- Integer queueReadyMax = 0;
+ //PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>();
+ Map<Integer, PriorityBlockingQueue<BedQueueBO>> mapCheckTypeVsPriorityQueue = new HashMap();
+
+ Map<Integer, Integer> mapCheckTypeVsReadyMax = null;
/**
* 宸插叧闂� 鎴栬�� 鍏抽棴涓紝鍙互寮�閫氬伐浣�
@@ -100,15 +89,18 @@
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);
bedQueueBO.setBedNo(bedNo);
- bedQueueBO.setMaxQueueNum(queueReadyMax);
+ bedQueueBO.setMaxQueueNum(getBedReadyMax(roomId, bedNo));
bedQueueBO.setQueueNum(new AtomicInteger(queueDOList.size()));
bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus());
- priorityQueue.offer(bedQueueBO);
+ bedQueueBO.setCheckTypes( roomDO.getCheckTypes() );
+ bedQueueBO.setOpType( roomDO.getOpType() );
mapBedVsQueue.put(String.format("%09d%s", roomId, bedNo), bedQueueBO);
return GlobalErrorCodeConstants.SUCCESS;
@@ -145,7 +137,7 @@
}
mapBedVsQueue.remove(String.format("%09d%s", roomId, bedNo));
- priorityQueue.remove(bedQueueBO);
+ removePriorityQueue(bedQueueBO);
return GlobalErrorCodeConstants.SUCCESS;
}
@@ -166,7 +158,7 @@
}
bedQueueBO.setStatus(BedStatusEnum.PAUSE.getStatus());
- priorityQueue.remove(bedQueueBO);
+ removePriorityQueue(bedQueueBO);
return GlobalErrorCodeConstants.SUCCESS;
}
@@ -188,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;
}
@@ -215,6 +201,7 @@
}
bedQueueBO.setStatus(BedStatusEnum.DOCTOR_ON.getStatus());
+ addPriorityQueue(bedQueueBO);
return GlobalErrorCodeConstants.SUCCESS;
}
@@ -235,15 +222,7 @@
return ROOM_INVALID_STATUS;
}
- // 濡傛灉鏄湪 PAUSE 鐘舵�佺搴х殑锛岄渶瑕侀噸鏂板姞鍥� 浼樺厛闃熷垪
- if (bedQueueBO.getStatus().equals(BedStatusEnum.PAUSE.getStatus())) {
- if (!priorityQueue.contains(bedQueueBO)) {
- priorityQueue.offer(bedQueueBO);
- } else {
- log.error("bedDoctorResume priorityQueue still exist!. " + roomId + " " + bedNo);
- return ECG_INNER_ERROR;
- }
- }
+ removePriorityQueue(bedQueueBO);
bedQueueBO.setStatus(BedStatusEnum.OPENING.getStatus());
return GlobalErrorCodeConstants.SUCCESS;
@@ -261,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;
}
@@ -272,7 +250,7 @@
* 2. 鏈嶅姟杩愮淮閲嶅惎鏃�
*/
public ErrorCode bedReload() {
- priorityQueue.clear();
+ mapCheckTypeVsPriorityQueue.clear();
mapBedVsQueue.clear();
// 娓呴櫎闈炲綋澶╃殑鎺掗槦浜哄憳
@@ -294,16 +272,16 @@
List<QueueStatisticDO> queueStatisticDOList = queueMapper.queueStatistic(queueStatusList);
bedQueueBOList.forEach(item -> {
- item.maxQueueNum = queueReadyMax;
+ item.maxQueueNum = getBedReadyMax(item.roomId, item.bedNo);
Optional<QueueStatisticDO> queueStatisticDOOptional = queueStatisticDOList.stream().filter(it->it.getRoomId()==item.roomId && it.getBedNo().equals(item.getBedNo())).findFirst();
int queueNum = queueStatisticDOOptional.isPresent() ? queueStatisticDOOptional.get().getTotalInStatus() : 0;
- if ( queueReadyMax < queueNum )
+ if ( item.maxQueueNum < queueNum )
throw new RuntimeException("init: exceed max queue number!");
item.queueNum.set( queueNum );
mapBedVsQueue.put(String.format("%09d%s", item.roomId, item.bedNo), item);
- if (BedStatusEnum.PAUSE.getStatus() != item.getStatus()) {
- priorityQueue.offer(item);
+ if (BedStatusEnum.DOCTOR_ON.getStatus() == item.getStatus()) {
+ addPriorityQueue(item);
}
});
@@ -313,7 +291,7 @@
return GlobalErrorCodeConstants.SUCCESS;
}
- public void resetRoom() {
+ public void resetRoom(Boolean needCloseBed) {
// 韪㈠嚭鍦ㄥ骇鐨勫尰鐢�
List<BedStatusEnum> bedStatusEnumList = new ArrayList<BedStatusEnum>();
bedStatusEnumList.add(BedStatusEnum.DOCTOR_ON);
@@ -323,42 +301,60 @@
oAuth2TokenApi.tick(userIdList);
// 鍏抽棴鎵�鏈夊伐浣�
- Integer ret = roomMapper.resetRoom(BedStatusEnum.CLOSED.getStatus());
+ if (needCloseBed) {
+ Integer ret = roomMapper.resetRoom(BedStatusEnum.CLOSED.getStatus());
+ }
+ }
+
+ public void hurryupAllBed() {
+ if (0 == openingFlag.get())
+ return;
+
+ mapBedVsQueue.values().forEach(bedQueueBO -> hurryupOneBed(bedQueueBO.roomId, bedQueueBO.bedNo));
}
/**
* 鎶婂尰鐢熷�欒瘖鐨勯槦鍒楀婊�
*/
- public void hurryup() {
+ 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)
@@ -366,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;
@@ -378,7 +374,8 @@
bedQueueBO.getBedNo(),
curSeqNum.get() + 1,
QueueStatusEnum.WAITING.getStatus(),
- QueueStatusEnum.READY.getStatus());
+ QueueStatusEnum.READY.getStatus(),
+ checkType);
// 娌℃湁鎶㈠埌鎺掗槦鎮h��
if (null == updateNum || 0 == updateNum) {
@@ -391,8 +388,7 @@
bedQueueBO.queueNum.incrementAndGet();
// 鍙兘宸茬粡銆愬苟鍙戠殑銆戝湪 nextPatient 涓敼鍙樹簡浼樺厛闃熷垪椤哄簭
- priorityQueue.remove(bedQueueBO);
- priorityQueue.offer(bedQueueBO);
+ refreshPriorityQueue(bedQueueBO);
}
}
@@ -404,8 +400,8 @@
openingFlag.set(flag);
}
- public void setQueueReadyMax(Integer max) {
- queueReadyMax = max;
+ public void setCheckTypeReadyMax(Map<Integer, Integer> max) {
+ mapCheckTypeVsReadyMax = max;
}
public BedQueueBO getBedQueueBO(Long roomId, String bedNo) {
@@ -415,14 +411,109 @@
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) {
+ RoomDO roomDO = roomMapper.getRoom(roomId, bedNo);
+ Integer[] checkTypes = roomDO.getCheckTypes();
+ Integer ret = 0;
+ for (int i=0; i<checkTypes.length; i++) {
+ Integer tmp = mapCheckTypeVsReadyMax.get(checkTypes[i]);
+ ret = ret < tmp ? tmp : ret; //鍙栧ぇ鍊�
+ }
+ 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 void roomBedStatistic(MonitorInfoVO monitorInfoVO) {
+ 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 );
+ });
+ });
+
+ //杩愯惀涓伐浣嶇粺璁�
+ 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 );
+ });
+ });
+
+ Map<Integer, String> mapCheckTypeBedInfo = new HashMap<>();
+ mapCheckTypeVsReadyMax.keySet().forEach( checkType -> {
+ String str = mapOpeningCheckBedStatInfo.get(checkType) + " " +
+ mapOpeningReadyBedStatInfo.get(checkType) + " " +
+ mapOperatingCheckBedStatInfo.get(checkType) + " " +
+ mapOperatingReadyBedStatInfo.get(checkType) + " ";
+ mapCheckTypeBedInfo.put( checkType, str);
+ });
+
+ monitorInfoVO.setCheckTypeBedInfo(mapCheckTypeBedInfo);
+ monitorInfoVO.setQueueNum(mapBedVsQueue.size());
+ monitorInfoVO.setActiveQueueNum(hashSetOperatingBedQueue.size());
}
}
--
Gitblit v1.9.3