diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleSelectValidator.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleSelectValidator.java index 293daeb49c..a93edadd5a 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleSelectValidator.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleSelectValidator.java @@ -8,7 +8,10 @@ import io.metersphere.system.domain.CustomFieldOption; import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import org.apache.commons.lang3.StringUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -50,18 +53,16 @@ public class CustomFieldMultipleSelectValidator extends CustomFieldSelectValidat @Override public Object parse2Value(String keyOrValuesStr, TemplateCustomFieldDTO customField) { - Map optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getFieldId, CustomFieldOption::getValue)); - if (StringUtils.isBlank(keyOrValuesStr)) { - return JSON.toJSONString(new ArrayList<>()); + if (StringUtils.isBlank(keyOrValuesStr) || StringUtils.equals(keyOrValuesStr, "[]")) { + return StringUtils.EMPTY; } - List keyOrValues = parse2Array(keyOrValuesStr); - for (int i = 0; i < keyOrValues.size(); i++) { - String item = keyOrValues.get(i); - if (optionValueMap.containsKey(item)) { - keyOrValues.set(i, optionValueMap.get(item)); - } + String keyOrValues = String.join(",", JSON.parseArray(keyOrValuesStr)); + List result = new ArrayList<>(); + Map optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText)); + if (optionValueMap.containsKey(keyOrValues)) { + result.add(optionValueMap.get(keyOrValues)); } - return JSON.toJSONString(keyOrValues); + return String.join(",", JSON.parseArray(JSON.toJSONString(result))); } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldSelectValidator.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldSelectValidator.java index e4007b1000..17e0b9d322 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldSelectValidator.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldSelectValidator.java @@ -62,7 +62,7 @@ public class CustomFieldSelectValidator extends AbstractCustomFieldValidator { @Override public Object parse2Value(String keyOrValuesStr, TemplateCustomFieldDTO customField) { - Map optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getFieldId, CustomFieldOption::getValue)); + Map optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText)); if (optionValueMap.containsKey(keyOrValuesStr)) { return optionValueMap.get(keyOrValuesStr); }