feat(消息管理): add user list
This commit is contained in:
parent
7a191e2c40
commit
f62cf72b0d
|
@ -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<OptionDTO> getUserList(@PathVariable String projectId, @Schema(description = "查询关键字,根据用户名查询")
|
||||
@RequestParam(value = "keyword", required = false) String keyword) {
|
||||
return noticeMessageTaskService.getUserList(projectId, keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<User> getProjectUserList(@Param("sourceId") String sourceId);
|
||||
|
||||
/**
|
||||
* 根据关键字获取下拉框用户数据
|
||||
* @param projectId 项目ID
|
||||
* @param keyword 远程搜索时的关键字 (name)
|
||||
* @return List<User>
|
||||
*/
|
||||
List<OptionDTO> getProjectUserSelectList(@Param("projectId") String projectId, @Param("keyword") String keyword);
|
||||
}
|
||||
|
|
|
@ -42,4 +42,19 @@
|
|||
and u.deleted = false
|
||||
order by u.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="getProjectUserSelectList" resultType="io.metersphere.sdk.dto.OptionDTO">
|
||||
select u.id,
|
||||
u.name
|
||||
from user_role_relation urr
|
||||
join `user` u on urr.user_id = u.id
|
||||
where urr.role_id = 'project_member'
|
||||
and urr.source_id = #{projectId}
|
||||
<if test="keyword != null and keyword != ''">
|
||||
and name LIKE CONCAT('%', #{keyword}, '%')
|
||||
</if>
|
||||
and u.deleted = false
|
||||
order by u.update_time desc
|
||||
limit 100
|
||||
</select>
|
||||
</mapper>
|
|
@ -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<OptionDTO> getUserList(String projectId, String keyword) {
|
||||
return extProjectUserRoleMapper.getProjectUserSelectList(projectId, keyword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<OptionDTO> 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<OptionDTO> 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<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
|
||||
Assertions.assertEquals(0, userDtoList.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue