diff --git a/test-track/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java b/test-track/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java index 9c58749d75..e30a6720b3 100644 --- a/test-track/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java +++ b/test-track/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java @@ -35,6 +35,7 @@ import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.Serial; import java.lang.reflect.Field; import java.util.*; import java.util.stream.Collectors; @@ -117,14 +118,14 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener mergeInfoSet) { this.mergeInfoSet = mergeInfoSet; - this.excelDataClass = c; - this.testCaseService = CommonBeanFactory.getBean(TestCaseService.class); - this.testCaseNodeService = CommonBeanFactory.getBean(TestCaseNodeService.class); + excelDataClass = c; + testCaseService = CommonBeanFactory.getBean(TestCaseService.class); + testCaseNodeService = CommonBeanFactory.getBean(TestCaseNodeService.class); customIds = new HashSet<>(); this.request = request; - this.customFieldValidatorMap = CustomFieldValidatorFactory.getValidatorMap(); + customFieldValidatorMap = CustomFieldValidatorFactory.getValidatorMap(); List customFields = request.getCustomFields(); if (CollectionUtils.isNotEmpty(customFields)) { @@ -138,14 +139,15 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener headMap, AnalysisContext context) { this.headMap = headMap; try { - this.genExcelHeadToFieldNameDicAndGetNotRequiredFields(); + genExcelHeadToFieldNameDicAndGetNotRequiredFields(); } catch (NoSuchFieldException e) { LogUtil.error(e); } - this.formatHeadMap(); + formatHeadMap(); super.invokeHeadMap(headMap, context); } + @Override public void invoke(Map data, AnalysisContext analysisContext) { if (headMap == null) { @@ -158,41 +160,51 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener() {{ - add(testCaseExcelData.getStepDesc()); - }}); - testCaseExcelData.setMergeStepResult(new ArrayList<>() {{ - add(testCaseExcelData.getStepResult()); - }}); + testCaseExcelData = parseDataToModel(data); + testCaseExcelData.setMergeStepDesc(new ArrayList<>() { + @Serial + private static final long serialVersionUID = -2563948462432733672L; + + { + add(testCaseExcelData.getStepDesc()); + } + }); + testCaseExcelData.setMergeStepResult(new ArrayList<>() { + @Serial + private static final long serialVersionUID = 8985001651375529701L; + + { + add(testCaseExcelData.getStepResult()); + } + }); // 记录下数据并返回 - this.currentMergeData = testCaseExcelData; - if (!this.isMergeLastRow) { + currentMergeData = testCaseExcelData; + if (!isMergeLastRow) { return; } else { - this.currentMergeData = null; + currentMergeData = null; } } else { // 获取存储的数据,并添加多个步骤 - this.currentMergeData.getMergeStepDesc() + currentMergeData.getMergeStepDesc() .add(data.get(getStepDescColIndex())); - this.currentMergeData.getMergeStepResult() + currentMergeData.getMergeStepResult() .add(data.get(getStepResultColIndex())); // 是最后一行的合并单元格,保存并清空 currentMergeData,走之后的逻辑 - if (this.isMergeLastRow) { - testCaseExcelData = this.currentMergeData; - this.currentMergeData = null; + if (isMergeLastRow) { + testCaseExcelData = currentMergeData; + currentMergeData = null; } else { return; } } } else { - this.firstMergeRowIndex = null; - testCaseExcelData = this.parseDataToModel(data); + firstMergeRowIndex = null; + testCaseExcelData = parseDataToModel(data); } buildUpdateOrErrorList(rowIndex, testCaseExcelData); @@ -246,8 +258,8 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener data, Integer rowIndex) { - this.isMergeRow = false; - this.isMergeLastRow = false; + isMergeRow = false; + isMergeLastRow = false; if (getNameColIndex() == null) { MSException.throwException("缺少名称表头"); } @@ -260,7 +272,7 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener getNames() { - return this.names; + return names; } public List getIds() { - return this.ids; + return ids; } public void setNames(List names) { @@ -533,27 +546,27 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener result = list.stream() - .map(item -> this.convert2TestCase(item)) + .map(item -> convert2TestCase(item)) .collect(Collectors.toList()); testCaseService.saveImportData(result, request, testCaseCustomFieldMap, pathMap); - this.names = result.stream().map(TestCase::getName).collect(Collectors.toList()); - this.ids = result.stream().map(TestCase::getId).collect(Collectors.toList()); - this.isUpdated = true; + names = result.stream().map(TestCase::getName).collect(Collectors.toList()); + ids = result.stream().map(TestCase::getId).collect(Collectors.toList()); + isUpdated = true; } if (CollectionUtils.isNotEmpty(updateList)) { List result2 = updateList.stream() - .map(item -> this.convert2TestCaseForUpdate(item)) + .map(item -> convert2TestCaseForUpdate(item)) .collect(Collectors.toList()); testCaseService.updateImportData(result2, request, testCaseCustomFieldMap); - this.isUpdated = true; - this.names = result2.stream().map(TestCase::getName).collect(Collectors.toList()); - this.ids = result2.stream().map(TestCase::getId).collect(Collectors.toList()); + isUpdated = true; + names = result2.stream().map(TestCase::getName).collect(Collectors.toList()); + ids = result2.stream().map(TestCase::getId).collect(Collectors.toList()); updateList.clear(); } } @@ -573,6 +586,7 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener textFieldSet = data.getTextFieldSet(); List testCaseCustomFields = new ArrayList<>(); customData.forEach((k, v) -> { - if ((v instanceof List && CollectionUtils.isNotEmpty((List)v)) + if ((v instanceof List && CollectionUtils.isNotEmpty((List) v)) || StringUtils.isNotBlank(v.toString())) { CustomFieldDao customFieldDao = customFieldsMap.get(k); if (customFieldDao != null) { @@ -678,6 +692,7 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener 0) { - String indexString = rowSplit[0]; - if (StringUtils.isNumeric(indexString) && indexString.equals(String.valueOf(rowIndex))) { - try { - index = Integer.parseInt(indexString); - rowMessage = StringUtils.substring(parseString, indexString.length() + splitChar.length()); - } catch (Exception e) { - } - - if (index > -1) { - break; - } else { - rowMessage = row; - } - } - } - } - } - rowInfo.index = index; - if (rowMessage == null) { - rowMessage = StringUtils.EMPTY; - } - rowInfo.rowInfo = rowMessage; - return rowInfo; - } - private Integer getNameColIndex() { return findColIndex("name"); } @@ -872,13 +839,13 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener> getErrList() { - return this.errList; + return errList; } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { // 如果文件最后一行是没有内容的步骤,这里处理最后一条合并单元格的数据 - if (this.currentMergeData != null) { + if (currentMergeData != null) { buildUpdateOrErrorList(firstMergeRowIndex, currentMergeData); } saveData();