From db6ffd6a99b46bd27173503c10aa4cd1afc9c775 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期三, 25 十一月 2026 11:16:33 +0800
Subject: [PATCH] 算税优化
---
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/QueueMapper.java | 700 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 640 insertions(+), 60 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 34aedca..4dd2914 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
@@ -27,7 +28,7 @@
.eqIfPresent(QueueDO::getBookTimeslot, reqVO.getBookTimeslot())
.eqIfPresent(QueueDO::getBookCheckType, reqVO.getBookCheckType())
.eqIfPresent(QueueDO::getSeqNum, reqVO.getSeqNum())
- .eqIfPresent(QueueDO::getStatus, reqVO.getStatus())
+ .inIfPresent(QueueDO::getStatus, reqVO.getStatus())
.eqIfPresent(QueueDO::getPassed, reqVO.getPassed())
.eqIfPresent(QueueDO::getExpired, reqVO.getExpired())
.eqIfPresent(QueueDO::getRoomId, reqVO.getRoomId())
@@ -36,31 +37,123 @@
.orderByDesc(QueueDO::getId));
}
- @Select("SELECT max(seq_num) FROM lihu.queue")
- Integer getMaxSeqNum();
+ @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);
- @Select("SELECT * FROM lihu.queue where pat_id = #{patId}")
- QueueDO getQueueByPatId(@Param("patId")String patId);
+ /**
+ * 璇婇棿灞忥紙{@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 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)
+ })
+ List<QueueDO> getRoomQueueByStatus(@Param("roomId")Long roomId, @Param("statusList")List<Integer> statusList);
+
+ /**
+ * 澶у睆鍙栨暟銆�
+ *
+ * <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)
+ })
+ List<QueueDO> getBigScreenQueueByStatus(@Param("statusList")List<Integer> statusList);
@Select("<script>" +
"SELECT * FROM lihu.queue " +
- "where room_id = #{roomId} and status in (" +
- " <foreach collection='statusList' separator=',' item='status'>" +
- " #{status} " +
- " </foreach> )" +
- " order by status desc, seq_num" +
+ "where pat_id = #{patId} " +
+ " and book_check_type in (" +
+ " <foreach collection='arrCheckType' separator=',' item='checkType'>" +
+ " #{checkType} " +
+ " </foreach> )" +
+ " and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
"</script>")
- List<QueueDO> getRoomQueueByStatus(@Param("roomId")Long roomId, @Param("statusList")List<Byte> statusList);
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ List<QueueDO> getCurPatGivenCheckTypes(@Param("patId")String patId, @Param("arrCheckType")Integer[] arrCheckType);
@Select("<script>" +
"SELECT * FROM lihu.queue " +
- "where status in (" +
- " <foreach collection='statusList' separator=',' item='status'>" +
- " #{status} " +
- " </foreach> )" +
- " order by status desc, seq_num" +
+ "where pat_id = #{patId} " +
+ " and book_check_type in (" +
+ " <foreach collection='arrCheckType' separator=',' item='_checkType'>" +
+ " #{_checkType} " +
+ " </foreach> ) " +
+ " and status = #{status} " +
+ " and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
"</script>")
- List<QueueDO> getQueueByStatus( @Param("statusList")List<Byte> statusList);
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ List<QueueDO> getCurPatGivenCheckTypesAndStatus(@Param("patId")String patId, @Param("arrCheckType")Integer[] arrCheckType, @Param("status")Integer status);
+
+ @Select("<script>" +
+ "SELECT * FROM lihu.queue " +
+ "where pat_id = #{patId} " +
+ " and book_check_type in (" +
+ " <foreach collection='arrCheckType' separator=',' item='_checkType'>" +
+ " #{_checkType} " +
+ " </foreach> ) " +
+ " and status in (" +
+ " <foreach collection='statusList' separator=',' item='_status'>" +
+ " #{_status} " +
+ " </foreach> ) " +
+ " and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+ "</script>")
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ List<QueueDO> getCurPatGivenCheckTypesAndStatusList(@Param("patId")String patId, @Param("arrCheckType")Integer[] arrCheckType, @Param("statusList")List<Integer> statusList);
@Select("<script>" +
"SELECT * FROM lihu.queue " +
@@ -71,7 +164,10 @@
" limit #{size} " +
" order by id" +
"</script>")
- List<QueueDO> getPartialQueueByStatus( @Param("statusList")List<Byte> statusList, @Param("from") Integer from, @Param("size") Integer size);
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ List<QueueDO> getPartialQueueByStatus( @Param("statusList")List<Integer> statusList, @Param("from") Integer from, @Param("size") Integer size);
@Select("<script>" +
"SELECT count(1) as total_in_status FROM lihu.queue where status in (" +
@@ -79,7 +175,21 @@
" #{status} " +
" </foreach> );" +
"</script>")
- Integer statusStatistic(@Param("statusList")List<Byte> statusList);
+ Integer statusStatistic(@Param("statusList")List<Integer> statusList);
+
+ @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} " +
+ " </foreach> ) " +
+ " and book_check_type in ( " +
+ " <foreach collection='checkTypes' separator=',' item='checkType'>" +
+ " #{checkType} " +
+ " </foreach> ) " +
+ "</script>")
+ Integer checkTypeAndStatusStatistic( @Param("checkTypes")Integer[] checkTypes, @Param("statusList")List<Integer> statusList );
@Select("<script>" +
"SELECT room_id, bed_no, count(1) as total_in_status FROM lihu.queue where status in (" +
@@ -88,75 +198,545 @@
" </foreach> )" +
" group by room_id, bed_no; "
+"</script>")
- List<QueueStatisticDO> queueStatistic(@Param("statusList")List<Byte> statusList);
+ List<QueueStatisticDO> queueStatistic(@Param("statusList")List<Integer> statusList);
@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>")
List<BedQueueStatisticDO> bedQueueStatistic(@Param("roomId")Long roomId, @Param("bedNo")String bedNo);
@Select("<script>" +
- "SELECT count(1) FROM lihu.queue " +
- "where room_id = #{roomId} and bed_no = #{bedNo} and status in (" +
- " <foreach collection='statusList' separator=',' item='status'>" +
- " #{status} " +
- " </foreach> )" +
+ "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>")
- Integer bedQueueStatisticByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("statusList")List<Byte> statusList);
+ List<BedQueueStatisticDO> roomQueueStatistic(@Param("roomId")Long roomId);
@Select("<script>" +
- "SELECT * FROM lihu.queue " +
- "where room_id = #{roomId} and bed_no = #{bedNo} and status in (" +
+ "SELECT count(1) FROM lihu.queue " +
+ "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> )" +
- " order by status desc, seq_num" +
"</script>")
- List<QueueDO> getBedQueueByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("statusList")List<Byte> statusList);
+ Integer bedQueueStatisticByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("statusList")List<Integer> statusList);
- @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 updateBedQueueStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus);
+ @Select("""
+ <script>
+ SELECT * FROM lihu.queue
+ where deleted = 0 and room_id = #{roomId} and bed_no = #{bedNo} and status in (
+ <foreach collection='statusList' separator=',' item='status'>
+ #{status}
+ </foreach> )
+ 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({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ List<QueueDO> getBedQueueByStatus(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("statusList")List<Integer> statusList);
- // 鏌愪釜璇婂鑼冨洿鍐� [宸查鐢╙浜哄憳 鎶㈠崰
- @Update("update lihu.queue set status = #{newStatus}, bed_no = #{bedNo} 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 status = #{curStatus}) a )")
- Integer preemptReceivedPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus);
+ /**
+ * 鍙彿鍙栦汉锛氭湰宸ヤ綅銆屽�欒瘖涓�(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} 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);
- @Update("update lihu.queue set status = #{newStatus} where pat_id = #{patId} and status = #{curStatus}")
- Integer updatePatientQueueStatus(@Param("patId")String patId, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus);
+ /**
+ * 銆愰渶姹�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);
- // 鏁翠釜绯荤粺鑼冨洿鍐� [鎺掗槦涓璢浜哄憳 鎶㈠崰
- @Update("update lihu.queue set status = #{newStatus}, room_id = #{roomId}, room_name = #{roomName}, \n" +
- " bed_no = #{bedNo}, seq_num = #{seqNum} where id = \n" +
+ /**
+ * 鎸夈�屽伐浣� + 鎮h�� + 妫�鏌ョ被鍨� + 鐘舵��**闆嗗悎**銆嶅彇涓�琛岋紙浠婃棩锛屽彿鏈�灏忥級銆�
+ *
+ * <p>銆愭湰闇�姹偮蜂笉鍙彿鐩存帴妫�鏌ャ�戠敤浜庛�屾鏌ュ畬鎴愩�嶆椂鏀跺熬**浠栬嚜宸辩殑**鎺掗槦琛岋細
+ * 浠庡伐浣滃彴鍙充晶鍒楄〃鐐广�屾鏌ャ�嶅姞杞界殑鎮h�咃紝鍏ㄧ▼涓嶄細琚疆涓恒�屽氨璇婁腑(30)銆�
+ * 锛堝洜涓鸿姹備笉涓婂ぇ灞忋�佷笉鍙彿锛夛紝瀹屾垚妫�鏌ユ椂灏辨病鏈� 30 鐨勮鍙互鏀� 40锛�
+ * 鑻ヤ笉澶勭悊浠栦細涓�鐩寸暀鍦ㄥ�欒瘖鍒楄〃鍜屽ぇ灞忎笂銆�
+ *
+ * <p>鍏佽鐨勭姸鎬侊細鎺掗槦涓�(10)/宸插彫鍥�(15)/鍑嗗涓�(20)鈥斺�旈兘鏄�"杩樻病鍋氬畬"鐨勭姸鎬併��
+ */
+ @Select("<script>" +
+ "SELECT * from lihu.queue " +
+ "where room_id = #{roomId} and bed_no = #{bedNo} " +
+ " and pat_id = #{patId} and book_check_type = #{checkType} " +
+ " and status in ( " +
+ " <foreach collection='statusList' separator=',' item='_status'>#{_status}</foreach> " +
+ " ) " +
+ " and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+ "order by seq_num limit 1" +
+ "</script>")
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ QueueDO getBedQueueItemByPatAndStatuses(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+ @Param("patId")String patId, @Param("checkType")Integer checkType,
+ @Param("statusList")List<Integer> statusList);
+
+ /**
+ * 鍙栥�岃繕娌″垎閰嶅伐浣嶃�嶇殑鎺掗槦琛岋紙{@code bed_no} 涓虹┖锛屼粖鏃ワ紝鍙锋渶灏忥級銆�
+ *
+ * <p>鍦烘櫙鍚屼笂锛氬尰鐢熷湪銆屾湰璇婂鎺掗槦涓紙鏈垎閰嶅伐浣嶏級銆嶉噷鐩存帴鐐广�屾鏌ャ�嶅仛鎺夋煇浣嶆偅鑰咃紝
+ * 璇ヨ娌℃湁 room/bed锛屽畬鎴愭鏌ユ椂瑕佹寜鎮h�� + 妫�鏌ラ」鐩妸瀹冩敹灏俱��
+ */
+ @Select("<script>" +
+ "SELECT * from lihu.queue " +
+ "where pat_id = #{patId} and book_check_type = #{checkType} " +
+ " and (bed_no is null or trim(bed_no) = '') " +
+ " and status in ( " +
+ " <foreach collection='statusList' separator=',' item='_status'>#{_status}</foreach> " +
+ " ) " +
+ " and TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+ "order by seq_num limit 1" +
+ "</script>")
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ QueueDO getUnassignedQueueItemByPatAndStatuses(@Param("patId")String patId, @Param("checkType")Integer checkType,
+ @Param("statusList")List<Integer> statusList);
+
+ /**
+ * 鎸夊伐浣� + 鐘舵�� + 浠婃棩鍙�**鏈�杩戞洿鏂�**鐨勪竴鏉°��
+ * <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
+ """)
+ QueueDO getBedFirstQueueItemByApplyNo(@Param("applyNo")String applyNo, @Param("curStatus")Integer curStatus);
+
+ // 鏌愪釜璇婂鑼冨洿鍐� [宸查鐢╙ [宸插彫鍥�-瀹夎] 浜哄憳 鎶㈠崰, 浼氭洿鏂� [宸ヤ綅鍙穄
+ // 娌℃湁闄愬畾妫�鏌ョ被鍨嬶紝涓嶈浣跨敤鏃堕棿妲�
+ // 鎺掑簭锛氬姞鎬ヤ紭鍏� 鈫� 鎺掗槦鍙峰崌搴忥紙鍙蜂负绌烘帓鏈�鍚庯級銆傝鏈哄彨鍙峰彇浜轰篃璧拌繖閲屻��
+ @Select("<script> " +
+ "select * from lihu.queue where deleted = 0 and room_id = #{roomId} and status in ( " +
+ " <foreach collection='curStatusList' separator=',' item='status'>" +
+ " #{status} " +
+ " </foreach> )" +
+ " 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 deleted = 0 and appoint_id in ( " +
+ " <foreach collection='appointIdList' separator=',' item='appointId'>" +
+ " #{appointId} " +
+ " </foreach> )" +
+ "</script>" )
+ List<QueueDO> selectQueueByAppointIdList(@Param("appointIdList") List<Long> appointIdList);
+
+/*
+ @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}")
+ QueueDO XXX(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+ @Param("patId")String patId, @Param("checkType")Integer checkType,
+ @Param("curStatus")Integer curStatus);
+*/
+
+ @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);
+
+ /**
+ * 鎶婃湰宸ヤ綅銆佹寚瀹氱姸鎬佷腑銆屾帓闃熷彿鏈�灏忋�嶇殑涓�浣嶆敼鎴愭柊鐘舵�侊紙杩囧彿鐢級銆�
+ *
+ * <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);
+
+ // 寮冪敤鍘熷洜锛氶渶瑕佸厛鑾峰彇锛屽垽鏂�昏緫澶勭悊鍚庯紝鍐嶆洿鏂�
+ // 鏌愪釜璇婂鑼冨洿鍐� [宸查鐢╙ [宸插彫鍥�-瀹夎] 浜哄憳 鎶㈠崰, 浼氭洿鏂� [宸ヤ綅鍙穄
+ // 娌℃湁闄愬畾妫�鏌ョ被鍨嬶紝涓嶈浣跨敤鏃堕棿妲�
+ @Update("<script> " +
+ "update lihu.queue set status = #{newStatus}, bed_no = #{bedNo} 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")Byte curStatus, @Param("newStatus")Byte newStatus,
- @Param("checkType")Integer checkType);
+ " (select id from lihu.queue where room_id = #{roomId} " +
+ " and status in ( " +
+ " <foreach collection='curStatusList' separator=',' item='status'>" +
+ " #{status} " +
+ " </foreach> )" +
+ " order by seq_num, book_timeslot limit 1 " +
+ " ) a " +
+ " )" +
+ "</script>"
+ )
+ 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}, seq_num = #{seqNum}, passed = 1 " +
- " 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 limit 1) a)")
- Integer queueRecalledPatient(@Param("roomId")Long roomId, @Param("roomName")String roomName, @Param("bedNo")String bedNo,
- @Param("seqNum")Integer seqNum, @Param("curStatus")Byte curStatus, @Param("newStatus")Byte newStatus);
+ /**
+ * 鍙栥�屾湰宸ヤ綅寮�灞曠殑妫�鏌ラ」鐩�嶄腑涓嬩竴浣嶅簲鍒嗘祦鐨勩�屾帓闃熶腑(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>")
+ @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} " +
- " where room_id = #{roomId} and bed_no = #{bedNo} and status = #{curStatus} and pat_id = #{patId} ")
- Integer recallPassedPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo, @Param("patId")String patId,
- @Param("curStatus")Byte curStatus, @Param("newStatus")Byte 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);
+
+ /**
+ * 銆愪慨澶嵚风幇鍦洪棶棰樸�戞妸鏌愬伐浣嶄笂鐨勩�屽噯澶囦腑/宸插彫鍥�/浜插拰銆嶆偅鑰�**閫�鍥炪�屾帓闃熶腑銆�**锛屽苟娓呯┖璇婂/宸ヤ綅銆�
+ *
+ * <p>鐢ㄤ簬銆岀鐞嗗憳娓呯┖宸ヤ綅銆嶄笌銆岄棴璇娿�嶃�傚師瀹炵幇鍙敼 `clinic_room`锛屾偅鑰呬粛鎸傚湪杩欎釜宸ヤ綅涓婏紝
+ * 鑰屽伐浣嶅凡缁忔病浜轰簡 鈥斺�� 浠栦滑鏃笉鍦ㄤ换浣曞尰鐢熺殑鍊欒瘖鍒楄〃閲岋紝涔熶笉鍦�
+ * 銆屾湰璇婂鎺掗槦涓紙鏈垎閰嶏級銆嶉噷锛堥偅涓垪琛ㄥ彧鏌� {@code status=10 涓� bed_no 涓虹┖}锛夛紝
+ * 绛変簬"娑堝け"锛屽彧鑳界瓑姣忔棩閲嶇疆銆傞��鍥炲悗鍗冲彲琚叾瀹冨紑璇婂伐浣嶉噸鏂板垎娴� / 鎵嬪伐銆屾媺鍏ャ�嶃��
+ *
+ * <p>鍚屾椂鎶� {@code affinity_item} 澶嶄綅涓� 0锛氫翰鍜岄」閲嶆柊鍙樻垚鐙珛鐨勬帓闃熸偅鑰咃紝
+ * 涓嬫琚垎娴佹椂浼氱敱浜插拰閫昏緫閲嶆柊鎸傚埌涓婚」涓婏紙{@code procAffinityWhenPreempt}锛夈��
+ */
+ @Update("<script>" +
+ "update lihu.queue " +
+ "set status = #{newStatus}, room_id = 0, room_name = '', bed_no = null, affinity_item = 0 " +
+ "where room_id = #{roomId} and bed_no = #{bedNo} and deleted = 0 " +
+ " and status in ( <foreach collection='statusList' separator=',' item='_status'>#{_status}</foreach> )" +
+ "</script>")
+ Integer releaseBedPatientsToWaiting(@Param("roomId") Long roomId, @Param("bedNo") String bedNo,
+ @Param("newStatus") Integer newStatus,
+ @Param("statusList") List<Integer> statusList);
+
+ /**
+ * 銆愭湰闇�姹偮峰苟鍙戝姞鍥恒�戞寜涓婚敭 + **褰撳墠鐘舵��**鏉′欢鎺ㄨ繘鐘舵�侊紙鍙彿锛氬�欒瘖涓�(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 " +
+ " where room_id = #{roomId} and bed_no = #{bedNo} and status = #{curStatus} and pat_id = #{patId} and book_check_type=#{checkType}")
+ Integer recallPassedPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+ @Param("patId")String patId, @Param("checkType")Integer checkType,
+ @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
+
+ // 瑁呮満鍖荤敓 鍏佽鎶㈠崰 鏈瀹� [瀹夎杩囧彿] 鐨勬偅鑰�
+ @Update("update lihu.queue set status = #{newStatus}, bed_no = #{bedNo}, passed = 1 " +
+ " where room_id = #{roomId} and status = #{curStatus} and pat_id = #{patId} and book_check_type=#{checkType}")
+ Integer recallPassedInstallPatient(@Param("roomId")Long roomId, @Param("bedNo")String bedNo,
+ @Param("patId")String patId, @Param("checkType")Integer checkType,
+ @Param("curStatus")Integer curStatus, @Param("newStatus")Integer newStatus);
@Update("update lihu.queue set jump_flag = #{jumped} " +
- " where status = #{curStatus} and pat_id = #{patId}")
- Integer queueJump(@Param("patId")String patId, @Param("curStatus")Byte curStatus, @Param("jumped")Byte jumped );
+ " where status = #{curStatus} and pat_id = #{patId} and book_check_type=#{bookCheckType}")
+ 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();
+
+ // ========================================================================
+ // 鍏变韩鍊欒瘖姹狅紙check_type.share_pool = 1锛岃瑙� _prep/鏂规-1-2璇婂鍏变韩鍊欒瘖姹�.md锛�
+ //
+ // 姹犱腑鎮h�呯殑鍒ゅ畾锛歴tatus = 20(鍑嗗涓�) 涓� **鏈粦瀹氳瘖瀹�**锛坆ed_no 涓虹┖锛夈��
+ // 涓�"宸茬粦瀹氭煇宸ヤ綅鐨� 20"鍖哄垎锛氬悗鑰� room_id/bed_no 鏈夊�硷紝浠嶆寜宸ヤ綅鏌ャ��
+ // ========================================================================
+
+ /**
+ * 鍙栧叡浜睜/鍏变韩鎺掗槦涓�屽彿鏈�灏忋�嶇殑涓�浣嶏紙浠婃棩锛屾湭缁戝畾璇婂锛夈��
+ *
+ * <p>{@code curStatus}=20 鍙�"鍑嗗涓�"锛�=10 鍙�"鎺掗槦涓�"锛堟睜绌烘椂鍙彿鐨勫厹搴曪級銆�
+ * 鎺掑簭涓庣幇鏈夊彨鍙蜂竴鑷达細鍔犳�ヤ紭鍏� 鈫� 鎺掗槦鍙� 鈫� 鏃舵 鈫� 鍒涘缓鏃堕棿銆�
+ */
+ @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='_t'>#{_t}</foreach> " +
+ " ) " +
+ " AND TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+ "ORDER BY jump_flag DESC, CASE WHEN seq_num IS NULL THEN 1 ELSE 0 END, seq_num, book_timeslot, create_time " +
+ "LIMIT 1" +
+ "</script>")
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ QueueDO selectSharedFirst(@Param("curStatus") Integer curStatus,
+ @Param("checkTypeArray") Integer[] checkTypeArray);
+
+ /**
+ * 鍙栧叡浜睜/鍏变韩鎺掗槦涓殑鎮h�呭垪琛紙宸ヤ綔鍙般�屽叡浜�欒瘖鍖恒�嶇敤锛夈��
+ */
+ @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='_t'>#{_t}</foreach> " +
+ " ) " +
+ " AND TO_DAYS(book_date) = TO_DAYS(NOW()) " +
+ "ORDER BY jump_flag DESC, CASE WHEN seq_num IS NULL THEN 1 ELSE 0 END, seq_num, book_timeslot, create_time" +
+ "</script>")
+ @Results({
+ @Result(property = "patDetails", column = "pat_details", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
+ })
+ List<QueueDO> selectSharedList(@Param("curStatus") Integer curStatus,
+ @Param("checkTypeArray") Integer[] checkTypeArray);
+
+ /**
+ * 缁熻鍏变韩姹犲綋鍓嶃�屽噯澶囦腑涓旀湭缁戝畾銆嶇殑浜烘暟锛堢敤浜庢睜瀹归噺鎺у埗锛夈��
+ */
+ @Select("<script>" +
+ "SELECT COUNT(1) FROM lihu.queue WHERE deleted = 0 AND status = 20 " +
+ " AND (bed_no IS NULL OR TRIM(bed_no) = '') " +
+ " AND book_check_type IN ( " +
+ " <foreach collection='checkTypeArray' separator=',' item='_t'>#{_t}</foreach> " +
+ " ) " +
+ " AND TO_DAYS(book_date) = TO_DAYS(NOW())" +
+ "</script>")
+ Integer countSharedPool(@Param("checkTypeArray") Integer[] checkTypeArray);
+
+ /**
+ * 鎶娿�屾帓闃熶腑(10)銆嶆彁鍗囦负鍏变韩姹犮�屽噯澶囦腑(20)銆嶏紝淇濇寔涓嶇粦瀹氳瘖瀹ゃ��
+ * <p>{@code and status = 10} 淇濊瘉骞跺彂涓嬪彧鏈変竴鏂规姠鍒拌琛屻��
+ */
+ @Update("update lihu.queue set status = 20, room_id = 0, room_name = '', bed_no = null " +
+ " where id = #{id} and status = 10 and deleted = 0")
+ Integer promoteToSharedPool(@Param("id") Integer id);
+
+ /**
+ * 銆屾媺鍏ャ�嶅叡浜睜鎮h�咃細鎶婃睜涓�屽噯澶囦腑(20) 鏈粦瀹氥�嶇殑琛岀粦瀹氬埌鏈伐浣嶏紙鐘舵�佷粛涓� 20锛夈��
+ * <p>{@code bed_no 涓虹┖} 鏄苟鍙戜繚鎶わ細姹犱腑鍚屼竴琛屽彧浼氳涓�涓瘖瀹ゆ媺璧般��
+ */
+ @Update("update lihu.queue set room_id = #{roomId}, room_name = #{roomName}, bed_no = #{bedNo} " +
+ " where id = #{id} and status = 20 and (bed_no is null or trim(bed_no) = '') and deleted = 0")
+ Integer bindSharedPoolItem(@Param("id") Integer id, @Param("roomId") Long roomId,
+ @Param("roomName") String roomName, @Param("bedNo") String bedNo);
+
+ /**
+ * 鍙彿锛氭妸鍏变韩姹�(20)/鍏变韩鎺掗槦涓�(10)鐨勬偅鑰呮敼涓恒�屽氨璇婁腑(30)銆嶅苟缁戝畾鍒板彨鍙疯瘖瀹ゃ��
+ * <p>{@code and status = #{curStatus}} 淇濊瘉涓や釜璇婂鍚屾椂鍙悓涓�浜烘椂鍙湁涓�涓垚鍔熴��
+ */
+ @Update("update lihu.queue set status = 30, room_id = #{roomId}, room_name = #{roomName}, bed_no = #{bedNo} " +
+ " where id = #{id} and status = #{curStatus} and deleted = 0")
+ Integer callSharedItem(@Param("id") Integer id, @Param("roomId") Long roomId,
+ @Param("roomName") String roomName, @Param("bedNo") String bedNo,
+ @Param("curStatus") Integer curStatus);
+
+ /**
+ * 闂瘖/璺ㄥぉ鏀跺熬锛氭妸鍏变韩姹犻噷鏈粦瀹氱殑銆屽噯澶囦腑(20)銆嶉��鍥炪�屾帓闃熶腑(10)銆嶃��
+ */
+ @Update("update lihu.queue set status = 10, room_id = 0, room_name = '', bed_no = null " +
+ " where status = 20 and (bed_no is null or trim(bed_no) = '') and deleted = 0")
+ Integer releaseSharedPoolToWaiting();
+
+ /**
+ * 鍏变韩椤圭洰銆岃繃鍙�(5)銆嶅彫鍥烇細**鍥炲叡浜睜**锛堟竻绌鸿瘖瀹�/宸ヤ綅锛岀疆涓烘帓闃熶腑(10)锛夛紝
+ * 闅忓悗鐢辨睜濉厖鍣ㄦ寜瀹归噺鎻愬崌涓哄噯澶囦腑锛屼换涓�璇婂閮藉彲鍙��
+ */
+ @Update("update lihu.queue set status = #{newStatus}, passed = 1, room_id = 0, room_name = '', bed_no = null " +
+ " where room_id = #{roomId} and bed_no = #{bedNo} and status = #{curStatus} " +
+ " and pat_id = #{patId} and book_check_type = #{checkType} and deleted = 0")
+ Integer recallPassedPatientToPool(@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) 鈫� 鎺掗槦涓�(10)锛屽苟娓呯┖璇婂/宸ヤ綅锛堝洖鍏变韩姹狅級銆�
+ */
+ @Update("update lihu.queue set status = 10, room_id = 0, room_name = '', bed_no = null " +
+ " where id = #{id} and status = 30 and deleted = 0")
+ Integer undoCallToSharedPool(@Param("id") Integer id);
+
+ /**
+ * 鍏变韩椤圭洰銆屾挙閿�瀹屾垚銆嶏細宸插氨璇�(40) 鈫� 鎺掗槦涓�(10)锛屽苟娓呯┖璇婂/宸ヤ綅锛堝洖鍏变韩姹狅級銆�
+ */
+ @Update("update lihu.queue set status = 10, passed = 0, room_id = 0, room_name = '', bed_no = null " +
+ " where room_id = #{roomId} and bed_no = #{bedNo} and status = 40 " +
+ " and pat_id = #{patId} and book_check_type = #{checkType} " +
+ " and TO_DAYS(book_date) = TO_DAYS(NOW())")
+ Integer undoFinishToSharedPool(@Param("roomId") Long roomId, @Param("bedNo") String bedNo,
+ @Param("patId") String patId, @Param("checkType") Integer checkType);
}
--
Gitblit v1.9.3