diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java new file mode 100644 index 0000000000..87d4a5869d --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java @@ -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.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("/system/task-center") +public class SystemTaskHubController { + + @Resource + private BaseTaskHubService baseTaskHubService; + + @PostMapping("/exec-task/page") + @Operation(summary = "系统-任务中心-执行任务列表") + @RequiresPermissions(PermissionConstants.SYSTEM_TASK_CENTER_READ) + public Pager> projectList(@Validated @RequestBody BasePageRequest request) { + return baseTaskHubService.getTaskList(request); + } + +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java new file mode 100644 index 0000000000..07d9ed13be --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java @@ -0,0 +1,24 @@ +package io.metersphere.system.dto.taskhub; + +import io.metersphere.system.domain.ExecTask; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @author: LAN + * @date: 2024/1/17 11:20 + * @version: 1.0 + */ +@Data +public class TaskHubDTO extends ExecTask { + + @Schema(description = "所属组织") + private String organizationName; + + @Schema(description = "所属项目") + private String projectName; + + @Schema(description = "操作人名称") + private String createUserName; + +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java new file mode 100644 index 0000000000..7f280191cd --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java @@ -0,0 +1,14 @@ +package io.metersphere.system.mapper; + +import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.taskhub.TaskHubDTO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author wx + */ +public interface ExtExecTaskMapper { + List selectList(@Param("request") BasePageRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId); +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml new file mode 100644 index 0000000000..767e7ca5dc --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java new file mode 100644 index 0000000000..b3174eb20a --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -0,0 +1,45 @@ +package io.metersphere.system.service; + +import com.github.pagehelper.Page; +import com.github.pagehelper.page.PageMethod; +import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.taskhub.TaskHubDTO; +import io.metersphere.system.mapper.ExtExecTaskMapper; +import io.metersphere.system.utils.PageUtils; +import io.metersphere.system.utils.Pager; +import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @author wx + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class BaseTaskHubService { + + @Resource + private ExtExecTaskMapper extExecTaskMapper; + + + /** + * 系统-获取执行任务列表 + * + * @param request + * @return + */ + public Pager> getTaskList(BasePageRequest request) { + Page page = PageMethod.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); + return PageUtils.setPageInfo(page, getPage(request, null, null)); + } + + private List getPage(BasePageRequest request, String orgId, String projectId) { + return extExecTaskMapper.selectList(request, orgId, projectId); + } + + +} diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java new file mode 100644 index 0000000000..b702f3e5b1 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java @@ -0,0 +1,35 @@ +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); + } +}