From e57f96a017146695ff1deb3479f2cf52b70d43e5 Mon Sep 17 00:00:00 2001 From: AnAngle <1323481023@qq.com> Date: Sun, 21 Aug 2022 23:20:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E5=AF=BC=E5=85=A5=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=8D=95=E5=85=83=E6=A0=BC=E4=B8=AD=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C=EF=BC=8C=E5=AF=BC=E5=85=A5=E9=94=99=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015965 --user=陈建星 【测试跟踪】导入功能用例,导入后的步骤描述信息和导入前不一致 https://www.tapd.cn/55049933/s/1228606 --- .../listener/TestCaseNoModelDataListener.java | 33 ++++++++++--------- .../TestCasePretreatmentListener.java | 20 +++++++++-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java index a32dd8c3bc..43a17dd857 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java @@ -39,8 +39,6 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; -import static io.metersphere.xpack.ui.constants.ArgTypeEnum.testCase; - /** * 由于功能案例中含有自定义字段。导入的时候使用无模板对象的读取方式 * @@ -158,7 +156,11 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener mergeInfo.getLastRowIndex()) { - // TreeSet 按照行号排序了 - // 清除掉上一次已经遍历完成的数据,提高查询效率 - iterator.remove(); } } }); @@ -404,11 +405,11 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener mergeInfoSet; + private Integer lastRowIndex = 0; + Map emptyRowIndexMap = new HashMap<>(); public TestCasePretreatmentListener(Set mergeInfoSet) { this.mergeInfoSet = mergeInfoSet; } @Override - public void invoke(Object integerStringMap, AnalysisContext analysisContext) {} + public void invoke(Object integerStringMap, AnalysisContext analysisContext) { + Integer rowIndex = analysisContext.readRowHolder().getRowIndex(); + if (rowIndex - lastRowIndex > 1) { + // 记录空行的行号 + for (int i = lastRowIndex + 1; i < rowIndex; i++) { + emptyRowIndexMap.put(i, lastRowIndex); + } + } + this.lastRowIndex = rowIndex; + } @Override public void extra(CellExtra extra, AnalysisContext context) { @@ -30,6 +42,10 @@ public class TestCasePretreatmentListener extends AnalysisEventListener { // 将合并单元格信息保留 ExcelMergeInfo mergeInfo = new ExcelMergeInfo(); BeanUtils.copyBean(mergeInfo, extra); + if (emptyRowIndexMap.keySet().contains(mergeInfo.getLastRowIndex())) { + // 如果合并单元格的最后一行是空行,则将最后一行设置成非空的行 + mergeInfo.setLastRowIndex(emptyRowIndexMap.get(mergeInfo.getLastRowIndex())); + } this.mergeInfoSet.add(mergeInfo); } }