From 89d026719793fa488c90e710b8d280f32a80c0ba Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 8 Nov 2024 10:23:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=B7=A5=E4=BD=9C=E5=8F=B0):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=94=A8=E6=88=B7=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/service/DashboardService.java | 12 +++++++++-- .../DashboardFrontPageControllerTests.java | 20 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 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 6c4de81f8d..b3ca423ec4 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 @@ -236,13 +236,21 @@ public class DashboardService { public List editLayout(String organizationId, String userId, List layoutDTO) { + UserLayoutExample userLayoutExample = new UserLayoutExample(); + userLayoutExample.createCriteria().andUserIdEqualTo(userId).andOrgIdEqualTo(organizationId); + List userLayouts = userLayoutMapper.selectByExample(userLayoutExample); UserLayout userLayout = new UserLayout(); - userLayout.setId(IDGenerator.nextStr()); userLayout.setUserId(userId); userLayout.setOrgId(organizationId); String configuration = JSON.toJSONString(layoutDTO); userLayout.setConfiguration(configuration.getBytes()); - userLayoutMapper.insert(userLayout); + if (CollectionUtils.isEmpty(userLayouts)) { + userLayout.setId(IDGenerator.nextStr()); + userLayoutMapper.insert(userLayout); + } else { + userLayout.setId(userLayouts.getFirst().getId()); + userLayoutMapper.updateByPrimaryKeyWithBLOBs(userLayout); + } return layoutDTO; } 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 3c45bcedf3..935f5e96a9 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 @@ -9,7 +9,6 @@ import io.metersphere.dashboard.service.DashboardService; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; -import io.metersphere.system.mapper.UserLayoutMapper; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -32,9 +31,6 @@ public class DashboardFrontPageControllerTests extends BaseTest { @Resource private DashboardService dashboardService; - @Resource - private UserLayoutMapper userLayoutMapper; - private static final String EDIT_LAYOUT = "/dashboard/layout/edit/"; private static final String GET_LAYOUT = "/dashboard/layout/get/"; @@ -113,6 +109,22 @@ public class DashboardFrontPageControllerTests extends BaseTest { resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class); Assertions.assertNotNull(layoutDTOS); + + LayoutDTO layoutDTO2 = new LayoutDTO(); + layoutDTO2.setId(UUID.randomUUID().toString()); + layoutDTO2.setPos(2); + layoutDTO2.setKey(DashboardUserLayoutKeys.ASSOCIATE_CASE_COUNT.toString()); + layoutDTO2.setLabel("关联用例数量"); + layoutDTO2.setProjectIds(new ArrayList<>()); + layoutDTO2.setHandleUsers(new ArrayList<>()); + layoutDTO2.setFullScreen(false); + layoutDTO.add(layoutDTO1); + + mvcResult = this.requestPostWithOkAndReturn(EDIT_LAYOUT+DEFAULT_ORGANIZATION_ID, layoutDTO); + contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class); + Assertions.assertNotNull(layoutDTOS); } }