From 5db20ddcc2143a7ec6e4b9817a8bb23839be3503 Mon Sep 17 00:00:00 2001 From: zhaoyun Date: Sun, 17 May 2026 19:11:17 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#461:=20[=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=AE=A1=E7=90=86-=E6=89=A7=E8=A1=8C=E7=A7=91=E5=AE=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE]=20=E4=BF=9D=E5=AD=98=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=90=8E=EF=BC=8C=E9=A1=B9=E7=9B=AE=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=9B=9E=E6=98=BE=E4=B8=BAID=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E6=9C=AA=E6=98=BE=E7=A4=BA=E6=AD=A3=E7=A1=AE=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:DictAspect 的 @Around 后置处理中,SQL查询失败返回空字符串,覆盖了控制器方法中手动设置的 activityDefinitionId_dictText 有效值。前端 el-select 因 _dictText 为空而回显 ID 码。 修复: 1. DictAspect 在执行 SQL 查询前,先检查 _dictText 字段是否已被手动填充(非空),若已有值则跳过查询,避免覆盖 2. 增加空字符串防护:dictLabel 为空字符串时不设置 _dictText Co-Authored-By: Claude Opus 4.7 --- .../com/openhis/common/aspectj/DictAspect.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/openhis-server-new/openhis-common/src/main/java/com/openhis/common/aspectj/DictAspect.java b/openhis-server-new/openhis-common/src/main/java/com/openhis/common/aspectj/DictAspect.java index 8aba6c518..80c493b2a 100755 --- a/openhis-server-new/openhis-common/src/main/java/com/openhis/common/aspectj/DictAspect.java +++ b/openhis-server-new/openhis-common/src/main/java/com/openhis/common/aspectj/DictAspect.java @@ -100,11 +100,25 @@ public class DictAspect { String dictText = dictAnnotation.dictText(); String dictTable = dictAnnotation.dictTable(); String deleteFlag = dictAnnotation.deleteFlag(); + + // 检查 _dictText 字段是否已被手动填充(如控制器方法中预先查询设置) + // 如果已非空则跳过 SQL 查询,避免覆盖有效值 + String textFieldName = field.getName() + "_dictText"; + try { + Field existingTextField = dto.getClass().getDeclaredField(textFieldName); + existingTextField.setAccessible(true); + Object existingValue = existingTextField.get(dto); + if (existingValue != null && !existingValue.toString().isEmpty()) { + continue; // _dictText 已有值,跳过 + } + } catch (NoSuchFieldException e) { + // _dictText 字段不存在,继续正常流程 + } + // 查询字典值 String dictLabel = queryDictLabel(dictTable, dictCode, dictText, deleteFlag, fieldValue.toString()); - if (dictLabel != null) { + if (dictLabel != null && !dictLabel.isEmpty()) { // 动态生成 _dictText 字段名 - String textFieldName = field.getName() + "_dictText"; try { Field textField = dto.getClass().getDeclaredField(textFieldName); textField.setAccessible(true);