From 68ff33beff11310e830b0615b5a81f83fad0f683 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期日, 08 十一月 2026 23:33:14 +0800
Subject: [PATCH] ai优化

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/QueueMapper.java |  341 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 279 insertions(+), 62 deletions(-)

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 a9c331c..14c7549 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 java.util.List;
+import java.util.Map;
 
 /**
  * 鎺掗槦 Mapper
@@ -36,29 +37,34 @@
                 .orderByDesc(QueueDO::getId));
     }
 
-    @Select("SELECT max(seq_num) FROM lihu.queue")
-    Integer getMaxSeqNum();
-
-    @Select("SELECT * FROM lihu.queue where seq_num = #{seqNum}")
-    @Results({
-            @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
-    })
-    QueueDO getQueueItemBySeqNum(@Param("seqNum")Integer seqNum);
-
     @Select("SELECT * FROM lihu.queue where pat_id = #{patId} and book_check_type = #{bookCheckType}")
     @Results({
             @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
     })
     QueueDO getQueueByPatId(@Param("patId")String patId, @Param("bookCheckType")Integer bookCheckType);
 
+    /**
+     * 璇婇棿灞忥紙{@code ecg_call/small.html}锛夊彇鏁帮細鏈瘖瀹ょ殑妫�鏌ラ槦鍒椼��
+     *
+     * <p>鎺掑簭瑙勫垯锛堝彿缁熶竴鍚庣殑鏈�缁堣鍒欙級锛�<b>灏辫瘖涓�(30) 缃《 鈫� 鍔犳��(jump_flag=1) 鈫� 鍏朵綑鎸夋帓闃熷彿 seq_num 鍗囧簭</b>锛�
+     * 鍙蜂负绌猴紙鏀归�犲綋澶╁皻鏈縼绉荤殑瀛橀噺琛岋級鐨勬帓鍦ㄦ渶鍚庛��
+     * <p>杩囧彿(3/5) <b>涓嶅啀鍗曠嫭鎻愬墠涓�缁�</b>锛氬畠涓庛�岀瓑鍊欍�嶆贩鎺掋�佺暀鍦ㄨ嚜宸辩殑鍙蜂綅涓婏紝
+     * 鐢卞睆涓婄敤绾㈣壊 +銆�(杩�)銆嶅皬瀛楀尯鍒嗭紙闇�姹傦細璇婇棿灞忋�岀瓑鍊欍�嶄笌銆岃繃鍙枫�嶅悎骞朵负涓�涓�岀瓑鍊欍�嶉潰鏉匡級銆�
+     */
     @Select("""
             <script>
                 SELECT * FROM lihu.queue
-                where room_id = #{roomId} and status in (
+                where room_id = #{roomId} and deleted = 0 and status in (
                  <foreach collection='statusList' separator=',' item='status'>
                    #{status} 
                  </foreach> )
-                order by status desc, seq_num, book_timeslot
+                order by case
+                           when status = 30 then 0
+                           when jump_flag = 1 then 1
+                           when seq_num is null then 3
+                           else 2
+                         end,
+                         seq_num, book_timeslot
             </script>
             """)
     @Results({
@@ -66,14 +72,37 @@
     })
     List<QueueDO> getRoomQueueByStatus(@Param("roomId")Long roomId, @Param("statusList")List<Integer> statusList);
 
-    @Select("<script>" +
-            "SELECT * FROM lihu.queue " +
-            "where status in (" +
-            " <foreach collection='statusList' separator=',' item='status'>" +
-            "  #{status} " +
-            " </foreach> )" +
-            " order by status desc, seq_num, book_timeslot" +
-            "</script>")
+    /**
+     * 澶у睆鍙栨暟銆�
+     *
+     * <p>鎺掑簭瑙勫垯锛堝彿缁熶竴鍚庣殑鏈�缁堣鍒欙級锛�<b>灏辫瘖涓�(30) 缃《 鈫� 鍔犳��(jump_flag=1) 鈫� 鍏朵綑鎸夋帓闃熷彿 seq_num 鍗囧簭</b>锛�
+     * 鍙蜂负绌猴紙鏀归�犲綋澶╁皻鏈縼绉荤殑瀛橀噺琛岋級鐨勬帓鍦ㄦ渶鍚庛��
+     * <ul>
+     *   <li>杩囧彿(3/5) <b>涓嶅啀鍗曠嫭鎻愬墠涓�缁�</b>锛氬畠鐣欏湪鑷繁鐨勫彿浣嶄笂锛屽睆涓婄敤绾㈣壊 + 杩囧彿鏍囪鍖哄垎锛�
+     *       涓庤瘖闂村睆锛坽@code ecg_call/small.html}锛夋敼閫犲悗鐨勫彛寰勪竴鑷淬��
+     *       锛堝師瀹炵幇鏄� {@code status desc}锛屼細鎶婅繃鍙峰帇鍒版渶搴曢儴銆佺瓑鍚屼簬"杩囧彿涓嶆樉绀�"銆傦級</li>
+     *   <li>鍔犳�ュ繀椤诲弬涓庢帓搴忥細鎺掗槦鍙锋敼涓虹鍒版椂涓�娆℃�у垎閰嶃�佷箣鍚庝笉鍐嶆敼鍔紝
+     *       鍔犳�ユ棤娉曞啀闈�"鍒嗘祦鏃舵敼鍙�/鎻掗槦閲嶇紪鍙�"浣撶幇銆�</li>
+     *   <li>娌跨敤 {@code deleted = 0}锛氭湰鏂规硶鏄嚜瀹氫箟 {@code @Select}锛�
+     *       浼氱粫杩� MyBatis-Plus 鐨� {@code @TableLogic} 閫昏緫鍒犻櫎杩囨护銆�</li>
+     * </ul>
+     */
+    @Select("""
+            <script>
+                SELECT * FROM lihu.queue
+                where deleted = 0 and status in (
+                 <foreach collection='statusList' separator=',' item='status'>
+                   #{status} 
+                 </foreach> )
+                order by case
+                           when status = 30 then 0
+                           when jump_flag = 1 then 1
+                           when seq_num is null then 3
+                           else 2
+                         end,
+                         seq_num, book_timeslot
+            </script>
+            """)
     @Results({
             @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
     })
@@ -150,6 +179,7 @@
 
     @Select("<script>" +
             "SELECT count(1) as total_in_status FROM lihu.queue where " +
+            " deleted = 0 and book_date = CURDATE() and " +
             " status in ( " +
             " <foreach collection='statusList' separator=',' item='status'>" +
             "  #{status} " +
@@ -172,6 +202,7 @@
 
     @Select("<script>" +
             "SELECT status, count(1) as total_in_status FROM lihu.queue where " +
+            " deleted = 0 and book_date = CURDATE() and " +
             " room_id = #{roomId} and bed_no = #{bedNo} " +
             " group by status " +
             "</script>")
@@ -179,6 +210,7 @@
 
     @Select("<script>" +
             "SELECT status, count(1) as total_in_status FROM lihu.queue where " +
+            " deleted = 0 and book_date = CURDATE() and " +
             " room_id = #{roomId} " +
             " group by status " +
             "</script>")
@@ -186,7 +218,8 @@
 
     @Select("<script>" +
             "SELECT count(1) FROM lihu.queue " +
-            "where room_id = #{roomId} and bed_no = #{bedNo} and status in (" +
+            "where deleted = 0 and book_date = CURDATE() and " +
+            " room_id = #{roomId} and bed_no = #{bedNo} and status in (" +
             " <foreach collection='statusList' separator=',' item='status'>" +
             "   #{status} " +
             " </foreach> )" +
@@ -196,11 +229,14 @@
     @Select("""
             <script>
                 SELECT * FROM lihu.queue 
-                where room_id = #{roomId} and bed_no = #{bedNo} and status in (
+                where deleted = 0 and room_id = #{roomId} and bed_no = #{bedNo} and status in (
                   <foreach collection='statusList' separator=',' item='status'>
                     #{status} 
                   </foreach> ) 
-                order by status desc, seq_num, book_timeslot 
+                order by case when status = 30 then 0 else 1 end,
+                         jump_flag desc,
+                         case when seq_num is null then 1 else 0 end,
+                         seq_num, book_timeslot
             </script>
             """)
     @Results({
@@ -208,11 +244,64 @@
     })
     List<QueueDO> getBedQueueByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("statusList")List<Integer> statusList);
 
+    /**
+     * 鍙彿鍙栦汉锛氭湰宸ヤ綅銆屽�欒瘖涓�(20)銆嶉噷**搴斾紭鍏堝彨**鐨勯偅涓�浣嶃��
+     *
+     * <p>鎺掑簭锛堝彿缁熶竴鍚庣殑鏈�缁堣鍒欙級锛�<b>鍔犳��(jump_flag=1) 鈫� 鎺掗槦鍙� seq_num 鍗囧簭</b>锛屽彿涓虹┖锛堝瓨閲忚锛夋帓鏈�鍚庛��
+     * <p>鎺掗槦鍙峰湪绛惧埌鏃朵竴娆℃�у垎閰嶃�佷箣鍚庝笉鍐嶆敼鍔紝鎵�浠�"涓嬩竴浣嶅彨璋�"瀹屽叏鐢辨湰鏂规硶鍐冲畾锛�
+     * 鍔犳�ュ繀椤诲湪杩欓噷鍙備笌鎺掑簭锛屽惁鍒欏姞鎬ユ偅鑰呮案杩滀笉浼氳浼樺厛鍙埌銆�
+     */
     @Select("""
             SELECT * from lihu.queue where room_id = #{roomId} and bed_no = #{bedNo}
-               and status = #{curStatus} order by seq_num, book_timeslot limit 1
+               and status = #{curStatus} and deleted = 0
+             order by jump_flag desc,
+                      case when seq_num is null then 1 else 0 end,
+                      seq_num, book_timeslot
+             limit 1
             """)
     QueueDO getBedFirstQueueItemByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("curStatus")Integer curStatus);
+
+    /**
+     * 銆愰渶姹�2 鐩稿叧缂洪櫡淇銆戞寜銆屽伐浣� + 鎮h�� + 妫�鏌ョ被鍨� + 鐘舵�併��**绮剧‘**瀹氫綅闃熷垪琛屻��
+     * <p>
+     * 鐢ㄤ簬鏇夸唬 {@link #getBedFirstQueueItemByStatus}锛氬悗鑰呭彧鎸�"宸ヤ綅 + 鐘舵�佸彇 seq_num 鏈�灏忕殑涓�鏉�"锛�
+     * 褰撳尰鐢熷厛鐐�"鏀惧純妫�鏌�"锛堜細鎶婅鎮h�呯疆涓� 40锛夊悗鍐嶇偣"妫�鏌ュ畬鎴�"鏃讹紝
+     * 浼氬彇鍒�**涓嬩竴浣嶆偅鑰�**骞舵妸浠栬缃负宸插畬鎴愶紙璇﹁ DevRentServiceImpl.routineFinishOperation锛夈��
+     */
+    @Select("""
+            SELECT * from lihu.queue
+            where room_id = #{roomId} and bed_no = #{bedNo}
+              and status = #{curStatus}
+              and pat_id = #{patId}
+              and book_check_type = #{checkType}
+              and TO_DAYS(book_date) = TO_DAYS(NOW())
+            order by seq_num limit 1
+            """)
+    @Results({
+            @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+    })
+    QueueDO getBedQueueItemByPatAndStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+                                          @Param("patId")String patId, @Param("checkType")Integer checkType,
+                                          @Param("curStatus")Integer curStatus);
+
+    /**
+     * 鎸夊伐浣� + 鐘舵�� + 浠婃棩鍙�**鏈�杩戞洿鏂�**鐨勪竴鏉°��
+     * <p>
+     * 姣斻�宻eq_num 鏈�灏忋�嶆洿璐村悎"褰撳墠姝e湪灏辫瘖/瑁呮満鐨勯偅浣嶆偅鑰�"锛歴eq_num 鏈�灏忔槸鏈椂娈垫渶鏃╂帓闃熺殑锛�
+     * 鑰� update_time 鏈�鏂版墠鏄垰琚彨鍙锋帹杩涘埌璇ョ姸鎬佺殑銆�
+     */
+    @Select("""
+            SELECT * from lihu.queue
+            where room_id = #{roomId} and bed_no = #{bedNo}
+              and status = #{curStatus}
+              and TO_DAYS(book_date) = TO_DAYS(NOW())
+            order by update_time desc, seq_num limit 1
+            """)
+    @Results({
+            @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+    })
+    QueueDO getBedLatestQueueItemByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+                                          @Param("curStatus")Integer curStatus);
 
     @Select("""
             SELECT * from lihu.queue where apply_no = #{applyNo} and status = #{curStatus}  order by seq_num, book_timeslot limit 1
@@ -221,22 +310,30 @@
 
     // 鏌愪釜璇婂鑼冨洿鍐� [宸查鐢╙ [宸插彫鍥�-瀹夎] 浜哄憳 鎶㈠崰, 浼氭洿鏂� [宸ヤ綅鍙穄
     // 娌℃湁闄愬畾妫�鏌ョ被鍨嬶紝涓嶈浣跨敤鏃堕棿妲�
+    // 鎺掑簭锛氬姞鎬ヤ紭鍏� 鈫� 鎺掗槦鍙峰崌搴忥紙鍙蜂负绌烘帓鏈�鍚庯級銆傝鏈哄彨鍙峰彇浜轰篃璧拌繖閲屻��
     @Select("<script> " +
-            "select * from lihu.queue where room_id = #{roomId} and status in ( " +
+            "select * from lihu.queue where deleted = 0 and room_id = #{roomId} and status in ( " +
             "       <foreach collection='curStatusList' separator=',' item='status'>" +
             "           #{status} " +
             "       </foreach> )" +
-            "       order by seq_num, book_timeslot limit 1 " +
+            "       order by jump_flag desc, case when seq_num is null then 1 else 0 end, seq_num, book_timeslot limit 1 " +
             "</script>" )
     QueueDO getRoomFirstQueueItemByStatus(@Param("roomId")Long roomId, @Param("curStatusList")List<Integer> curStatusList);
 
+    /**
+     * 鎸夐绾﹀崟 id 鎵归噺鍙� queue 琛屻��
+     *
+     * <p>鐢ㄩ�旓細棰勭害绛惧埌鍓嶏紝鎶娿�岃棰勭害鏄惁宸叉帓闃熴�佹嬁鍒扮殑鎺掗槦鍙锋槸澶氬皯銆嶅洖濉粰鍓嶇銆�
+     * 鍙风粺涓�鍚庡彇鐨勬槸 {@code seq_num}锛堣 AppointmentServiceImpl#queryAndCreateAppointmentByPatId锛夈��
+     * <p>鍘熸柟娉曞悕涓� {@code selectBookSeqNumByAppointIdList}锛屽洜鍙峰凡缁熶竴涓� seq_num 鑰屾敼鍚嶃��
+     */
     @Select("<script> " +
-            "select * from lihu.queue where appoint_id in ( " +
+            "select * from lihu.queue where deleted = 0 and appoint_id in ( " +
             "       <foreach collection='appointIdList' separator=',' item='appointId'>" +
             "           #{appointId} " +
             "       </foreach> )" +
             "</script>" )
-    List<QueueDO> selectBookSeqNumByAppointIdList(@Param("appointIdList") List<Long> appointIdList);
+    List<QueueDO> selectQueueByAppointIdList(@Param("appointIdList") List<Long> appointIdList);
 
 /*
     @Select("select * from lihu.queue where room_id = #{roomId} and bed_no = #{bedNo} " +
@@ -249,9 +346,21 @@
     @Update("update lihu.queue set status = #{newStatus} where pat_id = #{patId} and book_check_type = #{checkType} and status = #{curStatus}; " )
     Integer updatePatientQueueStatus(@Param("patId")String patId, @Param("checkType")Integer checkType, @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
 
-    @Update("update lihu.queue set status = #{newStatus} where status = #{curStatus} and 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 )")
+    /**
+     * 鎶婃湰宸ヤ綅銆佹寚瀹氱姸鎬佷腑銆屾帓闃熷彿鏈�灏忋�嶇殑涓�浣嶆敼鎴愭柊鐘舵�侊紙杩囧彿鐢級銆�
+     *
+     * <p><b>銆愬彿缁熶竴鏀归�犲繀淇�戝繀椤绘寜琛� id 鏇存柊銆�</b>
+     * 鏃у疄鐜板灞傛潯浠舵槸 {@code where status = ? and seq_num = (select min(seq_num) ...)}鈥斺��
+     * 澶栧眰<b>娌℃湁 room_id / bed_no 鏉′欢</b>锛屽畬鍏ㄤ緷璧�"seq_num 鍏ㄨ〃鍞竴"鎵嶄笉浼氳浼ゃ��
+     * 鏈渶姹傛妸鎺掗槦鍙锋敼涓恒�屾寜妫�鏌ョ被鍨嬪悇鑷紪鍙枫�嶏紝鍙蜂細璺ㄦ鏌ョ被鍨嬮噸澶嶏紝
+     * 鏃у啓娉曚細涓�娆℃�ф妸<b>鍏ㄩ櫌鎵�鏈夊悓鍙峰悓鐘舵�佺殑鎮h��</b>涓�璧锋敼鎺�
+     * 锛堜緥锛氬父瑙勫績鐢� 5 鍙疯繃鍙凤紝鍔ㄦ�佸績鐢电殑 5 鍙蜂篃琚繃鍙凤級銆傛晠鏀逛负鍏堝彇 id銆佸啀鎸� id 鏇存柊銆�
+     */
+    @Update("update lihu.queue set status = #{newStatus} where id = " +
+            "  (select a.id from " +
+            "    (select id from lihu.queue where room_id = #{roomId} and bed_no = #{bedNo} " +
+            "       and status = #{curStatus} and deleted = 0 " +
+            "       order by case when seq_num is null then 1 else 0 end, seq_num, book_timeslot limit 1) a)")
     Integer updateBedQueueStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
 
     // 寮冪敤鍘熷洜锛氶渶瑕佸厛鑾峰彇锛屽垽鏂�昏緫澶勭悊鍚庯紝鍐嶆洿鏂�
@@ -272,40 +381,84 @@
     )
     Integer preemptToBeInstalledPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("curStatusList")List<Integer> curStatusList, @Param("newStatus")Integer newStatus);
 
-    // 鏁翠釜绯荤粺鑼冨洿鍐� [鎺掗槦涓璢浜哄憳 [琚伐浣嶅尰鐢焆鎶㈠崰
-    @Update("update lihu.queue set status = #{newStatus}, room_id = #{roomId}, room_name = #{roomName}, \n" +
-            " bed_no = #{bedNo}, seq_num = #{seqNum} where id = \n" +
-            "  (select a.id from \n" +
-            "    (select id from lihu.queue where status = #{curStatus} and book_check_type= #{checkType} order by jump_flag desc, book_timeslot, create_time limit 1) a)")
-    Integer preemptWaitingPatient(@Param("roomId")Long roomId, @Param("roomName")String roomName, @Param("bedNo")String bedNo,
-                                  @Param("seqNum")Integer seqNum, @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus,
-                                  @Param("checkType")Integer checkType);
-
-    // 鏁翠釜绯荤粺鑼冨洿鍐� [鎺掗槦涓璢浜哄憳 [琚伐浣嶅尰鐢焆鎶㈠崰 鏍规嵁 澶氫釜妫�鏌ラ」鐩�
-    @Update("<script>" +
-            "update lihu.queue set status = #{newStatus}, room_id = #{roomId}, room_name = #{roomName}, \n" +
-            " bed_no = #{bedNo}, seq_num = #{seqNum} where id = \n" +
-            "  (select a.id from \n" +
-            "    (select id from lihu.queue where status = #{curStatus} " +
-            "       and book_check_type in ( " +
-            "           <foreach collection='checkTypeArray' separator=',' item='_checkType'>" +
-            "             #{_checkType} " +
-            "           </foreach> )" +
-            "       order by jump_flag desc, book_timeslot, create_time limit 1) a) " +
+    /**
+     * 鍙栥�屾湰宸ヤ綅寮�灞曠殑妫�鏌ラ」鐩�嶄腑涓嬩竴浣嶅簲鍒嗘祦鐨勩�屾帓闃熶腑(10)銆嶆偅鑰呫��
+     *
+     * <p>鎺掑簭锛�<b>鍔犳��(jump_flag=1) 鈫� 棰勭害鏃舵 鈫� 寤哄崟鏃堕棿</b>锛涘彿涓虹┖锛堝瓨閲忚锛夋帓鏈�鍚庛��
+     * <p><b>杩欓噷涓嶅啀鍒嗛厤鎺掗槦鍙�</b>锛氬彿宸插湪绛惧埌鏃朵竴娆℃�у啓鍏� {@code seq_num}锛�
+     * 鍒嗘祦鍙礋璐f妸鎮h�呬粠銆屾帓闃熶腑銆嶆惉鍒版煇涓伐浣嶇殑銆屽�欒瘖涓�嶃��
+     * <p>鍙栧嚭鍚庡啀鐢� {@link #preemptWaitingPatientById} 鍋氭潯浠舵洿鏂帮紝
+     * 闈� {@code and status = 10} 淇濊瘉骞跺彂涓嬪彧鏈変竴鏂硅兘鎶㈠埌璇ヨ銆�
+     */
+    @Select("<script>" +
+            "select * from lihu.queue where deleted = 0 and status = #{curStatus} " +
+            "   and book_check_type in ( " +
+            "     <foreach collection='checkTypeArray' separator=',' item='_checkType'>" +
+            "       #{_checkType} " +
+            "     </foreach> )" +
+            "   order by jump_flag desc, case when seq_num is null then 1 else 0 end, book_timeslot, create_time limit 1" +
             "</script>")
-    Integer preemptWaitingPatientWithBedCheckTypes(@Param("roomId")Long roomId, @Param("roomName")String roomName, @Param("bedNo")String bedNo,
-                                  @Param("seqNum")Integer seqNum, @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus,
-                                  @Param("checkTypeArray")Integer[] checkTypeArray);
+    @Results({
+            @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+    })
+    QueueDO getFirstWaitingByCheckTypes(@Param("curStatus")Integer curStatus, @Param("checkTypeArray")Integer[] checkTypeArray);
 
-    @Update("update lihu.queue set status = #{newStatus}, seq_num = #{seqNum} " +
-            " where id = " +
-            "  (select a.id from \n" +
-            "    (select id from lihu.queue where room_id = #{roomId} and bed_no = #{bedNo} and status = #{curStatus} " +
-            "      order by seq_num, book_timeslot limit 1" +
-            "    ) a" +
-            "  )" )
-    Integer queueRecalledPatient(@Param("roomId")Long roomId, @Param("roomName")String roomName, @Param("bedNo")String bedNo,
-                                 @Param("seqNum")Integer seqNum, @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
+    /**
+     * 銆屾湰璇婂/鏈伐浣�**鎺掗槦涓�佽繕娌″垎閰嶅伐浣�**銆嶇殑鎮h�咃紙宸ヤ綔鍙�"鏈瘖瀹ゆ帓闃熶腑锛堟湭鍒嗛厤锛�"鍒嗗尯鐢級銆�
+     *
+     * <p>鑳屾櫙锛氬伐浣滃彴鐨勫�欒瘖鍒楄〃鎸� {@code room_id + bed_no} 鏌ワ紝鍙寘鍚�**宸茬粡鍒嗘祦鍒拌宸ヤ綅**鐨勬偅鑰咃紱
+     * 鑰�"鎺掗槦涓�(10)"鐨勬偅鑰� {@code bed_no} 鏄┖鐨勶紙瑙� QueueServiceImpl 閲嶇疆閫昏緫锛歳oom_id=0 / bed_no=' '锛夛紝
+     * 澶у睆浼氭樉绀轰粬浠紙澶у睆涓嶆寜璇婂/宸ヤ綅杩囨护锛夛紝浜庢槸鍑虹幇"澶у睆鏈夈�佸伐浣滃彴鍒楄〃娌℃湁"鐨勫洶鎯戙��
+     * 杩欓噷鎶�"鏈伐浣嶆鏌ョ被鍨嬨�佸皻鏈垎閰嶅伐浣�"鐨勬帓闃熸偅鑰呭崟鐙煡鍑烘潵锛岀敱鍖荤敓**鎵嬪伐鎷夊叆**銆�
+     *
+     * <p>鍒ゅ畾"鏈垎閰�"鐢� {@code bed_no} 涓虹┖锛堝吋瀹� null / 绌轰覆 / 鍗曚釜绌烘牸锛夛紝
+     * 涓嶄緷璧� {@code room_id = 0} 杩欎竴绾﹀畾锛屽閿欐洿濂姐��
+     */
+    @Select("""
+            <script>
+                SELECT * FROM lihu.queue
+                where deleted = 0 and status = #{curStatus}
+                  and (bed_no is null or trim(bed_no) = '')
+                  and book_check_type in (
+                    <foreach collection='checkTypeArray' separator=',' item='_checkType'>
+                      #{_checkType}
+                    </foreach> )
+                order by jump_flag desc,
+                         case when seq_num is null then 1 else 0 end,
+                         book_timeslot, create_time
+            </script>
+            """)
+    @Results({
+            @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+    })
+    List<QueueDO> selectUnassignedWaitingByCheckTypes(@Param("curStatus")Integer curStatus,
+                                                      @Param("checkTypeArray")Integer[] checkTypeArray);
+
+    /**
+     * 鎶娿�屾帓闃熶腑銆嶇殑鏌愪竴琛屾姠鍗犲埌鎸囧畾宸ヤ綅銆�
+     *
+     * <p><b>涓嶆敼鎺掗槦鍙�</b>锛堝彿鏄鍒版椂瀹氱殑锛夛細鍙敼鐘舵�併�佽瘖瀹ゃ�佸伐浣嶃��
+     * <p>{@code and status = #{curStatus}} 鏄苟鍙戜繚鎶� 鈥斺�� 涓や釜宸ヤ綅鍚屾椂鎶㈠悓涓�浣嶆偅鑰呮椂锛�
+     * 鍙湁绗竴涓� UPDATE 浼氬懡涓紙杩斿洖 1锛夛紝鍙︿竴鏂硅繑鍥� 0锛岄渶閲嶆柊鍙栦汉銆�
+     */
+    @Update("update lihu.queue set status = #{newStatus}, room_id = #{roomId}, room_name = #{roomName}, bed_no = #{bedNo} " +
+            " where id = #{id} and status = #{curStatus} and deleted = 0")
+    Integer preemptWaitingPatientById(@Param("id")Integer id, @Param("roomId")Long roomId, @Param("roomName")String roomName,
+                                      @Param("bedNo")String bedNo, @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
+
+    /**
+     * 銆愭湰闇�姹偮峰苟鍙戝姞鍥恒�戞寜涓婚敭 + **褰撳墠鐘舵��**鏉′欢鎺ㄨ繘鐘舵�侊紙鍙彿锛氬�欒瘖涓�(20) 鈫� 灏辫瘖涓�(30)锛夈��
+     *
+     * <p>涓轰粈涔堥渶瑕佸畠锛歿@code nextPatient} 鍘熸潵鏄�"鍏堟煡鏈�灏忓彿鐨勫�欒瘖琛� 鈫� updateById"锛�
+     * 涓や釜骞跺彂璇锋眰锛堝弻鍑� / 澶氱锛夊彲鑳藉悇鎺ㄨ繘涓�鏉� READY锛屽鑷村悓涓�宸ヤ綅鍑虹幇 **2 涓�屽氨璇婁腑銆�**銆�
+     * 鏈変簡 {@code and status = #{curStatus}}锛氬彧鏈夌涓�涓� UPDATE 鍛戒腑锛堣繑鍥� 1锛夛紝
+     * 鍙︿竴鏂硅繑鍥� 0锛岀敱璋冪敤鏂规斁寮冩湰娆″彨鍙凤紝绛変笅涓�娆″啀鍙栥��
+     */
+    @Update("update lihu.queue set status = #{newStatus}, update_time = NOW() "
+            + " where id = #{id} and status = #{curStatus} and deleted = 0")
+    Integer updateStatusByIdIfCurrent(@Param("id") Integer id,
+                                      @Param("curStatus") Integer curStatus,
+                                      @Param("newStatus") Integer newStatus);
 
     // 甯歌妫�鏌� 鎴� 棰嗙敤 鐨勬偅鑰呭彫鍥�, 鍘熷伐浣嶅鐞�
     @Update("update lihu.queue set status = #{newStatus}, passed = 1 " +
@@ -326,6 +479,70 @@
     Integer queueJump(@Param("patId")String patId, @Param("bookCheckType")Integer bookCheckType,
                       @Param("curStatus")Integer curStatus, @Param("jumped")Byte jumped );
 
+    // ==================== 闇�姹�2锛氳鐐广�屽彨鍙� / 妫�鏌ュ畬鎴愩�嶇殑鎾ら攢 ====================
+
+    /**
+     * 鎵归噺鍙栥�岃繖浜涙偅鑰呬粖鏃ョ殑闃熷垪鐘舵�併�嶏紙鐢ㄤ簬鍒ゆ柇"宸插畬鎴愯褰�"鏄惁琚挙閿�杩囷級銆�
+     *
+     * <p>銆愰渶姹傦細鎾ら攢鏍囪瘑銆戞挙閿�銆屾鏌ュ畬鎴愩�嶅彧鏄妸闃熷垪琛� 40(宸插氨璇�) 鏀瑰洖 20(鍑嗗涓�)锛�
+     * 涓嶇 job_record銆傚洜姝�"杩欐潯瀹屾垚璁板綍鏄惁宸叉挙閿�"鐢�**褰撴棩闃熷垪琛岀殑褰撳墠鐘舵��**鍒ゆ柇鍗冲彲锛�
+     * 鐘舵�� 鈮� 40 鈫� 宸茶鎾ら攢锛涘啀娆″畬鎴愭椂浼氬彉鍥� 40 鈫� 鑷姩鎭㈠鎴�"宸插畬鎴�"锛堟棤闇�棰濆娓呮爣璁帮級銆�
+     *
+     * <p>鍙彇褰撴棩锛堟挙閿�鏈韩灏卞彧鏀寔褰撴棩锛夛紝涓�娆℃煡璇㈣В鍐虫暣椤佃褰曘��
+     */
+    @Select("<script>" +
+            "select pat_id as patId, book_check_type as checkType, status " +
+            "  from lihu.queue " +
+            " where deleted = 0 and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+            "   and pat_id in ( " +
+            "     <foreach collection='patIdList' separator=',' item='_patId'>#{_patId}</foreach> ) " +
+            "</script>")
+    List<Map<String, Object>> selectTodayStatusByPatIds(@Param("patIdList")List<String> patIdList);
+
+    /**
+     * 鎾ら攢銆屾鏌ュ畬鎴愩�嶏細鎶婃湰宸ヤ綅浠婃棩鐨�**鎸囧畾鎮h��**浠� 宸插氨璇�(40) 閫�鍥� 鍊欒瘖涓�(20)銆�
+     * <p>
+     * 蹇呴』鎸� {@code pat_id + book_check_type + 浠婃棩} 绮剧‘瀹氫綅锛�**涓嶈兘**鍙寜
+     * "宸ヤ綅 + status=40 鍙栫涓�鏉�"鈥斺�旈偅浼氬湪鏈熼棿宸插彨涓嬩竴浣嶆偅鑰呮椂璇敼浠栦汉锛堣
+     * {@code DevRentServiceImpl.routineFinishOperation} 鐨勬棦鏈夌己闄凤級銆�
+     * <p>
+     * {@code passed = 0} 鏄负浜嗚鎮h�呴噸鏂板洖鍒版甯稿�欒瘖搴忓垪锛堥潪"杩囧彿"鎬侊級銆�
+     */
+    @Update("update lihu.queue set status = #{newStatus}, passed = 0 " +
+            " where room_id = #{roomId} and bed_no = #{bedNo} and status = #{curStatus} " +
+            "   and pat_id = #{patId} and book_check_type = #{checkType} " +
+            "   and TO_DAYS(book_date) = TO_DAYS(NOW())")
+    Integer undoFinishPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+                              @Param("patId")String patId, @Param("checkType")Integer checkType,
+                              @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
+
+    /**
+     * 鎾ら攢銆岃鐐瑰彨鍙枫�嶏細鎶婃湰宸ヤ綅褰撳墠 灏辫瘖涓�(30) 鐨勬偅鑰呴��鍥� 鍊欒瘖涓�(20)銆�
+     * <p>
+     * 浠呮寜宸ヤ綅+鐘舵�佸畾浣嶏紙"褰撳墠姝e湪灏辫瘖鐨勯偅涓�浣�"锛夛紝涓嶄娇鐢� seq_num 瀛愭煡璇紝
+     * 閬垮厤涓� {@code updateBedQueueStatus} 鐨勫啓娉曟贩娣嗐��
+     */
+    @Update("update lihu.queue set status = #{newStatus} " +
+            " where id = " +
+            "  (select a.id from " +
+            "    (select id from lihu.queue where room_id = #{roomId} and bed_no = #{bedNo} " +
+            "       and status = #{curStatus} and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+            "       order by seq_num, book_timeslot limit 1) a)")
+    Integer undoCallPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+                            @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
+
+    /**
+     * 鍙栨湰宸ヤ綅浠婃棩**鏈�杩戜竴浣嶅凡瀹屾垚**鐨勬偅鑰咃紙鐢ㄤ簬鐣岄潰鎻愮ず"鍙挙閿�鐨勬槸璋�"锛夈��
+     */
+    @Select("SELECT * FROM lihu.queue where room_id = #{roomId} and bed_no = #{bedNo} " +
+            " and status = #{status} and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+            " order by update_time desc, seq_num desc limit 1")
+    @Results({
+            @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+    })
+    QueueDO getBedLastFinishedQueueItem(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+                                        @Param("status")Integer status);
+
     //@Update("TRUNCATE TABLE lihu.queue")
     @Delete("delete from lihu.queue where TO_DAYS(book_date) != TO_DAYS(NOW())")
     void clearQueue();

--
Gitblit v1.9.3