fix(测试用例): 去除关联取消关联日志

--bug=1042896 --user=王旭 【测试计划】关联&取消关联用例-生成系统日志 https://www.tapd.cn/55049933/s/1534639
This commit is contained in:
WangXu10 2024-06-24 11:55:39 +08:00 committed by Craftsman
parent 1996e03bab
commit dfb97f4063
5 changed files with 13 additions and 90 deletions

View File

@ -41,9 +41,6 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator;
@ -564,18 +561,16 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
@Override
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanApiCase> testPlanApiCaseList = new ArrayList<>();
List<LogDTO> logDTOS = new ArrayList<>();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
//处理数据
handleApiData(collectionAssociates.get(AssociateCaseType.API), user, testPlanApiCaseList, testPlan, logDTOS);
handleApiCaseData(collectionAssociates.get(AssociateCaseType.API_CASE), user, testPlanApiCaseList, testPlan, logDTOS);
handleApiData(collectionAssociates.get(AssociateCaseType.API), user, testPlanApiCaseList, testPlan);
handleApiCaseData(collectionAssociates.get(AssociateCaseType.API_CASE), user, testPlanApiCaseList, testPlan);
if (CollectionUtils.isNotEmpty(testPlanApiCaseList)) {
testPlanApiCaseMapper.batchInsert(testPlanApiCaseList);
operationLogService.batchAdd(logDTOS);
}
}
private void handleApiCaseData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan, List<LogDTO> logDTOS) {
private void handleApiCaseData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan) {
if (CollectionUtils.isNotEmpty(apiCaseList)) {
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
ApiTestCaseExample example = new ApiTestCaseExample();
@ -586,13 +581,13 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
if (CollectionUtils.isNotEmpty(apiCaseIds)) {
List<ApiTestCase> apiTestCases = apiTestCaseList.stream().filter(item -> apiCaseIds.contains(item.getId())).toList();
Map<String, ApiTestCase> apiTestCaseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, Function.identity()));
buildTestPlanApiCase(testPlan, apiCaseIds, apiTestCaseMap, apiCase.getCollectionId(), user, testPlanApiCaseList, logDTOS);
buildTestPlanApiCase(testPlan, apiCaseIds, apiTestCaseMap, apiCase.getCollectionId(), user, testPlanApiCaseList);
}
});
}
}
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan, List<LogDTO> logDTOS) {
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan) {
if (CollectionUtils.isNotEmpty(apiCaseList)) {
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
boolean isRepeat = testPlanConfigService.isRepeatCase(testPlan.getId());
@ -607,7 +602,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
Map<String, List<String>> apiTestCaseMapIds = apiTestCases.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId, Collectors.mapping(ApiTestCase::getId, Collectors.toList())));
Collections.reverse(apiCaseIds);
apiCaseIds.forEach(apiCaseId -> {
buildTestPlanApiCase(testPlan, apiTestCaseMapIds.get(apiCaseId), apiTestCaseMap, apiCase.getCollectionId(), user, testPlanApiCaseList, logDTOS);
buildTestPlanApiCase(testPlan, apiTestCaseMapIds.get(apiCaseId), apiTestCaseMap, apiCase.getCollectionId(), user, testPlanApiCaseList);
});
}
});
@ -623,7 +618,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
* @param user
* @param testPlanApiCaseList
*/
private void buildTestPlanApiCase(TestPlan testPlan, List<String> ids, Map<String, ApiTestCase> apiTestCases, String collectionId, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, List<LogDTO> logDTOS) {
private void buildTestPlanApiCase(TestPlan testPlan, List<String> ids, Map<String, ApiTestCase> apiTestCases, String collectionId, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList) {
super.checkCollection(testPlan.getId(), collectionId, CaseType.API_CASE.getKey());
AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId));
Collections.reverse(ids);
@ -641,25 +636,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
testPlanApiCase.setExecuteUser(apiTestCase.getCreateUser());
testPlanApiCase.setLastExecResult(ExecStatus.PENDING.name());
testPlanApiCaseList.add(testPlanApiCase);
buildLog(logDTOS, testPlan, user, apiTestCase);
});
}
private void buildLog(List<LogDTO> logDTOS, TestPlan testPlan, SessionUser user, ApiTestCase apiTestCase) {
LogDTO dto = new LogDTO(
testPlan.getProjectId(),
user.getLastOrganizationId(),
testPlan.getId(),
user.getId(),
OperationLogType.ASSOCIATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("log.test_plan.api_case") + ":" + apiTestCase.getName());
dto.setHistory(true);
dto.setPath("/test-plan/mind/data/edit");
dto.setMethod(HttpMethodConstants.POST.name());
logDTOS.add(dto);
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.API_CASE.getKey())

View File

@ -40,9 +40,6 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils;
@ -177,15 +174,14 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
@Override
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanApiScenario> testPlanApiScenarioList = new ArrayList<>();
List<LogDTO> logDTOS = new ArrayList<>();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
handleApiScenarioData(collectionAssociates.get(AssociateCaseType.API_SCENARIO), user, testPlanApiScenarioList, testPlan, logDTOS);
handleApiScenarioData(collectionAssociates.get(AssociateCaseType.API_SCENARIO), user, testPlanApiScenarioList, testPlan);
if (CollectionUtils.isNotEmpty(testPlanApiScenarioList)) {
testPlanApiScenarioMapper.batchInsert(testPlanApiScenarioList);
}
}
private void handleApiScenarioData(List<BaseCollectionAssociateRequest> apiScenarioList, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, TestPlan testPlan, List<LogDTO> logDTOS) {
private void handleApiScenarioData(List<BaseCollectionAssociateRequest> apiScenarioList, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, TestPlan testPlan) {
if (CollectionUtils.isNotEmpty(apiScenarioList)) {
List<String> ids = apiScenarioList.stream().flatMap(item -> item.getIds().stream()).toList();
ApiScenarioExample scenarioExample = new ApiScenarioExample();
@ -197,7 +193,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
List<ApiScenario> scenarios = apiScenarios.stream().filter(item -> apiScenarioIds.contains(item.getId())).toList();
// 生成map key为id value为scenario
Map<String, ApiScenario> scenarioMap = scenarios.stream().collect(Collectors.toMap(ApiScenario::getId, Function.identity()));
buildTestPlanApiScenario(testPlan, apiScenarioIds, scenarioMap, apiScenario.getCollectionId(), user, testPlanApiScenarioList, logDTOS);
buildTestPlanApiScenario(testPlan, apiScenarioIds, scenarioMap, apiScenario.getCollectionId(), user, testPlanApiScenarioList);
}
});
}
@ -212,7 +208,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
* @param user
* @param testPlanApiScenarioList
*/
private void buildTestPlanApiScenario(TestPlan testPlan, List<String> ids, Map<String, ApiScenario> scenarios, String collectionId, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, List<LogDTO> logDTOS) {
private void buildTestPlanApiScenario(TestPlan testPlan, List<String> ids, Map<String, ApiScenario> scenarios, String collectionId, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList) {
super.checkCollection(testPlan.getId(), collectionId, CaseType.SCENARIO_CASE.getKey());
AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId));
Collections.reverse(ids);
@ -231,25 +227,9 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
testPlanApiScenario.setExecuteUser(scenario.getCreateUser());
testPlanApiScenario.setLastExecResult(ExecStatus.PENDING.name());
testPlanApiScenarioList.add(testPlanApiScenario);
buildLog(logDTOS, testPlan, user, scenario);
});
}
private void buildLog(List<LogDTO> logDTOS, TestPlan testPlan, SessionUser user, ApiScenario scenario) {
LogDTO dto = new LogDTO(
testPlan.getProjectId(),
user.getLastOrganizationId(),
testPlan.getId(),
user.getId(),
OperationLogType.ASSOCIATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("log.test_plan.api_scenario") + ":" + scenario.getName());
dto.setHistory(true);
dto.setPath("/test-plan/mind/data/edit");
dto.setMethod(HttpMethodConstants.POST.name());
logDTOS.add(dto);
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.SCENARIO_CASE.getKey())

View File

@ -759,14 +759,12 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanFunctionalCase> testPlanFunctionalCaseList = new ArrayList<>();
List<BaseCollectionAssociateRequest> functionalList = collectionAssociates.get(AssociateCaseType.FUNCTIONAL);
List<LogDTO> logDTOS = new ArrayList<>();
if (CollectionUtils.isNotEmpty(functionalList)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
functionalList.forEach(functional -> buildTestPlanFunctionalCase(testPlan, functional, user, testPlanFunctionalCaseList, logDTOS));
functionalList.forEach(functional -> buildTestPlanFunctionalCase(testPlan, functional, user, testPlanFunctionalCaseList));
}
if (CollectionUtils.isNotEmpty(testPlanFunctionalCaseList)) {
testPlanFunctionalCaseMapper.batchInsert(testPlanFunctionalCaseList);
operationLogService.batchAdd(logDTOS);
}
}
@ -778,7 +776,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
* @param user
* @param testPlanFunctionalCaseList
*/
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList, List<LogDTO> logDTOS) {
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList) {
super.checkCollection(testPlan.getId(), functional.getCollectionId(), CaseType.FUNCTIONAL_CASE.getKey());
List<String> functionalIds = functional.getIds();
if (CollectionUtils.isNotEmpty(functionalIds)) {
@ -802,26 +800,10 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
testPlanFunctionalCase.setExecuteUser(functionalCase.getCreateUser());
testPlanFunctionalCase.setLastExecResult(ExecStatus.PENDING.name());
testPlanFunctionalCaseList.add(testPlanFunctionalCase);
buildLog(logDTOS, testPlan, user, functionalCase);
});
}
}
private void buildLog(List<LogDTO> logDTOS, TestPlan testPlan, SessionUser user, FunctionalCase functionalCase) {
LogDTO dto = new LogDTO(
testPlan.getProjectId(),
user.getLastOrganizationId(),
testPlan.getId(),
user.getId(),
OperationLogType.ASSOCIATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("log.test_plan.functional_case") + ":" + functionalCase.getName());
dto.setHistory(true);
dto.setPath("/test-plan/mind/data/edit");
dto.setMethod(HttpMethodConstants.POST.name());
logDTOS.add(dto);
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.FUNCTIONAL_CASE.getKey())

View File

@ -88,23 +88,6 @@ public class TestPlanResourceLogService {
}
public void saveDisassociateLog(TestPlan module, @Validated ResourceLogInsertModule logInsertModule) {
Project project = projectMapper.selectByPrimaryKey(module.getProjectId());
LogDTO dto = LogDTOBuilder.builder()
.projectId(module.getProjectId())
.organizationId(project.getOrganizationId())
.type(OperationLogType.DISASSOCIATE.name())
.module(logModule)
.method(logInsertModule.getRequestMethod())
.path(logInsertModule.getRequestUrl())
.sourceId(module.getId())
.content(generateContent(module.getName(), logInsertModule.getResourceType(), "disassociate"))
.createUser(logInsertModule.getOperator())
.build().getLogDTO();
operationLogService.add(dto);
}
public void saveAssociateLog(TestPlan module, @Validated ResourceLogInsertModule logInsertModule) {
Project project = projectMapper.selectByPrimaryKey(module.getProjectId());
LogDTO dto = LogDTOBuilder.builder()

View File

@ -57,7 +57,6 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(associationIdList, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), logInsertModule.getOperator());
disassociate.accept(associationParam);
response.setAssociationCount(associationIdList.size());
testPlanResourceLogService.saveDisassociateLog(testPlan, new ResourceLogInsertModule(resourceType, logInsertModule));
}
return response;
}