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.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.metersphere.excel.annotation.NotRequired;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
@ -40,6 +41,7 @@ public class TestCaseExcelDataCn extends TestCaseExcelData {
@ColumnWidth(50) @ColumnWidth(50)
@ExcelProperty("标签") @ExcelProperty("标签")
@NotRequired
@Length(min = 0, max = 1000) @Length(min = 0, max = 1000)
private String tags; 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.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.metersphere.excel.annotation.NotRequired;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length; 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}") @Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
private String priority; private String priority;
@ColumnWidth(50)
@ExcelProperty("標簽")
@NotRequired
@Length(min = 0, max = 1000)
private String tags;
@NotBlank(message = "{cannot_be_null}") @NotBlank(message = "{cannot_be_null}")
@ExcelProperty("測試方式") @ExcelProperty("測試方式")
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}") @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.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.metersphere.excel.annotation.NotRequired;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length; 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}") @Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
private String priority; private String priority;
@ColumnWidth(50)
@ExcelProperty("Tag")
@NotRequired
@Length(min = 0, max = 1000)
private String tags;
@NotBlank(message = "{cannot_be_null}") @NotBlank(message = "{cannot_be_null}")
@ExcelProperty("Method") @ExcelProperty("Method")
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}") @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.exception.ExcelAnalysisException;
import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.StringUtils;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.excel.annotation.NotRequired;
import io.metersphere.excel.domain.ExcelErrData; import io.metersphere.excel.domain.ExcelErrData;
import io.metersphere.excel.domain.TestCaseExcelData; import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.excel.domain.UserExcelData;
import io.metersphere.excel.utils.ExcelValidateHelper; import io.metersphere.excel.utils.ExcelValidateHelper;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*; import java.util.*;
public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> { 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()) { for (String v : excelProperty.value()) {
value.append(v); value.append(v);
} }
// 检查是否必有的头部信息
if (field.getAnnotation(NotRequired.class) == null) {
result.add(value.toString()); result.add(value.toString());
} }
} }
}
return result; return result;
} }

View File

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

View File

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