refactor(系统设置): 优化组织与项目&组织用户组下拉用户选项查询
This commit is contained in:
parent
1e5a94c05f
commit
8e9e01a8b4
|
@ -118,7 +118,9 @@ public class SystemOrganizationController {
|
||||||
@Operation(summary = "系统设置-系统-组织与项目-获取成员下拉选项")
|
@Operation(summary = "系统设置-系统-组织与项目-获取成员下拉选项")
|
||||||
@RequiresPermissions(value = {PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ})
|
@RequiresPermissions(value = {PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ})
|
||||||
@Parameter(name = "sourceId", description = "组织ID或项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
@Parameter(name = "sourceId", description = "组织ID或项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
public List<UserExtend> getMemberOption(@PathVariable String sourceId) {
|
public List<UserExtend> getMemberOption(@PathVariable String sourceId,
|
||||||
return userService.getMemberOption(sourceId);
|
@Schema(description = "查询关键字,根据邮箱和用户名查询")
|
||||||
|
@RequestParam(value = "keyword", required = false) String keyword) {
|
||||||
|
return userService.getMemberOption(sourceId, keyword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||||
|
|
||||||
public interface ExtUserMapper {
|
public interface ExtUserMapper {
|
||||||
|
|
||||||
List<UserExtend> getMemberOption(String sourceId);
|
List<UserExtend> getMemberOption(@Param("sourceId") String sourceId, @Param("keyword") String keyword);
|
||||||
|
|
||||||
List<User> getUserListByOrgId(@Param("sourceId") String sourceId, @Param("keyword") String keyword);
|
List<User> getUserListByOrgId(@Param("sourceId") String sourceId, @Param("keyword") String keyword);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
select distinct u.*, count(urr.id) > 0 as memberFlag
|
select distinct u.*, count(urr.id) > 0 as memberFlag
|
||||||
from `user` u left join user_role_relation urr on urr.user_id = u.id and urr.source_id = #{sourceId}
|
from `user` u left join user_role_relation urr on urr.user_id = u.id and urr.source_id = #{sourceId}
|
||||||
where u.deleted = 0
|
where u.deleted = 0
|
||||||
|
<if test="keyword != null and keyword != ''">
|
||||||
|
and (u.name like concat('%', #{keyword}, '%') or u.email like concat('%', #{keyword}, '%'))
|
||||||
|
</if>
|
||||||
group by u.id
|
group by u.id
|
||||||
|
limit 100
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getUserListByOrgId" resultType="io.metersphere.system.domain.User">
|
<select id="getUserListByOrgId" resultType="io.metersphere.system.domain.User">
|
||||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.mapper.BaseUserMapper;
|
import io.metersphere.sdk.mapper.BaseUserMapper;
|
||||||
import io.metersphere.sdk.service.BaseUserRoleService;
|
import io.metersphere.sdk.service.BaseUserRoleService;
|
||||||
|
import io.metersphere.sdk.service.BaseUserService;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.*;
|
import io.metersphere.system.domain.*;
|
||||||
|
@ -42,6 +43,8 @@ public class OrganizationUserRoleService extends BaseUserRoleService {
|
||||||
@Resource
|
@Resource
|
||||||
BaseUserMapper baseUserMapper;
|
BaseUserMapper baseUserMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
BaseUserService baseUserService;
|
||||||
|
@Resource
|
||||||
UserRoleMapper userRoleMapper;
|
UserRoleMapper userRoleMapper;
|
||||||
@Resource
|
@Resource
|
||||||
ExtUserRoleMapper extUserRoleMapper;
|
ExtUserRoleMapper extUserRoleMapper;
|
||||||
|
@ -83,9 +86,6 @@ public class OrganizationUserRoleService extends BaseUserRoleService {
|
||||||
|
|
||||||
public List<UserExtend> getMember(String organizationId, String roleId) {
|
public List<UserExtend> getMember(String organizationId, String roleId) {
|
||||||
List<UserExtend> userExtends = new ArrayList<>();
|
List<UserExtend> userExtends = new ArrayList<>();
|
||||||
// 查询所有用户
|
|
||||||
List<User> users = baseUserMapper.findAll();
|
|
||||||
Map<String, User> userMap = users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
|
||||||
// 查询组织下所有用户关系
|
// 查询组织下所有用户关系
|
||||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||||
example.createCriteria().andSourceIdEqualTo(organizationId);
|
example.createCriteria().andSourceIdEqualTo(organizationId);
|
||||||
|
@ -95,17 +95,32 @@ public class OrganizationUserRoleService extends BaseUserRoleService {
|
||||||
Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
|
Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
|
||||||
userRoleMap.forEach((k, v) -> {
|
userRoleMap.forEach((k, v) -> {
|
||||||
UserExtend userExtend = new UserExtend();
|
UserExtend userExtend = new UserExtend();
|
||||||
User user = userMap.get(k);
|
userExtend.setId(k);
|
||||||
if (user != null) {
|
|
||||||
BeanUtils.copyBean(userExtend, user);
|
|
||||||
v.forEach(roleItem -> {
|
v.forEach(roleItem -> {
|
||||||
if (StringUtils.equals(roleItem, roleId)) {
|
if (StringUtils.equals(roleItem, roleId)) {
|
||||||
|
// 该用户已存在用户组关系, 设置为选中状态
|
||||||
userExtend.setCheckRoleFlag(true);
|
userExtend.setCheckRoleFlag(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
userExtends.add(userExtend);
|
userExtends.add(userExtend);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
// 设置用户信息, 用户不存在或者已删除, 则不展示
|
||||||
|
List<String> userIds = userExtends.stream().map(UserExtend::getId).toList();
|
||||||
|
UserExample userExample = new UserExample();
|
||||||
|
userExample.createCriteria().andIdIn(userIds).andDeletedEqualTo(false);
|
||||||
|
List<User> users = userMapper.selectByExample(userExample);
|
||||||
|
if (CollectionUtils.isNotEmpty(users)) {
|
||||||
|
Map<String, User> userMap = users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
||||||
|
userExtends.removeIf(userExtend -> {
|
||||||
|
if (userMap.containsKey(userExtend.getId())) {
|
||||||
|
BeanUtils.copyBean(userExtend, userMap.get(userExtend.getId()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
userExtends.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return userExtends;
|
return userExtends;
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,8 +307,8 @@ public class UserService {
|
||||||
* @param sourceId 组织ID, 项目ID
|
* @param sourceId 组织ID, 项目ID
|
||||||
* @return 系统用户选项
|
* @return 系统用户选项
|
||||||
*/
|
*/
|
||||||
public List<UserExtend> getMemberOption(String sourceId) {
|
public List<UserExtend> getMemberOption(String sourceId, String keyword) {
|
||||||
return extUserMapper.getMemberOption(sourceId);
|
return extUserMapper.getMemberOption(sourceId, keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableBatchProcessResponse resetPassword(TableBatchProcessDTO request, String operator) {
|
public TableBatchProcessResponse resetPassword(TableBatchProcessDTO request, String operator) {
|
||||||
|
|
|
@ -322,7 +322,10 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(15)
|
@Order(15)
|
||||||
public void testOrganizationUserRoleGetMemberOption() throws Exception {
|
public void testOrganizationUserRoleGetMemberOption() throws Exception {
|
||||||
|
// 组织下存在已删除用户
|
||||||
this.responseGet(ORGANIZATION_USER_ROLE_GET_MEMBER_OPTION + "/default-organization-2/default-org-role-id-4");
|
this.responseGet(ORGANIZATION_USER_ROLE_GET_MEMBER_OPTION + "/default-organization-2/default-org-role-id-4");
|
||||||
|
// 组织下用户都已删除
|
||||||
|
this.responseGet(ORGANIZATION_USER_ROLE_GET_MEMBER_OPTION + "/default-organization-4/default-org-role-id-3");
|
||||||
// 组织下无用户
|
// 组织下无用户
|
||||||
this.responseGet(ORGANIZATION_USER_ROLE_GET_MEMBER_OPTION + "/default-organization-3/default-org-role-id-3");
|
this.responseGet(ORGANIZATION_USER_ROLE_GET_MEMBER_OPTION + "/default-organization-3/default-org-role-id-3");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,3 +17,5 @@ INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id
|
||||||
(UUID(), 'default-admin-user', 'default-org-role-id-4', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
|
(UUID(), 'default-admin-user', 'default-org-role-id-4', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
|
||||||
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
|
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
|
||||||
(UUID(), 'default-admin-user-x', 'default-org-role-id-4', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
|
(UUID(), 'default-admin-user-x', 'default-org-role-id-4', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
|
||||||
|
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
|
||||||
|
(UUID(), 'default-admin-user-x', 'default-org-role-id-3', 'default-organization-4', 'default-organization-4', UNIX_TIMESTAMP() * 1000, 'admin');
|
Loading…
Reference in New Issue