feat(测试计划): 批量修改执行人
This commit is contained in:
parent
9cf50f3872
commit
58140fb2b7
|
@ -97,4 +97,5 @@ log.test_plan.api_scenario=Api scenario
|
|||
test_plan.type.not_blank=Test plan type cannot be empty
|
||||
test_plan.group.not_plan=There are no archived plans in the current testing plan group
|
||||
test_plan_group.batch.log={0} test plan group
|
||||
test_plan.batch.log={0} plan
|
||||
test_plan.batch.log={0} plan
|
||||
run_functional_case=Run functional case
|
|
@ -97,4 +97,5 @@ log.test_plan.api_scenario=接口场景
|
|||
test_plan.type.not_blank=测试计划类型不能为空
|
||||
test_plan.group.not_plan=当前测试计划组没有可归档计划
|
||||
test_plan_group.batch.log={0}测试计划组
|
||||
test_plan.batch.log={0}测试计划
|
||||
test_plan.batch.log={0}测试计划
|
||||
run_functional_case=执行功能用例
|
|
@ -97,4 +97,5 @@ log.test_plan.api_scenario=接口場景
|
|||
test_plan.type.not_blank=測試計劃類型不能為空
|
||||
test_plan.group.not_plan=當前測試計劃組沒有可歸檔計劃
|
||||
test_plan_group.batch.log={0}測試計劃組
|
||||
test_plan.batch.log={0}測試計劃
|
||||
test_plan.batch.log={0}測試計劃
|
||||
run_functional_case=執行功能用例
|
|
@ -8,6 +8,7 @@ import io.metersphere.plan.dto.request.*;
|
|||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||
import io.metersphere.plan.dto.response.TestPlanCasePageResponse;
|
||||
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
|
||||
import io.metersphere.plan.service.TestPlanCaseLogService;
|
||||
import io.metersphere.plan.service.TestPlanFunctionalCaseService;
|
||||
import io.metersphere.plan.service.TestPlanManagementService;
|
||||
import io.metersphere.request.AssociateBugPageRequest;
|
||||
|
@ -149,4 +150,15 @@ public class TestPlanFunctionalCaseController {
|
|||
return PageUtils.setPageInfo(page, testPlanFunctionalCaseService.hasAssociateBugPage(request));
|
||||
}
|
||||
|
||||
|
||||
@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 = TestPlanCaseLogService.class)
|
||||
public void batchUpdateExecutor(@Validated @RequestBody TestPlanCaseUpdateRequest request) {
|
||||
testPlanFunctionalCaseService.batchUpdateExecutor(request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
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 TestPlanCaseUpdateRequest extends BasePlanCaseBatchRequest {
|
||||
|
||||
@Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan.user_id.not_blank}")
|
||||
private String userId;
|
||||
}
|
|
@ -48,7 +48,7 @@ public interface ExtTestPlanFunctionalCaseMapper {
|
|||
*/
|
||||
List<TestPlanFunctionalCase> getPlanFunctionalCaseByIds(@Param("planIds") List<String> planIds);
|
||||
|
||||
List<String> selectIdByConditions(@Param("request") BasePlanCaseBatchRequest request, @Param("projectId") String projectId);
|
||||
|
||||
void batchUpdate(@Param("ids") List<String> ids, @Param("lastExecResult") String lastExecResult, @Param("lastExecTime") long lastExecTime, @Param("userId") String userId);
|
||||
|
||||
void batchUpdateExecutor(@Param("ids") List<String> ids, @Param("userId") String userId);
|
||||
}
|
||||
|
|
|
@ -481,58 +481,6 @@
|
|||
</select>
|
||||
|
||||
|
||||
<select id="selectIdByConditions" resultType="java.lang.String">
|
||||
SELECT
|
||||
test_plan_functional_case.id
|
||||
FROM test_plan_functional_case
|
||||
join functional_case on test_plan_functional_case.functional_case_id = functional_case.id
|
||||
WHERE functional_case.project_id = #{projectId}
|
||||
and functional_case.deleted = false
|
||||
and test_plan_functional_case.test_plan_id = #{request.testPlanId}
|
||||
<include refid="queryWhereConditionByBaseQueryRequest"/>
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="queryWhereConditionByBaseQueryRequest">
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
and functional_case.module_id in
|
||||
<foreach collection="request.moduleIds" item="moduleId" separator="," open="(" close=")">
|
||||
#{moduleId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.condition.keyword != null and request.condition.keyword != ''">
|
||||
and (
|
||||
functional_case.name like concat('%', #{request.condition.keyword},'%')
|
||||
or functional_case.num like concat('%', #{request.condition.keyword},'%')
|
||||
or functional_case.tags like concat('%', #{request.condition.keyword},'%')
|
||||
)
|
||||
</if>
|
||||
<include refid="filters">
|
||||
<property name="filter" value="request.condition.filter"/>
|
||||
</include>
|
||||
<choose>
|
||||
<when test='request.condition.searchMode == "AND"'>
|
||||
AND <include refid="baseQueryCombine"/>
|
||||
</when>
|
||||
<when test='request.condition.searchMode == "OR"'>
|
||||
and (
|
||||
<include refid="baseQueryCombine"/>
|
||||
)
|
||||
</when>
|
||||
</choose>
|
||||
</sql>
|
||||
|
||||
<sql id="baseQueryCombine">
|
||||
<if test="request.condition.combine != null">
|
||||
<include refid="combine">
|
||||
<property name="condition" value="request.condition.combine"/>
|
||||
<property name="searchMode" value="request.condition.searchMode"/>
|
||||
</include>
|
||||
</if>
|
||||
1=1
|
||||
</sql>
|
||||
|
||||
|
||||
<update id="batchUpdate">
|
||||
update test_plan_functional_case
|
||||
set last_exec_result = #{lastExecResult},
|
||||
|
@ -543,4 +491,14 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="batchUpdateExecutor">
|
||||
update test_plan_functional_case
|
||||
set execute_user = #{userId}
|
||||
where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,71 @@
|
|||
package io.metersphere.plan.service;
|
||||
|
||||
import io.metersphere.functional.domain.FunctionalCase;
|
||||
import io.metersphere.functional.domain.FunctionalCaseExample;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
||||
import io.metersphere.plan.domain.TestPlanFunctionalCase;
|
||||
import io.metersphere.plan.domain.TestPlanFunctionalCaseExample;
|
||||
import io.metersphere.plan.dto.request.TestPlanCaseUpdateRequest;
|
||||
import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper;
|
||||
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 TestPlanCaseLogService {
|
||||
|
||||
@Resource
|
||||
private TestPlanFunctionalCaseService testPlanFunctionalCaseService;
|
||||
@Resource
|
||||
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
|
||||
@Resource
|
||||
private FunctionalCaseMapper functionalCaseMapper;
|
||||
|
||||
public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) {
|
||||
List<String> ids = testPlanFunctionalCaseService.doSelectIds(request);
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
List<TestPlanFunctionalCase> planCaseList = testPlanFunctionalCaseMapper.selectByExample(example);
|
||||
Map<String, String> userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getExecuteUser));
|
||||
Map<String, String> idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getFunctionalCaseId));
|
||||
List<String> caseIds = planCaseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList());
|
||||
FunctionalCaseExample caseExample = new FunctionalCaseExample();
|
||||
caseExample.createCriteria().andIdIn(caseIds);
|
||||
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(caseExample);
|
||||
Map<String, String> caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::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/functional/case/batch/update/executer");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k)));
|
||||
dto.setModifiedValue(JSON.toJSONBytes(request.getUserId()));
|
||||
dtoList.add(dto);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -302,7 +302,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
this::deleteTestPlanResource);
|
||||
}
|
||||
|
||||
private List<String> doSelectIds(BasePlanCaseBatchRequest request) {
|
||||
public List<String> doSelectIds(BasePlanCaseBatchRequest request) {
|
||||
if (request.isSelectAll()) {
|
||||
List<String> ids = extTestPlanFunctionalCaseMapper.getIds(request, false);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
|
@ -411,7 +411,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量执行功能用例
|
||||
*
|
||||
|
@ -419,7 +418,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
* @param logInsertModule
|
||||
*/
|
||||
public void batchRun(TestPlanCaseBatchRunRequest request, String organizationId, LogInsertModule logInsertModule) {
|
||||
List<String> ids = doSelectIds(request, request.getProjectId());
|
||||
List<String> ids = doSelectIds(request);
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
handleBatchRun(ids, organizationId, request, logInsertModule);
|
||||
}
|
||||
|
@ -488,19 +487,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
}
|
||||
|
||||
|
||||
public List<String> doSelectIds(BasePlanCaseBatchRequest request, String projectId) {
|
||||
if (request.isSelectAll()) {
|
||||
List<String> ids = extTestPlanFunctionalCaseMapper.selectIdByConditions(request, projectId);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
ids.removeAll(request.getExcludeIds());
|
||||
}
|
||||
return ids;
|
||||
} else {
|
||||
return request.getSelectIds();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<LogDTO> runLog(Map<String, String> idsMap, List<String> caseIds, String projectId, String organizationId, ResourceLogInsertModule logInsertModule) {
|
||||
FunctionalCaseExample example = new FunctionalCaseExample();
|
||||
example.createCriteria().andIdIn(caseIds);
|
||||
|
@ -523,4 +509,17 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量更新执行人
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) {
|
||||
List<String> ids = doSelectIds(request);
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
extTestPlanFunctionalCaseMapper.batchUpdateExecutor(ids, request.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public class TestPlanCaseControllerTests extends BaseTest {
|
|||
|
||||
public static final String FUNCTIONAL_CASE_RUN_URL = "/test-plan/functional/case/run";
|
||||
public static final String FUNCTIONAL_CASE_BATCH_RUN_URL = "/test-plan/functional/case/batch/run";
|
||||
public static final String FUNCTIONAL_CASE_BATCH_UPDATE_EXECUTOR_URL = "/test-plan/functional/case/batch/update/executor";
|
||||
@Resource
|
||||
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
|
||||
@Resource
|
||||
|
@ -211,4 +212,20 @@ public class TestPlanCaseControllerTests extends BaseTest {
|
|||
this.requestPostWithOk(FUNCTIONAL_CASE_BATCH_RUN_URL, request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void testBatchUpdateExecutor() throws Exception {
|
||||
TestPlanCaseUpdateRequest request = new TestPlanCaseUpdateRequest();
|
||||
request.setUserId("test_user");
|
||||
request.setTestPlanId("plan_4");
|
||||
request.setSelectAll(true);
|
||||
this.requestPostWithOk(FUNCTIONAL_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||
request.setTestPlanId("plan_2");
|
||||
request.setSelectAll(false);
|
||||
request.setSelectIds(List.of("relate_case_3"));
|
||||
this.requestPostWithOk(FUNCTIONAL_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue