diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index cb9f1f61f9..cc39c78407 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -74,17 +74,6 @@ public class ApiDefinitionExecResultService { saveResult.setName(item.getName()); saveResult.setTriggerMode(triggerMode); saveResult.setType(type); - if (!StringUtils.equals(type, ApiRunMode.API_PLAN.name())) { - ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(item.getName()); - if (apiDefinition != null) { - saveResult.setName(apiDefinition.getName()); - } else { - ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(item.getName()); - if (caseWithBLOBs != null) { - saveResult.setName(caseWithBLOBs.getName()); - } - } - } if (StringUtils.isNotEmpty(result.getUserId())) { saveResult.setUserId(result.getUserId()); } else { @@ -92,34 +81,14 @@ public class ApiDefinitionExecResultService { } saved = false; } + String status = item.isSuccess() ? "success" : "error"; + saveResult.setName(getName(type, item.getName(), status, saveResult.getCreateTime())); + saveResult.setStatus(status); saveResult.setCreateTime(item.getStartTime()); - if (item.getName().indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) { - saveResult.setName(item.getName().substring(0, item.getName().indexOf(DelimiterConstants.SEPARATOR.toString()))); - } saveResult.setResourceId(item.getName()); saveResult.setContent(JSON.toJSONString(item)); saveResult.setStartTime(item.getStartTime()); - String status = item.isSuccess() ? "success" : "error"; saveResult.setEndTime(item.getResponseResult().getResponseTime()); - saveResult.setStatus(status); - if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) { - TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(item.getName()); - String id = null; - if (testPlanApiCase != null) { - testPlanApiCaseService.setExecResult(item.getName(), status, item.getStartTime()); - id = testPlanApiCase.getApiCaseId(); - } - TestCaseReviewApiCase testCaseReviewApiCase = testCaseReviewApiCaseMapper.selectByPrimaryKey(item.getName()); - if (testCaseReviewApiCase != null) { - testCaseReviewApiCaseService.setExecResult(item.getName(), status, item.getStartTime()); - id = testCaseReviewApiCase.getApiCaseId(); - } - ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(id); - if (caseWithBLOBs != null) { - saveResult.setName(caseWithBLOBs.getName()); - saveResult.setResourceId(id); - } - } // 清空上次执行结果的内容,只保留当前最新一条内容 ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), type); @@ -145,6 +114,39 @@ public class ApiDefinitionExecResultService { } } + private String getName(String type, String id, String status, Long time) { + if (id.indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) { + return id.substring(0, id.indexOf(DelimiterConstants.SEPARATOR.toString())); + } + if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) { + TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(id); + ApiTestCaseWithBLOBs caseWithBLOBs = null; + if (testPlanApiCase != null) { + testPlanApiCaseService.setExecResult(id, status, time); + caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testPlanApiCase.getApiCaseId()); + } + TestCaseReviewApiCase testCaseReviewApiCase = testCaseReviewApiCaseMapper.selectByPrimaryKey(id); + if (testCaseReviewApiCase != null) { + testCaseReviewApiCaseService.setExecResult(id, status, time); + caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testCaseReviewApiCase.getApiCaseId()); + } + if (caseWithBLOBs != null) { + return caseWithBLOBs.getName(); + } + } else { + ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id); + if (apiDefinition != null) { + return apiDefinition.getName(); + } else { + ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(id); + if (caseWithBLOBs != null) { + return caseWithBLOBs.getName(); + } + } + } + return id; + } + /** * 定时任务触发的保存逻辑 * 定时任务时,userID要改为定时任务中的用户 diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml index f71d943de0..4e24d35fb0 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml @@ -16,9 +16,11 @@ ) UNION ALL (select t.id,t.name,'API' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, ifnull(t.trigger_mode,'MANUAL') as triggerMode ,ifnull(t.status,'Saved') as executionStatus - from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id - left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id - where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId}) + from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id + left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id + left join test_plan_api_case t5 on t.resource_id = t5.id left join test_plan t6 on t5.test_plan_id = t6.id + where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and + (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId} OR t6.project_id = #{request.projectId}) and t.trigger_mode = #{request.triggerMode} @@ -51,7 +53,8 @@ (select t.id,t.create_time as executionTime from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id - where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId}) and t.status not in ("saved","completed","success","error") + left join test_plan_api_case t5 on t.resource_id = t5.id left join test_plan t6 on t5.test_plan_id = t6.id + where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId} OR t6.project_id = #{request.projectId}) and t.status not in ("saved","completed","success","error") ) UNION ALL (select t.id,t.create_time as executionTime diff --git a/backend/src/main/java/io/metersphere/task/service/TaskService.java b/backend/src/main/java/io/metersphere/task/service/TaskService.java index e870c17cc1..7618f8cfb0 100644 --- a/backend/src/main/java/io/metersphere/task/service/TaskService.java +++ b/backend/src/main/java/io/metersphere/task/service/TaskService.java @@ -3,9 +3,11 @@ package io.metersphere.task.service; import io.metersphere.base.mapper.ext.ExtTaskMapper; import io.metersphere.task.dto.TaskCenterDTO; import io.metersphere.task.dto.TaskCenterRequest; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; @Service @@ -14,10 +16,16 @@ public class TaskService { private ExtTaskMapper extTaskMapper; public List getTasks(TaskCenterRequest request) { + if (StringUtils.isEmpty(request.getProjectId())) { + return new ArrayList<>(); + } return extTaskMapper.getTasks(request); } public List getRunningTasks(TaskCenterRequest request) { + if (StringUtils.isEmpty(request.getProjectId())) { + return new ArrayList<>(); + } return extTaskMapper.getRunningTasks(request); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java index 31de746f55..a8845dc7a7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -271,7 +271,7 @@ public class TestPlanApiCaseService { if (element.getString("type").equals("HTTPSamplerProxy")) { MsHTTPSamplerProxy httpSamplerProxy = JSON.parseObject(api, MsHTTPSamplerProxy.class); httpSamplerProxy.setHashTree(list); - httpSamplerProxy.setName(caseWithBLOBs.getId()); + httpSamplerProxy.setName(planId); httpSamplerProxy.setUseEnvironment(apiCase.getEnvironmentId()); return httpSamplerProxy; } @@ -279,21 +279,21 @@ public class TestPlanApiCaseService { MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class); msTCPSampler.setUseEnvironment(apiCase.getEnvironmentId()); msTCPSampler.setHashTree(list); - msTCPSampler.setName(caseWithBLOBs.getId()); + msTCPSampler.setName(planId); return msTCPSampler; } if (element.getString("type").equals("DubboSampler")) { MsDubboSampler dubboSampler = JSON.parseObject(api, MsDubboSampler.class); dubboSampler.setUseEnvironment(apiCase.getEnvironmentId()); dubboSampler.setHashTree(list); - dubboSampler.setName(caseWithBLOBs.getId()); + dubboSampler.setName(planId); return dubboSampler; } if (element.getString("type").equals("JDBCSampler")) { MsJDBCSampler jDBCSampler = JSON.parseObject(api, MsJDBCSampler.class); jDBCSampler.setUseEnvironment(apiCase.getEnvironmentId()); jDBCSampler.setHashTree(list); - jDBCSampler.setName(caseWithBLOBs.getId()); + jDBCSampler.setName(planId); return jDBCSampler; } } catch (Exception e) {