refactor(项目管理): 增加查询项目成员的接口

This commit is contained in:
wxg0103 2024-02-22 17:28:41 +08:00 committed by 刘瑞斌
parent deb0a5fc4e
commit 90d0dabd6e
5 changed files with 51 additions and 2 deletions

View File

@ -9,12 +9,14 @@ import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.SessionUtils;
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.RequiresPermissions;
@ -75,4 +77,13 @@ public class ProjectController {
return projectService.hasPermission(id, SessionUtils.getUserId());
}
@GetMapping("/get-member/option/{projectId}")
@Operation(summary = "项目管理-获取成员下拉选项")
@RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ)
public List<UserExtendDTO> getMemberOption(@PathVariable String projectId,
@Schema(description = "查询关键字,根据邮箱和用户名查询")
@RequestParam(value = "keyword", required = false) String keyword) {
return projectService.getMemberOption(projectId, keyword);
}
}

View File

@ -21,9 +21,10 @@ import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.mapper.OrganizationMapper;
import io.metersphere.system.mapper.TestResourcePoolMapper;
import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.service.CommonProjectService;
import io.metersphere.system.service.UserLoginService;
@ -62,7 +63,7 @@ public class ProjectService {
@Resource
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
@Resource
private TestResourcePoolOrganizationMapper testResourcePoolOrganizationMapper;
private ExtSystemProjectMapper extSystemProjectMapper;
public static final Long ORDER_STEP = 5000L;
@ -219,4 +220,13 @@ public class ProjectService {
}
return hasPermission;
}
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

@ -436,4 +436,17 @@ public class ProjectControllerTests extends BaseTest {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
}
@Test
@Order(12)
public void testGetProjectMember() throws Exception {
// 成员列表
MvcResult mvcResult = this.responseGet(prefix + "/get-member/option/" + DEFAULT_PROJECT_ID);
List list = parseObjectFromMvcResult(mvcResult, List.class);
Assertions.assertNotNull(list);
this.requestGet(prefix + "/get-member/option/" + "123");
requestGetPermissionTest(PermissionConstants.PROJECT_BASE_INFO_READ, prefix + "/get-member/option/" + DEFAULT_PROJECT_ID);
}
}

View File

@ -29,4 +29,6 @@ public interface ExtSystemProjectMapper {
List<ProjectResourcePoolDTO> getProjectResourcePoolDTOList(@Param("projectIds") List<String> projectIds);
String selectModuleSettingsByResourceIdAndTable(@Param("resourceId") String resourceId, @Param("resourceTable") String resourceTable);
List<UserExtendDTO> getMemberByProjectId(@Param("projectId") String projectId, @Param("keyword") String keyword);
}

View File

@ -196,4 +196,17 @@
</select>
<select id="getMemberByProjectId" resultType="io.metersphere.system.dto.user.UserExtendDTO">
select distinct u.* from user_role_relation urr join `user` u on urr.user_id = u.id
where
u.deleted = 0 and u.enable = 1
<if test="projectId != null and projectId != ''">
and urr.source_id = #{projectId}
</if>
<if test="keyword != null and keyword != ''">
and (u.name like concat('%', #{keyword}, '%') or u.email like concat('%', #{keyword}, '%'))
</if>
order by u.name
limit 100
</select>
</mapper>