diff --git a/test-track/backend/src/main/java/io/metersphere/excel/constants/TestCaseImportFiled.java b/test-track/backend/src/main/java/io/metersphere/excel/constants/TestCaseImportFiled.java index 65bcea77ff..ca18f7c150 100644 --- a/test-track/backend/src/main/java/io/metersphere/excel/constants/TestCaseImportFiled.java +++ b/test-track/backend/src/main/java/io/metersphere/excel/constants/TestCaseImportFiled.java @@ -20,10 +20,10 @@ public enum TestCaseImportFiled { MODULE("module","所属模块", "所屬模塊", "Module", TestCaseExcelData::getNodePath), TAGS("tags","标签", "標簽", "Tag", TestCaseImportFiled::parseTags), PREREQUISITE("prerequisite","前置条件", "前置條件", "Prerequisite", TestCaseExcelData::getPrerequisite), - REMARK("remark","备注", "備註", "Remark", TestCaseExcelData::getRemark), STEP_DESC("stepDesc","步骤描述", "步驟描述", "Step description", TestCaseExcelData::getStepDesc), STEP_RESULT("stepResult","预期结果", "預期結果", "Step result", TestCaseExcelData::getStepResult), STEP_MODEL("stepModel","编辑模式", "編輯模式", "Edit Model", TestCaseExcelData::getStepModel), + REMARK("remark","备注", "備註", "Remark", TestCaseExcelData::getRemark), STATUS("status","用例状态", "用例狀態", "Case status", TestCaseExcelData::getStatus), MAINTAINER("maintainer","责任人", "責任人", "Maintainer", TestCaseExcelData::getMaintainer), PRIORITY("priority","用例等级", "用例等級", "Priority", TestCaseExcelData::getPriority); diff --git a/test-track/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java b/test-track/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java index 41733a31e3..d731492288 100644 --- a/test-track/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java +++ b/test-track/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java @@ -34,6 +34,8 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { private Integer priorityIndex; private Integer tagIndex; private Integer statusIndex; + private Integer stepDescIndex; + private Integer stepResultIndex; private Integer stepModelIndex; private Sheet sheet; @@ -61,6 +63,10 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { tagIndex = index; } else if (TestCaseImportFiled.STATUS.containsHead(head)) { statusIndex = index; + } else if (TestCaseImportFiled.STEP_DESC.containsHead(head)) { + stepDescIndex = index; + } else if (TestCaseImportFiled.STEP_RESULT.containsHead(head)) { + stepResultIndex = index; } else if (TestCaseImportFiled.STEP_MODEL.containsHead(head)) { stepModelIndex = index; } @@ -83,6 +89,8 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { setComment(moduleIndex, Translator.get("module_created_automatically")); setComment(maintainerIndex, Translator.get("please_input_project_member")); setComment(tagIndex, Translator.get("tag_tip_pattern")); + setComment(stepDescIndex, Translator.get("step_desc_tip")); + setComment(stepResultIndex, Translator.get("step_result_tip")); setComment(stepModelIndex, Translator.get("step_model_tip")); List list = new ArrayList<>(); 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 2ef67a45ce..bfbe497edb 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 @@ -685,41 +685,61 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener(); + List> steps = new ArrayList<>(); - // 如果是合并单元格,则组合多条单元格的数据 - if (CollectionUtils.isNotEmpty(data.getMergeStepDesc()) - || CollectionUtils.isNotEmpty(data.getMergeStepResult())) { + if (CollectionUtils.isNotEmpty(data.getMergeStepDesc()) || CollectionUtils.isNotEmpty(data.getMergeStepResult())) { + // 如果是合并单元格,则组合多条单元格的数据 for (int i = 0; i < data.getMergeStepDesc().size(); i++) { - Map step = new LinkedHashMap<>(); - step.put("num", i + 1); - step.put("desc", Optional.ofNullable(data.getMergeStepDesc().get(i)).orElse(StringUtils.EMPTY)); - step.put("result", Optional.ofNullable(data.getMergeStepResult().get(i)).orElse(StringUtils.EMPTY)); - jsonArray.add(step); + List> rowSteps = getSingleRowSteps(data.getMergeStepDesc().get(i), data.getMergeStepResult().get(i), steps.size()); + steps.addAll(rowSteps); } - return JSON.toJSONString(jsonArray); + } else { + // 如果不是合并单元格,则直接解析单元格数据 + steps.addAll(getSingleRowSteps(data.getStepDesc(), data.getStepResult(), steps.size())); } + return JSON.toJSONString(steps); + } + + /** + * 解析单行步骤描述, 预期结果数据 + * @param cellDesc 步骤描述 + * @param cellResult 预期结果 + * @param startStepIndex 步骤开始序号 + * @return 步骤JSON-String + */ + private List> getSingleRowSteps(String cellDesc, String cellResult, Integer startStepIndex) { + List> steps = new ArrayList<>(); List stepDescList = new ArrayList<>(); List stepResList = new ArrayList<>(); - - Set rowNums = new HashSet<>(); - if (data.getStepDesc() != null) { - String[] stepDesc = data.getStepDesc().split("\r|\n|\r\n"); + if (StringUtils.isNotEmpty(cellDesc)) { + // 根据[1], [2]...分割步骤描述, 开头空字符去掉, 末尾保留 + String[] stepDesc = cellDesc.split("\\[\\d+]", -1); + if (StringUtils.isEmpty(stepDesc[0])) { + stepDesc = Arrays.copyOfRange(stepDesc, 1, stepDesc.length); + } int rowIndex = 1; for (String row : stepDesc) { RowInfo rowInfo = this.parseIndexInRow(row, rowIndex); stepDescList.add(rowInfo.rowInfo); - rowNums.add(rowIndex++); } } else { stepDescList.add(StringUtils.EMPTY); } - if (data.getStepResult() != null) { - String[] stepRes = data.getStepResult().split("\r|\n|\r\n"); + if (StringUtils.isNotEmpty(cellResult)) { + // 根据[1], [2]...分割步骤描述, 开头空字符去掉, 末尾保留 + String[] stepRes = cellResult.split("\\[\\d+]", -1); + if (StringUtils.isEmpty(stepRes[0])) { + stepRes = Arrays.copyOfRange(stepRes, 1, stepRes.length); + } int lastStepIndex = 1; for (String row : stepRes) { RowInfo rowInfo = this.parseIndexInRow(row, lastStepIndex); @@ -731,13 +751,11 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener stepResList.size() ? stepDescList.size() : stepResList.size(); - + int index = Math.max(stepDescList.size(), stepResList.size()); for (int i = 0; i < index; i++) { - // 保持插入顺序,判断用例是否有相同的steps Map step = new LinkedHashMap<>(); - step.put("num", i + 1); + step.put("num", startStepIndex + i + 1); if (i < stepDescList.size()) { step.put("desc", stepDescList.get(i)); } else { @@ -750,9 +768,9 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener