From 3bbd86f1d271473631c7b6c5f3b2c869ea9b53d5 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 1 Jul 2021 17:36:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=97=B6=E7=94=A8=E4=BE=8B=E7=8A=B6=E6=80=81=E4=B8=8D?= =?UTF-8?q?=E5=9B=9E=E6=98=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复测试用例导入时用例状态不回显的问题 --- .../excel/domain/TestCaseExcelData.java | 8 +++ .../excel/domain/TestCaseExcelDataCn.java | 5 ++ .../excel/domain/TestCaseExcelDataTw.java | 4 ++ .../excel/domain/TestCaseExcelDataUs.java | 4 ++ .../TestCaseDataIgnoreErrorListener.java | 62 +++++++++++++++++++ .../excel/listener/TestCaseDataListener.java | 62 +++++++++++++++++++ .../track/service/TestCaseService.java | 13 ++-- 7 files changed, 152 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java index bbbe5f60e1..590dfe893f 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java @@ -37,6 +37,14 @@ public class TestCaseExcelData { @ExcelIgnore private String stepModel; + /** + * 责任人 + * 用例状态 + * 用例等级 + */ + @ExcelIgnore + private String status; + public Set getExcludeColumnFiledNames(boolean needNum){ Set excludeColumnFiledNames = new HashSet<>(); if(!needNum){ diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java index 9934b40137..a7ddf657d7 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java @@ -70,6 +70,11 @@ public class TestCaseExcelDataCn extends TestCaseExcelData { @ExcelProperty("预期结果") private String stepResult; + @ColumnWidth(50) + @ExcelProperty("用例状态") + private String status; + + @ColumnWidth(50) @ExcelProperty("编辑模式") @NotRequired diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java index c8e8479877..28fd263840 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java @@ -70,6 +70,10 @@ public class TestCaseExcelDataTw extends TestCaseExcelData { @ExcelProperty("預期結果") private String stepResult; + @ColumnWidth(50) + @ExcelProperty("用例狀態") + private String status; + @ColumnWidth(50) @ExcelProperty("編輯模式") @NotRequired diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java index b63d626c22..8185de5261 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java @@ -71,6 +71,10 @@ public class TestCaseExcelDataUs extends TestCaseExcelData { @ExcelProperty("Step result") private String stepResult; + @ColumnWidth(50) + @ExcelProperty("Case status") + private String status; + @ColumnWidth(50) @ExcelProperty("Edit Model") @NotRequired diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataIgnoreErrorListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataIgnoreErrorListener.java index a1597d474a..9123c0ec7e 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataIgnoreErrorListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataIgnoreErrorListener.java @@ -257,6 +257,37 @@ public class TestCaseDataIgnoreErrorListener extends EasyExcelListener0){ + testCase.setCustomFields(customArr.toString()); + } + //将标签设置为前端可解析的格式 String modifiedTags = modifyTagPattern(data); testCase.setTags(modifiedTags); @@ -297,6 +328,37 @@ public class TestCaseDataIgnoreErrorListener extends EasyExcelListener0){ + testCase.setCustomFields(customArr.toString()); + } + //将标签设置为前端可解析的格式 String modifiedTags = modifyTagPattern(data); testCase.setTags(modifiedTags); diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index 0716710255..4ea8b6b606 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -272,6 +272,37 @@ public class TestCaseDataListener extends EasyExcelListener { testCase.setTags(modifiedTags); testCase.setType("functional"); + JSONArray customArr = new JSONArray(); + String caseStatusValue = ""; + if(StringUtils.equalsAny(data.getStatus(),"Underway","进行中","進行中")){ + caseStatusValue = "Underway"; + }else if(StringUtils.equalsAny(data.getStatus(),"Prepare","未开始","未開始")){ + caseStatusValue = "Prepare"; + }else if(StringUtils.equalsAny(data.getStatus(),"Completed","已完成","已完成")){ + caseStatusValue = "Completed"; + } + if(StringUtils.isNotEmpty(caseStatusValue)){ + JSONObject statusObj = new JSONObject(); + statusObj.put("id",UUID.randomUUID().toString()); + statusObj.put("name","用例状态"); + statusObj.put("value",caseStatusValue); + statusObj.put("customData",null); + customArr.add(statusObj); + } + + if(StringUtils.isNotEmpty(data.getMaintainer())){ + JSONObject obj = new JSONObject(); + obj.put("id",UUID.randomUUID().toString()); + obj.put("name","责任人"); + obj.put("value",data.getMaintainer()); + obj.put("customData",null); + customArr.add(obj); + } + + if(customArr.size()>0){ + testCase.setCustomFields(customArr.toString()); + } + if (StringUtils.isNotBlank(data.getStepModel()) && StringUtils.equals(data.getStepModel(), TestCaseConstants.StepModel.TEXT.name())) { testCase.setStepDescription(data.getStepDesc()); @@ -308,6 +339,37 @@ public class TestCaseDataListener extends EasyExcelListener { String steps = getSteps(data); testCase.setSteps(steps); + JSONArray customArr = new JSONArray(); + String caseStatusValue = ""; + if(StringUtils.equalsAny(data.getStatus(),"Underway","进行中","進行中")){ + caseStatusValue = "Underway"; + }else if(StringUtils.equalsAny(data.getStatus(),"Prepare","未开始","未開始")){ + caseStatusValue = "Prepare"; + }else if(StringUtils.equalsAny(data.getStatus(),"Completed","已完成","已完成")){ + caseStatusValue = "Completed"; + } + if(StringUtils.isNotEmpty(caseStatusValue)){ + JSONObject statusObj = new JSONObject(); + statusObj.put("id",UUID.randomUUID().toString()); + statusObj.put("name","用例状态"); + statusObj.put("value",caseStatusValue); + statusObj.put("customData",null); + customArr.add(statusObj); + } + + if(StringUtils.isNotEmpty(data.getMaintainer())){ + JSONObject obj = new JSONObject(); + obj.put("id",UUID.randomUUID().toString()); + obj.put("name","责任人"); + obj.put("value",data.getMaintainer()); + obj.put("customData",null); + customArr.add(obj); + } + + if(customArr.size()>0){ + testCase.setCustomFields(customArr.toString()); + } + //将标签设置为前端可解析的格式 String modifiedTags = modifyTagPattern(data); testCase.setTags(modifiedTags); diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index ec16fdbcd9..733cad5ef3 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -242,13 +242,13 @@ public class TestCaseService { // 如果上边字段全部相同,去检查 remark 和 steps if (!CollectionUtils.isEmpty(caseList)) { - String caseRemark = testCase.getRemark(); - String caseSteps = testCase.getSteps(); - String casePrerequisite = testCase.getPrerequisite(); + String caseRemark = testCase.getRemark() == null? "" : testCase.getRemark(); + String caseSteps = testCase.getSteps() == null? "" : testCase.getSteps(); + String casePrerequisite = testCase.getPrerequisite() == null? "" : testCase.getPrerequisite(); for (TestCaseWithBLOBs tc : caseList) { - String steps = tc.getSteps(); - String remark = tc.getRemark(); - String prerequisite = tc.getPrerequisite(); + String steps = tc.getSteps() == null?"" : tc.getSteps(); + String remark = tc.getRemark() == null?"" : tc.getRemark(); + String prerequisite = tc.getPrerequisite() == null?"" : tc.getPrerequisite(); if (StringUtils.equals(steps, caseSteps) && StringUtils.equals(remark, caseRemark) && StringUtils.equals(prerequisite, casePrerequisite)) { //MSException.throwException(Translator.get("test_case_already_exists")); return tc; @@ -872,6 +872,7 @@ public class TestCaseService { } } data.setMaintainer(t.getMaintainer()); + data.setStatus(t.getStatus()); list.add(data); }); return list;