feat(任务中心): 组织任务中心列表查询&项目任务中心列表查询初版
This commit is contained in:
parent
1c0583fe21
commit
c07dc55252
|
@ -0,0 +1,32 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.metersphere.system.dto.taskhub.TaskHubDTO;
|
||||
import io.metersphere.system.service.BaseTaskHubService;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "项目任务中心")
|
||||
@RestController
|
||||
@RequestMapping("/project/task-center")
|
||||
public class ProjectTaskHubController {
|
||||
|
||||
@Resource
|
||||
private BaseTaskHubService baseTaskHubService;
|
||||
|
||||
@PostMapping("/exec-task/page")
|
||||
@Operation(summary = "项目-任务中心-执行任务列表")
|
||||
public Pager<List<TaskHubDTO>> projectList(@Validated @RequestBody BasePageRequest request) {
|
||||
return baseTaskHubService.getTaskList(request, null, SessionUtils.getCurrentProjectId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ProjectTaskHubControllerTests extends BaseTest {
|
||||
/**
|
||||
* 项目任务中心测试用例
|
||||
*/
|
||||
public static final String PROJECT_TASK_PAGE = "/project/task-center/exec-task/page";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Sql(scripts = {"/dml/init_project_exec_task_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void getProjectTaskPage() throws Exception {
|
||||
BasePageRequest request = new BasePageRequest();
|
||||
this.requestPost(PROJECT_TASK_PAGE, request);
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_TASK_PAGE, request);
|
||||
// 获取返回值
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
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`)
|
||||
VALUES
|
||||
('pro_1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639),
|
||||
('pro_2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639),
|
||||
('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639);
|
|
@ -0,0 +1,35 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.metersphere.system.dto.taskhub.TaskHubDTO;
|
||||
import io.metersphere.system.service.BaseTaskHubService;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "组织任务中心")
|
||||
@RestController
|
||||
@RequestMapping("/organization/task-center")
|
||||
public class OrganizationTaskHubController {
|
||||
|
||||
@Resource
|
||||
private BaseTaskHubService baseTaskHubService;
|
||||
|
||||
@PostMapping("/exec-task/page")
|
||||
@Operation(summary = "组织-任务中心-执行任务列表")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_TASK_CENTER_READ)
|
||||
public Pager<List<TaskHubDTO>> projectList(@Validated @RequestBody BasePageRequest request) {
|
||||
return baseTaskHubService.getTaskList(request, SessionUtils.getCurrentOrganizationId(), null);
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ public class SystemTaskHubController {
|
|||
@Operation(summary = "系统-任务中心-执行任务列表")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TASK_CENTER_READ)
|
||||
public Pager<List<TaskHubDTO>> projectList(@Validated @RequestBody BasePageRequest request) {
|
||||
return baseTaskHubService.getTaskList(request);
|
||||
return baseTaskHubService.getTaskList(request, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
and exec_task.organization_id = #{orgId}
|
||||
</if>
|
||||
<if test="projectId != null">
|
||||
and exec_task.projectId = #{projectId}
|
||||
and exec_task.project_id = #{projectId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
|
|
@ -29,12 +29,14 @@ public class BaseTaskHubService {
|
|||
* 系统-获取执行任务列表
|
||||
*
|
||||
* @param request
|
||||
* @param orgId
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
public Pager<List<TaskHubDTO>> getTaskList(BasePageRequest request) {
|
||||
public Pager<List<TaskHubDTO>> getTaskList(BasePageRequest request, String orgId, String projectId) {
|
||||
Page<Object> page = PageMethod.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc");
|
||||
return PageUtils.setPageInfo(page, getPage(request, null, null));
|
||||
return PageUtils.setPageInfo(page, getPage(request, orgId, projectId));
|
||||
}
|
||||
|
||||
private List<TaskHubDTO> getPage(BasePageRequest request, String orgId, String projectId) {
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class BaseTaskHubControllerTests extends BaseTest {
|
||||
|
||||
/**
|
||||
* 系统任务中心测试用例
|
||||
*/
|
||||
public static final String SYSTEM_TASK_PAGE = "/system/task-center/exec-task/page";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Sql(scripts = {"/dml/init_exec_task_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void getSystemTaskPage() throws Exception {
|
||||
BasePageRequest request = new BasePageRequest();
|
||||
this.requestPost(SYSTEM_TASK_PAGE, request);
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_PAGE, request);
|
||||
// 获取返回值
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 组织任务中心测试用例
|
||||
*/
|
||||
public static final String ORG_TASK_PAGE = "/organization/task-center/exec-task/page";
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void getOrgTaskPage() throws Exception {
|
||||
BasePageRequest request = new BasePageRequest();
|
||||
this.requestPost(ORG_TASK_PAGE, request);
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_TASK_PAGE, request);
|
||||
// 获取返回值
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class SystemTaskHubControllerTests extends BaseTest {
|
||||
|
||||
public static final String TASK_PAGE = "/system/task-center/exec-task/page";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void getTaskPage() throws Exception {
|
||||
BasePageRequest request = new BasePageRequest();
|
||||
this.requestPost(TASK_PAGE, request);
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(TASK_PAGE, request);
|
||||
// 获取返回值
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
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`)
|
||||
VALUES
|
||||
('1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639),
|
||||
('2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639),
|
||||
('3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639);
|
Loading…
Reference in New Issue