fix(工作台): 修复工作台一些数据显示问题的bug

This commit is contained in:
guoyuqi 2024-11-20 14:26:42 +08:00 committed by Craftsman
parent 6477bca961
commit b36f2825a7
7 changed files with 66 additions and 22 deletions

View File

@ -17,11 +17,13 @@ import io.metersphere.project.service.PermissionCheckService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.security.CheckOwner; import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -48,7 +50,7 @@ public class DashboardController {
@PostMapping("/layout/edit/{organizationId}") @PostMapping("/layout/edit/{organizationId}")
@Operation(summary = "编辑用户布局") @Operation(summary = "编辑用户布局")
@CheckOwner(resourceId = "#organizationId", resourceType = "organization") @CheckOwner(resourceId = "#organizationId", resourceType = "organization")
public List<LayoutDTO> editLayout(@PathVariable String organizationId, @Validated @RequestBody List<LayoutDTO> layoutDTO) { public List<LayoutDTO> editLayout(@PathVariable String organizationId, @RequestBody List<LayoutDTO> layoutDTO ) {
return dashboardService.editLayout(organizationId, SessionUtils.getUserId(), layoutDTO); return dashboardService.editLayout(organizationId, SessionUtils.getUserId(), layoutDTO);
} }
@ -94,6 +96,15 @@ public class DashboardController {
return dashboardService.getBugHandleUserList(projectId); return dashboardService.getBugHandleUserList(projectId);
} }
@GetMapping("/member/get-project-member/option/{projectId}")
@Operation(summary = "获取项目成员列表")
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public List<UserExtendDTO> getMemberOption(@PathVariable String projectId,
@Schema(description = "查询关键字,根据邮箱和用户名查询")
@RequestParam(value = "keyword", required = false) String keyword) {
return dashboardService.getMemberOption(projectId, keyword);
}
@PostMapping("/case_count") @PostMapping("/case_count")
@Operation(summary = "用例数") @Operation(summary = "用例数")
@CheckOwner(resourceId = "#request.getOrganizationId()", resourceType = "organization") @CheckOwner(resourceId = "#request.getOrganizationId()", resourceType = "organization")

View File

@ -5,12 +5,17 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.util.List; import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class LayoutDTO { public class LayoutDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "布局卡片id") @Schema(description = "布局卡片id")
private String id; private String id;
@Schema(description = "布局卡片key") @Schema(description = "布局卡片key")

View File

@ -59,7 +59,9 @@ import io.metersphere.system.domain.UserLayoutExample;
import io.metersphere.system.dto.ProtocolDTO; import io.metersphere.system.dto.ProtocolDTO;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.ProjectUserMemberDTO; import io.metersphere.system.dto.user.ProjectUserMemberDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.mapper.ExtExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskItemMapper;
import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.mapper.UserLayoutMapper; import io.metersphere.system.mapper.UserLayoutMapper;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.PageUtils;
@ -127,6 +129,8 @@ public class DashboardService {
private CaseReviewService caseReviewService; private CaseReviewService caseReviewService;
@Resource @Resource
private ApiTestService apiTestService; private ApiTestService apiTestService;
@Resource
private ExtSystemProjectMapper extSystemProjectMapper;
public static final String FUNCTIONAL = "FUNCTIONAL"; // 功能用例 public static final String FUNCTIONAL = "FUNCTIONAL"; // 功能用例
@ -366,10 +370,10 @@ public class DashboardService {
} }
public List<LayoutDTO> getLayout(String organizationId, String userId) { public List<LayoutDTO> getLayout(String organizationId, String userId) {
List<Project> allPermissionProjects = projectService.getUserProject(organizationId, userId);
UserLayoutExample userLayoutExample = new UserLayoutExample(); UserLayoutExample userLayoutExample = new UserLayoutExample();
userLayoutExample.createCriteria().andUserIdEqualTo(userId).andOrgIdEqualTo(organizationId); userLayoutExample.createCriteria().andUserIdEqualTo(userId).andOrgIdEqualTo(organizationId);
List<UserLayout> userLayouts = userLayoutMapper.selectByExampleWithBLOBs(userLayoutExample); List<UserLayout> userLayouts = userLayoutMapper.selectByExampleWithBLOBs(userLayoutExample);
List<Project>allPermissionProjects = extProjectMapper.getProjectNameModule(organizationId, null);
if (CollectionUtils.isEmpty(allPermissionProjects)) { if (CollectionUtils.isEmpty(allPermissionProjects)) {
return new ArrayList<>(); return new ArrayList<>();
} }
@ -379,6 +383,9 @@ public class DashboardService {
UserLayout userLayout = userLayouts.getFirst(); UserLayout userLayout = userLayouts.getFirst();
byte[] configuration = userLayout.getConfiguration(); byte[] configuration = userLayout.getConfiguration();
String layoutDTOStr = new String(configuration); String layoutDTOStr = new String(configuration);
if (StringUtils.isBlank(layoutDTOStr)) {
return new ArrayList<>();
}
List<LayoutDTO> layoutDTOS = JSON.parseArray(layoutDTOStr, LayoutDTO.class); List<LayoutDTO> layoutDTOS = JSON.parseArray(layoutDTOStr, LayoutDTO.class);
Map<String, Set<String>> permissionModuleProjectIdMap = dashboardProjectService.getPermissionModuleProjectIds(allPermissionProjects, userId); Map<String, Set<String>> permissionModuleProjectIdMap = dashboardProjectService.getPermissionModuleProjectIds(allPermissionProjects, userId);
List<ProjectUserMemberDTO> orgProjectMemberList = extProjectMemberMapper.getOrgProjectMemberList(organizationId, null); List<ProjectUserMemberDTO> orgProjectMemberList = extProjectMemberMapper.getOrgProjectMemberList(organizationId, null);
@ -1399,6 +1406,14 @@ public class DashboardService {
statisticsDTO.setStatusPercentList(statusPercentList); statisticsDTO.setStatusPercentList(statusPercentList);
return statisticsDTO; return statisticsDTO;
} }
public List<UserExtendDTO> getMemberOption(String projectId, String keyword) {
Project project = projectMapper.selectByPrimaryKey(projectId);
if (project == null) {
return new ArrayList<>();
}
return extSystemProjectMapper.getMemberByProjectId(projectId, keyword);
}
} }

View File

@ -27,6 +27,7 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BasePluginTestService; import io.metersphere.system.base.BasePluginTestService;
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.dto.user.UserExtendDTO;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
@ -101,6 +102,8 @@ public class DashboardFrontPageControllerTests extends BaseTest {
private static final String API_CHANGE = "/dashboard/api_change"; private static final String API_CHANGE = "/dashboard/api_change";
private static final String BUG_HANDLE_USER_LIST = "/dashboard/bug_handle_user/list/"; private static final String BUG_HANDLE_USER_LIST = "/dashboard/bug_handle_user/list/";
private static final String PROJECT_MEMBER_USER_LIST = "/dashboard/member/get-project-member/option/";
@Test @Test
@Order(1) @Order(1)
@Sql(scripts = {"/dml/init_dashboard.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = {"/dml/init_dashboard.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
@ -202,11 +205,7 @@ public class DashboardFrontPageControllerTests extends BaseTest {
@Test @Test
@Order(2) @Order(2)
public void testLayout() throws Exception { public void testLayout() throws Exception {
MvcResult mvcResultGrt = this.requestGetWithOkAndReturn(GET_LAYOUT + "DEFAULT_ORGANIZATION_ID"); this.requestGet(GET_LAYOUT + "DEFAULT_ORGANIZATION_ID").andExpect(status().is5xxServerError());
String contentAsString = mvcResultGrt.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<LayoutDTO> layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class);
Assertions.assertEquals(0, layoutDTOS.size());
ProjectExample projectExample = new ProjectExample(); ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andOrganizationIdEqualTo(DEFAULT_ORGANIZATION_ID); projectExample.createCriteria().andOrganizationIdEqualTo(DEFAULT_ORGANIZATION_ID);
@ -261,12 +260,12 @@ public class DashboardFrontPageControllerTests extends BaseTest {
layoutDTO1.setFullScreen(false); layoutDTO1.setFullScreen(false);
layoutDTO.add(layoutDTO1); layoutDTO.add(layoutDTO1);
MvcResult mvcResult = this.requestPostWithOkAndReturn(EDIT_LAYOUT + DEFAULT_ORGANIZATION_ID, layoutDTO); MvcResult mvcResult = this.requestPostWithOkAndReturn(EDIT_LAYOUT + DEFAULT_ORGANIZATION_ID, layoutDTO);
contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class); List<LayoutDTO>layoutDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), LayoutDTO.class);
Assertions.assertNotNull(layoutDTOS); Assertions.assertNotNull(layoutDTOS);
mvcResultGrt = this.requestGetWithOkAndReturn(GET_LAYOUT + DEFAULT_ORGANIZATION_ID); MvcResult mvcResultGrt = this.requestGetWithOkAndReturn(GET_LAYOUT + DEFAULT_ORGANIZATION_ID);
contentAsString = mvcResultGrt.getResponse().getContentAsString(StandardCharsets.UTF_8); contentAsString = mvcResultGrt.getResponse().getContentAsString(StandardCharsets.UTF_8);
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);
@ -546,6 +545,22 @@ public class DashboardFrontPageControllerTests extends BaseTest {
Assertions.assertNotNull(list); Assertions.assertNotNull(list);
} }
@Test
@Order(6)
public void testProjectUserList() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_MEMBER_USER_LIST + DEFAULT_PROJECT_ID);
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
List<UserExtendDTO> list = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), UserExtendDTO.class);
Assertions.assertNotNull(list);
mvcResult = this.requestGetWithOkAndReturn(PROJECT_MEMBER_USER_LIST + "id");
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
list = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), UserExtendDTO.class);
Assertions.assertNotNull(list);
}
private void enableDefaultPlatformConfig() { private void enableDefaultPlatformConfig() {
ProjectApplication record = new ProjectApplication(); ProjectApplication record = new ProjectApplication();
record.setTypeValue("true"); record.setTypeValue("true");

View File

@ -82,7 +82,6 @@ public interface ExtTestPlanMapper {
@BaseConditionFilter @BaseConditionFilter
List<TestPlanResponse> selectMyFollowByConditions(@Param("request") TestPlanTableRequest request); List<TestPlanResponse> selectMyFollowByConditions(@Param("request") TestPlanTableRequest request);
List<TestPlan> getSimpleTestPlanList(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
/** /**
* 获取项目下的计划关联缺陷 * 获取项目下的计划关联缺陷

View File

@ -789,6 +789,7 @@
<if test="userId != null and userId != ''"> <if test="userId != null and userId != ''">
AND test_plan.create_user = #{userId} AND test_plan.create_user = #{userId}
</if> </if>
AND test_plan.type = 'TEST_PLAN'
group by test_plan.project_id; group by test_plan.project_id;
</select> </select>
@ -806,6 +807,7 @@
#{userId} #{userId}
</foreach> </foreach>
</if> </if>
AND test_plan.type = 'TEST_PLAN'
group by test_plan.create_user; group by test_plan.create_user;
</select> </select>
@ -860,14 +862,7 @@
) t ) t
</select> </select>
<select id="getSimpleTestPlanList" resultType="io.metersphere.plan.domain.TestPlan">
SELECT test_plan.id, test_plan.status
FROM test_plan
WHERE test_plan.project_id = #{projectId}
<if test="startTime != null and endTime != null">
AND test_plan.create_time BETWEEN #{startTime} AND #{endTime}
</if>
</select>
<select id="selectIdAndStatusByProjectIdAndCreateTimeRangeAndType" resultType="io.metersphere.plan.domain.TestPlan"> <select id="selectIdAndStatusByProjectIdAndCreateTimeRangeAndType" resultType="io.metersphere.plan.domain.TestPlan">
SELECT id, status SELECT id, status
FROM test_plan FROM test_plan

View File

@ -44,7 +44,11 @@ const transform: AxiosTransform = {
config.url += params; config.url += params;
config.params = undefined; config.params = undefined;
} else { } else {
if (Reflect.has(config, 'data') && config.data && Object.keys(config.data).length > 0) { if (
Reflect.has(config, 'data') &&
config.data &&
(Object.keys(config.data).length > 0 || Array.isArray(config.data))
) {
config.data = data; config.data = data;
config.params = params; config.params = params;
} else { } else {