feat(测试计划): 批量更新执行人
This commit is contained in:
parent
635d92fad0
commit
3e2dd15f82
|
@ -5,14 +5,14 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.plan.dto.request.*;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse;
|
||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||
import io.metersphere.plan.service.TestPlanApiScenarioBatchRunService;
|
||||
import io.metersphere.plan.service.TestPlanApiScenarioService;
|
||||
import io.metersphere.plan.service.TestPlanService;
|
||||
import io.metersphere.plan.service.*;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
|
||||
import io.metersphere.system.dto.LogInsertModule;
|
||||
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.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
|
@ -105,4 +105,13 @@ public class TestPlanApiScenarioController {
|
|||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||
return response;
|
||||
}
|
||||
|
||||
@PostMapping("/batch/update/executor")
|
||||
@Operation(summary = "测试计划-计划详情-场景用例列表-批量更新执行人")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiScenarioLogService.class)
|
||||
public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiScenarioUpdateRequest request) {
|
||||
testPlanApiScenarioService.batchUpdateExecutor(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.plan.dto.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Data
|
||||
public class TestPlanApiScenarioUpdateRequest extends BasePlanCaseBatchRequest {
|
||||
|
||||
@Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan.user_id.not_blank}")
|
||||
private String userId;
|
||||
}
|
|
@ -684,7 +684,8 @@
|
|||
<select id="selectApiCaseByDefinitionIds" resultType="io.metersphere.api.domain.ApiTestCase">
|
||||
SELECT
|
||||
api_test_case.id,
|
||||
api_test_case.api_definition_id
|
||||
api_test_case.api_definition_id,
|
||||
api_test_case.environment_id
|
||||
FROM
|
||||
api_test_case
|
||||
WHERE
|
||||
|
|
|
@ -60,4 +60,6 @@ public interface ExtTestPlanApiScenarioMapper {
|
|||
List<TestPlanApiScenario> getScenarioExecuteInfoByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<String> getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted);
|
||||
|
||||
void batchUpdateExecutor(@Param("ids") List<String> ids, @Param("userId") String userId);
|
||||
}
|
||||
|
|
|
@ -437,4 +437,14 @@
|
|||
</include>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
|
||||
<update id="batchUpdateExecutor">
|
||||
update test_plan_api_scenario
|
||||
set execute_user = #{userId}
|
||||
where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
</mapper>
|
|
@ -0,0 +1,78 @@
|
|||
package io.metersphere.plan.service;
|
||||
|
||||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiScenarioExample;
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.domain.ApiTestCaseExample;
|
||||
import io.metersphere.api.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.plan.domain.TestPlanApiCase;
|
||||
import io.metersphere.plan.domain.TestPlanApiCaseExample;
|
||||
import io.metersphere.plan.domain.TestPlanApiScenario;
|
||||
import io.metersphere.plan.domain.TestPlanApiScenarioExample;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiScenarioUpdateRequest;
|
||||
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
|
||||
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper;
|
||||
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 TestPlanApiScenarioLogService {
|
||||
|
||||
@Resource
|
||||
private TestPlanApiScenarioService testPlanApiScenarioService;
|
||||
@Resource
|
||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
@Resource
|
||||
private ApiScenarioMapper apiScenarioMapper;
|
||||
|
||||
public void batchUpdateExecutor(TestPlanApiScenarioUpdateRequest request) {
|
||||
List<String> ids = testPlanApiScenarioService.doSelectIds(request);
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
List<TestPlanApiScenario> planApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
|
||||
Map<String, String> userMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getExecuteUser));
|
||||
Map<String, String> idsMap = planApiScenarioList.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, TestPlanApiScenario::getApiScenarioId));
|
||||
List<String> scenarioIds = planApiScenarioList.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList());
|
||||
ApiScenarioExample scenarioExample = new ApiScenarioExample();
|
||||
scenarioExample.createCriteria().andIdIn(scenarioIds);
|
||||
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(scenarioExample);
|
||||
Map<String, String> caseMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenario::getId, ApiScenario::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/scenario/batch/update/executor");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k)));
|
||||
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId()));
|
||||
dtoList.add(dto);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -519,4 +519,11 @@ public class TestPlanApiScenarioService extends TestPlanResourceService implemen
|
|||
return request.getSelectIds();
|
||||
}
|
||||
}
|
||||
|
||||
public void batchUpdateExecutor(TestPlanApiScenarioUpdateRequest request) {
|
||||
List<String> ids = doSelectIds(request);
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
extTestPlanApiScenarioMapper.batchUpdateExecutor(ids, request.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
public static final String BATCH_RUN = "batch/run";
|
||||
public static final String API_SCENARIO_DISASSOCIATE = "disassociate";
|
||||
public static final String API_SCENARIO_BATCH_DISASSOCIATE = "batch/disassociate";
|
||||
public static final String API_SCENARIO_BATCH_UPDATE_EXECUTOR_URL = "batch/update/executor";
|
||||
|
||||
@Resource
|
||||
private TestPlanApiScenarioService testPlanApiScenarioService;
|
||||
|
@ -301,4 +302,18 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
public void testBatchUpdateExecutor() throws Exception {
|
||||
TestPlanApiScenarioUpdateRequest request = new TestPlanApiScenarioUpdateRequest();
|
||||
request.setUserId("test_user");
|
||||
request.setTestPlanId("wxxx_plan_2");
|
||||
request.setSelectAll(true);
|
||||
this.requestPostWithOk(API_SCENARIO_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||
request.setTestPlanId("wxxx_plan_1");
|
||||
request.setSelectAll(false);
|
||||
request.setSelectIds(List.of("wxxx_plan_scenario_1"));
|
||||
this.requestPostWithOk(API_SCENARIO_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue