feat(测试计划): 接口用例批量更新执行人
This commit is contained in:
parent
4e4266972a
commit
dc8d772658
|
@ -4,15 +4,19 @@ import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||||
|
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
||||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||||
|
import io.metersphere.plan.service.TestPlanApiCaseLogService;
|
||||||
import io.metersphere.plan.service.TestPlanApiCaseService;
|
import io.metersphere.plan.service.TestPlanApiCaseService;
|
||||||
import io.metersphere.plan.service.TestPlanService;
|
import io.metersphere.plan.service.TestPlanService;
|
||||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
import io.metersphere.system.dto.LogInsertModule;
|
import io.metersphere.system.dto.LogInsertModule;
|
||||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||||
|
import io.metersphere.system.log.annotation.Log;
|
||||||
|
import io.metersphere.system.log.constants.OperationLogType;
|
||||||
import io.metersphere.system.security.CheckOwner;
|
import io.metersphere.system.security.CheckOwner;
|
||||||
import io.metersphere.system.utils.PageUtils;
|
import io.metersphere.system.utils.PageUtils;
|
||||||
import io.metersphere.system.utils.Pager;
|
import io.metersphere.system.utils.Pager;
|
||||||
|
@ -79,6 +83,15 @@ public class TestPlanApiCaseController {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/batch/update/executor")
|
||||||
|
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
|
||||||
|
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
|
||||||
|
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||||
|
@Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiCaseLogService.class)
|
||||||
|
public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiCaseUpdateRequest request) {
|
||||||
|
testPlanApiCaseService.batchUpdateExecutor(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO 计划集 type
|
//TODO 计划集 type
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class TestPlanFunctionalCaseController {
|
||||||
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
|
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
|
||||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
|
||||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||||
@Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanCaseLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanCaseLogService.class)
|
||||||
public void batchUpdateExecutor(@Validated @RequestBody TestPlanCaseUpdateRequest request) {
|
public void batchUpdateExecutor(@Validated @RequestBody TestPlanCaseUpdateRequest request) {
|
||||||
testPlanFunctionalCaseService.batchUpdateExecutor(request);
|
testPlanFunctionalCaseService.batchUpdateExecutor(request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package io.metersphere.plan.dto.request;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wx
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TestPlanApiCaseUpdateRequest extends BasePlanCaseBatchRequest {
|
||||||
|
|
||||||
|
@Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank(message = "{test_plan.user_id.not_blank}")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "{api_definition.protocol.not_blank}")
|
||||||
|
private List<String> protocols;
|
||||||
|
}
|
|
@ -49,5 +49,7 @@ public interface ExtTestPlanApiCaseMapper {
|
||||||
|
|
||||||
List<ApiCaseModuleDTO> selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId);
|
List<ApiCaseModuleDTO> selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId);
|
||||||
|
|
||||||
List<String> getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted);
|
List<String> getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted, @Param("protocols") List<String> protocols);
|
||||||
|
|
||||||
|
void batchUpdateExecutor(@Param("ids") List<String> ids, @Param("userId") String userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -599,11 +599,11 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<sql id="queryWhereConditionByBatchQueryRequest">
|
<sql id="queryWhereConditionByBatchQueryRequest">
|
||||||
<if test="request.protocol != null and request.protocol!=''">
|
<if test="protocols != null and protocols.size() > 0">
|
||||||
and a.protocol = #{request.protocol}
|
and a.protocol in
|
||||||
</if>
|
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
|
||||||
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
|
#{protocol}
|
||||||
and atc.api_definition_id = #{request.apiDefinitionId}
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
<if test="request.condition.keyword != null and request.condition.keyword !=''">
|
<if test="request.condition.keyword != null and request.condition.keyword !=''">
|
||||||
and (
|
and (
|
||||||
|
@ -630,4 +630,14 @@
|
||||||
</include>
|
</include>
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<update id="batchUpdateExecutor">
|
||||||
|
update test_plan_api_case
|
||||||
|
set execute_user = #{userId}
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -0,0 +1,71 @@
|
||||||
|
package io.metersphere.plan.service;
|
||||||
|
|
||||||
|
import io.metersphere.api.domain.ApiTestCase;
|
||||||
|
import io.metersphere.api.domain.ApiTestCaseExample;
|
||||||
|
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||||
|
import io.metersphere.plan.domain.TestPlanApiCase;
|
||||||
|
import io.metersphere.plan.domain.TestPlanApiCaseExample;
|
||||||
|
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||||
|
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
|
||||||
|
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||||
|
import io.metersphere.sdk.util.JSON;
|
||||||
|
import io.metersphere.system.log.constants.OperationLogModule;
|
||||||
|
import io.metersphere.system.log.constants.OperationLogType;
|
||||||
|
import io.metersphere.system.log.dto.LogDTO;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class TestPlanApiCaseLogService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestPlanApiCaseService testPlanApiCaseService;
|
||||||
|
@Resource
|
||||||
|
private TestPlanApiCaseMapper testPlanApiCaseMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseMapper apiTestCaseMapper;
|
||||||
|
|
||||||
|
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
|
||||||
|
List<String> ids = testPlanApiCaseService.doSelectIds(request, request.getProtocols());
|
||||||
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
|
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||||
|
example.createCriteria().andIdIn(ids);
|
||||||
|
List<TestPlanApiCase> planCaseList = testPlanApiCaseMapper.selectByExample(example);
|
||||||
|
Map<String, String> userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getExecuteUser));
|
||||||
|
Map<String, String> idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanApiCase::getId, TestPlanApiCase::getApiCaseId));
|
||||||
|
List<String> caseIds = planCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
|
||||||
|
ApiTestCaseExample caseExample = new ApiTestCaseExample();
|
||||||
|
caseExample.createCriteria().andIdIn(caseIds);
|
||||||
|
List<ApiTestCase> functionalCases = apiTestCaseMapper.selectByExample(caseExample);
|
||||||
|
Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(ApiTestCase::getId, ApiTestCase::getName));
|
||||||
|
List<LogDTO> dtoList = new ArrayList<>();
|
||||||
|
idsMap.forEach((k, v) -> {
|
||||||
|
LogDTO dto = new LogDTO(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
k,
|
||||||
|
null,
|
||||||
|
OperationLogType.UPDATE.name(),
|
||||||
|
OperationLogModule.TEST_PLAN,
|
||||||
|
caseMap.get(v));
|
||||||
|
dto.setPath("/test-plan/api/case/batch/update/executor");
|
||||||
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
|
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k)));
|
||||||
|
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId()));
|
||||||
|
dtoList.add(dto);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||||
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
|
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
|
||||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||||
|
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
||||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||||
|
@ -324,12 +325,11 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TestPlanAssociationResponse disassociate(BasePlanCaseBatchRequest request, LogInsertModule logInsertModule) {
|
public TestPlanAssociationResponse disassociate(BasePlanCaseBatchRequest request, LogInsertModule logInsertModule) {
|
||||||
List<String> selectIds = doSelectIds(request);
|
|
||||||
return super.disassociate(
|
return super.disassociate(
|
||||||
TestPlanResourceConstants.RESOURCE_API_CASE,
|
TestPlanResourceConstants.RESOURCE_API_CASE,
|
||||||
request,
|
request,
|
||||||
logInsertModule,
|
logInsertModule,
|
||||||
selectIds,
|
request.getSelectIds(),
|
||||||
this::deleteTestPlanResource);
|
this::deleteTestPlanResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,9 +341,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> doSelectIds(BasePlanCaseBatchRequest request) {
|
public List<String> doSelectIds(BasePlanCaseBatchRequest request, List<String> protocols) {
|
||||||
if (request.isSelectAll()) {
|
if (request.isSelectAll()) {
|
||||||
List<String> ids = extTestPlanApiCaseMapper.getIds(request, false);
|
List<String> ids = extTestPlanApiCaseMapper.getIds(request, false, protocols);
|
||||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||||
ids.removeAll(request.getExcludeIds());
|
ids.removeAll(request.getExcludeIds());
|
||||||
}
|
}
|
||||||
|
@ -352,4 +352,17 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
return request.getSelectIds();
|
return request.getSelectIds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新执行人
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
*/
|
||||||
|
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
|
||||||
|
List<String> ids = doSelectIds(request, request.getProtocols());
|
||||||
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
|
extTestPlanApiCaseMapper.batchUpdateExecutor(ids, request.getUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class TestPlanCaseLogService {
|
||||||
OperationLogType.UPDATE.name(),
|
OperationLogType.UPDATE.name(),
|
||||||
OperationLogModule.TEST_PLAN,
|
OperationLogModule.TEST_PLAN,
|
||||||
caseMap.get(v));
|
caseMap.get(v));
|
||||||
dto.setPath("/test-plan/functional/case/batch/update/executer");
|
dto.setPath("/test-plan/functional/case/batch/update/executor");
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k)));
|
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k)));
|
||||||
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId()));
|
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId()));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.plan.controller;
|
package io.metersphere.plan.controller;
|
||||||
|
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||||
|
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.base.BaseTest;
|
import io.metersphere.system.base.BaseTest;
|
||||||
|
@ -14,6 +15,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
|
@ -24,6 +26,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
||||||
public static final String API_CASE_TREE_COUNT = "/test-plan/api/case/module/count";
|
public static final String API_CASE_TREE_COUNT = "/test-plan/api/case/module/count";
|
||||||
public static final String API_CASE_TREE_MODULE_TREE = "/test-plan/api/case/tree/";
|
public static final String API_CASE_TREE_MODULE_TREE = "/test-plan/api/case/tree/";
|
||||||
public static final String API_CASE_DISASSOCIATE = "/test-plan/api/case/disassociate";
|
public static final String API_CASE_DISASSOCIATE = "/test-plan/api/case/disassociate";
|
||||||
|
public static final String API_CASE_BATCH_UPDATE_EXECUTOR_URL = "/test-plan/api/case/batch/update/executor";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
|
@ -86,4 +89,19 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
||||||
Assertions.assertNotNull(resultHolder);
|
Assertions.assertNotNull(resultHolder);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(5)
|
||||||
|
public void testBatchUpdateExecutor() throws Exception {
|
||||||
|
TestPlanApiCaseUpdateRequest request = new TestPlanApiCaseUpdateRequest();
|
||||||
|
request.setUserId("test_user");
|
||||||
|
request.setTestPlanId("wxxx_2");
|
||||||
|
request.setSelectAll(true);
|
||||||
|
request.setProtocols(List.of("HTTP"));
|
||||||
|
this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||||
|
request.setTestPlanId("wxxx_1");
|
||||||
|
request.setSelectAll(false);
|
||||||
|
request.setSelectIds(List.of("wxxx_1"));
|
||||||
|
this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue