From f62cf72b0db511580610b010bb8ec20ae53de057 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 28 Sep 2023 16:14:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B6=88=E6=81=AF=E7=AE=A1=E7=90=86):=20a?= =?UTF-8?q?dd=20user=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NoticeMessageTaskController.java | 10 ++++ .../mapper/ExtProjectUserRoleMapper.java | 9 ++++ .../mapper/ExtProjectUserRoleMapper.xml | 15 ++++++ .../service/NoticeMessageTaskService.java | 11 +++-- .../NoticeMessageTaskControllerTests.java | 48 +++++++++++++++++++ 5 files changed, 89 insertions(+), 4 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java index 51843168ec..6183f614c2 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java @@ -5,6 +5,7 @@ import io.metersphere.project.dto.MessageTaskDTO; import io.metersphere.project.service.MessageTaskLogService; import io.metersphere.project.service.NoticeMessageTaskService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.sdk.dto.request.MessageTaskRequest; @@ -14,6 +15,7 @@ import io.metersphere.system.utils.SessionUtils; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.Logical; @@ -47,5 +49,13 @@ public class NoticeMessageTaskController { return noticeMessageTaskService.getMessageList(projectId); } + @GetMapping("message/task/get/user/{projectId}") + @Operation(summary = "项目管理-消息管理-消息设置-获取用户列表") + @RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_ADD) + public List getUserList(@PathVariable String projectId, @Schema(description = "查询关键字,根据用户名查询") + @RequestParam(value = "keyword", required = false) String keyword) { + return noticeMessageTaskService.getUserList(projectId, keyword); + } + } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java index 9a7bee50ad..ec9112c584 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java @@ -3,6 +3,7 @@ package io.metersphere.project.mapper; import io.metersphere.project.dto.ProjectUserRoleDTO; import io.metersphere.project.request.ProjectUserRoleMemberRequest; import io.metersphere.project.request.ProjectUserRoleRequest; +import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.system.domain.User; import io.metersphere.system.domain.UserRoleRelation; import org.apache.ibatis.annotations.Param; @@ -46,4 +47,12 @@ public interface ExtProjectUserRoleMapper { * @return */ List getProjectUserList(@Param("sourceId") String sourceId); + + /** + * 根据关键字获取下拉框用户数据 + * @param projectId 项目ID + * @param keyword 远程搜索时的关键字 (name) + * @return List + */ + List getProjectUserSelectList(@Param("projectId") String projectId, @Param("keyword") String keyword); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml index 57fc4c8f9e..f1e4ac7a8c 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml @@ -42,4 +42,19 @@ and u.deleted = false order by u.create_time desc + + \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java index 9261237d76..9cc6004c9d 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java @@ -8,10 +8,7 @@ import io.metersphere.project.dto.MessageTaskTypeDTO; import io.metersphere.project.dto.ProjectRobotConfigDTO; import io.metersphere.project.enums.ProjectRobotPlatform; import io.metersphere.project.enums.result.ProjectResultCode; -import io.metersphere.project.mapper.MessageTaskBlobMapper; -import io.metersphere.project.mapper.MessageTaskMapper; -import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.project.mapper.ProjectRobotMapper; +import io.metersphere.project.mapper.*; import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.util.JSON; import io.metersphere.system.controller.handler.ResultHolder; @@ -63,6 +60,9 @@ public class NoticeMessageTaskService { private MessageTaskBlobMapper messageTaskBlobMapper; @Resource private ProjectMapper projectMapper; + @Resource + private ExtProjectUserRoleMapper extProjectUserRoleMapper; + public static final String USER_IDS = "user_ids"; @@ -401,4 +401,7 @@ public class NoticeMessageTaskService { return projectRobotConfigDTO; } + public List getUserList(String projectId, String keyword) { + return extProjectUserRoleMapper.getProjectUserSelectList(projectId, keyword); + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java index 954115002b..8d20f16feb 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java @@ -9,6 +9,7 @@ import io.metersphere.project.dto.MessageTaskDTO; import io.metersphere.project.mapper.MessageTaskBlobMapper; import io.metersphere.project.mapper.MessageTaskMapper; import io.metersphere.sdk.constants.SessionConstants; +import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.dto.request.MessageTaskRequest; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; @@ -433,4 +434,51 @@ public class NoticeMessageTaskControllerTests extends BaseTest { Assertions.assertEquals(100200, resultHolder.getCode()); } + @Test + @Order(16) + public void getUserSuccess() throws Exception { + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .param("keyword", "project-message-user-1") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + List userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); + Assertions.assertTrue(userDtoList.size()>0); + } + + @Test + @Order(17) + public void getUserSuccessAll() throws Exception { + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + List userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); + Assertions.assertTrue(userDtoList.size()>0); + + } + + @Test + @Order(18) + public void getUserSuccessEmpty() throws Exception { + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test-x") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + List userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); + Assertions.assertEquals(0, userDtoList.size()); + + } }