From 057d7d9394cbb486b39bc72ddfb96c243539e3a6 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 14 Jun 2022 18:13:45 +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=E7=82=B9=E5=87=BB=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=95=B0=E6=8D=AE=E5=8A=A0=E8=BD=BD=E6=97=B6=E9=97=B4?= =?UTF-8?q?=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/1181599 --- .../mapper/ext/ExtOperatingLogMapper.java | 2 ++ .../base/mapper/ext/ExtOperatingLogMapper.xml | 9 ++++-- .../log/service/OperatingLogService.java | 31 ++++++++++++------- .../metersphere/log/vo/OperatingLogDTO.java | 2 ++ .../settings/operatinglog/OperatingLog.vue | 7 ++--- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.java index 74453ca396..600eb87054 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOperatingLogMapper.java @@ -14,5 +14,7 @@ public interface ExtOperatingLogMapper { List findBySourceIdEnv(@Param("request") OperatingLogRequest request); + List findSourceIdByLogIds(@Param("ids") List ids); + boolean isNewInstallation(); } \ No newline at end of file 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 a410a9f08a..002f093299 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 @@ -7,7 +7,6 @@ t.id, t.project_id, t.oper_user, - t3.source_id, t.oper_type, upper (t.oper_module) oper_module , t.oper_title, @@ -17,7 +16,6 @@ FROM operating_log t LEFT JOIN project t2 ON t.project_id = t2.id - LEFT JOIN operating_log_resource t3 ON t.id = t3.operating_log_id t.project_id in @@ -115,4 +113,11 @@ + 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 ddd12d06c5..469608e326 100644 --- a/backend/src/main/java/io/metersphere/log/service/OperatingLogService.java +++ b/backend/src/main/java/io/metersphere/log/service/OperatingLogService.java @@ -22,10 +22,7 @@ import org.springframework.stereotype.Service; 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.*; import java.util.stream.Collectors; @Service @@ -72,14 +69,24 @@ public class OperatingLogService { request.setEndTime(request.getTimes().get(1)); } 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(), "")); + if (CollectionUtils.isNotEmpty(list)) { + List userIds = list.stream().map(OperatingLogDTO::getOperUser).collect(Collectors.toList()); + List projectIds = list.stream().map(OperatingLogDTO::getProjectId).collect(Collectors.toList()); + List logIds = list.stream().map(OperatingLogDTO::getId).collect(Collectors.toList()); + Map sourceMap = new HashMap<>(); + if (CollectionUtils.isNotEmpty(logIds)) { + List logDtoArr = extOperatingLogMapper.findSourceIdByLogIds(logIds); + // 如果重复是批量操作,置空sourceID + sourceMap = logDtoArr.stream() + .collect(Collectors.toMap(OperatingLogDTO::getOperatingLogId, OperatingLogDTO::getSourceId, (val1, val2) -> "")); + } + 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(), "")); + dto.setSourceId(sourceMap.getOrDefault(dto.getId(), "")); + } } return list; } 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 77204cb35f..47ce58692d 100644 --- a/backend/src/main/java/io/metersphere/log/vo/OperatingLogDTO.java +++ b/backend/src/main/java/io/metersphere/log/vo/OperatingLogDTO.java @@ -35,4 +35,6 @@ public class OperatingLogDTO implements Serializable { private OperatingLogDetails details; private String projectId; + + private String operatingLogId; } \ No newline at end of file diff --git a/frontend/src/business/components/settings/operatinglog/OperatingLog.vue b/frontend/src/business/components/settings/operatinglog/OperatingLog.vue index 19e410651c..5f846a029f 100644 --- a/frontend/src/business/components/settings/operatinglog/OperatingLog.vue +++ b/frontend/src/business/components/settings/operatinglog/OperatingLog.vue @@ -188,7 +188,7 @@ export default { } }, watch: { - '$route'(to, from) { + '$route'(to) { switch (to.name) { case "system": this.getWorkSpaceList(); @@ -201,13 +201,12 @@ export default { } }, '$route.path': { - handler(toPath, fromPath) { + handler(toPath) { if (toPath === '/setting/operatingLog/workspace') { this.isSystem = false; this.sysList = new WORKSYSLIST(); this.condition.workspaceId = getCurrentWorkspaceId(); } else { - this.getWorkSpaceList(); this.isSystem = true; this.sysList = new SYSLIST(); this.condition.workspaceId = ''; @@ -313,7 +312,7 @@ export default { this.initTableData(); }, getWorkSpaceList() { - this.$get("/workspace/list/userworkspace", response => { + this.$get("/workspace/list", response => { let workspaceList = response.data; let workspaceIds = []; if (workspaceList) {