From cc479e6a056785103996cc7ea67dbd5faa3e800e Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 19 十月 2026 18:07:22 +0800
Subject: [PATCH] 数据采集模块

---
 ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml |  304 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 190 insertions(+), 114 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..fd25c50 100644
--- a/ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml
+++ b/ruoyi-inhospvisit/src/main/resources/mapper/inhospvisit/PatMedInhospMapper.xml
@@ -163,6 +163,148 @@
         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>
+        <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>
+        <!--
+          鍦ㄩ櫌锛坈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,120 +381,7 @@
         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>
+        <include refid="selectPatMedInhospListFromWhere"/>
         GROUP BY
         b.inhospid,
         a.age,
@@ -403,6 +432,28 @@
                 </otherwise>
             </choose>
         </if>
+    </select>
+
+    <!--
+      鍒嗛〉鎬绘暟锛圥ageHelper 鎵嬪啓 count锛宨d = 涓绘煡璇� id + _COUNT 浼氳鑷姩閲囩敤锛夈��
+
+      鍘熺姸鎬侊細涓绘煡璇㈠甫 GROUP BY锛宲agehelper 鐨� CountSqlParser#isSimpleCount 鍒ゅ畾涓�
+      "涓嶈兘绠�鍖�"锛屼簬鏄�绘暟鍙樻垚 SELECT count(0) FROM ( 涓婇潰閭f潯 60 鍒楁煡璇� ) tmp_count 鈥�
+      绛変簬姣忔缈婚〉鎶婃暣鏉℃煡璇㈠啀璺戜竴閬嶃��
+
+      杩欓噷淇濇寔銆愬畬鍏ㄧ浉鍚岀殑 FROM/WHERE/GROUP BY銆戯紙鍏辩敤 selectPatMedInhospListFromWhere 鐗囨锛�
+      鏉′欢涓嶄細婕傦級锛屼絾瀛愭煡璇㈠彧 select 1锛屼笉鐗╁寲 60 鍒楋紝涔熶笉甯� order by銆�
+      鍥犱负鍒嗙粍閿寘鍚� a.id 鑰岃繖涓� join 鏄竴瀵逛竴锛屽垎缁勬暟 == join 缁撴灉琛屾暟锛屾�绘暟涓庡師鏉ヤ竴鑷淬��
+    -->
+    <select id="selectPatMedInhospList_COUNT" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp"
+            resultType="java.lang.Long">
+        select count(1)
+        from (
+            select 1
+            FROM
+            <include refid="selectPatMedInhospListFromWhere"/>
+            group by b.inhospid, a.age, a.age_unit, a.telcode, a.id, a.sex
+        ) t
     </select>
 
     <select id="selectPatMedInhospListBySerialnum" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp"
@@ -503,6 +554,31 @@
         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"
             resultMap="PatMedInhospResult">
         select CONCAT( a.age, a.age_unit ) AS age,

--
Gitblit v1.9.3