feat(任务中心): 系统任务中心列表查询初版
This commit is contained in:
parent
a498986752
commit
df5a657b9c
|
@ -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<List<TaskHubDTO>> projectList(@Validated @RequestBody BasePageRequest request) {
|
||||
return baseTaskHubService.getTaskList(request);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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<TaskHubDTO> selectList(@Param("request") BasePageRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.system.mapper.ExtExecTaskMapper">
|
||||
<select id="selectList" resultType="io.metersphere.system.dto.taskhub.TaskHubDTO">
|
||||
SELECT *
|
||||
FROM exec_task
|
||||
<where>
|
||||
<if test="request.keyword != null and request.keyword != ''">
|
||||
and (
|
||||
exec_task.num like concat('%', #{request.keyword},'%')
|
||||
or exec_task.task_name like concat('%', #{request.keyword},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="orgId != null">
|
||||
and exec_task.organization_id = #{orgId}
|
||||
</if>
|
||||
<if test="projectId != null">
|
||||
and exec_task.projectId = #{projectId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -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<List<TaskHubDTO>> getTaskList(BasePageRequest request) {
|
||||
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));
|
||||
}
|
||||
|
||||
private List<TaskHubDTO> getPage(BasePageRequest request, String orgId, String projectId) {
|
||||
return extExecTaskMapper.selectList(request, orgId, projectId);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue