From ed37d3e21abe64be75fe98e4d9a1657227cd41c3 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 4 Apr 2022 18:31:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E8=A1=A8=E6=A0=BC=E6=95=B0=E6=8D=AE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复接口用例为空时表格数据加载报错的问题 --- .../track/service/TestCaseService.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) 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 8109b8af10..3764ff89c1 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -648,48 +648,48 @@ public class TestCaseService { } private List parseStatus(List returnList) { - TestCaseExcelData excelData = new TestCaseExcelDataFactory().getTestCaseExcelDataLocal(); - List testCaseIdList = new ArrayList<>(); - returnList.forEach(item -> { - testCaseIdList.add(item.getId()); - }); + if (CollectionUtils.isNotEmpty(returnList)) { + TestCaseExcelData excelData = new TestCaseExcelDataFactory().getTestCaseExcelDataLocal(); + List testCaseIdList = new ArrayList<>(); + returnList.forEach(item -> { + testCaseIdList.add(item.getId()); + }); - List testCaseDTOList = extTestCaseMapper.getLastExecStatusByIdList(testCaseIdList); - Map testCaseStatusMap = new HashMap<>(); - testCaseDTOList.forEach(item -> { - testCaseStatusMap.put(item.getId(), item.getStatus()); - }); - - for (TestCaseDTO data : returnList) { - String lastStatus = testCaseStatusMap.get(data.getId()); - if (StringUtils.isNotEmpty(lastStatus)) { - data.setLastExecuteResult(lastStatus); - } else { - data.setLastExecuteResult(null); - } - String dataStatus = excelData.parseStatus(data.getStatus()); - - if (StringUtils.equalsAnyIgnoreCase(data.getStatus(), "Trash")) { - try { - JSONArray arr = JSONArray.parseArray(data.getCustomFields()); - JSONArray newArr = new JSONArray(); - for (int i = 0; i < arr.size(); i++) { - JSONObject obj = arr.getJSONObject(i); - if (obj.containsKey("name") && obj.containsKey("value")) { - String name = obj.getString("name"); - if (StringUtils.equalsAny(name, "用例状态", "用例狀態", "Case status")) { - obj.put("value", dataStatus); - } - } - newArr.add(obj); - } - data.setCustomFields(newArr.toJSONString()); - } catch (Exception e) { + List testCaseDTOList = extTestCaseMapper.getLastExecStatusByIdList(testCaseIdList); + Map testCaseStatusMap = new HashMap<>(); + testCaseDTOList.forEach(item -> { + testCaseStatusMap.put(item.getId(), item.getStatus()); + }); + for (TestCaseDTO data : returnList) { + String lastStatus = testCaseStatusMap.get(data.getId()); + if (StringUtils.isNotEmpty(lastStatus)) { + data.setLastExecuteResult(lastStatus); + } else { + data.setLastExecuteResult(null); } + String dataStatus = excelData.parseStatus(data.getStatus()); + if (StringUtils.equalsAnyIgnoreCase(data.getStatus(), "Trash")) { + try { + JSONArray arr = JSONArray.parseArray(data.getCustomFields()); + JSONArray newArr = new JSONArray(); + for (int i = 0; i < arr.size(); i++) { + JSONObject obj = arr.getJSONObject(i); + if (obj.containsKey("name") && obj.containsKey("value")) { + String name = obj.getString("name"); + if (StringUtils.equalsAny(name, "用例状态", "用例狀態", "Case status")) { + obj.put("value", dataStatus); + } + } + newArr.add(obj); + } + data.setCustomFields(newArr.toJSONString()); + } catch (Exception e) { + LogUtil.error("Parse case exec status error:" + e.getMessage()); + } + } + data.setStatus(dataStatus); } - - data.setStatus(dataStatus); } return returnList; }