diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml b/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml index 7605af25ec..4d9a144cba 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/mapper/BaseOperationLogMapper.xml @@ -8,6 +8,7 @@ t.organization_id, t.create_time, t.create_user, + t.source_id, t.module, t.type, t.content @@ -42,10 +43,12 @@ AND t.type = #{request.type} - AND t.module = #{request.module} + + AND t.module like #{module} - AND t.content like CONCAT('%', #{request.content},'%') + + AND t.content like #{content} ORDER BY t.create_time DESC diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java index 74d2c46669..48df5c0cfd 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OperationLogController.java @@ -51,7 +51,7 @@ public class OperationLogController { //获取全部组织 List organizationList = organizationService.getOrganizationOptions(); //获取全部项目 - List projectList = systemProjectService.getProjectOptions(); + List projectList = systemProjectService.getProjectOptions(null); OrganizationProjectOptionsResponse optionsResponse = new OrganizationProjectOptionsResponse(); optionsResponse.setOrganizationList(organizationList); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationLogController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationLogController.java new file mode 100644 index 0000000000..1927761532 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationLogController.java @@ -0,0 +1,76 @@ +package io.metersphere.system.controller; + + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.log.service.OperationLogService; +import io.metersphere.sdk.log.vo.OperationLogRequest; +import io.metersphere.sdk.log.vo.OperationLogResponse; +import io.metersphere.sdk.util.PageUtils; +import io.metersphere.sdk.util.Pager; +import io.metersphere.system.domain.User; +import io.metersphere.system.dto.OrganizationProjectOptionsDTO; +import io.metersphere.system.dto.response.OrganizationProjectOptionsResponse; +import io.metersphere.system.service.SystemProjectService; +import io.metersphere.system.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +/** + * @author wx + */ +@Tag(name = "组织日志") +@RestController +@RequestMapping("/organization/log") +public class OrganizationLogController { + + @Resource + private SystemProjectService systemProjectService; + + @Resource + private OperationLogService operationLogService; + + @Resource + private UserService userService; + + + @GetMapping("/get/options/{organizationId}") + @Operation(summary = "组织日志-获取项目级联下拉框选项") + @RequiresPermissions(PermissionConstants.ORGANIZATION_OPERATING_LOG_READ) + public OrganizationProjectOptionsResponse getOrganizationOptions(@PathVariable(value = "organizationId") String organizationId) { + //获取全部项目 + List projectList = systemProjectService.getProjectOptions(organizationId); + OrganizationProjectOptionsResponse optionsResponse = new OrganizationProjectOptionsResponse(); + optionsResponse.setProjectList(projectList); + + return optionsResponse; + } + + + @GetMapping("/user/list/{organizationId}") + @Operation(summary = "组织日志-获取用户列表") + @RequiresPermissions(PermissionConstants.ORGANIZATION_OPERATING_LOG_READ) + public List getLogUserList(@PathVariable(value = "organizationId") String organizationId) { + return userService.getUserListByOrgId(organizationId); + } + + + @PostMapping("/list") + @Operation(summary = "组织菜单下操作日志列表查询") + @RequiresPermissions(PermissionConstants.ORGANIZATION_OPERATING_LOG_READ) + public Pager> organizationLogList(@Validated @RequestBody OperationLogRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + return PageUtils.setPageInfo(page, operationLogService.list(request)); + } + +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java index 099e2474bd..71eab46885 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java @@ -18,5 +18,5 @@ public interface ExtSystemProjectMapper { List getProjectAdminList(String projectId); - List selectProjectOptions(); + List selectProjectOptions(@Param("organizationId") String organizationId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml index c85b4ac73e..45e533d241 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml @@ -54,7 +54,14 @@ diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java index de9e08c460..ea81175a9a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java @@ -1,10 +1,14 @@ package io.metersphere.system.mapper; +import io.metersphere.system.domain.User; import io.metersphere.system.dto.UserExtend; +import org.apache.ibatis.annotations.Param; import java.util.List; public interface ExtUserMapper { List getMemberOption(String sourceId); + + List getUserListByOrgId(@Param("sourceId") String sourceId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml index b3746744d2..41dad0b158 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml @@ -6,4 +6,15 @@ from `user` u left join user_role_relation urr on urr.user_id = u.id and urr.source_id = #{sourceId} group by u.id + + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java index b50010b94a..1cb34e2e97 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java @@ -87,8 +87,8 @@ public class SystemProjectService { commonProjectService.deleteProject(projects); } - public List getProjectOptions() { - return extSystemProjectMapper.selectProjectOptions(); + public List getProjectOptions(String organizationId) { + return extSystemProjectMapper.selectProjectOptions(organizationId); } public void enable(String id) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java index 51ad2d0545..2e30e5ff05 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java @@ -476,4 +476,8 @@ public class UserService { return request.getUserIds(); } } + + public List getUserListByOrgId(String organizationId) { + return extUserMapper.getUserListByOrgId(organizationId); + } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationLogControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationLogControllerTests.java new file mode 100644 index 0000000000..e13d662984 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationLogControllerTests.java @@ -0,0 +1,84 @@ +package io.metersphere.system.controller; + +import io.metersphere.sdk.base.BaseTest; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.log.vo.OperationLogRequest; +import io.metersphere.system.controller.param.OperationLogRequestDefinition; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.Arrays; +import java.util.HashMap; + +@SpringBootTest +@AutoConfigureMockMvc +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class OrganizationLogControllerTests extends BaseTest { + + public static final String ORGANIZATION = "ORGANIZATION"; + public static final String ORGANIZATION_OPTIONS_LIST = "/organization/log/get/options"; + public static final String ORGANIZATION_USER_LIST = "/organization/log/user/list"; + public static final String ORGANIZATION_LOG_LIST = "/organization/log/list"; + + + /** + * 组织菜单-操作日志接口 测试用例 + * + * @throws Exception + */ + @Test + @Order(1) + public void testGetOrganizationOptions() throws Exception { + this.requestGetWithOkAndReturn(ORGANIZATION_OPTIONS_LIST + "/organization_id_001"); + } + + + @Test + @Order(2) + public void testOrganizationUserList() throws Exception { + this.requestGetWithOkAndReturn(ORGANIZATION_USER_LIST + "/organization_id_001"); + } + + + @Test + @Order(3) + public void testOrganizationLogList() throws Exception { + OperationLogRequest request = buildParam(ORGANIZATION); + //项目级别 全部 + this.requestPostWithOkAndReturn(ORGANIZATION_LOG_LIST, request); + + //其他查询条件 + request.setOperUser("admin"); + request.setType("add"); + request.setModule("SYSTEM_PARAMETER_SETTING"); + request.setContent("认证配置"); + this.requestPostWithOkAndReturn(ORGANIZATION_LOG_LIST, request); + + //项目级别 指定项目查询 + request.setProjectIds(Arrays.asList("project_id_001", "project_id_002")); + request.setSort(new HashMap<>() {{ + put("createTime", "desc"); + }}); + + this.requestPostWithOkAndReturn(ORGANIZATION_LOG_LIST, request); + // @@异常参数校验 + updatedGroupParamValidateTest(OperationLogRequestDefinition.class, ORGANIZATION_LOG_LIST); + + requestPostPermissionTest(PermissionConstants.ORGANIZATION_OPERATING_LOG_READ, ORGANIZATION_LOG_LIST, request); + + } + + private OperationLogRequest buildParam(String level) { + OperationLogRequest request = new OperationLogRequest(); + request.setCurrent(1); + request.setPageSize(10); + request.setStartTime(1689131059000l); + request.setEndTime(1689149059000l); + request.setLevel(level); + return request; + } +}