From df5a657b9c9d0f0e79998fe933eb73cc04a24082 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 30 Sep 2024 11:42:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SystemTaskHubController.java | 35 +++++++++++++++ .../system/dto/taskhub/TaskHubDTO.java | 24 ++++++++++ .../system/mapper/ExtExecTaskMapper.java | 14 ++++++ .../system/mapper/ExtExecTaskMapper.xml | 23 ++++++++++ .../system/service/BaseTaskHubService.java | 45 +++++++++++++++++++ .../SystemTaskHubControllerTests.java | 35 +++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java create mode 100644 backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java 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); + } +}