fix(系统设置): 操作日志点击查询数据加载时间过长

--bug=1013896 --user=李玉号 【系统设置】66环境系统-操作日志点击查询数据加载时间过长
https://www.tapd.cn/55049933/s/1181599
This commit is contained in:
shiziyuan9527 2022-06-14 18:13:45 +08:00 committed by f2c-ci-robot[bot]
parent ec720f8657
commit 057d7d9394
5 changed files with 33 additions and 18 deletions

View File

@ -14,5 +14,7 @@ public interface ExtOperatingLogMapper {
List<OperatingLogDTO> findBySourceIdEnv(@Param("request") OperatingLogRequest request);
List<OperatingLogDTO> findSourceIdByLogIds(@Param("ids") List<String> ids);
boolean isNewInstallation();
}

View File

@ -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
<where>
<if test="request.projectIds != null and request.projectIds.size > 0 ">
t.project_id in
@ -115,4 +113,11 @@
<select id="isNewInstallation" resultType="boolean">
SELECT count(1) = 0 from operating_log limit 1
</select>
<select id="findSourceIdByLogIds" resultType="io.metersphere.log.vo.OperatingLogDTO">
select * from operating_log_resource where operating_log_id in
<foreach collection="ids" item="id" index="index"
open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>

View File

@ -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<OperatingLogDTO> list = extOperatingLogMapper.list(request);
List<String> userIds = list.stream().map(OperatingLogDTO::getOperUser).collect(Collectors.toList());
List<String> projectIds = list.stream().map(OperatingLogDTO::getProjectId).collect(Collectors.toList());
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(userIds);
Map<String, String> 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<String> userIds = list.stream().map(OperatingLogDTO::getOperUser).collect(Collectors.toList());
List<String> projectIds = list.stream().map(OperatingLogDTO::getProjectId).collect(Collectors.toList());
List<String> logIds = list.stream().map(OperatingLogDTO::getId).collect(Collectors.toList());
Map<String, String> sourceMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(logIds)) {
List<OperatingLogDTO> logDtoArr = extOperatingLogMapper.findSourceIdByLogIds(logIds);
// 如果重复是批量操作置空sourceID
sourceMap = logDtoArr.stream()
.collect(Collectors.toMap(OperatingLogDTO::getOperatingLogId, OperatingLogDTO::getSourceId, (val1, val2) -> ""));
}
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(userIds);
Map<String, String> 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;
}

View File

@ -35,4 +35,6 @@ public class OperatingLogDTO implements Serializable {
private OperatingLogDetails details;
private String projectId;
private String operatingLogId;
}

View File

@ -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) {