From dafa5961c443f8e9249189f1b3340a07562e2ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E7=BE=BD?= <关羽@gentronhealth.com> Date: Mon, 11 May 2026 15:29:50 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#489:=20=E6=8A=A4=E5=A3=AB=E6=A0=A1?= =?UTF-8?q?=E5=AF=B9=E7=95=8C=E9=9D=A2=E9=87=8D=E5=A4=8D=E5=BE=85=E6=A0=A1?= =?UTF-8?q?=E5=AF=B9=E8=AE=B0=E5=BD=95=20-=20SQL=20JOIN=20=E4=B9=98?= =?UTF-8?q?=E6=B3=95=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: AdviceProcessAppMapper.xml 中 LEFT JOIN med_medication_dispense 直接关联时,一条药品医嘱若有多条发药记录会产生多行结果(SQL 笛卡尔积), 导致护士校对界面显示重复的待校对记录。 修复: 将直接 JOIN 改为 ROW_NUMBER() 子查询,每个 med_req_id 只取最新 一条发药记录的状态,避免行倍增。 Co-Authored-By: Claude Opus 4.7 --- .../AdviceProcessAppMapper.xml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/inhospitalnursestation/AdviceProcessAppMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/inhospitalnursestation/AdviceProcessAppMapper.xml index 3aa27ecb..c31e33cf 100755 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/inhospitalnursestation/AdviceProcessAppMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/inhospitalnursestation/AdviceProcessAppMapper.xml @@ -280,9 +280,17 @@ aa.balance_amount ) AS personal_account ON personal_account.encounter_id = ae.id - LEFT JOIN med_medication_dispense mmd + LEFT JOIN ( + SELECT med_req_id, status_enum + FROM ( + SELECT med_req_id, status_enum, + ROW_NUMBER() OVER (PARTITION BY med_req_id ORDER BY id DESC) AS rn + FROM med_medication_dispense + WHERE delete_flag = '0' + ) t + WHERE rn = 1 + ) mmd ON mmd.med_req_id = T1.id - AND mmd.delete_flag = '0' WHERE T1.delete_flag = '0' AND T1.refund_medicine_id IS NULL AND T1.generate_source_enum = #{doctorPrescription}