feat(工作台): 更新用户布局

This commit is contained in:
guoyuqi 2024-11-08 10:23:14 +08:00 committed by Craftsman
parent 1aaa6c3515
commit 89d0267197
2 changed files with 26 additions and 6 deletions

View File

@ -236,13 +236,21 @@ public class DashboardService {
public List<LayoutDTO> editLayout(String organizationId, String userId, List<LayoutDTO> layoutDTO) { public List<LayoutDTO> editLayout(String organizationId, String userId, List<LayoutDTO> layoutDTO) {
UserLayoutExample userLayoutExample = new UserLayoutExample();
userLayoutExample.createCriteria().andUserIdEqualTo(userId).andOrgIdEqualTo(organizationId);
List<UserLayout> userLayouts = userLayoutMapper.selectByExample(userLayoutExample);
UserLayout userLayout = new UserLayout(); UserLayout userLayout = new UserLayout();
userLayout.setId(IDGenerator.nextStr());
userLayout.setUserId(userId); userLayout.setUserId(userId);
userLayout.setOrgId(organizationId); userLayout.setOrgId(organizationId);
String configuration = JSON.toJSONString(layoutDTO); String configuration = JSON.toJSONString(layoutDTO);
userLayout.setConfiguration(configuration.getBytes()); userLayout.setConfiguration(configuration.getBytes());
if (CollectionUtils.isEmpty(userLayouts)) {
userLayout.setId(IDGenerator.nextStr());
userLayoutMapper.insert(userLayout); userLayoutMapper.insert(userLayout);
} else {
userLayout.setId(userLayouts.getFirst().getId());
userLayoutMapper.updateByPrimaryKeyWithBLOBs(userLayout);
}
return layoutDTO; return layoutDTO;
} }

View File

@ -9,7 +9,6 @@ import io.metersphere.dashboard.service.DashboardService;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.mapper.UserLayoutMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@ -32,9 +31,6 @@ public class DashboardFrontPageControllerTests extends BaseTest {
@Resource @Resource
private DashboardService dashboardService; private DashboardService dashboardService;
@Resource
private UserLayoutMapper userLayoutMapper;
private static final String EDIT_LAYOUT = "/dashboard/layout/edit/"; private static final String EDIT_LAYOUT = "/dashboard/layout/edit/";
private static final String GET_LAYOUT = "/dashboard/layout/get/"; private static final String GET_LAYOUT = "/dashboard/layout/get/";
@ -113,6 +109,22 @@ public class DashboardFrontPageControllerTests extends BaseTest {
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class); layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class);
Assertions.assertNotNull(layoutDTOS); 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);
} }
} }