From 95f6c458fee5660f4e941183fb5939ff4849d963 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 13 Jun 2022 18:50:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E5=8A=A0=E8=BD=BD=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=BF=87=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1013896 --user=李玉号 【系统设置】66环境系统-操作日志点击查询数据加载时间过长 https://www.tapd.cn/55049933/s/1180309 --- .../base/mapper/ext/ExtOperatingLogMapper.xml | 19 ++----------------- .../base/mapper/ext/ExtProjectMapper.java | 4 ++++ .../base/mapper/ext/ExtProjectMapper.xml | 9 +++++++++ .../commons/utils/ServiceUtils.java | 16 ++++++++++++++++ .../controller/WorkspaceController.java | 1 + .../log/service/OperatingLogService.java | 15 ++++++++++++++- .../metersphere/log/vo/OperatingLogDTO.java | 2 ++ .../metersphere/service/ProjectService.java | 7 +++++++ .../business/components/project/menu/Log.vue | 2 +- .../settings/operatinglog/OperatingLog.vue | 4 ++-- 10 files changed, 58 insertions(+), 21 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.xml index c6b09927f8..a410a9f08a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.xml @@ -12,15 +12,11 @@ upper (t.oper_module) oper_module , t.oper_title, t.oper_time, - t1.NAME userName, t2.`name` projectName , - t2.workspace_id workspace_id , - w.name workspaceName + t2.workspace_id workspace_id FROM operating_log t - LEFT JOIN `user` t1 ON t.oper_user = t1.id LEFT JOIN project t2 ON t.project_id = t2.id - LEFT JOIN workspace w on t2.workspace_id = w.id LEFT JOIN operating_log_resource t3 ON t.id = t3.operating_log_id @@ -29,19 +25,8 @@ #{projectId} - - t2.workspace_id in - - #{workspaceId} - - - - or t.project_id is null - or t.project_id = "" - - and (t.oper_user like #{request.operUser, jdbcType=VARCHAR} or t1.name like - #{request.operUser, jdbcType=VARCHAR}) + and t.oper_user like #{request.operUser, jdbcType=VARCHAR} and t.project_id = #{request.projectId} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.java index 8406dcbc2c..6e8e7f7400 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.java @@ -1,6 +1,7 @@ package io.metersphere.base.mapper.ext; import io.metersphere.base.domain.Project; +import io.metersphere.base.domain.Workspace; import io.metersphere.controller.request.ProjectRequest; import io.metersphere.dto.ProjectDTO; import org.apache.ibatis.annotations.MapKey; @@ -30,6 +31,9 @@ public interface ExtProjectMapper { @MapKey("id") Map queryNameByIds(@Param("ids") List ids); + @MapKey("id") + Map queryWorkNameByProjectIds(@Param("ids") List ids); + Project selectProjectByResourceId(@Param("resourceId") String resourceId); long getProjectMemberSize(@Param("projectId") String projectId); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml index d3b3874ad3..320ef80ce5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml @@ -396,4 +396,13 @@ + diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 8bc61b3dad..a601564831 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -3,6 +3,7 @@ package io.metersphere.commons.utils; import io.metersphere.base.domain.Project; import io.metersphere.base.domain.ProjectVersion; import io.metersphere.base.domain.User; +import io.metersphere.base.domain.Workspace; import io.metersphere.commons.exception.MSException; import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.controller.request.OrderRequest; @@ -135,6 +136,21 @@ public class ServiceUtils { return nameMap; } + public static Map getWorkspaceNameByProjectIds(List projectIds) { + ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class); + HashMap nameMap = new HashMap<>(); + + if (!CollectionUtils.isEmpty(projectIds)) { + Map workspaceMap = projectService.getWorkspaceNameByProjectIds(projectIds); + workspaceMap.forEach((k, v) -> { + nameMap.put(k, v.getName()); + }); + return nameMap; + } + + return nameMap; + } + public static Map getProjectMap(List ids) { ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class); if (!CollectionUtils.isEmpty(ids)) { diff --git a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java index 389b12409d..530978f72a 100644 --- a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java +++ b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java @@ -37,6 +37,7 @@ public class WorkspaceController { PermissionConstants.SYSTEM_GROUP_READ_EDIT, PermissionConstants.SYSTEM_USER_READ_CREATE, PermissionConstants.SYSTEM_USER_READ_EDIT, + PermissionConstants.SYSTEM_WORKSPACE_READ }, logical = Logical.OR) public List getWorkspaceList() { return workspaceService.getWorkspaceList(new WorkspaceRequest()); diff --git a/backend/src/main/java/io/metersphere/log/service/OperatingLogService.java b/backend/src/main/java/io/metersphere/log/service/OperatingLogService.java index 0bd385e5be..ddd12d06c5 100644 --- a/backend/src/main/java/io/metersphere/log/service/OperatingLogService.java +++ b/backend/src/main/java/io/metersphere/log/service/OperatingLogService.java @@ -7,6 +7,7 @@ import io.metersphere.base.mapper.OperatingLogMapper; import io.metersphere.base.mapper.OperatingLogResourceMapper; import io.metersphere.base.mapper.ext.ExtOperatingLogMapper; import io.metersphere.commons.utils.BeanUtils; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.i18n.Translator; import io.metersphere.log.vo.OperatingLogDTO; import io.metersphere.log.vo.OperatingLogDetails; @@ -23,7 +24,9 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -68,7 +71,17 @@ public class OperatingLogService { request.setStartTime(request.getTimes().get(0)); request.setEndTime(request.getTimes().get(1)); } - return extOperatingLogMapper.list(request); + List list = extOperatingLogMapper.list(request); + List userIds = list.stream().map(OperatingLogDTO::getOperUser).collect(Collectors.toList()); + List projectIds = list.stream().map(OperatingLogDTO::getProjectId).collect(Collectors.toList()); + + Map userNameMap = ServiceUtils.getUserNameMap(userIds); + Map workspaceNameMap = ServiceUtils.getWorkspaceNameByProjectIds(projectIds); + for (OperatingLogDTO dto : list) { + dto.setUserName(userNameMap.getOrDefault(dto.getOperUser(), "")); + dto.setWorkspaceName(workspaceNameMap.getOrDefault(dto.getProjectId(), "")); + } + return list; } public OperatingLogDTO get(String id) { diff --git a/backend/src/main/java/io/metersphere/log/vo/OperatingLogDTO.java b/backend/src/main/java/io/metersphere/log/vo/OperatingLogDTO.java index 45c9d0e8b1..77204cb35f 100644 --- a/backend/src/main/java/io/metersphere/log/vo/OperatingLogDTO.java +++ b/backend/src/main/java/io/metersphere/log/vo/OperatingLogDTO.java @@ -33,4 +33,6 @@ public class OperatingLogDTO implements Serializable { private String operContent; private OperatingLogDetails details; + + private String projectId; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index f29f4a32bc..a294ea111e 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -825,6 +825,13 @@ public class ProjectService { return extProjectMapper.queryNameByIds(ids); } + public Map getWorkspaceNameByProjectIds(List projectIds) { + if (projectIds.isEmpty()) { + return new HashMap<>(0); + } + return extProjectMapper.queryWorkNameByProjectIds(projectIds); + } + public void openMockTcp(Project project) { if (project == null) { MSException.throwException("Project not found!"); diff --git a/frontend/src/business/components/project/menu/Log.vue b/frontend/src/business/components/project/menu/Log.vue index c1f03022ef..120f528040 100644 --- a/frontend/src/business/components/project/menu/Log.vue +++ b/frontend/src/business/components/project/menu/Log.vue @@ -257,7 +257,7 @@ export default { }, reset() { let projectIds = this.condition.projectIds; - this.condition = {projectIds: projectIds, projectId: getCurrentProjectID()}; + this.condition = {projectIds: projectIds, projectId: getCurrentProjectID(), times: [new Date().getTime() - 3600 * 1000 * 24 * 7, new Date().getTime()]}; this.initTableData(); }, initProject(url) { diff --git a/frontend/src/business/components/settings/operatinglog/OperatingLog.vue b/frontend/src/business/components/settings/operatinglog/OperatingLog.vue index 5c3d891b27..118c40ce2d 100644 --- a/frontend/src/business/components/settings/operatinglog/OperatingLog.vue +++ b/frontend/src/business/components/settings/operatinglog/OperatingLog.vue @@ -43,7 +43,7 @@ - @@ -301,7 +301,7 @@ export default { }, reset() { let projectIds = this.condition.projectIds; - this.condition = {projectIds: projectIds}; + this.condition = {projectIds: projectIds, times: [new Date().getTime() - 3600 * 1000 * 24 * 7, new Date().getTime()]}; this.initTableData(); }, getWorkSpaceList() {