refactor(系统设置): 系统日志-查询用户接口支持远程搜索

This commit is contained in:
WangXu10 2023-09-04 10:08:27 +08:00 committed by 刘瑞斌
parent fecf72d108
commit 9c555775a6
7 changed files with 37 additions and 21 deletions

View File

@ -16,6 +16,7 @@ import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.service.SystemProjectService; import io.metersphere.system.service.SystemProjectService;
import io.metersphere.system.service.UserService; import io.metersphere.system.service.UserService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -74,8 +75,9 @@ public class OperationLogController {
@GetMapping("/user/list") @GetMapping("/user/list")
@Operation(summary = "系统设置-系统-日志-系统日志页面,获取用户列表") @Operation(summary = "系统设置-系统-日志-系统日志页面,获取用户列表")
@RequiresPermissions(PermissionConstants.SYSTEM_LOG_READ) @RequiresPermissions(PermissionConstants.SYSTEM_LOG_READ)
public List<User> getUserList() { public List<User> getUserList(@Schema(description = "查询关键字,根据邮箱和用户名查询")
List<User> userList = userService.getUserList(); @RequestParam(value = "keyword", required = false) String keyword) {
List<User> userList = userService.getUserList(keyword);
return userList; return userList;
} }
} }

View File

@ -5,10 +5,7 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.AddProjectRequest; import io.metersphere.sdk.dto.*;
import io.metersphere.sdk.dto.ProjectDTO;
import io.metersphere.sdk.dto.ProjectExtendDTO;
import io.metersphere.sdk.dto.UpdateProjectRequest;
import io.metersphere.sdk.log.annotation.Log; import io.metersphere.sdk.log.annotation.Log;
import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.PageUtils;
@ -149,8 +146,9 @@ public class SystemProjectController {
@GetMapping("/user-list") @GetMapping("/user-list")
@Operation(summary = "系统设置-系统-组织与项目-项目-系统-组织及项目, 获取管理员下拉选项") @Operation(summary = "系统设置-系统-组织与项目-项目-系统-组织及项目, 获取管理员下拉选项")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ) @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public List<User> getUserList() { public List<User> getUserList(@Schema(description = "查询关键字,根据邮箱和用户名查询")
return userService.getUserList(); @RequestParam(value = "keyword", required = false) String keyword) {
return userService.getUserList(keyword);
} }
} }

View File

@ -11,4 +11,6 @@ public interface ExtUserMapper {
List<UserExtend> getMemberOption(String sourceId); List<UserExtend> getMemberOption(String sourceId);
List<User> getUserListByOrgId(@Param("sourceId") String sourceId); List<User> getUserListByOrgId(@Param("sourceId") String sourceId);
List<User> selectUserList(@Param("keyword") String keyword);
} }

View File

@ -19,4 +19,22 @@
WHERE WHERE
urr.source_id = #{sourceId} and u.deleted = false urr.source_id = #{sourceId} and u.deleted = false
</select> </select>
<select id="selectUserList" resultType="io.metersphere.system.domain.User">
SELECT DISTINCT
u.id,
u.NAME,
u.email
FROM
`user` u
WHERE
u.deleted = false
<if test="keyword != null and keyword != ''">
and (LOCATE(#{keyword},name)>0 or LOCATE(#{keyword},email)>0)
</if>
order by u.create_time desc
limit 100
</select>
</mapper> </mapper>

View File

@ -297,11 +297,8 @@ public class UserService {
return insertIndex; return insertIndex;
} }
public List<User> getUserList() { public List<User> getUserList(String keyword) {
UserExample example = new UserExample(); return extUserMapper.selectUserList(keyword.trim());
example.createCriteria().andDeletedEqualTo(false);
example.setOrderByClause("update_time desc");
return userMapper.selectByExample(example);
} }
/** /**

View File

@ -138,10 +138,11 @@ public class OperationLogControllerTests extends BaseTest {
@Test @Test
@Order(3) @Order(3)
public void testUserList() throws Exception { public void testUserList() throws Exception {
this.requestGetWithOkAndReturn(USER_LIST); String keyword = "a";
this.requestGetWithOkAndReturn(USER_LIST + "?keyword=" + keyword);
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.SYSTEM_LOG_READ, USER_LIST); requestGetPermissionTest(PermissionConstants.SYSTEM_LOG_READ, USER_LIST + "?keyword=" + keyword);
} }
@Test @Test

View File

@ -8,10 +8,7 @@ import io.metersphere.sdk.constants.InternalUserRole;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.controller.handler.ResultHolder; import io.metersphere.sdk.controller.handler.ResultHolder;
import io.metersphere.sdk.dto.AddProjectRequest; import io.metersphere.sdk.dto.*;
import io.metersphere.sdk.dto.ProjectDTO;
import io.metersphere.sdk.dto.ProjectExtendDTO;
import io.metersphere.sdk.dto.UpdateProjectRequest;
import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.Pager;
@ -708,9 +705,10 @@ public class SystemProjectControllerTests extends BaseTest {
@Test @Test
@Order(21) @Order(21)
public void testUserList() throws Exception { public void testUserList() throws Exception {
this.requestGetWithOkAndReturn(userList); String keyword = "a";
this.requestGetWithOkAndReturn(userList + "?keyword=" + keyword);
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, userList); requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, userList + "?keyword=" + keyword);
} }
} }