From 29b84693cd0e5cf4f02f22e8e56ee25dfe84c0aa Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 9 Dec 2024 17:38:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=B7=A5=E4=BD=9C=E5=8F=B0):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=A6=82=E8=A7=88=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E9=BB=98=E8=AE=A4=E6=98=BE=E7=A4=BA=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=85=B3=E8=81=94=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/service/DashboardService.java | 23 ++++++++++++------- .../DashboardFrontPageControllerTests.java | 2 +- .../plan/mapper/ExtTestPlanApiCaseMapper.xml | 18 +++++++-------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java index 30641490a1..c12420d309 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java @@ -491,13 +491,7 @@ public class DashboardService { Set hasReadProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.TEST_PLAN_READ); checkHasPermissionProject(layoutDTO, hasReadProjectIds); if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.PROJECT_PLAN_VIEW.toString())) { - TestPlan testPlan = testPlanMapper.selectByPrimaryKey(layoutDTO.getPlanId()); - if (testPlan == null || StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { - TestPlan latestPlan = extTestPlanMapper.getLatestPlan(layoutDTO.getProjectIds().getFirst()); - if (latestPlan != null) { - layoutDTO.setPlanId(latestPlan.getId()); - } - } + setPlanId(layoutDTO); } } else if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.BUG_COUNT.toString()) || StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.CREATE_BUG_BY_ME.toString()) @@ -513,6 +507,16 @@ public class DashboardService { } } + private void setPlanId(LayoutDTO layoutDTO) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(layoutDTO.getPlanId()); + if (testPlan == null || StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { + TestPlan latestPlan = extTestPlanMapper.getLatestPlan(layoutDTO.getProjectIds().getFirst()); + if (latestPlan != null) { + layoutDTO.setPlanId(latestPlan.getId()); + } + } + } + private void checkHasPermissionProject(LayoutDTO layoutDTO, Set hasReadProjectIds) { if (CollectionUtils.isEmpty(hasReadProjectIds)) { return; @@ -531,7 +535,7 @@ public class DashboardService { * @param projectId 项目ID * @return List */ - private static List getDefaultLayoutDTOS(String projectId, List userIds) { + private List getDefaultLayoutDTOS(String projectId, List userIds) { List layoutDTOS = new ArrayList<>(); LayoutDTO projectLayoutDTO = buildDefaultLayoutDTO(DashboardUserLayoutKeys.PROJECT_VIEW, "workbench.homePage.projectOverview", 0, new ArrayList<>(), new ArrayList<>()); layoutDTOS.add(projectLayoutDTO); @@ -539,6 +543,9 @@ public class DashboardService { layoutDTOS.add(createByMeLayoutDTO); LayoutDTO projectMemberLayoutDTO = buildDefaultLayoutDTO(DashboardUserLayoutKeys.PROJECT_MEMBER_VIEW, "workbench.homePage.staffOverview", 2, List.of(projectId), userIds); layoutDTOS.add(projectMemberLayoutDTO); + LayoutDTO planLayoutDTO = buildDefaultLayoutDTO(DashboardUserLayoutKeys.PROJECT_PLAN_VIEW, "workbench.homePage.testPlanOverview", 3, List.of(projectId), userIds); + setPlanId(planLayoutDTO); + layoutDTOS.add(planLayoutDTO); return layoutDTOS; } diff --git a/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/DashboardFrontPageControllerTests.java b/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/DashboardFrontPageControllerTests.java index 7dcbd7d612..bab701984e 100644 --- a/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/DashboardFrontPageControllerTests.java +++ b/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/DashboardFrontPageControllerTests.java @@ -246,7 +246,7 @@ public class DashboardFrontPageControllerTests extends BaseTest { String defaultString = defaultResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder defaultHolder = JSON.parseObject(defaultString, ResultHolder.class); ListdefaultDTOS = JSON.parseArray(JSON.toJSONString(defaultHolder.getData()), LayoutDTO.class); - Assertions.assertEquals(3, defaultDTOS.size()); + Assertions.assertEquals(4, defaultDTOS.size()); ProjectExample projectExample = new ProjectExample(); projectExample.createCriteria().andOrganizationIdEqualTo(DEFAULT_ORGANIZATION_ID); List projects = projectMapper.selectByExample(projectExample); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml index 2462672615..5307617e03 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml @@ -88,7 +88,7 @@ a.project_id, a.module_id, a.latest, a.version_id, a.ref_id, a.description, a.create_time, a.create_user, a.update_time, a.update_user, a.delete_user, a.delete_time, a.deleted, project_version.name as version_name - from api_definition a left join project_version on project_version.id = a.version_id + from api_definition a left join project_version on project_version.id = a.version_id where a.deleted = false and exists ( @@ -116,7 +116,7 @@ and ( - a.name like concat('%', #{request.keyword},'%') + a.name like concat('%', #{request.keyword},'%') or a.num like concat('%', #{request.keyword},'%') or a.path like concat('%', #{request.keyword},'%') or a.tags like concat('%', #{request.keyword},'%') @@ -152,27 +152,27 @@ - and api_definition.status in + and a.status in - and api_definition.method in + and a.method in - and api_definition.create_user in + and a.create_user in - and api_definition.version_id in + and a.version_id in - and api_definition.delete_user in + and a.delete_user in - and api_definition.id in ( + and a.id in ( select api_id from api_definition_custom_field where concat('custom_single_', field_id) = #{key} and trim(both '"' from `value`) in @@ -180,7 +180,7 @@ ) - and api_definition.id in ( + and a.id in ( select api_id from api_definition_custom_field where concat('custom_multiple_', field_id) = #{key} and JSON_CONTAINS(`value`, json_array(#{value}))