fix(用例管理): 用例导入校验,用例等级不区分大小写

--bug=1035534 --user=王旭 【用例管理】建议不区分大小写,并且给出具体不能为空的字段名称 https://www.tapd.cn/55049933/s/1462436
This commit is contained in:
WangXu10 2024-02-19 18:02:24 +08:00 committed by 刘瑞斌
parent d9ad727c3b
commit ecbf7b49b6
2 changed files with 9 additions and 1 deletions

View File

@ -43,6 +43,9 @@ public class CustomFieldSelectValidator extends AbstractCustomFieldValidator {
prepareCache(customField); prepareCache(customField);
Set<String> idSet = optionValueSetCache.get(customField.getFieldId()); Set<String> idSet = optionValueSetCache.get(customField.getFieldId());
Set<String> textSet = optionTextSetCache.get(customField.getFieldId()); Set<String> textSet = optionTextSetCache.get(customField.getFieldId());
if (customField.getFieldName().equals(Translator.get("custom_field.functional_priority"))) {
value = value.toUpperCase();
}
if (!idSet.contains(value) && !textSet.contains(value)) { if (!idSet.contains(value) && !textSet.contains(value)) {
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_select_tip"), customField.getFieldName(), textSet)); CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_select_tip"), customField.getFieldName(), textSet));
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.system.dto.excel; package io.metersphere.system.dto.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolation;
@ -7,6 +8,7 @@ import jakarta.validation.Validator;
import jakarta.validation.groups.Default; import jakarta.validation.groups.Default;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.util.Set; import java.util.Set;
@Component @Component
@ -22,7 +24,10 @@ public class ExcelValidateHelper {
Set<ConstraintViolation<T>> set = excelValidateHelper.validator.validate(obj, Default.class); Set<ConstraintViolation<T>> set = excelValidateHelper.validator.validate(obj, Default.class);
if (set != null && !set.isEmpty()) { if (set != null && !set.isEmpty()) {
for (ConstraintViolation<T> cv : set) { for (ConstraintViolation<T> cv : set) {
result.append(cv.getMessage()).append("; "); Field declaredField = obj.getClass().getDeclaredField(cv.getPropertyPath().toString());
ExcelProperty annotation = declaredField.getAnnotation(ExcelProperty.class);
//拼接错误信息包含当前出错数据的标题名字+错误信息
result.append(annotation.value()[0] + cv.getMessage()).append("; ");
} }
} }
return result.toString(); return result.toString();