fix(测试跟踪): 修复接口用例为空时表格数据加载报错的问题

修复接口用例为空时表格数据加载报错的问题
This commit is contained in:
song-tianyang 2022-04-04 18:31:12 +08:00 committed by 刘瑞斌
parent 4098c3ab54
commit ed37d3e21a
1 changed files with 38 additions and 38 deletions

View File

@ -648,48 +648,48 @@ public class TestCaseService {
}
private List<TestCaseDTO> parseStatus(List<TestCaseDTO> returnList) {
TestCaseExcelData excelData = new TestCaseExcelDataFactory().getTestCaseExcelDataLocal();
List<String> testCaseIdList = new ArrayList<>();
returnList.forEach(item -> {
testCaseIdList.add(item.getId());
});
if (CollectionUtils.isNotEmpty(returnList)) {
TestCaseExcelData excelData = new TestCaseExcelDataFactory().getTestCaseExcelDataLocal();
List<String> testCaseIdList = new ArrayList<>();
returnList.forEach(item -> {
testCaseIdList.add(item.getId());
});
List<TestCaseDTO> testCaseDTOList = extTestCaseMapper.getLastExecStatusByIdList(testCaseIdList);
Map<String, String> 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<TestCaseDTO> testCaseDTOList = extTestCaseMapper.getLastExecStatusByIdList(testCaseIdList);
Map<String, String> 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;
}