From d047a35e640a59e02a422d9a9a62c752c88b69b5 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 28 十月 2026 15:51:52 +0800
Subject: [PATCH] 【丽水】 同一 inhospid + taskid 已存在未删除的首次随访(upid 为空)时,不再插入,避免出现两条首次随访

---
 ruoyi-quartz/src/main/resources/mapper/quartz/CollectHISMapper.xml |  112 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 83 insertions(+), 29 deletions(-)

diff --git a/ruoyi-quartz/src/main/resources/mapper/quartz/CollectHISMapper.xml b/ruoyi-quartz/src/main/resources/mapper/quartz/CollectHISMapper.xml
index 4767c80..ab800a8 100644
--- a/ruoyi-quartz/src/main/resources/mapper/quartz/CollectHISMapper.xml
+++ b/ruoyi-quartz/src/main/resources/mapper/quartz/CollectHISMapper.xml
@@ -226,7 +226,7 @@
     <resultMap type="com.smartor.domain.PatMedOuthosp" id="PatMedOuthospResult">
         <result property="id" column="id"/>
         <result property="serialnum" column="serialnum"/>
-        <result property="patid" column="patid"/>
+        <result property="patidHis" column="patid"/>
         <result property="hospitalname" column="hospitalname"/>
         <result property="hospitalcode" column="hospitalcode"/>
         <result property="icd10code" column="icd10code"/>
@@ -338,7 +338,7 @@
 
     <resultMap type="com.smartor.domain.PatMedOperation" id="PatMedOperationResult">
         <result property="id" column="id"/>
-        <result property="patid" column="patid"/>
+        <result property="patidHis" column="patid_his"/>
         <result property="patcode" column="patcode"/>
         <result property="paname" column="paname"/>
         <result property="opreqid" column="opreqid"/>
@@ -395,6 +395,10 @@
         <result property="deptname" column="deptname"/>
         <result property="hospitaldistrictcode" column="hospitaldistrictcode"/>
         <result property="hospitaldistrictname" column="hospitaldistrictname"/>
+        <result property="leaveldeptcode" column="leaveldeptcode"/>
+        <result property="leaveldeptname" column="leaveldeptname"/>
+        <result property="leavehospitaldistrictcode" column="leavehospitaldistrictcode"/>
+        <result property="leavehospitaldistrictname" column="leavehospitaldistrictname"/>
         <result property="roomno" column="roomno"/>
         <result property="bedNo" column="bed_no"/>
         <result property="drcode" column="drcode"/>
@@ -484,27 +488,41 @@
     </select>
 
     <select id="yhyksxx" parameterType="com.ruoyi.common.core.domain.entity.SysUser" resultMap="SysUserDeptResult">
-        select user_id , user_code , dept_type ,dept_code,dept_name,deptparent,del_flag,orgid
-        FROM healthy_user_dept
+        select ud.user_id , ud.user_code , ud.dept_type ,ud.dept_code,ud.dept_name,ud.deptparent,ud.del_flag,ud.orgid
+        FROM healthy_user_dept ud
         where 1=1
-        and user_id != 'admin'
-        and dept_type = '1'
+        and ud.user_id != 'admin'
+        and ud.dept_type = '1'
         <if test="orgid != null and orgid != ''">
-            AND orgid = #{orgid}
+            AND ud.orgid = #{orgid}
         </if>
-        <if test="hisUserId != null ">and user_id = #{hisUserId}</if>
+        <if test="hisUserId != null ">and ud.user_id = #{hisUserId}</if>
+        <if test="campusid != null and campusid != ''">
+            AND EXISTS (
+                SELECT 1 FROM healthy_dept d
+                WHERE d.his_dept_id = ud.dept_code
+                  AND d.orgid = #{campusid}
+            )
+        </if>
     </select>
 
     <select id="yhybfxx" parameterType="com.ruoyi.common.core.domain.entity.SysUser" resultMap="SysUserDeptResult">
-        select user_id , user_code , dept_type ,dept_code,dept_name,deptparent,del_flag,orgid
-        FROM healthy_user_dept
+        select ud.user_id , ud.user_code , ud.dept_type ,ud.dept_code,ud.dept_name,ud.deptparent,ud.del_flag,ud.orgid
+        FROM healthy_user_dept ud
         where 1=1
-        and user_id != 'admin'
-        and dept_type = '2'
+        and ud.user_id != 'admin'
+        and ud.dept_type = '2'
         <if test="orgid != null and orgid != ''">
-            AND orgid = #{orgid}
+            AND ud.orgid = #{orgid}
         </if>
-        <if test="hisUserId != null ">and user_id = #{hisUserId}</if>
+        <if test="hisUserId != null ">and ud.user_id = #{hisUserId}</if>
+        <if test="campusid != null and campusid != ''">
+            AND EXISTS (
+                SELECT 1 FROM healthy_dept d
+                WHERE d.his_dept_id = ud.dept_code
+                  AND d.orgid = #{campusid}
+            )
+        </if>
     </select>
 
     <select id="yhyyqxx" parameterType="com.ruoyi.common.core.domain.entity.SysUser" resultMap="SysUserOrgResult">
@@ -522,7 +540,7 @@
         <if test="hisUserId != null ">
             AND ud.user_id = #{hisUserId}
         </if>
-        <if test="campusid != null">
+        <if test="campusid != null and campusid != ''">
             AND d.orgid = #{campusid}
         </if>
         union all
@@ -540,7 +558,7 @@
         <if test="hisUserId != null ">
             AND udb.user_id = #{hisUserId}
         </if>
-        <if test="campusid != null">
+        <if test="campusid != null and campusid != ''">
             AND d.orgid = #{campusid}
         </if>
     </select>
@@ -654,8 +672,8 @@
         b.leavehospitaldistrictname,
         b.leavehospitaldistrictid,
         b.deptid,
-        b.leaveldeptid
-
+        b.leaveldeptid,
+        b.del_flag
         FROM
         healthy_inhosp b
         where 1=1
@@ -765,6 +783,30 @@
             <if test="orgid != null and orgid != ''">
                 AND u.orgid = #{orgid}
             </if>
+            <if test="lastStartTime != null and lastStartTime != ''">
+                AND u.last_Update_Time &gt;= to_date(#{lastStartTime}, 'YYYY-MM-DD HH24:MI:SS')
+            </if>
+            <if test="lastEndTime != null and lastEndTime != ''">
+                AND u.last_Update_Time &lt;= to_date(#{lastEndTime}, 'YYYY-MM-DD HH24:MI:SS')
+            </if>
+            <if test="campusid != null and campusid != ''">
+                AND (
+                    EXISTS (
+                        SELECT 1
+                        FROM healthy_user_dept ud
+                        JOIN healthy_dept d ON d.his_dept_id = ud.dept_code
+                        WHERE ud.user_id = u.his_user_id
+                          AND d.orgid = #{campusid}
+                    )
+                    OR EXISTS (
+                        SELECT 1
+                        FROM healthy_user_dept_bf udb
+                        JOIN healthy_dept d2 ON d2.his_dept_id = udb.dept_code
+                        WHERE udb.user_id = u.his_user_id
+                          AND d2.orgid = #{campusid}
+                    )
+                )
+            </if>
             <if test="userId != null and userId != 0">
                 AND u.user_id = #{userId}
             </if>
@@ -818,11 +860,12 @@
     <select id="selectOperList" parameterType="com.smartor.domain.PatMedOperation"
             resultMap="PatMedOperationResult">
         select
-        o.patid,
+        o.patid_his,
         o.patcode,
         o.paname,
         o.opreqid,
         o.opreqcode,
+        o.canceltime,
         o.opsstatus,
         o.optypecode,
         o.optypename,
@@ -872,6 +915,10 @@
         o.deptname ,
         o.hospitaldistrictcode,
         o.hospitaldistrictname ,
+        o.deptcode as leaveldeptcode,
+        o.deptname as leaveldeptname,
+        o.hospitaldistrictcode as leavehospitaldistrictcode,
+        o.hospitaldistrictname as leavehospitaldistrictname,
         o.roomno  ,
         o.bed_no ,
         o.drcode  ,
@@ -880,15 +927,19 @@
         o.nurse_name ,
         o.check_flag ,
         o.long_task_reason,
-        o.opid ,
-        o.vopcode ,
+        null as opid ,
+        o.opcode ,
         o.opdesc,
         o.oplevelcode ,
-        o.opleveldesc
-        from PAT_MED_OPERATION o
+        o.opleveldesc,
+        o.last_Update_Time
+        from HEALTHY_PAT_MED_OPERATION o
         where 1=1
         <if test="orgid != null and orgid != ''">
             AND o.orgid = #{orgid}
+        </if>
+        <if test="opreqid != null and opreqid != ''">
+            AND o.opreqid = #{opreqid}
         </if>
         <if test="lastStartTime != null and lastStartTime != ''">
             and to_char(o.last_Update_Time, 'YYYY-MM-DD HH24:MI:SS') >= #{lastStartTime}
@@ -902,7 +953,7 @@
             resultMap="PatMedOperationItemResult">
         select
                oi.operationid,
-               oi.opid,
+               null as opid,
                oi.opcode,
                oi.opdesc,
                oi.main_flag,
@@ -922,9 +973,9 @@
                oi.pguid,
                oi.guid,
                oi.pid,
-               oi.opercheck_flag,
-               oi.long_task_reason
-        from PAT_MED_OPERATION_ITEM oi
+               oi.long_task_reason,
+               oi.last_Update_Time
+        from HEALTHY_PAT_MED_OPERATION_ITEM oi
         where 1=1
         <if test="orgid != null and orgid != ''">
             AND oi.orgid = #{orgid}
@@ -932,11 +983,14 @@
         <if test="opid != null and opid != ''">
             AND oi.opid = #{opid}
         </if>
+        <if test="operationid != null and operationid != ''">
+            AND oi.operationid = #{operationid}
+        </if>
         <if test="lastStartTime != null and lastStartTime != ''">
-            and to_char(oi.last_Update_Time, 'YYYY-MM-DD HH24:MI:SS') >= #{lastStartTime}
+            and oi.last_Update_Time &gt;= to_date(#{lastStartTime}, 'YYYY-MM-DD HH24:MI:SS')
         </if>
         <if test="lastEndTime != null and lastEndTime != ''">
-            and to_char(oi.last_Update_Time, 'YYYY-MM-DD HH24:MI:SS') &lt;= #{lastEndTime}
+            and oi.last_Update_Time &lt;= to_date(#{lastEndTime}, 'YYYY-MM-DD HH24:MI:SS')
         </if>
     </select>
 </mapper>

--
Gitblit v1.9.3