fix(测试计划): 多选成员导出值转换

This commit is contained in:
WangXu10 2024-08-20 19:42:52 +08:00 committed by Craftsman
parent e29fdbfb88
commit d370961a28
3 changed files with 19 additions and 13 deletions

View File

@ -15,6 +15,10 @@ import java.util.List;
*/ */
public class CustomFieldMultipleMemberValidator extends CustomFieldMemberValidator { public class CustomFieldMultipleMemberValidator extends CustomFieldMemberValidator {
public CustomFieldMultipleMemberValidator(String projectId) {
super(projectId);
}
@Override @Override
public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException { public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException {
validateArrayRequired(customField, value); validateArrayRequired(customField, value);
@ -54,15 +58,15 @@ public class CustomFieldMultipleMemberValidator extends CustomFieldMemberValidat
if (StringUtils.isBlank(keyOrValuesStr)) { if (StringUtils.isBlank(keyOrValuesStr)) {
return JSON.toJSONString(new ArrayList<>()); return JSON.toJSONString(new ArrayList<>());
} }
List<String> keyOrValues = parse2Array(keyOrValuesStr); List list = JSON.parseArray(keyOrValuesStr);
List<String> result = new ArrayList<>();
list.forEach(item -> {
if (super.userIdEmailMap.containsKey(item)) {
result.add(userIdEmailMap.get(item));
}
});
for (int i = 0; i < keyOrValues.size(); i++) { return String.join(",", JSON.parseArray(JSON.toJSONString(result)));
String item = keyOrValues.get(i).toLowerCase();
if (userIdEmailMap.containsKey(item)) {
keyOrValues.set(i, userIdEmailMap.get(item));
}
}
return JSON.toJSONString(keyOrValues);
} }
} }

View File

@ -56,12 +56,14 @@ public class CustomFieldMultipleSelectValidator extends CustomFieldSelectValidat
if (StringUtils.isBlank(keyOrValuesStr) || StringUtils.equals(keyOrValuesStr, "[]")) { if (StringUtils.isBlank(keyOrValuesStr) || StringUtils.equals(keyOrValuesStr, "[]")) {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
String keyOrValues = String.join(",", JSON.parseArray(keyOrValuesStr)); List list = JSON.parseArray(keyOrValuesStr);
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
Map<String, String> optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText)); Map<String, String> optionValueMap = customField.getOptions().stream().collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText));
if (optionValueMap.containsKey(keyOrValues)) { list.forEach(item -> {
result.add(optionValueMap.get(keyOrValues)); if (optionValueMap.containsKey(item)) {
result.add(optionValueMap.get(item));
} }
});
return String.join(",", JSON.parseArray(JSON.toJSONString(result))); return String.join(",", JSON.parseArray(JSON.toJSONString(result)));
} }

View File

@ -29,7 +29,7 @@ public class CustomFieldValidatorFactory {
validatorMap.put(CustomFieldType.DATETIME.name(), new CustomFieldDateTimeValidator()); validatorMap.put(CustomFieldType.DATETIME.name(), new CustomFieldDateTimeValidator());
validatorMap.put(CustomFieldType.MEMBER.name(), new CustomFieldMemberValidator(projectId)); validatorMap.put(CustomFieldType.MEMBER.name(), new CustomFieldMemberValidator(projectId));
validatorMap.put(CustomFieldType.MULTIPLE_MEMBER.name(), new CustomFieldMultipleMemberValidator()); validatorMap.put(CustomFieldType.MULTIPLE_MEMBER.name(), new CustomFieldMultipleMemberValidator(projectId));
validatorMap.put(CustomFieldType.INT.name(), new CustomFieldIntegerValidator()); validatorMap.put(CustomFieldType.INT.name(), new CustomFieldIntegerValidator());
validatorMap.put(CustomFieldType.FLOAT.name(), new CustomFieldFloatValidator()); validatorMap.put(CustomFieldType.FLOAT.name(), new CustomFieldFloatValidator());