Fix Bug #461: [系统管理-执行科室配置] 保存项目配置后,项目名称回显为ID码,未显示正确名称
根因:DictAspect 的 @Around 后置处理中,SQL查询失败返回空字符串,覆盖了控制器方法中手动设置的 activityDefinitionId_dictText 有效值。前端 el-select 因 _dictText 为空而回显 ID 码。 修复: 1. DictAspect 在执行 SQL 查询前,先检查 _dictText 字段是否已被手动填充(非空),若已有值则跳过查询,避免覆盖 2. 增加空字符串防护:dictLabel 为空字符串时不设置 _dictText Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -100,11 +100,25 @@ public class DictAspect {
|
|||||||
String dictText = dictAnnotation.dictText();
|
String dictText = dictAnnotation.dictText();
|
||||||
String dictTable = dictAnnotation.dictTable();
|
String dictTable = dictAnnotation.dictTable();
|
||||||
String deleteFlag = dictAnnotation.deleteFlag();
|
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());
|
String dictLabel = queryDictLabel(dictTable, dictCode, dictText, deleteFlag, fieldValue.toString());
|
||||||
if (dictLabel != null) {
|
if (dictLabel != null && !dictLabel.isEmpty()) {
|
||||||
// 动态生成 _dictText 字段名
|
// 动态生成 _dictText 字段名
|
||||||
String textFieldName = field.getName() + "_dictText";
|
|
||||||
try {
|
try {
|
||||||
Field textField = dto.getClass().getDeclaredField(textFieldName);
|
Field textField = dto.getClass().getDeclaredField(textFieldName);
|
||||||
textField.setAccessible(true);
|
textField.setAccessible(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user