fix(系统设置): 操作日志加载时间过长
--bug=1013896 --user=李玉号 【系统设置】66环境系统-操作日志点击查询数据加载时间过长 https://www.tapd.cn/55049933/s/1180309
This commit is contained in:
parent
543a0a41ef
commit
95f6c458fe
|
@ -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
|
||||
<where>
|
||||
<if test="request.projectIds != null and request.projectIds.size > 0 ">
|
||||
|
@ -29,19 +25,8 @@
|
|||
#{projectId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.workspaceIds != null and request.workspaceIds.size > 0 ">
|
||||
t2.workspace_id in
|
||||
<foreach collection="request.workspaceIds" item="workspaceId" separator="," open="(" close=")">
|
||||
#{workspaceId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.workspaceId == ''">
|
||||
or t.project_id is null
|
||||
or t.project_id = ""
|
||||
</if>
|
||||
<if test="request.operUser != null and request.operUser != ''">
|
||||
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}
|
||||
</if>
|
||||
<if test="request.projectId != null and request.projectId !=''">
|
||||
and t.project_id = #{request.projectId}
|
||||
|
|
|
@ -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<String, Project> queryNameByIds(@Param("ids") List<String> ids);
|
||||
|
||||
@MapKey("id")
|
||||
Map<String, Workspace> queryWorkNameByProjectIds(@Param("ids") List<String> ids);
|
||||
|
||||
Project selectProjectByResourceId(@Param("resourceId") String resourceId);
|
||||
|
||||
long getProjectMemberSize(@Param("projectId") String projectId);
|
||||
|
|
|
@ -396,4 +396,13 @@
|
|||
<select id="getProjectForCustomField" resultType="io.metersphere.base.domain.Project">
|
||||
select id, platform, third_part_template from project where workspace_id = #{workspaceId}
|
||||
</select>
|
||||
<select id="queryWorkNameByProjectIds" resultType="io.metersphere.base.domain.Workspace">
|
||||
SELECT project.id, workspace.name
|
||||
FROM project inner join workspace on project.workspace_id = workspace.id
|
||||
WHERE project.id IN
|
||||
<foreach collection="ids" item="id" index="index"
|
||||
open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -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<String, String> getWorkspaceNameByProjectIds(List<String> projectIds) {
|
||||
ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class);
|
||||
HashMap<String, String> nameMap = new HashMap<>();
|
||||
|
||||
if (!CollectionUtils.isEmpty(projectIds)) {
|
||||
Map<String, Workspace> workspaceMap = projectService.getWorkspaceNameByProjectIds(projectIds);
|
||||
workspaceMap.forEach((k, v) -> {
|
||||
nameMap.put(k, v.getName());
|
||||
});
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public static Map<String, Project> getProjectMap(List<String> ids) {
|
||||
ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class);
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
|
|
|
@ -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<Workspace> getWorkspaceList() {
|
||||
return workspaceService.getWorkspaceList(new WorkspaceRequest());
|
||||
|
|
|
@ -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<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(), ""));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public OperatingLogDTO get(String id) {
|
||||
|
|
|
@ -33,4 +33,6 @@ public class OperatingLogDTO implements Serializable {
|
|||
private String operContent;
|
||||
|
||||
private OperatingLogDetails details;
|
||||
|
||||
private String projectId;
|
||||
}
|
|
@ -825,6 +825,13 @@ public class ProjectService {
|
|||
return extProjectMapper.queryNameByIds(ids);
|
||||
}
|
||||
|
||||
public Map<String, Workspace> getWorkspaceNameByProjectIds(List<String> 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!");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
<el-col :span="8" v-if="isSystem">
|
||||
<el-form-item :label="$t('commons.workspace')" prop="workspace">
|
||||
<el-select size="small" v-model="condition.workspaceId" @change="initTableData" clearable
|
||||
<el-select size="small" v-model="condition.workspaceId" @change="initTableData" clearable filterable
|
||||
style="width: 100%">
|
||||
<el-option v-for="o in workspaceList" :key="o.id" :label="$t(o.label)" :value="o.id"/>
|
||||
</el-select>
|
||||
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue