fix(测试用例): 导出自定义多选类型解析处理
This commit is contained in:
parent
2820fdf6ec
commit
685e5d9934
|
@ -8,7 +8,10 @@ import io.metersphere.system.domain.CustomFieldOption;
|
||||||
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
|
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,18 +53,16 @@ public class CustomFieldMultipleSelectValidator extends CustomFieldSelectValidat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse2Value(String keyOrValuesStr, TemplateCustomFieldDTO customField) {
|
public Object parse2Value(String keyOrValuesStr, TemplateCustomFieldDTO customField) {
|
||||||
Map<String, String> optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getFieldId, CustomFieldOption::getValue));
|
if (StringUtils.isBlank(keyOrValuesStr) || StringUtils.equals(keyOrValuesStr, "[]")) {
|
||||||
if (StringUtils.isBlank(keyOrValuesStr)) {
|
return StringUtils.EMPTY;
|
||||||
return JSON.toJSONString(new ArrayList<>());
|
|
||||||
}
|
}
|
||||||
List<String> keyOrValues = parse2Array(keyOrValuesStr);
|
String keyOrValues = String.join(",", JSON.parseArray(keyOrValuesStr));
|
||||||
for (int i = 0; i < keyOrValues.size(); i++) {
|
List<String> result = new ArrayList<>();
|
||||||
String item = keyOrValues.get(i);
|
Map<String, String> optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText));
|
||||||
if (optionValueMap.containsKey(item)) {
|
if (optionValueMap.containsKey(keyOrValues)) {
|
||||||
keyOrValues.set(i, optionValueMap.get(item));
|
result.add(optionValueMap.get(keyOrValues));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return JSON.toJSONString(keyOrValues);
|
return String.join(",", JSON.parseArray(JSON.toJSONString(result)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class CustomFieldSelectValidator extends AbstractCustomFieldValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse2Value(String keyOrValuesStr, TemplateCustomFieldDTO customField) {
|
public Object parse2Value(String keyOrValuesStr, TemplateCustomFieldDTO customField) {
|
||||||
Map<String, String> optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getFieldId, CustomFieldOption::getValue));
|
Map<String, String> optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText));
|
||||||
if (optionValueMap.containsKey(keyOrValuesStr)) {
|
if (optionValueMap.containsKey(keyOrValuesStr)) {
|
||||||
return optionValueMap.get(keyOrValuesStr);
|
return optionValueMap.get(keyOrValuesStr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue