From 192eba815f89c11f74361d62b4d083d88673f55f Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 13 十一月 2026 11:30:26 +0800
Subject: [PATCH] 报错处理

---
 ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml |  304 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 182 insertions(+), 122 deletions(-)

diff --git a/ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml b/ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml
index 7a0dc7d..97e03fe 100644
--- a/ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml
+++ b/ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml
@@ -163,6 +163,140 @@
         from pat_med_inhosp
     </sql>
 
+    <sql id="selectPatMedInhospListFromWhere">
+        pat_med_inhosp b
+        JOIN
+        pat_archive a ON a.id = b.patid
+        where 1=1
+        <!--
+          del_flag 蹇呴』鐢ㄥ瓧绗︿覆甯搁噺姣旇緝锛氬畠鍙栧�兼槸 '0'/'1'锛坈har 鍒楋級銆�
+          鍐欐垚 del_flag = 0 鏃� MySQL 浼氭妸銆愬垪銆戞寜 DOUBLE 闅愬紡杞崲锛岃鏉′欢灏卞彧鏄繃婊ゃ��
+          涓嶈兘鐢ㄦ潵瀹氫綅绱㈠紩锛涜�� b.del_flag 姝f槸 idx_inhosp_optimize / idx_pmi_del_org_end
+          鐨勯鍒� 鈥斺�� 鏁板瓧鍐欐硶绛変簬鎶婄储寮曢鍒楃櫧缁欍��
+          鍚屼竴缁撹瑙� sql/sltdMydTotalByDimension_index_20260924.sql 绗� 117-134 琛屻��
+          锛堝垪鏄� int 鏃跺啓 '0' 涔熷畨鍏細杞崲鍙戠敓鍦ㄥ父閲忎晶锛岀储寮曠収鏍峰彲鐢ㄣ�傦級
+        -->
+        AND a.del_flag = '0'
+        AND b.del_flag = '0'
+        AND a.idcardno IS NOT NULL
+        <if test="inhospid != null">and b.inhospid = #{inhospid}</if>
+        <!-- 鏃堕棿鑼冨洿淇濇寔鈥滄寜鏃ユ湡銆佺粨鏉熸棩鍚綋澶┾�濈殑璇箟锛涘垪淇濇寔瑁稿垪锛岄伩鍏� date_format 瀵艰嚧绱㈠紩澶辨晥 -->
+        <if test="startOutHospTime != null ">and b.endtime &gt;= DATE(#{startOutHospTime})</if>
+        <if test="endOutHospTime != null ">and b.endtime &lt; DATE_ADD(DATE(#{endOutHospTime}), INTERVAL 1 DAY)</if>
+        <if test="startInHospTime != null ">and b.starttime &gt;= DATE(#{startInHospTime})</if>
+        <if test="endInHospTime != null ">and b.starttime &lt; DATE_ADD(DATE(#{endInHospTime}), INTERVAL 1 DAY)</if>
+        <if test="hospitalname != null  and hospitalname != ''">and hospitalname like concat('%', #{hospitalname},
+            '%')
+        </if>
+        <if test="patname != null  and patname != ''">and patname like concat('%', #{patname}, '%')</if>
+        <if test="hospitaldistrictname != null  and hospitaldistrictname != ''">and hospitaldistrictname like
+            concat('%', #{hospitaldistrictname}, '%')
+        </if>
+        <if test="endtime != null ">and b.endtime = #{endtime}</if>
+        <if test="bedNo != null ">and b.bed_no = #{bedNo}</if>
+        <if test="inhospMydFlag != null ">and b.inhosp_myd_flag = #{inhospMydFlag}</if>
+        <if test="managementDoctor != null ">and b.management_doctor = #{managementDoctor}</if>
+        <if test="managementDoctorCode != null ">and b.management_doctor_code = #{managementDoctorCode}</if>
+        <if test="inhospno != null ">and b.inhospno = #{inhospno}</if>
+        <if test="fuflag != null ">and b.fuflag = #{fuflag}</if>
+        <if test="orgid != null ">and b.orgid = #{orgid}</if>
+        <if test="campusid != null ">and b.campusid = #{campusid}</if>
+        <if test="serialnum != null ">and b.serialnum = #{serialnum}</if>
+        <if test="patno != null ">and b.patno = #{patno}</if>
+        <if test="nurseId != null ">and b.nurse_id = #{nurseId}</if>
+        <if test="nurseName != null and nurseName != ''">and b.nurse_name = #{nurseName}</if>
+        <if test="deptcheckFlag != null ">and b.deptcheck_flag = #{deptcheckFlag}</if>
+        <if test="scheduleCheckFlag != null ">and b.schedulecheck_flag = #{scheduleCheckFlag}</if>
+        <if test="wardcheckFlag != null ">and b.wardcheck_flag = #{wardcheckFlag}</if>
+        <if test="inDeptcheckFlag != null ">and b.in_deptcheck_flag = #{inDeptcheckFlag}</if>
+        <if test="inWardcheckFlag != null ">and b.in_wardcheck_flag = #{inWardcheckFlag}</if>
+        <if test="diagcheckFlag != null ">and b.diagcheck_flag = #{diagcheckFlag}</if>
+        <if test="encounterSourceId != null ">and b.encounter_source_id = #{encounterSourceId}</if>
+        <if test="importanceFlagCode != null ">and b.importance_flag_code = #{importanceFlagCode}</if>
+        <if test="emergencyLevelCode != null ">and b.emergency_level_code = #{emergencyLevelCode}</if>
+        <!--
+          鍦ㄩ櫌锛坈ry=0锛夛細涓や釜鏉′欢閮借銆�
+          鈶� b.endtime is null 鈥斺�� 鍘� XML 灏辨湁锛屼繚鎸佷笉鍔紱
+          鈶� b.inhospstate = '0' 鈥斺�� 杩佸嚭鍓嶇敱 PatMedInhospServiceImpl 琛ワ紙cry=0 鏃�
+             setInhospstate("0")锛夛紝杩佸埌鏈ā鍧楀悗杩欐潯閾剧洿杩� Mapper锛岃繖鍙ュ氨涓簡銆�
+          涓轰粈涔堝繀椤昏ˉ鍥炴潵锛堜笉鍙槸"鎭㈠鍘熻涓�"锛屼篃鏄�ц兘闂锛夛細
+            路 绱㈠紩 idx_inhosp_optimize / idx_pmi_del_org_state_end 鐨勫墠涓夊垪鏄�
+              (del_flag, orgid, inhospstate)锛屽彧鏈変笁涓瓑鍊兼潯浠堕綈浜嗘墠鑳界簿纭畾浣�"鍦ㄩ櫌"閭e嚑鍗冭锛�
+              灏戜簡 inhospstate锛屽氨鍙兘鐢ㄥ埌 (del_flag, orgid) 鍓嶇紑 = 璇ユ満鏋勩�愬叏閮ㄥ巻鍙蹭綇闄㈣褰曘�戯紝
+              鍐嶅姞涓婂悗闈㈢殑 ORDER BY/GROUP BY锛屽疄娴嬪氨鏄� 4~5 绉掔殑鏉ユ簮銆�
+            路 cry=1/2/3 鏈潵灏辨槸鎸� inhospstate 鍒ょ殑锛屽彧鏈� cry=0 鐢� endtime 鍒� 鈥斺�� 琛ラ綈鍚庢墠瀵圭О銆�
+          涓轰粈涔堝姞 inhospstate == null 杩欎釜鍓嶆彁锛氳皟鐢ㄦ柟鑻ュ凡鏄惧紡鎸囧畾 inhospstate锛屽氨鍒拰瀹冩墦鏋�
+          锛堝惁鍒� cry=0 + inhospstate='2' 浼氬彉鎴�"鍜岃嚜韬煕鐩�"鐨勭┖缁撴灉锛夈��
+        -->
+        <if test="cry != null and cry == 0 ">and b.endtime is null</if>
+        <if test="cry != null and cry == 0 and inhospstate == null ">and b.inhospstate = '0'</if>
+        <!-- 鍚� del_flag锛歩nhospstate 鏄彇鍊艰寖鍥� '0'~'3' 鐨勫瓧绗﹀垪锛屽繀椤荤敤瀛楃涓插父閲忥紝
+             鍚﹀垯绱㈠紩涓婄敤涓嶅埌杩欎釜绛夊�兼潯浠讹紙鍑洪櫌/杞/棰勫叆闄� 涓変釜瑙嗗浘璧扮殑灏辨槸杩欎笁琛岋級 -->
+        <if test="cry != null and cry == 1 ">and b.inhospstate='1'</if>
+        <if test="cry != null and cry == 2 ">and b.inhospstate='2'</if>
+        <if test="cry != null and cry == 3 ">and b.inhospstate='3'</if>
+        <if test="inhospstate != null ">and b.inhospstate = #{inhospstate}</if>
+        <if test="schemestatus != null ">and b.schemestatus = #{schemestatus}</if>
+        <if test="outWayId != null ">and b.out_way_id = #{outWayId}</if>
+        <if test="outWayName != null ">and b.out_way_name = #{outWayName}</if>
+        <if test="leaveldeptcode != null ">and b.leaveldeptcode = #{leaveldeptcode}</if>
+        <if test="leavediagname != null  and leavediagname != ''">and b.leavediagname like concat('%',
+            #{leavediagname}, '%')
+        </if>
+        <if test="drname != null  and drname != ''">and b.drname like concat('%', #{drname}, '%')</if>
+        <if test="leaveldeptname != null  and leaveldeptname != ''">and b.leaveldeptname like concat('%',
+            #{leaveldeptname}, '%')
+        </if>
+        <if test="deptname != null  and deptname != ''">and b.deptname like concat('%',
+            #{deptname}, '%')
+        </if>
+        <if test="patid != null  and patid != ''">and a.id =#{patid}
+        </if>
+        <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
+            b.leavehospitaldistrictname like concat('%', #{leavehospitaldistrictname}, '%')
+        </if>
+
+        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
+            AND b.leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
+                     close=")">
+                #{leavehospitaldistrictcode}
+            </foreach>
+        </if>
+
+        <if test="hospitaldistrictcodeList != null and hospitaldistrictcodeList.size()>0">
+            AND b.hospitaldistrictcode IN
+            <foreach collection="hospitaldistrictcodeList" item="hospitaldistrictcode" open="(" separator=","
+                     close=")">
+                #{hospitaldistrictcode}
+            </foreach>
+        </if>
+        <if test="leaveldeptcodes != null and leaveldeptcodes.size()>0">
+            AND b.leaveldeptcode IN
+            <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
+                     close=")">
+                #{leaveldeptcode}
+            </foreach>
+        </if>
+        <if test="deptcodeList != null and deptcodeList.size()>0">
+            AND b.deptcode IN
+            <foreach collection="deptcodeList" item="deptcode" open="(" separator=","
+                     close=")">
+                #{deptcode}
+            </foreach>
+        </if>
+        <if test="icd10codeList != null and icd10codeList.size()>0">
+            AND b.leaveicd10code IN
+            <foreach collection="icd10codeList" item="icd10code" open="(" separator=","
+                     close=")">
+                #{icd10code}
+            </foreach>
+        </if>
+        <if test="medicalCode != null and medicalCode != ''">and b.medical_code = #{medicalCode}</if>
+        <if test="medicalName != null and medicalName != ''">and b.medical_name = #{medicalName}</if>
+        <if test="medicalCompany != null and medicalCompany != ''">and b.medical_company = #{medicalCompany}</if>
+    </sql>
+
     <select id="selectPatMedInhospList" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp" resultMap="PatMedInhospResult">
         select a.age AS age,
         a.telcode as telcode,
@@ -239,127 +373,14 @@
         b.medical_company,
         a.idcardno
         FROM
-        pat_med_inhosp b
-        JOIN
-        pat_archive a ON a.id = b.patid
-        where 1=1
-        AND a.del_flag = 0
-        AND b.del_flag = 0
-        AND a.idcardno IS NOT NULL
-        <if test="inhospid != null">and b.inhospid = #{inhospid}</if>
-        <if test="startOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &gt;=
-            date_format(#{startOutHospTime},'%y%m%d')
-        </if>
-        <if test="endOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &lt;=
-            date_format(#{endOutHospTime},'%y%m%d')
-        </if>
-        <if test="startInHospTime != null ">and date_format(b.starttime,'%y%m%d') &gt;=
-            date_format(#{startInHospTime},'%y%m%d')
-        </if>
-        <if test="endInHospTime != null ">and date_format(b.starttime,'%y%m%d') &lt;=
-            date_format(#{endInHospTime},'%y%m%d')
-        </if>
-        <if test="hospitalname != null  and hospitalname != ''">and hospitalname like concat('%', #{hospitalname},
-            '%')
-        </if>
-        <if test="patname != null  and patname != ''">and patname like concat('%', #{patname}, '%')</if>
-        <if test="hospitaldistrictname != null  and hospitaldistrictname != ''">and hospitaldistrictname like
-            concat('%', #{hospitaldistrictname}, '%')
-        </if>
-        <if test="endtime != null ">and b.endtime = #{endtime}</if>
-        <if test="bedNo != null ">and b.bed_no = #{bedNo}</if>
-        <if test="inhospMydFlag != null ">and b.inhosp_myd_flag = #{inhospMydFlag}</if>
-        <if test="managementDoctor != null ">and b.management_doctor = #{managementDoctor}</if>
-        <if test="managementDoctorCode != null ">and b.management_doctor_code = #{managementDoctorCode}</if>
-        <if test="inhospno != null ">and b.inhospno = #{inhospno}</if>
-        <if test="fuflag != null ">and b.fuflag = #{fuflag}</if>
-        <if test="orgid != null ">and b.orgid = #{orgid}</if>
-        <if test="campusid != null ">and b.campusid = #{campusid}</if>
-        <if test="serialnum != null ">and b.serialnum = #{serialnum}</if>
-        <if test="endtime != null ">and b.endtime = #{endtime}</if>
-        <if test="patno != null ">and b.patno = #{patno}</if>
-        <if test="nurseId != null ">and b.nurse_id = #{nurseId}</if>
-        <if test="nurseName != null and nurseName != ''">and b.nurse_name = #{nurseName}</if>
-        <if test="deptcheckFlag != null ">and b.deptcheck_flag = #{deptcheckFlag}</if>
-        <if test="scheduleCheckFlag != null ">and b.schedulecheck_flag = #{scheduleCheckFlag}</if>
-        <if test="wardcheckFlag != null ">and b.wardcheck_flag = #{wardcheckFlag}</if>
-        <if test="inDeptcheckFlag != null ">and b.in_deptcheck_flag = #{inDeptcheckFlag}</if>
-        <if test="inWardcheckFlag != null ">and b.in_wardcheck_flag = #{inWardcheckFlag}</if>
-        <if test="diagcheckFlag != null ">and b.diagcheck_flag = #{diagcheckFlag}</if>
-        <if test="encounterSourceId != null ">and b.encounter_source_id = #{encounterSourceId}</if>
-        <if test="importanceFlagCode != null ">and b.importance_flag_code = #{importanceFlagCode}</if>
-        <if test="emergencyLevelCode != null ">and b.emergency_level_code = #{emergencyLevelCode}</if>
-        <if test="cry != null and cry == 0 ">and b.endtime is null</if>
-        <if test="cry != null and cry == 1 ">and b.inhospstate=1</if>
-        <if test="cry != null and cry == 2 ">and b.inhospstate=2</if>
-        <if test="cry != null and cry == 3 ">and b.inhospstate=3</if>
-        <if test="inhospstate != null ">and b.inhospstate = #{inhospstate}</if>
-        <if test="schemestatus != null ">and b.schemestatus = #{schemestatus}</if>
-        <if test="outWayId != null ">and b.out_way_id = #{outWayId}</if>
-        <if test="outWayName != null ">and b.out_way_name = #{outWayName}</if>
-        <if test="leaveldeptcode != null ">and b.leaveldeptcode = #{leaveldeptcode}</if>
-        <if test="leavediagname != null  and leavediagname != ''">and b.leavediagname like concat('%',
-            #{leavediagname}, '%')
-        </if>
-        <if test="drname != null  and drname != ''">and b.drname like concat('%', #{drname}, '%')</if>
-        <if test="leaveldeptname != null  and leaveldeptname != ''">and b.leaveldeptname like concat('%',
-            #{leaveldeptname}, '%')
-        </if>
-        <if test="deptname != null  and deptname != ''">and b.deptname like concat('%',
-            #{deptname}, '%')
-        </if>
-        <if test="patid != null  and patid != ''">and a.id =#{patid}
-        </if>
-        <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
-            b.leavehospitaldistrictname like concat('%', #{leavehospitaldistrictname}, '%')
-        </if>
-
-        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
-            AND b.leavehospitaldistrictcode IN
-            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
-                     close=")">
-                #{leavehospitaldistrictcode}
-            </foreach>
-        </if>
-
-        <if test="hospitaldistrictcodeList != null and hospitaldistrictcodeList.size()>0">
-            AND b.hospitaldistrictcode IN
-            <foreach collection="hospitaldistrictcodeList" item="hospitaldistrictcode" open="(" separator=","
-                     close=")">
-                #{hospitaldistrictcode}
-            </foreach>
-        </if>
-        <if test="leaveldeptcodes != null and leaveldeptcodes.size()>0">
-            AND b.leaveldeptcode IN
-            <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
-                     close=")">
-                #{leaveldeptcode}
-            </foreach>
-        </if>
-        <if test="deptcodeList != null and deptcodeList.size()>0">
-            AND b.deptcode IN
-            <foreach collection="deptcodeList" item="deptcode" open="(" separator=","
-                     close=")">
-                #{deptcode}
-            </foreach>
-        </if>
-        <if test="icd10codeList != null and icd10codeList.size()>0">
-            AND b.leaveicd10code IN
-            <foreach collection="icd10codeList" item="icd10code" open="(" separator=","
-                     close=")">
-                #{icd10code}
-            </foreach>
-        </if>
-        <if test="medicalCode != null and medicalCode != ''">and b.medical_code = #{medicalCode}</if>
-        <if test="medicalName != null and medicalName != ''">and b.medical_name = #{medicalName}</if>
-        <if test="medicalCompany != null and medicalCompany != ''">and b.medical_company = #{medicalCompany}</if>
-        GROUP BY
-        b.inhospid,
-        a.age,
-        a.age_unit,
-        a.telcode,
-        a.id,
-        a.sex
+        <include refid="selectPatMedInhospListFromWhere"/>
+        <!--
+          鎬ц兘璇存槑锛歱at_med_inhosp.inhospid 鍞竴锛宲at_archive.id 鏄富閿紝a.id = b.patid 涓�瀵逛竴锛�
+          鍘� GROUP BY 鏄浣欑殑锛屼笖浼氳 MySQL 鍏堢墿鍖� 60 鍒椾复鏃惰〃鍐嶆帓搴忥紝LIMIT 鏃犳硶鎻愬墠缁撴潫銆�
+          涓婄嚎鍓嶈纭浠ヤ笅涓ゆ潯鍧囨棤閲嶅锛�
+            SELECT inhospid, COUNT(*) c FROM pat_med_inhosp GROUP BY inhospid HAVING c > 1 LIMIT 10;
+            SELECT id, COUNT(*) c FROM pat_archive GROUP BY id HAVING c > 1 LIMIT 10;
+        -->
         <if test="cry != null and cry==1">
             order by b.endtime desc
         </if>
@@ -403,6 +424,20 @@
                 </otherwise>
             </choose>
         </if>
+    </select>
+
+    <!--
+      鍒嗛〉鎬绘暟锛圥ageHelper 鎵嬪啓 count锛宨d = 涓绘煡璇� id + _COUNT 浼氳鑷姩閲囩敤锛夈��
+
+      涓绘煡璇㈠凡鍘绘帀 GROUP BY锛歱at_med_inhosp.inhospid 鍞竴銆乸at_archive.id 鏄富閿紝
+      a.id = b.patid 涓�瀵逛竴锛屽洜姝� join 缁撴灉琛屾暟灏辨槸涓氬姟璁板綍鏁般��
+      杩欓噷鐩存帴瀵圭浉鍚岀殑 FROM/WHERE 鍋� COUNT锛屼笉鍐嶅寘涓�灞傚垎缁勫瓙鏌ヨ銆�
+    -->
+    <select id="selectPatMedInhospList_COUNT" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp"
+            resultType="java.lang.Long">
+        select count(1)
+        FROM
+        <include refid="selectPatMedInhospListFromWhere"/>
     </select>
 
     <select id="selectPatMedInhospListBySerialnum" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp"
@@ -501,6 +536,31 @@
             and b.serialnum = #{serialnum}
         </if>
         order by b.inhospid desc
+    </select>
+
+    <!--
+      鍦ㄩ櫌淇℃伅鍒锋柊鐨勫彇鏁帮細鍙煡 pat_med_inhosp 鑷韩銆佸彧鍙栧埛鏂拌鐢ㄧ殑鍒椼��
+      鍒绘剰涓嶅鐢� selectPatMedInhospList 鈥斺�� 閭d釜鏌ヨ join 浜� pat_archive 涓旇姹�
+      a.idcardno IS NOT NULL锛屼細璁�"璇佷欢鍙疯繕娌¤ˉ涓婄殑鏂板叆闄㈡偅鑰�"闈欓粯婕忓埛鏂般��
+      WHERE (del_flag, orgid, inhospstate) 鍛戒腑 idx_inhosp_optimize 鐨勫墠缂�銆�
+    -->
+    <select id="selectInhospRefreshCandidates" resultMap="PatMedInhospResult">
+        select inhospid,
+               serialnum,
+               patname,
+               orgid,
+               campusid,
+               deptcode,
+               deptname,
+               hospitaldistrictcode,
+               hospitaldistrictname,
+               hospitaldistrictid,
+               bed_no
+        from pat_med_inhosp
+        where inhospstate = '0'
+          and del_flag = '0'
+          and orgid = #{orgid}
+        order by inhospid asc
     </select>
 
     <select id="selectPatMedInhospListByCondition" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhospVO"
@@ -1157,7 +1217,7 @@
             AND visit_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
         </if>
         <if test="deptcodeList != null and deptcodeList.size() > 0">
-            AND deptcode IN
+            AND leaveldeptcode IN
             <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                 #{deptcode}
             </foreach>

--
Gitblit v1.9.3