From 9b18e467d407c66ecc3c46a197aca45dcc3f8056 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期二, 27 八月 2024 09:11:02 +0800
Subject: [PATCH] update

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java               |    1 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorPauseCallable.java   |   27 +++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOnCallable.java      |   27 +++
 sql/mysql/jh.sql                                                                                                |   29 +-
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedCloseCallable.java         |   23 ++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java |   82 ++++++++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/listener/MySpringEventListener.java         |    1 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java         |  198 +++++++++++++++++++--
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java              |   44 ++++
 jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/BedStatusEnum.java                    |   12 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOffCallable.java     |   27 +++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/room/vo/RoomRespVO.java    |    6 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomDO.java             |   10 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java             |   14 +
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java          |   36 ++++
 15 files changed, 484 insertions(+), 53 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/BedStatusEnum.java b/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/BedStatusEnum.java
index 47a256d..df87e00 100644
--- a/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/BedStatusEnum.java
+++ b/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/BedStatusEnum.java
@@ -14,18 +14,18 @@
 @Getter
 @AllArgsConstructor
 public enum BedStatusEnum implements IntArrayValuable {
-    CLOSED((byte)0, "宸插叧闂�"),
-    CLOSING((byte)1, "鍏抽棴涓�"),
-    OPENING((byte)10, "宸插紑閫�"),
-    DOCTOR_ON((byte)20, "鏈夊尰鐢�"),
-    PAUSE((byte)30, "鏆傚仠");
+    CLOSED(0, "宸插叧闂�"),
+    CLOSING(1, "鍏抽棴涓�"),
+    OPENING(10, "宸插紑閫�"),
+    DOCTOR_ON(20, "鏈夊尰鐢�"),
+    PAUSE(30, "鏆傚仠");
 
     public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BedStatusEnum::getStatus).toArray();
 
     /**
      * 鐘舵�佸��
      */
-    private final Byte status;
+    private final Integer status;
     /**
      * 鐘舵�佸悕
      */
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java
index 3174a56..f9eab4e 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java
@@ -1,6 +1,7 @@
 package cn.lihu.jh.module.ecg.controller.admin.queue;
 
 import cn.lihu.jh.framework.common.exception.ErrorCode;
+import cn.lihu.jh.framework.security.core.util.SecurityFrameworkUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -95,16 +96,85 @@
                         BeanUtils.toBean(list, QueueRespVO.class));
     }
 
-    @GetMapping("/bed-control")
-    @Operation(summary = "宸ヤ綅鎺у埗")
+    @GetMapping("/bed-open")
+    @Operation(summary = "宸ヤ綅寮�閫�")
     @PreAuthorize("@ss.hasPermission('ecg:queue:bedcontrol')")
-    public CommonResult<Integer> bedControl(
+    public CommonResult<Integer> bedOpen(
+        @RequestParam("roomId") Long roomId,
+        @RequestParam("bedNo") String bedNo)
+    {
+        Integer result = queueService.startBedOpen(roomId, bedNo);
+        if (null == result || 0 == result)
+            return success(0);
+
+        return error(new ErrorCode(result, "鍑洪敊浜�"));
+    }
+
+    @GetMapping("/bed-close")
+    @Operation(summary = "宸ヤ綅鍏抽棴")
+    @PreAuthorize("@ss.hasPermission('ecg:queue:bedcontrol')")
+    public CommonResult<Integer> bedClose(
+        @RequestParam("roomId") Long roomId,
+        @RequestParam("bedNo") String bedNo)
+    {
+        Integer result = queueService.startBedClose(roomId, bedNo);
+        if (null == result || 0 == result)
+            return success(0);
+
+        return error(new ErrorCode(result, "鍑洪敊浜�"));
+    }
+
+    @GetMapping("/bed-doctor-pause")
+    @Operation(summary = "鍖荤敓鏆傚仠")
+    @PreAuthorize("@ss.hasPermission('ecg:queue:bedcontrol')")
+    public CommonResult<Integer> bedPause(
         @RequestParam("roomId") Long roomId,
         @RequestParam("bedNo") String bedNo,
-        @RequestParam("status") Integer status)
+        @RequestParam("docId") Long docId,
+        @RequestParam("docName") String docName)
     {
-        queueService.bedControl(roomId, bedNo, status);
-        return success(0);
+        Long userId = SecurityFrameworkUtils.getLoginUserId();
+        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
+
+        Integer result = queueService.startBedDoctorPause(roomId, bedNo, userId, userNickname);
+        if (null == result || 0 == result)
+            return success(0);
+
+        return error(new ErrorCode(result, "鍑洪敊浜�"));
+    }
+
+    @GetMapping("/bed-doctor-on")
+    @Operation(summary = "鍖荤敓鍏ュ骇")
+    @PreAuthorize("@ss.hasPermission('ecg:queue:bedcontrol')")
+    public CommonResult<Integer> bedDoctorOn(
+        @RequestParam("roomId") Long roomId,
+        @RequestParam("bedNo") String bedNo)
+    {
+        Long userId = SecurityFrameworkUtils.getLoginUserId();
+        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
+
+        Integer result = queueService.startBedDoctorOn(roomId, bedNo, userId, userNickname);
+        if (null == result || 0 == result)
+            return success(0);
+
+        return error(new ErrorCode(result, "鍑洪敊浜�"));
+    }
+
+    @GetMapping("/bed-doctor-off")
+    @Operation(summary = "鍖荤敓绂诲骇")
+    @PreAuthorize("@ss.hasPermission('ecg:queue:bedcontrol')")
+    public CommonResult<Integer> bedDoctorOff(
+        @RequestParam("roomId") Long roomId,
+        @RequestParam("bedNo") String bedNo)
+    {
+        Long userId = SecurityFrameworkUtils.getLoginUserId();
+        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
+
+        Integer result = queueService.startBedDoctorOff(roomId, bedNo, userId, userNickname);
+        if (null == result || 0 == result)
+            return success(0);
+
+        return error(new ErrorCode(result, "鍑洪敊浜�"));
     }
 
     @GetMapping("/startbiz")
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 a892bd4..17bb027 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
@@ -33,8 +33,12 @@
     private Integer status;
 
     @Schema(description = "鍖荤敓鍚�", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("鍖荤敓Id")
+    private Long docId;
+
+    @Schema(description = "鍖荤敓鍚�", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("鍖荤敓鍚�")
-    private String doctorName;
+    private String docName;
 
     @Schema(description = "鍒涘缓鏃堕棿", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("鍒涘缓鏃堕棿")
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 0fde66d..f8f139e 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
@@ -1,5 +1,6 @@
 package cn.lihu.jh.module.ecg.dal.dataobject.room;
 
+import cn.lihu.jh.module.ecg.enums.BedStatusEnum;
 import lombok.*;
 import java.util.*;
 import java.time.LocalDateTime;
@@ -41,11 +42,16 @@
     private String bedNo;
 
     /**
-     * 璇婄枟搴婄姸鎬�  0:鍋滆瘖 10:寮�璇� 20:鏆傚仠
+     * 璇婄枟搴婄姸鎬�
+     * @see BedStatusEnum
      */
     private Integer status;
     /**
+     * 鍖荤敓ID
+     */
+    private Long docId;
+    /**
      * 鍖荤敓鍚�
      */
-    private String doctorName;
+    private String docName;
 }
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 0f0a194..f8e1851 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
@@ -9,7 +9,9 @@
 import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomPageReqVO;
 import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO;
 import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomStatisticsDO;
+import cn.lihu.jh.module.ecg.enums.BedStatusEnum;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
@@ -32,9 +34,45 @@
     @Select({ "SELECT room_id, room_name, count(1) as bed_num FROM lihu.clinic_room group by room_id;" })
     List<RoomStatisticsDO> roomStatistic();
 
-    @Select({ "SELECT id, room_id, room_name, bed_no, status, doctor_name FROM lihu.clinic_room where status > 0;" })
+    @Select({ "SELECT id, room_id, room_name, bed_no, status, doc_id, doc_name FROM lihu.clinic_room where status >= 10;" })
     List<RoomDO> simpleRoomList();
 
-    @Update( "update lihu.clinic_room set status=#{status} where room_id=#{roomId} and bed_no=#{bedNo}" )
-    Integer setBedStatus(Long roomId, String bedNo, Integer status);
+    @Update("<script> " +
+            "update lihu.clinic_room set status=#{newStatus.status} where room_id=#{roomId} and bed_no=#{bedNo} " +
+            "and status=( " +
+            " <foreach collection='curStatusList' separator=',' item='curStatus'>" +
+            "  #{curStatus.status} " +
+            " </foreach> );" +
+            "</script>")
+    Integer setBedStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("newStatus") BedStatusEnum newStatus, @Param("curStatusList") List<BedStatusEnum> curStatusList);
+
+    @Update("<script> " +
+            "update lihu.clinic_room set status=#{newStatus.status} " +
+            "where room_id=#{roomId} and bed_no=#{bedNo} and doc_id=#{docId} and doc_name=#{docName}" +
+            "and status=( " +
+            " <foreach collection='curStatusList' separator=',' item='curStatus'>" +
+            "  #{curStatus.status} " +
+            " </foreach> );" +
+            "</script>")
+    Integer setBedDoctorPause(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("docId")Long docId, @Param("docName")String docName, @Param("newStatus") BedStatusEnum newStatus, @Param("curStatusList") List<BedStatusEnum> curStatusList);
+
+    @Update("<script> " +
+            "update lihu.clinic_room set status=#{newStatus.status}, doc_id=#{docId}, doc_name=#{docName} " +
+            "where room_id=#{roomId} and bed_no=#{bedNo} " +
+            "and status=( " +
+            " <foreach collection='curStatusList' separator=',' item='curStatus'>" +
+            "  #{curStatus.status} " +
+            " </foreach> );" +
+            "</script>")
+    Integer setBedDoctorOn(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("docId")Long docId, @Param("docName")String docName, @Param("newStatus") BedStatusEnum newStatus, @Param("curStatusList") List<BedStatusEnum> curStatusList);
+
+    @Update("<script> " +
+            "update lihu.clinic_room set status=#{newStatus.status}, doc_id=null, doc_name='' " +
+            "where room_id=#{roomId} and bed_no=#{bedNo} and doc_id=#{docId} and doc_name=#{docName}" +
+            "and status=( " +
+            " <foreach collection='curStatusList' separator=',' item='curStatus'>" +
+            "  #{curStatus.status} " +
+            " </foreach> );" +
+            "</script>")
+    Integer setBedDoctorOff(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("docId")Long docId, @Param("docName")String docName, @Param("newStatus") BedStatusEnum newStatus, @Param("curStatusList") List<BedStatusEnum> curStatusList);
 }
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/listener/MySpringEventListener.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/listener/MySpringEventListener.java
index 3cd057a..0b1026a 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/listener/MySpringEventListener.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/listener/MySpringEventListener.java
@@ -27,6 +27,7 @@
         System.out.println("搴旂敤鍚姩瀹屾垚锛岀郴缁熷垵濮嬨�傘�傘��");
 
         String strOpenCloseTime = configApi.getConfigValueByKey(ECG_OPENING_TIME_KEY);
+        strOpenCloseTime = "0:00~23:59";
         List<LocalTime> list = Utils.parseOpeningTime(strOpenCloseTime);
         LocalTime openingTime = list.get(0);
         LocalTime closeTime = list.get(1);
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedCloseCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedCloseCallable.java
new file mode 100644
index 0000000..fba487e
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedCloseCallable.java
@@ -0,0 +1,23 @@
+package cn.lihu.jh.module.ecg.service.queue;
+
+import java.util.concurrent.Callable;
+
+public class BedCloseCallable implements Callable<Integer> {
+
+    QueueService queueService;
+    private Long roomId;
+    private String bedNo;
+
+    public BedCloseCallable(QueueService queueService, Long roomId, String bedNo)
+    {
+        super();
+        this.roomId = roomId;
+        this.bedNo = bedNo;
+        this.queueService = queueService;
+    }
+
+    public Integer call() throws Exception {
+        return queueService.bedClose(roomId, bedNo);
+    }
+
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOffCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOffCallable.java
new file mode 100644
index 0000000..6dfbabe
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOffCallable.java
@@ -0,0 +1,27 @@
+package cn.lihu.jh.module.ecg.service.queue;
+
+import java.util.concurrent.Callable;
+
+public class BedDoctorOffCallable implements Callable<Integer> {
+
+    QueueService queueService;
+    private Long roomId;
+    private String bedNo;
+    private Long docId;
+    private String docName;
+
+    public BedDoctorOffCallable(QueueService queueService, Long roomId, String bedNo, Long docId, String docName)
+    {
+        super();
+        this.queueService = queueService;
+        this.roomId = roomId;
+        this.bedNo = bedNo;
+        this.docId = docId;
+        this.docName = docName;
+    }
+
+    public Integer call() throws Exception {
+        return queueService.bedDoctorOff(roomId, bedNo, docId, docName);
+    }
+
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOnCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOnCallable.java
new file mode 100644
index 0000000..bf36728
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorOnCallable.java
@@ -0,0 +1,27 @@
+package cn.lihu.jh.module.ecg.service.queue;
+
+import java.util.concurrent.Callable;
+
+public class BedDoctorOnCallable implements Callable<Integer> {
+
+    QueueService queueService;
+    private Long roomId;
+    private String bedNo;
+    private Long docId;
+    private String docName;
+
+    public BedDoctorOnCallable(QueueService queueService, Long roomId, String bedNo, Long docId, String docName)
+    {
+        super();
+        this.queueService = queueService;
+        this.roomId = roomId;
+        this.bedNo = bedNo;
+        this.docId = docId;
+        this.docName = docName;
+    }
+
+    public Integer call() throws Exception {
+        return queueService.bedDoctorOn(roomId, bedNo, docId, docName);
+    }
+
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorPauseCallable.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorPauseCallable.java
new file mode 100644
index 0000000..3db6221
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedDoctorPauseCallable.java
@@ -0,0 +1,27 @@
+package cn.lihu.jh.module.ecg.service.queue;
+
+import java.util.concurrent.Callable;
+
+public class BedDoctorPauseCallable implements Callable<Integer> {
+
+    QueueService queueService;
+    private Long roomId;
+    private String bedNo;
+    private Long docId;
+    private String docName;
+
+    public BedDoctorPauseCallable(QueueService queueService, Long roomId, String bedNo, Long docId, String docName)
+    {
+        super();
+        this.queueService = queueService;
+        this.roomId = roomId;
+        this.bedNo = bedNo;
+        this.docId = docId;
+        this.docName = docName;
+    }
+
+    public Integer call() throws Exception {
+        return queueService.bedDoctorPause(roomId, bedNo, docId, docName);
+    }
+
+}
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
new file mode 100644
index 0000000..2096007
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedOpenCallable.java
@@ -0,0 +1,36 @@
+package cn.lihu.jh.module.ecg.service.queue;
+
+import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
+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 java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static cn.lihu.jh.module.ecg.service.queue.QueueService.MAX_QUEUE_NUM;
+
+public class BedOpenCallable implements Callable<Integer> {
+
+    QueueService queueService;
+    private Long roomId;
+    private String bedNo;
+
+    public BedOpenCallable(QueueService queueService, Long roomId, String bedNo)
+    {
+        super();
+        this.roomId = roomId;
+        this.bedNo = bedNo;
+        this.queueService = queueService;
+    }
+
+    public Integer call() throws Exception {
+        return queueService.bedOpen(roomId, bedNo);
+    }
+
+}
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 ba361a5..67d71d6 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
@@ -1,5 +1,6 @@
 package cn.lihu.jh.module.ecg.service.queue;
 
+import cn.lihu.jh.module.ecg.enums.BedStatusEnum;
 import lombok.Data;
 import org.jetbrains.annotations.NotNull;
 
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 c342b25..518339f 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
@@ -14,6 +14,8 @@
  */
 public interface QueueService {
 
+    final static Integer MAX_QUEUE_NUM = 3;
+
     void startBiz();
     void closeBiz();
 
@@ -42,7 +44,17 @@
     /**
      *
      */
-    Integer bedControl(Long roomId, String bedNo, Integer status);
+    Integer startBedOpen(Long roomId, String bedNo);
+    Integer startBedClose(Long roomId, String bedNo);
+    Integer startBedDoctorPause(Long roomId, String bedNo, Long docId, String docName);
+    Integer startBedDoctorOn(Long roomId, String bedNo, Long docId, String docName);
+    Integer startBedDoctorOff(Long roomId, String bedNo, Long docId, String docName);
+
+    Integer bedOpen(Long roomId, String bedNo);
+    Integer bedClose(Long roomId, String bedNo);
+    Integer bedDoctorPause(Long roomId, String bedNo, Long docId, String docName);
+    Integer bedDoctorOn(Long roomId, String bedNo, Long docId, String docName);
+    Integer bedDoctorOff(Long roomId, String bedNo, Long docId, String docName);
 
     /**
      * 鑾峰緱鎺掗槦
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 8a806d3..fd31e8c 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
@@ -4,6 +4,7 @@
 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.room.RoomMapper;
+import cn.lihu.jh.module.ecg.enums.BedStatusEnum;
 import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -32,8 +33,6 @@
 @Service
 @Validated
 public class QueueServiceImpl implements QueueService {
-
-    final static Integer MAX_QUEUE_NUM = 3;
 
     @Resource
     private queueMapper queueMapper;
@@ -78,28 +77,190 @@
     }
 
     @Override
-    public Integer bedControl(Long roomId, String bedNo, Integer status) {
-        // 钀ヤ笟鏈熼棿涓嶈兘鍏抽棴宸ヤ綅
-        if ( status == 0 && openingFlag.get() == 1 )
-            return 301;
+    public Integer startBedOpen(Long roomId, String bedNo) {
+        Future<Integer> future = singleThreadExecutor.submit( new BedOpenCallable(this, roomId, bedNo));
 
-        // 褰撳墠鐘舵��
-        roomMapper.select
+        try {
+            Integer ret = future.get();
+            return ret;
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        }
 
+        return 100;
+    }
+
+    @Override
+    public Integer startBedClose(Long roomId, String bedNo) {
+        Future<Integer> future = singleThreadExecutor.submit( new BedCloseCallable(this, roomId, bedNo));
+
+        try {
+            Integer ret = future.get();
+            return ret;
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        }
+
+        return 100;
+    }
+
+    @Override
+    public Integer startBedDoctorPause(Long roomId, String bedNo, Long docId, String docName) {
+        Future<Integer> future = singleThreadExecutor.submit(
+            new BedDoctorPauseCallable(this, roomId, bedNo, docId, docName)
+        );
+
+        try {
+            Integer ret = future.get();
+            return ret;
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        }
+
+        return 100;
+    }
+
+    @Override
+    public Integer startBedDoctorOn(Long roomId, String bedNo, Long docId, String docName) {
+        Future<Integer> future = singleThreadExecutor.submit(
+            new BedDoctorOnCallable(this, roomId, bedNo, docId, docName)
+        );
+
+        try {
+            Integer ret = future.get();
+            return ret;
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        }
+
+        return 100;
+    }
+
+    @Override
+    public Integer startBedDoctorOff(Long roomId, String bedNo, Long docId, String docName) {
+        Future<Integer> future = singleThreadExecutor.submit(
+            new BedDoctorOffCallable(this, roomId, bedNo, docId, docName)
+        );
+
+        try {
+            Integer ret = future.get();
+            return ret;
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        }
+
+        return 100;
+    }
+
+
+    /**
+     * 宸插叧闂� 鎴栬�� 鍏抽棴涓紝鍙互寮�閫氬伐浣�
+     * @param roomId
+     * @param bedNo
+     * @return
+     */
+    @Override
+    public Integer bedOpen(Long roomId, String bedNo) {
         // DB update
-        Integer updateNum = roomMapper.setBedStatus(roomId, bedNo, status);
+        List statusList = new ArrayList<BedStatusEnum>();
+        statusList.add(BedStatusEnum.CLOSED);
+        statusList.add(BedStatusEnum.CLOSING);
+        Integer updateNum = roomMapper.setBedStatus(roomId, bedNo,
+                BedStatusEnum.OPENING, statusList);
         if ( null==updateNum || 0 == updateNum )
             return 310;
 
-        if ( status == 10 ) {
-            BedQueueBO bedQueueBO = new BedQueueBO();
-            bedQueueBO.setRoomId(roomId);
-            bedQueueBO.setBedNo(bedNo);
-            bedQueueBO.setMaxQueueNum(MAX_QUEUE_NUM);
-            bedQueueBO.setQueueNum(new AtomicInteger(0));
-            priorityQueue.offer(bedQueueBO);
-            mapBedVsQueue.put(String.format("%09d%s", bedQueueBO.roomId, bedQueueBO.bedNo), bedQueueBO);
-        }
+        List<Byte> queueStatusList = new ArrayList<>();
+        queueStatusList.add(QueueStatusEnum.READY.getStatus());
+        List<QueueDO> queueDOList = queueMapper.getDoctorQueueByStatus(roomId, bedNo, queueStatusList);
+
+        // 鏂板宸ヤ綅 浼樺厛闃熷垪
+        BedQueueBO bedQueueBO = new BedQueueBO();
+        bedQueueBO.setRoomId(roomId);
+        bedQueueBO.setBedNo(bedNo);
+        bedQueueBO.setMaxQueueNum(MAX_QUEUE_NUM);
+        bedQueueBO.setQueueNum(new AtomicInteger(queueDOList.size()));
+        priorityQueue.offer(bedQueueBO);
+        mapBedVsQueue.put(String.format("%09d%s", roomId, bedNo), bedQueueBO);
+        return 0;
+    }
+
+    @Override
+    public Integer bedClose(Long roomId, String bedNo) {
+        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
+        if (null == bedQueueBO)
+            return 320;
+
+        // DB update
+        List statusList = new ArrayList<BedStatusEnum>();
+        statusList.add(BedStatusEnum.OPENING);
+        statusList.add(BedStatusEnum.DOCTOR_ON);
+        statusList.add(BedStatusEnum.PAUSE);
+        Integer updateNum = roomMapper.setBedStatus(roomId, bedNo,
+                BedStatusEnum.CLOSING, statusList);
+        if ( null==updateNum || 0 == updateNum )
+            return 321;
+
+        return 0;
+    }
+
+    @Override
+    public Integer bedDoctorPause(Long roomId, String bedNo, Long docId, String docName) {
+        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
+        if (null == bedQueueBO)
+            return 320;
+
+        // DB update
+        List statusList = new ArrayList<BedStatusEnum>();
+        statusList.add(BedStatusEnum.DOCTOR_ON);
+        Integer updateNum = roomMapper.setBedDoctorPause(roomId, bedNo, docId, docName,
+                BedStatusEnum.PAUSE, statusList);
+        if ( null==updateNum || 0 == updateNum )
+            return 331;
+
+        return 0;
+    }
+
+    @Override
+    public Integer bedDoctorOn(Long roomId, String bedNo, Long docId, String docName) {
+        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
+        if (null == bedQueueBO)
+            return 320;
+
+        // DB update
+        List statusList = new ArrayList<BedStatusEnum>();
+        statusList.add(BedStatusEnum.OPENING);
+        Integer updateNum = roomMapper.setBedDoctorOn(roomId, bedNo, docId, docName,
+                BedStatusEnum.DOCTOR_ON, statusList);
+        if ( null==updateNum || 0 == updateNum )
+            return 341;
+
+        return 0;
+    }
+
+    @Override
+    public Integer bedDoctorOff(Long roomId, String bedNo, Long docId, String docName) {
+        BedQueueBO bedQueueBO = mapBedVsQueue.get(String.format("%09d%s", roomId, bedNo));
+        if (null == bedQueueBO)
+            return 320;
+
+        // DB update
+        List statusList = new ArrayList<BedStatusEnum>();
+        statusList.add(BedStatusEnum.DOCTOR_ON);
+        Integer updateNum = roomMapper.setBedDoctorOff(roomId, bedNo, docId, docName,
+                BedStatusEnum.OPENING, statusList);
+        if ( null==updateNum || 0 == updateNum )
+            return 351;
 
         return 0;
     }
@@ -341,4 +502,3 @@
     }
 
 }
-
diff --git a/sql/mysql/jh.sql b/sql/mysql/jh.sql
index 79a456c..70a6f3a 100644
--- a/sql/mysql/jh.sql
+++ b/sql/mysql/jh.sql
@@ -76,21 +76,20 @@
 -- ----------------------------
 DROP TABLE IF EXISTS `clinic_room`;
 CREATE TABLE `clinic_room` (
-  `id` int NOT NULL AUTO_INCREMENT COMMENT 'id',
-  `room_id` BIGINT NOT NULL COMMENT '璇婂缂栧彿',
-  `room_name` varchar(10) NOT NULL COMMENT '璇婂鍚嶇О',
-  `bed_no` varchar(10) NOT NULL COMMENT '璇婄枟搴婄紪鍙�',
-  `status` int 0 COMMENT '0:鍋滆瘖 10:寮�璇� 20:鏆傚仠',
-  `doctor_name` varchar(10) NOT NULL COMMENT '鍖荤敓鍚嶇О',
-  `tenant_id` int DEFAULT 1 COMMENT '绉熸埛缂栧彿',
-  `creator` varchar(10) DEFAULT '' COMMENT '鍒涘缓鑰�',
-  `create_time` datetime NOT NULL COMMENT '鍒涘缓鏃堕棿',
-  `updater` varchar(10) DEFAULT '' COMMENT '鏇存柊鑰�',
-  `update_time` datetime NOT NULL COMMENT '鏇存柊鏃堕棿',
-  `deleted` bit(1) DEFAULT 0 COMMENT '鍒犻櫎鏍囪',
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='璇婂鍜岃瘖鐤楀簥琛�';
-
+   `id` int NOT NULL AUTO_INCREMENT COMMENT 'id',
+   `room_id` bigint NOT NULL COMMENT '璇婂缂栧彿',
+   `room_name` varchar(10) NOT NULL COMMENT '璇婂鍚嶇О',
+   `bed_no` varchar(10) NOT NULL COMMENT '璇婄枟搴婄紪鍙�',
+   `status` int NOT NULL DEFAULT '0',
+   `doc_id` bigint DEFAULT NULL,
+   `doc_name` varchar(10) DEFAULT '',
+   `creator` varchar(10) DEFAULT '' COMMENT '鍒涘缓鑰�',
+   `create_time` datetime NOT NULL COMMENT '鍒涘缓鏃堕棿',
+   `updater` varchar(10) DEFAULT '' COMMENT '鏇存柊鑰�',
+   `update_time` datetime NOT NULL COMMENT '鏇存柊鏃堕棿',
+   `deleted` bit(1) DEFAULT b'0' COMMENT '鍒犻櫎鏍囪',
+   PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='璇婂鍜岃瘖鐤楀簥琛�';
 
 -- ----------------------------
 -- Table structure for device_model

--
Gitblit v1.9.3