feat(任务中心): 任务详情查看结果-用例

This commit is contained in:
WangXu10 2024-10-21 17:33:34 +08:00 committed by Craftsman
parent 18f09585d5
commit cd8962225a
8 changed files with 95 additions and 5 deletions

View File

@ -133,4 +133,12 @@ public class ApiReportController {
public void batchExportLog(@Validated @RequestBody ApiReportBatchRequest request) { public void batchExportLog(@Validated @RequestBody ApiReportBatchRequest request) {
apiReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId()); apiReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
} }
@GetMapping("/task-report/{id}")
@Operation(summary = "系统-任务中心-场景用例执行任务详情-查看")
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
public List<ApiReportDetailDTO> viewCaseItemReport(@PathVariable String id) {
return apiReportService.viewCaseTaskItemReport(id);
}
} }

View File

@ -15,8 +15,10 @@ import io.metersphere.sdk.mapper.EnvironmentMapper;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
import io.metersphere.system.mapper.ExtExecTaskMapper;
import io.metersphere.system.mapper.TestResourcePoolMapper; import io.metersphere.system.mapper.TestResourcePoolMapper;
import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
@ -67,6 +69,10 @@ public class ApiReportService {
private ApiReportNoticeService apiReportNoticeService; private ApiReportNoticeService apiReportNoticeService;
@Resource @Resource
private ApiReportRelateTaskMapper apiReportRelateTaskMapper; private ApiReportRelateTaskMapper apiReportRelateTaskMapper;
@Resource
private ApiReportStepMapper apiReportStepMapper;
@Resource
private ExtExecTaskMapper extExecTaskMapper;
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public void insertApiReport(ApiReport report) { public void insertApiReport(ApiReport report) {
@ -312,4 +318,45 @@ public class ApiReportService {
apiReportLogService.exportLog(reports, userId, projectId, "/api/report/case/batch-export"); apiReportLogService.exportLog(reports, userId, projectId, "/api/report/case/batch-export");
} }
} }
public List<ApiReportDetailDTO> viewCaseTaskItemReport(String id) {
List<ExecTask> taskList = extExecTaskMapper.selectTypeByItemId(id);
if (CollectionUtils.isNotEmpty(taskList)) {
if (taskList.getFirst().getIntegrated()) {
//集合报告 TODO
return new ArrayList<>();
} else {
//非集合报告
return reportDetail(id);
}
}
return new ArrayList<>();
}
private List<ApiReportDetailDTO> reportDetail(String id) {
List<ApiReportDetailDTO> list = new ArrayList<>();
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andTaskResourceIdEqualTo(id);
List<ApiReportRelateTask> apiReportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(apiReportRelateTasks)) {
//报告id
String reportId = apiReportRelateTasks.getFirst().getReportId();
//获取步骤id
String stepId = getStepId(reportId);
list = getDetail(reportId, stepId);
}
return list;
}
private String getStepId(String reportId) {
ApiReportStepExample example = new ApiReportStepExample();
example.createCriteria().andReportIdEqualTo(reportId);
List<ApiReportStep> apiReportSteps = apiReportStepMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(apiReportSteps)) {
return apiReportSteps.getFirst().getStepId();
}
return null;
}
} }

View File

@ -27,6 +27,7 @@ import io.metersphere.sdk.mapper.ShareInfoMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.domain.TestResourcePoolExample; import io.metersphere.system.domain.TestResourcePoolExample;
import io.metersphere.system.mapper.TestResourcePoolMapper; import io.metersphere.system.mapper.TestResourcePoolMapper;
@ -37,6 +38,8 @@ import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@ -83,6 +86,7 @@ public class ApiReportControllerTests extends BaseTest {
private static final String DETAIL = BASIC + "/get/detail/"; private static final String DETAIL = BASIC + "/get/detail/";
private static final String EXPORT_REPORT = BASIC + "/export/{0}"; private static final String EXPORT_REPORT = BASIC + "/export/{0}";
private static final String BATCH_EXPORT_REPORT = BASIC + "/batch-export"; private static final String BATCH_EXPORT_REPORT = BASIC + "/batch-export";
private static final String TASK_REPORT = BASIC + "/task-report/{0}";
@Test @Test
@ -506,4 +510,11 @@ public class ApiReportControllerTests extends BaseTest {
request.setSelectAll(true); request.setSelectAll(true);
this.requestPost(BATCH_EXPORT_REPORT, request); this.requestPost(BATCH_EXPORT_REPORT, request);
} }
@Test
@Order(7)
@Sql(scripts = {"/dml/init_task_item_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void getTaskReport() throws Exception {
this.requestGet(TASK_REPORT, "1");
}
} }

View File

@ -0,0 +1,16 @@
INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `result`, `task_type`, `trigger_mode`, `project_id`, `organization_id`, `create_time`, `create_user`, `start_time`, `end_time`, `integrated`)
VALUES
('1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'),
('2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'),
('3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'),
('4', 4, '删除任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0');
INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`)
VALUES
('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'),
('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin');
INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) VALUES ('1', 'test-report-id');

View File

@ -114,7 +114,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
@Test @Test
@Order(4) @Order(5)
public void getProStatistics() throws Exception { public void getProStatistics() throws Exception {
List<String> ids = List.of("pro_1", "pro_2"); List<String> ids = List.of("pro_1", "pro_2");
MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_STATISTICS, ids); MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_STATISTICS, ids);
@ -219,7 +219,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
@Test @Test
@Order(4) @Order(5)
public void projectTaskItemBatchStop() throws Exception { public void projectTaskItemBatchStop() throws Exception {
mockPost("/api/task/item/stop", ""); mockPost("/api/task/item/stop", "");
TaskHubItemBatchRequest request = new TaskHubItemBatchRequest(); TaskHubItemBatchRequest request = new TaskHubItemBatchRequest();

View File

@ -1,5 +1,6 @@
package io.metersphere.system.mapper; package io.metersphere.system.mapper;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.TaskHubDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO;
@ -26,4 +27,6 @@ public interface ExtExecTaskMapper {
* @return 任务ID列表 * @return 任务ID列表
*/ */
List<String> getTaskIdsByTime(@Param("timeMills") long timeMills, @Param("projectId") String projectId); List<String> getTaskIdsByTime(@Param("timeMills") long timeMills, @Param("projectId") String projectId);
List<ExecTask> selectTypeByItemId(@Param("itemId") String itemId);
} }

View File

@ -118,4 +118,9 @@
<select id="getTaskIdsByTime" resultType="java.lang.String"> <select id="getTaskIdsByTime" resultType="java.lang.String">
select id from exec_task where project_id = #{projectId} and start_time &lt;= #{timeMills} select id from exec_task where project_id = #{projectId} and start_time &lt;= #{timeMills}
</select> </select>
<select id="selectTypeByItemId" resultType="io.metersphere.system.domain.ExecTask">
select integrated from exec_task inner join exec_task_item on exec_task.id = exec_task_item.task_id where exec_task_item.id = #{itemId}
</select>
</mapper> </mapper>

View File

@ -191,7 +191,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
* 系统任务项停止 * 系统任务项停止
*/ */
@Test @Test
@Order(4) @Order(5)
public void systemTaskItemStop() throws Exception { public void systemTaskItemStop() throws Exception {
mockPost("/api/task/item/stop", ""); mockPost("/api/task/item/stop", "");
this.requestGet(SYSTEM_TASK_ITEM_STOP + "1"); this.requestGet(SYSTEM_TASK_ITEM_STOP + "1");
@ -200,7 +200,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
} }
@Test @Test
@Order(4) @Order(5)
public void systemGetTaskItemOrder() throws Exception { public void systemGetTaskItemOrder() throws Exception {
MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_ITEM_ORDER, List.of("1")); MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_ITEM_ORDER, List.of("1"));
HashMap resultData = getResultData(mvcResult, HashMap.class); HashMap resultData = getResultData(mvcResult, HashMap.class);
@ -392,7 +392,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
} }
@Test @Test
@Order(4) @Order(5)
public void getOrgStatistics() throws Exception { public void getOrgStatistics() throws Exception {
List<String> ids = List.of("1", "2"); List<String> ids = List.of("1", "2");
MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids); MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids);