兼容多选枚举

This commit is contained in:
2026-06-07 18:12:53 +08:00
parent cdf02f6de6
commit b764cb1cb5
2 changed files with 42 additions and 6 deletions

View File

@@ -249,12 +249,33 @@ public class EnumMapUtils {
if(enumItemId == null) { if(enumItemId == null) {
return null; return null;
} }
Long temp = enumItemId instanceof Long ? (Long)enumItemId : (enumItemId instanceof String ? Long.parseLong((String)enumItemId) : null); String str = enumItemId instanceof Long ? String.valueOf(enumItemId) : (enumItemId instanceof String ? (String)enumItemId : null);
if(temp == null) { if(str == null) {
return null; return null;
} }
EnumManager enumManagerNew = getEnumManager(); // 多选枚举 逗号分隔
CtpEnumItem ctpEnumItem = enumManagerNew.getCtpEnumItem(temp); if(str.contains(",")) {
StringBuilder sb = new StringBuilder();
for(String id : str.split(",")) {
String showValue = getSingleEnumShowValue(id.trim());
if(showValue != null) {
if(sb.length() > 0) sb.append(",");
sb.append(showValue);
}
}
return sb.length() > 0 ? sb.toString() : null;
}
return getSingleEnumShowValue(str);
}
private static String getSingleEnumShowValue(String enumItemId) throws BusinessException {
Long temp;
try {
temp = Long.parseLong(enumItemId);
} catch (NumberFormatException e) {
return null;
}
CtpEnumItem ctpEnumItem = getEnumManager().getCtpEnumItem(temp);
if(ctpEnumItem == null) { if(ctpEnumItem == null) {
return null; return null;
} }

View File

@@ -339,8 +339,23 @@ public class FormTableExecutor {
if (field == null) continue; if (field == null) continue;
Object value = e.getValue(); Object value = e.getValue();
if (changeEnum && field.isEnumField()) { if (changeEnum && field.isEnumField() && value != null) {
value = EnumMapUtils.getEnumShowValue(value); try {
if ("multiselect".equals(field.getInputType())) {
String str = String.valueOf(value);
String[] split = str.split(",");
List<String> showValueList = new ArrayList<>();
for (String enumId : split) {
String sv = EnumMapUtils.getEnumShowValue(enumId.trim());
showValueList.add(sv != null ? sv : enumId.trim());
}
value = showValueList;
} else {
value = EnumMapUtils.getEnumShowValue(value);
}
} catch (Exception ex) {
// 多选枚举等无法解析时保留原值
}
} }
// 枚举、部门、成员等特殊字段处理 // 枚举、部门、成员等特殊字段处理
// value = handleFieldSpecialType(field, value); // value = handleFieldSpecialType(field, value);