fix: 用例导入tag表头为空导入失败

This commit is contained in:
chenjianxing 2021-03-19 18:04:35 +08:00
parent 6446024cf8
commit 2b5483dc23
7 changed files with 32 additions and 6 deletions

View File

@ -0,0 +1,9 @@
package io.metersphere.excel.annotation;
import java.lang.annotation.*;
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface NotRequired {
}

View File

@ -2,6 +2,7 @@ package io.metersphere.excel.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.metersphere.excel.annotation.NotRequired;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
@ -40,6 +41,7 @@ public class TestCaseExcelDataCn extends TestCaseExcelData {
@ColumnWidth(50)
@ExcelProperty("标签")
@NotRequired
@Length(min = 0, max = 1000)
private String tags;

View File

@ -2,6 +2,7 @@ package io.metersphere.excel.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.metersphere.excel.annotation.NotRequired;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
@ -38,6 +39,12 @@ public class TestCaseExcelDataTw extends TestCaseExcelData {
@Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
private String priority;
@ColumnWidth(50)
@ExcelProperty("標簽")
@NotRequired
@Length(min = 0, max = 1000)
private String tags;
@NotBlank(message = "{cannot_be_null}")
@ExcelProperty("測試方式")
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}")

View File

@ -2,6 +2,7 @@ package io.metersphere.excel.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.metersphere.excel.annotation.NotRequired;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
@ -39,6 +40,12 @@ public class TestCaseExcelDataUs extends TestCaseExcelData {
@Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
private String priority;
@ColumnWidth(50)
@ExcelProperty("Tag")
@NotRequired
@Length(min = 0, max = 1000)
private String tags;
@NotBlank(message = "{cannot_be_null}")
@ExcelProperty("Method")
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}")

View File

@ -6,15 +6,13 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.util.StringUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.excel.annotation.NotRequired;
import io.metersphere.excel.domain.ExcelErrData;
import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.excel.domain.UserExcelData;
import io.metersphere.excel.utils.ExcelValidateHelper;
import io.metersphere.i18n.Translator;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> {
@ -131,9 +129,12 @@ public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> {
for (String v : excelProperty.value()) {
value.append(v);
}
// 检查是否必有的头部信息
if (field.getAnnotation(NotRequired.class) == null) {
result.add(value.toString());
}
}
}
return result;
}

View File

@ -8,6 +8,7 @@
@setTreeNodes="setTreeNodes"
@exportTestCase="exportTestCase"
@saveAsEdit="editTestCase"
@refreshAll="refreshAll"
:type="'edit'"
ref="nodeTree"
/>

View File

@ -101,7 +101,6 @@ export default {
this.$emit("refreshTable");
},
refreshAll() {
this.selectRows.clear();
this.$emit('refreshAll');
},
handleCommand(e) {