From 6619efe9a31271fd3d4958a6bf7915e482ea7cce Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 23 May 2024 18:30:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E7=94=A8=E4=BE=8B=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3.0.0/ddl/V3.0.0_12__beta_ddl.sql | 3 +++ .../controller/FunctionalCaseController.java | 2 +- .../service/FunctionalCaseService.java | 19 ++++++++++++------- .../TestPlanFunctionalCaseService.java | 4 +--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql index 9cbaacecf2..1e22bf0f56 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql @@ -173,6 +173,9 @@ ALTER TABLE test_plan DROP INDEX uq_name_project; CREATE INDEX idx_report_id ON api_scenario_report_step(report_id); +CREATE INDEX idx_source_id ON operation_history(`source_id`); + + -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java index 079e2cf89e..13aed1add5 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java @@ -90,7 +90,7 @@ public class FunctionalCaseController { @CheckOwner(resourceId = "#id", resourceType = "functional_case") public FunctionalCaseDetailDTO getFunctionalCaseDetail(@PathVariable String id) { String userId = SessionUtils.getUserId(); - return functionalCaseService.getFunctionalCaseDetail(id, userId); + return functionalCaseService.getFunctionalCaseDetail(id, userId, true); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 9b94d607f4..8d52838cc3 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -339,7 +339,7 @@ public class FunctionalCaseService { * @param functionalCaseId functionalCaseId * @return FunctionalCaseDetailDTO */ - public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId, String userId) { + public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId, String userId, boolean checkDetailCount) { FunctionalCase functionalCase = checkFunctionalCase(functionalCaseId); FunctionalCaseDetailDTO functionalCaseDetailDTO = new FunctionalCaseDetailDTO(); BeanUtils.copyBean(functionalCaseDetailDTO, functionalCase); @@ -369,9 +369,10 @@ public class FunctionalCaseService { //模块名称 handDTO(functionalCaseDetailDTO); - - //处理已关联需求数量/缺陷数量/用例数量 - handleCount(functionalCaseDetailDTO); + if (checkDetailCount) { + //处理已关联需求数量/缺陷数量/用例数量 + handleCount(functionalCaseDetailDTO); + } return functionalCaseDetailDTO; @@ -442,8 +443,7 @@ public class FunctionalCaseService { //获取变更历史数量数量 OperationHistoryExample operationHistoryExample = new OperationHistoryExample(); List types = List.of(OperationLogType.ADD.name(), OperationLogType.IMPORT.name(), OperationLogType.UPDATE.name()); - List modules = List.of(OperationLogModule.FUNCTIONAL_CASE); - operationHistoryExample.createCriteria().andSourceIdEqualTo(functionalCaseDetailDTO.getId()).andTypeIn(types).andModuleIn(modules); + operationHistoryExample.createCriteria().andSourceIdEqualTo(functionalCaseDetailDTO.getId()).andModuleEqualTo(OperationLogModule.FUNCTIONAL_CASE).andTypeIn(types); functionalCaseDetailDTO.setHistoryCount((int) operationHistoryMapper.countByExample(operationHistoryExample)); } @@ -482,12 +482,17 @@ public class FunctionalCaseService { TemplateDTO templateDTO = projectTemplateService.getTemplateDTOById(functionalCase.getTemplateId(), functionalCase.getProjectId(), TemplateScene.FUNCTIONAL.name()); if (CollectionUtils.isNotEmpty(templateDTO.getCustomFields())) { List customFields = templateDTO.getCustomFields(); + List fieldIds = customFields.stream().map(TemplateCustomFieldDTO::getFieldId).distinct().toList(); + FunctionalCaseCustomFieldExample example = new FunctionalCaseCustomFieldExample(); + example.createCriteria().andCaseIdEqualTo(functionalCase.getId()).andFieldIdIn(fieldIds); + List functionalCaseCustomFields = functionalCaseCustomFieldMapper.selectByExample(example); + Map customFieldMap = functionalCaseCustomFields.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getFieldId, t -> t)); List memberCustomOption = getMemberOptions(functionalCase.getProjectId()); customFields.forEach(item -> { if (StringUtils.equalsAnyIgnoreCase(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) { item.setOptions(memberCustomOption); } - FunctionalCaseCustomField caseCustomField = functionalCaseCustomFieldService.getCustomField(item.getFieldId(), functionalCase.getId()); + FunctionalCaseCustomField caseCustomField = customFieldMap.get(item.getFieldId()); Optional.ofNullable(caseCustomField).ifPresentOrElse(customField -> { item.setDefaultValue(customField.getValue()); if (Translator.get("custom_field.functional_priority").equals(item.getFieldName())) { diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java index 1f762fbc8f..16f6205b0d 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java @@ -91,8 +91,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { @Resource private BugRelationCaseMapper bugRelationCaseMapper; @Resource - private TestPlanModuleService testPlanModuleService; - @Resource private ExtTestPlanModuleMapper extTestPlanModuleMapper; @Resource private FunctionalCaseModuleService functionalCaseModuleService; @@ -553,7 +551,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { public TestPlanCaseDetailResponse getFunctionalCaseDetail(String id, String userId) { TestPlanFunctionalCase planFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(id); String caseId = planFunctionalCase.getFunctionalCaseId(); - FunctionalCaseDetailDTO functionalCaseDetail = functionalCaseService.getFunctionalCaseDetail(caseId, userId); + FunctionalCaseDetailDTO functionalCaseDetail = functionalCaseService.getFunctionalCaseDetail(caseId, userId, false); String caseDetailSteps = functionalCaseDetail.getSteps(); List testPlanCaseExecuteHistories = extTestPlanCaseExecuteHistoryMapper.selectSteps(id, caseId); Integer runListCount = 0;