From be69c3d9d175027cb8d43f60a7744dc6e8c52433 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期二, 20 八月 2024 15:01:32 +0800
Subject: [PATCH] update
---
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/doctor/DoctorController.java | 76 +++++++++++++++++++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java | 6 +
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java | 74 +++++++++++++++--
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java | 23 +++++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/MySpringEventLister.java | 21 +++++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java | 11 ++
6 files changed, 195 insertions(+), 16 deletions(-)
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/MySpringEventLister.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/MySpringEventLister.java
new file mode 100644
index 0000000..045f666
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/MySpringEventLister.java
@@ -0,0 +1,21 @@
+package cn.lihu.jh.module.ecg;
+
+import cn.lihu.jh.module.ecg.service.queue.QueueService;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Component
+public class MySpringEventLister implements ApplicationListener<ApplicationStartedEvent> {
+
+ @Resource
+ private QueueService queueService;
+
+ @Override
+ public void onApplicationEvent(ApplicationStartedEvent event) {
+ System.out.println("搴旂敤鍚姩瀹屾垚锛岄�氱煡鐩戝惉鍣ㄦ墽琛岀紦瀛橀鍔犺浇鎿嶄綔");
+ queueService.initQueue();
+ }
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/doctor/DoctorController.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/doctor/DoctorController.java
new file mode 100644
index 0000000..3caf902
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/doctor/DoctorController.java
@@ -0,0 +1,76 @@
+package cn.lihu.jh.module.ecg.controller.admin.doctor;
+
+import cn.lihu.jh.framework.apilog.core.annotation.ApiAccessLog;
+import cn.lihu.jh.framework.common.pojo.CommonResult;
+import cn.lihu.jh.framework.common.pojo.PageParam;
+import cn.lihu.jh.framework.common.pojo.PageResult;
+import cn.lihu.jh.framework.common.util.object.BeanUtils;
+import cn.lihu.jh.framework.excel.core.util.ExcelUtils;
+import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueuePageReqVO;
+import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueueRespVO;
+import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueueSaveReqVO;
+import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
+import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
+import cn.lihu.jh.module.ecg.service.queue.QueueService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static cn.lihu.jh.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.lihu.jh.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "绠$悊鍚庡彴 - 鍖荤敓鍙彿")
+@RestController
+@RequestMapping("/ecg/doctor")
+@Validated
+public class DoctorController {
+
+ @Resource
+ private QueueService queueService;
+
+ @GetMapping("/nextpatient")
+ @Operation(summary = "涓嬩竴浣嶆偅鑰�")
+ @Parameter(name = "roomId", description = "璇婂缂栧彿", required = true, example = "116")
+ @Parameter(name = "bedNo", description = "宸ヤ綅缂栧彿", required = true, example = "B2")
+ @PreAuthorize("@ss.hasPermission('ecg:doctor:nextpatient')")
+ public CommonResult<List<QueueRespVO>> nextPatient(
+ @RequestParam("roomId") Long roomId,
+ @RequestParam("bedNo") String bedNo)
+ {
+ queueService.nextPatient(roomId, bedNo);
+
+ List<Byte> queueStatusList = new ArrayList<>();
+ queueStatusList.add(QueueStatusEnum.READY.getStatus());
+ queueStatusList.add(QueueStatusEnum.ONSTAGE.getStatus());
+ queueStatusList.add(QueueStatusEnum.PASSED.getStatus());
+ List<QueueDO> queueDOList = queueService.getDoctorQueueByStatus(roomId, bedNo, queueStatusList);
+ return success(BeanUtils.toBean(queueDOList, QueueRespVO.class));
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "鑾峰緱鎺掗槦鍒嗛〉")
+ @PreAuthorize("@ss.hasPermission('ecg:queue:query')")
+ public CommonResult<PageResult<QueueRespVO>> getqueuePage(@Valid QueuePageReqVO pageReqVO) {
+ PageResult<QueueDO> pageResult = queueService.getqueuePage(pageReqVO);
+ return success(BeanUtils.toBean(pageResult, QueueRespVO.class));
+ }
+
+ @GetMapping("/opening-setting")
+ @Operation(summary = "寮�璇婅缃�")
+ @PreAuthorize("@ss.hasPermission('ecg:queue:setting')")
+ public CommonResult<Integer> openingSetting() {
+ queueService.initQueue();
+ queueService.hurryup();
+ return success(0);
+ }
+}
\ 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/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 6e8745d..1e4e097 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
@@ -10,6 +10,7 @@
import cn.lihu.jh.module.ecg.controller.admin.queue.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
import java.util.List;
@@ -49,4 +50,24 @@
" group by room_id, bed_no; "
+"</script>")
List<QueueStatisticDO> queueStatistic(@Param("statusList")List<Byte> statusList);
-}
\ No newline at end of file
+
+ //@Update("update lihu.queue set status = #{newStatus} where pat_id = #{patId} ans status = #{curStatus} ")
+
+ @Update("update lihu.queue set status = #{newStatus} where seq_num = \n" +
+ "(select a.min_seq_num from \n" +
+ " (select min(seq_num) as min_seq_num from lihu.queue where room_id = #{roomId} and bed_no = #{bedNo} and status = #{curStatus}) a )")
+ Integer updateQueueStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus);
+
+ @Select("select * from lihu.queue where status = #{status} order by book_timeslot, create_time limit 1")
+ QueueDO getFirstInQueueByStatus(Byte status);
+
+ @Select("<script>" +
+ "SELECT * FROM lihu.queue " +
+ "where room_id = #{roomId} and bed_no = #{bedNo} and status in (" +
+ " <foreach collection='statusList' separator=',' item='status'>" +
+ " #{status} " +
+ " </foreach> )" +
+ " order by status desc" +
+ "</script>")
+ List<QueueDO> getDoctorQueueByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("statusList")List<Byte> statusList);
+}
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 23d99c1..ba361a5 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
@@ -3,16 +3,18 @@
import lombok.Data;
import org.jetbrains.annotations.NotNull;
+import java.util.concurrent.atomic.AtomicInteger;
+
@Data
public class BedQueueBO implements Comparable<BedQueueBO> {
String bedNo;
Long roomId;
String roomName;
- Integer queueNum;
+ AtomicInteger queueNum = new AtomicInteger(0);
Integer maxQueueNum;
@Override
public int compareTo(@NotNull BedQueueBO o) {
- return Integer.compare(this.queueNum, o.queueNum);
+ return Integer.compare(this.queueNum.get(), o.queueNum.get());
}
}
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 0160b16..2b6c2b3 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
@@ -68,7 +68,14 @@
void initQueue();
/**
- *
+ * 鎶婂尰鐢熷�欒瘖鐨勯槦鍒楀婊�
*/
void hurryup();
-}
\ No newline at end of file
+
+ /**
+ * 鍖荤敓鍙笅涓�浣嶆偅鑰�
+ */
+ void nextPatient(Long roomId, String bedNo);
+
+ List<QueueDO> getDoctorQueueByStatus(Long roomId, String bedNo, List<Byte> statusList);
+}
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 7fdb051..69d68d9 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
@@ -21,6 +21,9 @@
import javax.annotation.Resource;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
@@ -36,9 +39,10 @@
final static Integer MAX_QUEUE_NUM = 2;
- Integer curSeqNum = 0;
+ AtomicInteger curSeqNum = new AtomicInteger(0);
- PriorityQueue<BedQueueBO> priorityQueue = new PriorityQueue<>();
+ PriorityBlockingQueue<BedQueueBO> priorityQueue = new PriorityBlockingQueue<>();
+ ConcurrentHashMap<String, BedQueueBO > mapBedVsQueue = new ConcurrentHashMap<>();
@Resource
private queueMapper queueMapper;
@@ -99,21 +103,21 @@
if (null == bedQueueBO)
return;
- if (bedQueueBO.queueNum == bedQueueBO.maxQueueNum) {
+ if (bedQueueBO.queueNum.get() == bedQueueBO.maxQueueNum) {
queueSaveReqVO.setStatus(QueueStatusEnum.WAITING.getStatus()); //鎺掗槦涓�
QueueDO queue = BeanUtils.toBean(queueSaveReqVO, QueueDO.class);
queueMapper.insert(queue); // queue.getId();
- } else if (bedQueueBO.queueNum < bedQueueBO.maxQueueNum) {
+ } else if (bedQueueBO.queueNum.get() < bedQueueBO.maxQueueNum) {
queueSaveReqVO.setStatus(QueueStatusEnum.READY.getStatus()); //鍊欒瘖鍑嗗涓�
queueSaveReqVO.setRoomId(bedQueueBO.getRoomId());
queueSaveReqVO.setRoomName(bedQueueBO.getRoomName());
queueSaveReqVO.setBedNo(bedQueueBO.getBedNo());
- queueSaveReqVO.setSeqNum(curSeqNum);
+ queueSaveReqVO.setSeqNum(curSeqNum.get());
QueueDO queue = BeanUtils.toBean(queueSaveReqVO, QueueDO.class);
queueMapper.insert(queue); // queue.getId();
- curSeqNum++;
- bedQueueBO.queueNum++;
+ curSeqNum.getAndIncrement();
+ bedQueueBO.queueNum.getAndIncrement();
BedQueueBO bedQueueBO2 = priorityQueue.poll();
priorityQueue.offer(bedQueueBO2);
}
@@ -121,13 +125,15 @@
}
- @PostConstruct
public void initQueue() {
priorityQueue.clear();
+ mapBedVsQueue.clear();
+ // 浠嶥B 鑾峰彇 宸ヤ綅鍒楄〃
List<RoomDO> roomDOList = roomMapper.simpleRoomList();
List<BedQueueBO> bedQueueBOList = roomDOList.stream().map(item -> BeanUtils.toBean(item, BedQueueBO.class)).toList();
+ // 浠嶥B 鑾峰彇 闃熷垪涓� 灏辫瘖鍑嗗涓汉鍛� 鍒楄〃
List<Byte> queueStatusList = new ArrayList<>();
queueStatusList.add(QueueStatusEnum.READY.getStatus());
List<QueueStatisticDO> queueStatisticDOList = queueMapper.queueStatistic(queueStatusList);
@@ -135,12 +141,15 @@
bedQueueBOList.forEach(item -> {
item.maxQueueNum = MAX_QUEUE_NUM;
Optional<QueueStatisticDO> queueStatisticDOOptional = queueStatisticDOList.stream().filter(it->it.getRoomId()==item.roomId && it.getBedNo().equals(item.getBedNo())).findFirst();
- item.queueNum = queueStatisticDOOptional.isPresent() ? queueStatisticDOOptional.get().getTotalInStatus() : 0;
+ item.queueNum.set( queueStatisticDOOptional.isPresent() ? queueStatisticDOOptional.get().getTotalInStatus() : 0 );
priorityQueue.offer(item);
+ mapBedVsQueue.put(String.format("%09d%s", item.roomId, item.bedNo), item);
});
- curSeqNum = queueMapper.getMaxSeqNum();
- curSeqNum = null == curSeqNum ? 1 : ++curSeqNum;
+ Integer num = queueMapper.getMaxSeqNum();
+ curSeqNum = new AtomicInteger(null == num ? 1 : ++num);
+
+ hurryup();
}
/**
@@ -148,5 +157,48 @@
* 绛夊埌鍙栦笅涓�涓� 鎺掗槦涓汉鍛� 鐨勯�昏緫瀹屾垚鍚庯紝鍐嶅洖鏉ヤ笉閿�
*/
public void hurryup() {
+ while (true) {
+ BedQueueBO bedQueueBO = priorityQueue.peek();
+ if (null == bedQueueBO)
+ return;
+
+ if (bedQueueBO.queueNum.get() == bedQueueBO.maxQueueNum)
+ return;
+
+ QueueDO queue = queueMapper.getFirstInQueueByStatus(QueueStatusEnum.WAITING.getStatus());
+ if (null == queue)
+ return;
+
+ queue.setStatus(QueueStatusEnum.READY.getStatus()); //鍊欒瘖鍑嗗涓�
+ queue.setRoomId(bedQueueBO.getRoomId());
+ queue.setRoomName(bedQueueBO.getRoomName());
+ queue.setBedNo(bedQueueBO.getBedNo());
+ queue.setSeqNum(curSeqNum.get());
+ queueMapper.updateById(queue); // queue.getId();
+
+ curSeqNum.getAndIncrement();
+ bedQueueBO.queueNum.getAndIncrement();
+ BedQueueBO bedQueueBO2 = priorityQueue.poll();
+ priorityQueue.offer(bedQueueBO2);
+ }
+ }
+
+ public void nextPatient(Long roomId, String bedNo) {
+ // 浠� DB 鎶� 搴忓彿鏈�灏忕殑 灏辫瘖鍑嗗涓殑浜� 璁剧疆涓哄氨璇婁腑
+ queueMapper.updateQueueStatus(roomId, bedNo,
+ QueueStatusEnum.READY.getStatus(), QueueStatusEnum.ONSTAGE.getStatus());
+
+ // 浼樺厛闃熷垪涓� 璇ュ伐浣� 灏辫瘖鍑嗗涓汉鐨勬暟閲� 鍑忎竴
+ BedQueueBO bo = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
+ boolean breturn = priorityQueue.remove(bo);
+ bo.queueNum.getAndDecrement();
+ priorityQueue.offer(bo);
+
+ hurryup();
+ }
+
+ public List<QueueDO> getDoctorQueueByStatus(Long roomId, String bedNo, List<Byte> statusList) {
+ List<QueueDO> queueDOList = queueMapper.getDoctorQueueByStatus(roomId, bedNo, statusList);
+ return queueDOList;
}
}
--
Gitblit v1.9.3