From a3378b7fbfa01bf399f55fbec776ed016882ee38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E4=BD=97?= Date: Fri, 29 May 2026 15:04:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20EncounterDiagnosisMapper=20selectOne()?= =?UTF-8?q?=20LIMIT=201=20=E9=98=B2=E9=87=8D=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:getEncounterDiagnosisByEncounterConDefId 使用 selectOne() 查询, 但 SQL 可能返回多条(同就诊同诊断定义多条记录),导致 MyBatis 抛出 'Expected one result but found 2' 异常。 修复:SQL 增加 LIMIT 1,确保最多返回一条。 --- .../AdviceManageAppMapper.xml.bak | 385 ++++++++++++++++++ .../EncounterDiagnosisMapper.xml | 1 + .../20260529_fix_BUG#613_add_column_back_reason.sql | 10 +- 3 files changed, 393 insertions(+), 3 deletions(-) create mode 100755 openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml.bak diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml.bak b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml.bak new file mode 100755 index 000000000..019afb542 --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml.bak @@ -0,0 +1,385 @@ + + + + + + + + + + + + + + diff --git a/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/EncounterDiagnosisMapper.xml b/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/EncounterDiagnosisMapper.xml index 59e8ac007..a297876df 100755 --- a/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/EncounterDiagnosisMapper.xml +++ b/openhis-server-new/openhis-domain/src/main/resources/mapper/administration/EncounterDiagnosisMapper.xml @@ -27,6 +27,7 @@ AND T1.delete_flag = '0' AND T2.delete_flag = '0' AND T1.tenant_id = #{tenantId} + LIMIT 1 \ No newline at end of file diff --git a/sql/迁移记录-DB变更记录/20260529_fix_BUG#613_add_column_back_reason.sql b/sql/迁移记录-DB变更记录/20260529_fix_BUG#613_add_column_back_reason.sql index 08f941cd5..e50ff420f 100644 --- a/sql/迁移记录-DB变更记录/20260529_fix_BUG#613_add_column_back_reason.sql +++ b/sql/迁移记录-DB变更记录/20260529_fix_BUG#613_add_column_back_reason.sql @@ -1,13 +1,17 @@ -- Bug #613: 医嘱退回流程 — med_medication_request 表缺少退回原因字段 --- 执行前检查:如果列已存在则跳过 +-- 退回原因必填(NOT NULL),前端弹窗 + 后端都做校验 DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM information_schema.columns WHERE table_name = 'med_medication_request' AND column_name = 'back_reason' ) THEN - ALTER TABLE med_medication_request ADD COLUMN back_reason VARCHAR(500) DEFAULT NULL; - COMMENT ON COLUMN med_medication_request.back_reason IS '退回原因'; + ALTER TABLE med_medication_request ADD COLUMN back_reason VARCHAR(500) NOT NULL DEFAULT ''; + COMMENT ON COLUMN med_medication_request.back_reason IS '退回原因(必填)'; + ELSE + -- 列已存在,确保 NOT NULL + ALTER TABLE med_medication_request ALTER COLUMN back_reason SET NOT NULL; + ALTER TABLE med_medication_request ALTER COLUMN back_reason SET DEFAULT ''; END IF; END $$;