refactor(系统设置): 优化获取用户的接口
This commit is contained in:
parent
666fce56a4
commit
a03bb16977
|
@ -5,16 +5,12 @@ import com.github.pagehelper.Page;
|
|||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.ProjectDTO;
|
||||
import io.metersphere.sdk.dto.ProjectExtendDTO;
|
||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||
import io.metersphere.sdk.dto.*;
|
||||
import io.metersphere.sdk.log.annotation.Log;
|
||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||
import io.metersphere.sdk.util.PageUtils;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.sdk.util.SessionUtils;
|
||||
import io.metersphere.sdk.dto.UserExtend;
|
||||
import io.metersphere.system.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.request.ProjectAddMemberRequest;
|
||||
|
@ -145,15 +141,18 @@ public class OrganizationProjectController {
|
|||
@GetMapping("/user-admin-list/{organizationId}")
|
||||
@Operation(summary = "系统设置-组织-项目-获取管理员列表")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
||||
public List<UserExtend> getUserAdminList(@PathVariable String organizationId) {
|
||||
return organizationProjectService.getUserAdminList(organizationId);
|
||||
public List<UserExtend> getUserAdminList(@PathVariable String organizationId, @Schema(description = "查询关键字,根据邮箱和用户名查询")
|
||||
@RequestParam(value = "keyword", required = false) String keyword) {
|
||||
return organizationProjectService.getUserAdminList(organizationId, keyword);
|
||||
}
|
||||
|
||||
@GetMapping("/user-member-list/{organizationId}/{projectId}")
|
||||
@Operation(summary = "系统设置-组织-项目-获取成员列表")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
||||
public List<UserExtend> getUserMemberList(@PathVariable String organizationId, @PathVariable String projectId) {
|
||||
return organizationProjectService.getUserMemberList(organizationId, projectId);
|
||||
public List<UserExtend> getUserMemberList(@PathVariable String organizationId, @PathVariable String projectId,
|
||||
@Schema(description = "查询关键字,根据邮箱和用户名查询")
|
||||
@RequestParam(value = "keyword", required = false) String keyword) {
|
||||
return organizationProjectService.getUserMemberList(organizationId, projectId, keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ public interface ExtSystemProjectMapper {
|
|||
|
||||
List<OrganizationProjectOptionsDTO> selectProjectOptions(@Param("organizationId") String organizationId);
|
||||
|
||||
List<UserExtend> getUserAdminList(@Param("organizationId") String organizationId);
|
||||
List<UserExtend> getUserAdminList(@Param("organizationId") String organizationId, @Param("keyword") String keyword);
|
||||
|
||||
List<UserExtend> getUserMemberList(@Param("userIds") List<String> userIds, @Param("projectId") String projectId);
|
||||
List<UserExtend> getUserMemberList(@Param("userIds") List<String> userIds, @Param("projectId") String projectId, @Param("keyword") String keyword);
|
||||
|
||||
}
|
||||
|
|
|
@ -118,14 +118,24 @@
|
|||
</sql>
|
||||
|
||||
<select id="getUserAdminList" resultType="io.metersphere.sdk.dto.UserExtend">
|
||||
select distinct u.*
|
||||
select distinct
|
||||
u.id,
|
||||
u.NAME,
|
||||
u.email
|
||||
from `user` u left join user_role_relation urr on urr.user_id = u.id
|
||||
where u.deleted = 0 and urr.source_id = #{organizationId}
|
||||
<if test="keyword != null and keyword != ''">
|
||||
and (LOCATE(#{keyword},u.name)>0 or LOCATE(#{keyword},u.email)>0)
|
||||
</if>
|
||||
order by u.create_time desc
|
||||
limit 100
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getUserMemberList" resultType="io.metersphere.sdk.dto.UserExtend">
|
||||
select distinct u.*, count(temp.id) > 0 as memberFlag from
|
||||
select distinct u.id,
|
||||
u.NAME,
|
||||
u.email, count(temp.id) > 0 as memberFlag from
|
||||
user u left join (select * from user_role_relation urr where urr.source_id = #{projectId}) temp on temp.user_id = u.id
|
||||
<where>
|
||||
u.deleted = 0
|
||||
|
@ -135,11 +145,13 @@
|
|||
#{userId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
and (LOCATE(#{keyword},u.name)>0 or LOCATE(#{keyword},u.email)>0)
|
||||
</if>
|
||||
</where>
|
||||
|
||||
group by u.id
|
||||
|
||||
|
||||
order by u.create_time desc
|
||||
limit 100
|
||||
</select>
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.ProjectDTO;
|
||||
import io.metersphere.sdk.dto.ProjectExtendDTO;
|
||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||
import io.metersphere.sdk.dto.*;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.log.constants.OperationLogModule;
|
||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||
|
@ -11,7 +8,6 @@ import io.metersphere.sdk.util.BeanUtils;
|
|||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||
import io.metersphere.sdk.dto.UserExtend;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
import io.metersphere.system.mapper.OrganizationMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
|
@ -105,12 +101,12 @@ public class OrganizationProjectService {
|
|||
commonProjectService.disable(id);
|
||||
}
|
||||
|
||||
public List<UserExtend> getUserAdminList(String organizationId) {
|
||||
public List<UserExtend> getUserAdminList(String organizationId, String keyword) {
|
||||
checkOrgIsExist(organizationId);
|
||||
return extSystemProjectMapper.getUserAdminList(organizationId);
|
||||
return extSystemProjectMapper.getUserAdminList(organizationId, keyword);
|
||||
}
|
||||
|
||||
public List<UserExtend> getUserMemberList(String organizationId, String projectId) {
|
||||
public List<UserExtend> getUserMemberList(String organizationId, String projectId, String keyword) {
|
||||
checkOrgIsExist(organizationId);
|
||||
commonProjectService.checkProjectNotExist(projectId);
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
|
@ -118,7 +114,7 @@ public class OrganizationProjectService {
|
|||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||
List<String> userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
return extSystemProjectMapper.getUserMemberList(userIds, projectId);
|
||||
return extSystemProjectMapper.getUserMemberList(userIds, projectId, keyword);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import io.metersphere.system.domain.User;
|
|||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||
import io.metersphere.system.dto.OrganizationDTO;
|
||||
import io.metersphere.sdk.dto.UserExtend;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.request.OrganizationProjectRequest;
|
||||
|
@ -750,6 +749,10 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
List<UserDTO> userDTOS = parseObjectFromMvcResult(mvcResult, List.class);
|
||||
assert userDTOS != null;
|
||||
Assertions.assertFalse(userDTOS.isEmpty());
|
||||
|
||||
String keyword = "a";
|
||||
responseGet(getAdminList + organizationId + "?keyword=" + keyword);
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getAdminList + organizationId);
|
||||
|
||||
|
@ -769,6 +772,9 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
List<UserDTO> userDTOS = parseObjectFromMvcResult(mvcResult, List.class);
|
||||
assert userDTOS != null;
|
||||
Assertions.assertFalse(userDTOS.isEmpty());
|
||||
|
||||
String keyword = "a";
|
||||
responseGet(getMemberList + organizationId + "/" + projectId + "?keyword=" + keyword);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getMemberList + organizationId + "/" + projectId);
|
||||
//组织下面没有成员 返回为空
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
disabled
|
||||
allow-search
|
||||
:options="affiliatedOrgOption"
|
||||
:default-value="isXpack ? '' : 'default_organization'"
|
||||
:default-value="isXpack ? '' : '100001'"
|
||||
:placeholder="t('system.project.affiliatedOrgPlaceholder')"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
:disabled="!isXpack"
|
||||
allow-search
|
||||
:options="affiliatedOrgOption"
|
||||
:default-value="isXpack ? '' : 'default_organization'"
|
||||
:default-value="isXpack ? '' : '100001'"
|
||||
:placeholder="t('system.project.affiliatedOrgPlaceholder')"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue