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/appointment/AppointmentMapper.java |   80 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 75 insertions(+), 5 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/appointment/AppointmentMapper.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/appointment/AppointmentMapper.java
index d61a930..8779ea3 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/appointment/AppointmentMapper.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/appointment/AppointmentMapper.java
@@ -25,7 +25,9 @@
     default PageResult<AppointmentDO> selectPage(AppointmentPageReqVO reqVO) {
         LambdaQueryWrapperX<AppointmentDO> wrapper = (LambdaQueryWrapperX<AppointmentDO>) new LambdaQueryWrapperX<AppointmentDO>().eqIfPresent(AppointmentDO::getPatId, reqVO.getPatId()).likeIfPresent(AppointmentDO::getPatName, reqVO.getPatName()).eqIfPresent(AppointmentDO::getPatGender, reqVO.getPatGender()).eqIfPresent(AppointmentDO::getPatBirthday, reqVO.getPatBirthday()).eqIfPresent(AppointmentDO::getPatMobile, reqVO.getPatMobile()).eqIfPresent(AppointmentDO::getPatPhone, reqVO.getPatPhone()).eqIfPresent(AppointmentDO::getPatIdentityId, reqVO.getPatIdentityId()).eqIfPresent(AppointmentDO::getPatAddr, reqVO.getPatAddr()).eqIfPresent(AppointmentDO::getPatDeptCode, reqVO.getPatDeptCode()).eqIfPresent(AppointmentDO::getPatDeptDesc, reqVO.getPatDeptDesc()).eqIfPresent(AppointmentDO::getPatWardCode, reqVO.getPatWardCode()).eqIfPresent(AppointmentDO::getPatWardDesc, reqVO.getPatWardDesc()).eqIfPresent(AppointmentDO::getBookDate, reqVO.getBookDate()).eqIfPresent(AppointmentDO::getBookTimeslot, reqVO.getBookTimeslot()).eqIfPresent(AppointmentDO::getBookCheckType, reqVO.getBookCheckType()).eqIfPresent(AppointmentDO::getBookSrc, reqVO.getBookSrc()).eqIfPresent(AppointmentDO::getPaid, reqVO.getPaid()).eqIfPresent(AppointmentDO::getApplyNo, reqVO.getApplyNo()).eqIfPresent(AppointmentDO::getEpisodeId, reqVO.getEpisodeId()).inIfPresent(AppointmentDO::getStatus, reqVO.getStatus())
                 // 鉁� 鏂板锛歝reateTime 鍖洪棿鏌ヨ
-                .betweenIfPresent(AppointmentDO::getCreateTime, reqVO.getCreateTimeStart(), reqVO.getCreateTimeEnd()).betweenIfPresent(AppointmentDO::getRegisterDate, reqVO.getRegisterDateStart(), reqVO.getRegisterDateEnd());
+                .betweenIfPresent(AppointmentDO::getCreateTime, reqVO.getCreateTimeStart(), reqVO.getCreateTimeEnd()).betweenIfPresent(AppointmentDO::getRegisterDate, reqVO.getRegisterDateStart(), reqVO.getRegisterDateEnd())
+                // 銆愭湰闇�姹傘�戦绾︽棩鏈�**鏃堕棿娈�**鏌ヨ锛堥绾﹁褰曢〉鐨勩�岄绾︽棩鏈熴�嶆棩鏈熻寖鍥达級
+                .betweenIfPresent(AppointmentDO::getBookDate, reqVO.getBookDateStart(), reqVO.getBookDateEnd());
         // 鍔ㄦ�佹帓搴�
         if (reqVO.getOrderCreateTime() != null) {
             wrapper.orderByDesc(AppointmentDO::getCreateTime);
@@ -36,21 +38,75 @@
     }
 
 
-    @Select("select * from lihu.appointment where pat_id = #{patId} and to_days(book_date) = to_days(Now())")
+    @Select("select * from lihu.appointment where deleted = 0 and pat_id = #{patId} and to_days(book_date) = to_days(Now())")
     List<AppointmentDO> getCurrentPatId(String patId);
 
-    @Select("select * from lihu.appointment where (apply_no = #{code} or episode_id= #{code} or hospital_no =#{code} or pat_identity_id=#{code}) and book_date >=  DATE_ADD(CURDATE(), INTERVAL -5 DAY)    AND book_date <=  DATE_ADD(CURDATE(), INTERVAL 15 DAY)")
+    /**
+     * 銆愭湰闇�姹傘�戞寜銆屾偅鑰呯紪鍙� / 鐢宠鍗曞彿 / 灏辫瘖娴佹按鍙� / 浣忛櫌鍙� / 韬唤璇佸彿銆嶅尮閰嶉绾︼紙卤5/+15 澶╃獥鍙o級銆�
+     *
+     * <h3>涓轰粈涔堝姞 {@code pat_id} 涓� {@code deleted = 0}</h3>
+     * <ul>
+     *   <li><b>pat_id</b>锛氭墜鍔ㄦ柊寤虹殑棰勭害锛坽@code /ecg/appointment/create}锛夊彧鏈� pat_id锛�
+     *       {@code apply_no} / {@code episode_id} / {@code hospital_no} / {@code pat_identity_id} 鍏ㄤ负绌猴紝
+     *       绛惧埌椤垫寜鎮h�呯紪鍙锋煡璇㈡椂姘歌繙鏌ヤ笉鍒� 鈫� 鎻愮ず銆岃鍏堥绾︺�嶁啋 鏃犳硶绛惧埌锛�</li>
+     *   <li><b>deleted = 0</b>锛氬師 SQL 鏄8鏌ヨ锛岄�昏緫鍒犻櫎鐨勬棫琛屼篃浼氳鎹炲嚭鏉ワ紝
+     *       鍐嶇粡 {@code queryAndCreateAppointmentByPatId} 鐨�"涓嶅瓨鍦ㄥ垯鎻掑叆"閫昏緫鍙兘鎶婂凡鍒犵殑鍗曞啀鎻掑洖鏉ャ��</li>
+     * </ul>
+     */
+    @Select("select * from lihu.appointment where deleted = 0 "
+            + " and (apply_no = #{code} or episode_id = #{code} or hospital_no = #{code} "
+            + "      or pat_identity_id = #{code} or pat_id = #{code}) "
+            + " and book_date >= DATE_ADD(CURDATE(), INTERVAL -5 DAY) "
+            + " and book_date <= DATE_ADD(CURDATE(), INTERVAL 15 DAY) "
+            + " order by book_date, id")
     List<AppointmentDO> getCurrentCode(String code);
 
     @Select("select * from lihu.appointment where pat_id = #{patId} and book_check_type = #{checkType} and to_days(book_date) = to_days(Now()) limit 1")
     AppointmentDO getByPatAndCheckTypeAndBookDate(@Param("patId") String patId, @Param("checkType") Integer checkType);
 
+    /**
+     * 銆愭湰闇�姹傦細绱ф�ユ偅鑰呬笉鎺掗槦鐩存帴妫�鏌ャ�戞寜銆岀敵璇峰崟鍙� / 灏辫瘖鍙� / 鎮h�呯紪鍙枫�嶆煡杩戜竴涓湀鐨勯绾﹁褰曘��
+     *
+     * <p>绐楀彛 = [浠婂ぉ-30 澶�, 浠婂ぉ+30 澶锛涚粨鏋�**鎸夐绾︽椂闂村�掑簭**锛堟渶杩戠殑鎺掑墠闈級锛屼究浜庡尰鐢熼�夋嫨銆�
+     * 妫�鏌ラ」鐩繃婊わ紙鏈獥鍙e紑灞曠殑妫�鏌ラ」鐩級鐢� {@code checkTypeList} 浼犲叆锛岀┖/鏈紶琛ㄧず涓嶉檺鍒躲��
+     */
+    @Select("<script>" +
+            "select * from lihu.appointment where deleted = 0 " +
+            " and (apply_no = #{code} or episode_id = #{code} or pat_id = #{code}) " +
+            " and book_date &gt;= DATE_ADD(CURDATE(), INTERVAL -30 DAY) " +
+            " and book_date &lt;= DATE_ADD(CURDATE(), INTERVAL 30 DAY) " +
+            " <if test='checkTypeList != null and checkTypeList.size() > 0'> " +
+            "   and book_check_type in ( <foreach collection='checkTypeList' separator=',' item='ct'>#{ct}</foreach> ) " +
+            " </if> " +
+            " order by book_date desc, book_timeslot desc, id desc " +
+            "</script>")
+    List<AppointmentDO> getEmergencyCandidates(@Param("code") String code,
+                                               @Param("checkTypeList") List<Integer> checkTypeList);
+
     Integer updateStatusByApplyNo(@Param("applyNo") String applyNo, @Param("status") String status, @Param("registerDate") Date registerDate);
 
-    @Select("select * from lihu.appointment where episode_id = #{episodeId} and apply_no = #{applyNo} limit 1")
+    /**
+     * 鍙洿鏂扮姸鎬侊紙涓嶅姩鍏跺畠瀛楁锛夈��
+     *
+     * <p>鑳屾櫙锛氱姸鎬佹祦鍘熸潵鏄妸 {@code getByApplyNo} 鏌ュ嚭鏉ョ殑鏁磋瀵硅薄鍐� {@code updateById} 鍐欏洖锛�
+     * 灞炰簬銆岃-鏀�-鍐欍�嶃�傚苟鍙�/浜ら敊鏃朵細鎶婂埆鐨勫瓧娈碉紙濡� book_date / book_check_type锛夋寜鏃у揩鐓ц鐩栨帀锛�
+     * 瀹炴祴 2026-10-05 07:58 灏卞嚭鐜拌繃涓�绗旈绾︾殑 check_type 琚姸鎬佹祦瑕嗙洊銆�
+     * 鐘舵�佹祦鍙鏀圭姸鎬侊紝鍥犳鍗曠嫭鎻愪緵杩欎釜鍙敼 status 鐨勮鍙ャ��</p>
+     */
+    @Update("update lihu.appointment set status = #{status}, update_time = sysdate() where apply_no = #{applyNo} and deleted = 0")
+    Integer updateStatusOnlyByApplyNo(@Param("applyNo") String applyNo, @Param("status") String status);
+    /** 銆愭湰娆′慨澶嶃�戣ˉ {@code deleted = 0}锛氶�昏緫鍒犻櫎鐨勮涓嶅簲鍐嶈褰撲綔"宸插瓨鍦�"鑰岃烦杩囨彃鍏ャ�� */
+    @Select("select * from lihu.appointment where deleted = 0 and episode_id = #{episodeId} and apply_no = #{applyNo} limit 1")
     AppointmentDO getByEpisodeIdAndApplyNo(@Param("episodeId") String episodeId, @Param("applyNo") String applyNo);
 
-    @Select("select * from lihu.appointment where apply_no = #{applyNo} limit 1")
+    /**
+     * 鎸夌敵璇峰崟鍙峰彇鏈垹闄ょ殑璁板綍銆�
+     *
+     * <p>娉ㄦ剰锛氳繖閲屽繀椤诲甫 {@code deleted = 0}銆傚師瀹炵幇鏄8 select锛屼細鎶�**閫昏緫鍒犻櫎**鐨勬棫琛屼篃鎹炲嚭鏉ワ紝
+     * 閰嶅悎 {@code LIMIT 1} 鏃惰嫢鏃ц id 鏇村皬灏变細鍙栧埌宸插垹闄ょ殑閭f潯 鈥斺�� 杩欐槸"鍒犱簡鍙堣鏇存柊鍥炴潵"鐨勯殣鎮c��
+     * 鍙﹀鏈柟娉曢厤鍚堝敮涓�绱㈠紩 {@code uk_appointment_apply_no_active}锛堝彧绾︽潫鏈垹闄よ锛変娇鐢ㄣ��</p>
+     */
+    @Select("select * from lihu.appointment where apply_no = #{applyNo} and deleted = 0 limit 1")
     AppointmentDO getByApplyNo(@Param("applyNo") String applyNo);
 
     /**
@@ -65,5 +121,19 @@
             " </foreach> )" +
             "</script>")
     List<AppointmentDO> getByApplyNoList(@Param("applyNoList") List<String> applyNoList);
+
+    /**
+     * 鍙栬鎮h��**鏈�杩戜竴鏉�**鏈垹闄よ褰曪紝鐢ㄤ簬瀹归敊鏂板鏃剁户鎵挎偅鑰呭浐鏈夊睘鎬�
+     * 锛堢敓鏃�/鐢佃瘽/韬唤璇�/鍦板潃绛� 鈥斺�� S050401 鎶ユ枃鍙甫濮撳悕锛岃繖浜涘瓧娈垫姤鏂囬噷娌℃湁锛夈��
+     *
+     * <p>鎸� {@code create_time desc, id desc} 鎺掑簭锛屼繚璇佺粨鏋滅ǔ瀹氾紙鍚屼竴绉掑唴鎻掑叆鐨勫鏉′篃鑳藉畾搴忥級銆�
+     * 鍙户鎵�**鎮h�呭浐鏈夊睘鎬�**锛屼笉缁ф壙寮�鍗曞尰鐢�/寮�鍗曟椂闂寸瓑娴佹按灞炴�э紙閭e睘浜庢帹鏂紝鍙兘寮犲啝鏉庢埓锛夈��</p>
+     *
+     * @param patId 鎮h�呯紪鍙凤紙{@code appointment.pat_id}锛�
+     * @return 鏈�杩戜竴鏉¤褰曪紱鏃犺褰曟椂杩斿洖 {@code null}
+     */
+    @Select("select * from lihu.appointment where pat_id = #{patId} and deleted = 0 "
+            + "order by create_time desc, id desc limit 1")
+    AppointmentDO getLatestByPatId(@Param("patId") String patId);
 }
 

--
Gitblit v1.9.3