fix(报告统计): 测试用例趋势报表查看项目不再以工作空间为条件

--bug=1018948 --user=宋天阳 【报表统计】用户A在测试用例趋势的项目列表中可以看见所有项目
https://www.tapd.cn/55049933/s/1283953
This commit is contained in:
song-tianyang 2022-10-31 17:12:19 +08:00 committed by 建国
parent ad228271e3
commit 189eb23bea
6 changed files with 22 additions and 44 deletions

View File

@ -2,14 +2,12 @@ package io.metersphere.reportstatistics.service;
import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.DateUtils;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.reportstatistics.dto.*; import io.metersphere.reportstatistics.dto.*;
import io.metersphere.reportstatistics.dto.charts.Legend; import io.metersphere.reportstatistics.dto.charts.Legend;
import io.metersphere.reportstatistics.dto.charts.Series; import io.metersphere.reportstatistics.dto.charts.Series;
import io.metersphere.reportstatistics.dto.charts.XAxis; import io.metersphere.reportstatistics.dto.charts.XAxis;
import io.metersphere.reportstatistics.dto.charts.YAxis; import io.metersphere.reportstatistics.dto.charts.YAxis;
import io.metersphere.reportstatistics.service.remote.track.TestCaseRemoteService; import io.metersphere.reportstatistics.service.remote.track.TestCaseRemoteService;
import io.metersphere.request.ProjectRequest;
import io.metersphere.service.BaseProjectService; import io.metersphere.service.BaseProjectService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -39,17 +37,10 @@ public class TestAnalysisService {
request.setStartTime(DateUtils.getDataStr(request.getTimes().get(0))); request.setStartTime(DateUtils.getDataStr(request.getTimes().get(0)));
request.setEndTime(DateUtils.getDataStr(request.getTimes().get(1))); request.setEndTime(DateUtils.getDataStr(request.getTimes().get(1)));
if (CollectionUtils.isEmpty(request.getProjects())) { if (CollectionUtils.isEmpty(request.getProjects())) {
// 获取当前组织空间下所有项目 String projectId = SessionUtils.getCurrentProjectId();
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId(); if (StringUtils.isNotBlank(projectId)) {
request.setProjects(new ArrayList<>() {{
ProjectRequest projectRequest = new ProjectRequest(); this.add(projectId);
projectRequest.setWorkspaceId(currentWorkspaceId);
List<ProjectDTO> projectDTOS = projectService.getProjectList(projectRequest);
if (CollectionUtils.isNotEmpty(projectDTOS)) {
request.setProjects(projectDTOS.stream().map(ProjectDTO::getId).collect(Collectors.toList()));
} else {
request.setProjects(new LinkedList<String>() {{
this.add(UUID.randomUUID().toString());
}}); }});
} }
} }
@ -117,7 +108,10 @@ public class TestAnalysisService {
List<Integer> upCollect = dtos.stream().map(item -> Integer.valueOf(item.getUpdateCount())).collect(Collectors.toList()); List<Integer> upCollect = dtos.stream().map(item -> Integer.valueOf(item.getUpdateCount())).collect(Collectors.toList());
// reduce求和 // reduce求和
Optional<Integer> updateCount = upCollect.stream().reduce(Integer::sum); Optional<Integer> updateCount = upCollect.stream().reduce(Integer::sum);
dtos.add(new TestAnalysisTableDTO("Count", createCount.get().toString(), updateCount.get().toString(), new LinkedList<>())); dtos.add(new TestAnalysisTableDTO("Count",
createCount.isEmpty() ? "0" : createCount.get().toString(),
updateCount.isEmpty() ? "0" : updateCount.get().toString(),
new LinkedList<>()));
TestAnalysisResult testAnalysisResult = new TestAnalysisResult(); TestAnalysisResult testAnalysisResult = new TestAnalysisResult();
testAnalysisResult.setChartDTO(dto); testAnalysisResult.setChartDTO(dto);

View File

@ -1,9 +1,5 @@
import {get} from "metersphere-frontend/src/plugins/request" import {get} from "metersphere-frontend/src/plugins/request"
export function listAllProject(workspaceId) {
return get(`/project/listAll/${workspaceId}`)
}
export function getProject(id) { export function getProject(id) {
return get(`/project/get/${id}`) return get(`/project/get/${id}`)
} }

View File

@ -30,8 +30,8 @@
</el-row> </el-row>
<el-row style="overflow: auto"> <el-row style="overflow: auto">
<ms-chart ref="chart1" v-if="!loading" :options="dataOption" <ms-chart ref="chart1" v-if="!loading" :options="dataOption"
:style="{width: chartWidthNumber+'px', height: (h-70) + 'px'}" class="chart-config" :autoresize="true" :style="{width: '100%', height: (h-70) + 'px'}" class="chart-config" :autoresize="true"
:id="reportId"/> id="picChart"/>
</el-row> </el-row>
</el-card> </el-card>
</div> </div>

View File

@ -1,13 +1,12 @@
<template> <template>
<div> <div>
<el-container v-loading="loading" :style="{ 'max-height': (h-50) + 'px', 'overflow': 'auto'}">
<el-container v-loading="loading" id="reportAnalysis" :style="{ 'max-height': (h-50) + 'px', 'overflow': 'auto'}">
<el-aside v-if="!isHide" :width="!isHide ?'235px':'0px'" :style="{ 'margin-left': '5px'}"> <el-aside v-if="!isHide" :width="!isHide ?'235px':'0px'" :style="{ 'margin-left': '5px'}">
<history-report-data report-type="TEST_CASE_COUNT" <history-report-data report-type="TEST_CASE_COUNT"
@selectReport="selectReport" @removeHistoryReportId="removeHistoryReportId" @selectReport="selectReport" @removeHistoryReportId="removeHistoryReportId"
ref="historyReport"/> ref="historyReport"/>
</el-aside> </el-aside>
<el-main class="ms-main" style="padding: 0px 5px 0px"> <el-main class="ms-main" id="reportAnalysis" style="padding: 0px 5px 0px">
<div> <div>
<test-case-count-chart @hidePage="hidePage" @orderCharts="orderCharts" <test-case-count-chart @hidePage="hidePage" @orderCharts="orderCharts"
ref="analysisChart" @updateChartType="updateChartType" ref="analysisChart" @updateChartType="updateChartType"

View File

@ -1,13 +1,13 @@
<template> <template>
<div :style="{ height: h + 'px'}"> <div :style="{ height: h + 'px'}">
<el-container v-loading="loading" id="reportAnalysis" style="overflow: scroll"> <el-container v-loading="loading" style="overflow: scroll">
<el-container class="ms-row"> <el-container class="ms-row">
<el-aside :width="!isHide ?'235px':'0px'" style="margin-left: 5px; max-height: 843px"> <el-aside :width="!isHide ?'235px':'0px'" style="margin-left: 5px; max-height: 843px">
<history-report-data report-type="TEST_CASE_ANALYSIS" <history-report-data report-type="TEST_CASE_ANALYSIS"
@selectReport="selectReport" @removeHistoryReportId="removeHistoryReportId" @selectReport="selectReport" @removeHistoryReportId="removeHistoryReportId"
ref="historyReport"/> ref="historyReport"/>
</el-aside> </el-aside>
<el-main class="ms-main"> <el-main class="ms-main" id="reportAnalysis">
<div> <div>
<test-analysis-chart @hidePage="hidePage" @orderCharts="orderCharts" ref="analysisChart" <test-analysis-chart @hidePage="hidePage" @orderCharts="orderCharts" ref="analysisChart"
:load-option="loadOption"/> :load-option="loadOption"/>

View File

@ -54,8 +54,8 @@
<script> <script>
import MsSelectTree from "@/business/compnent/form/MsSelectTree"; import MsSelectTree from "@/business/compnent/form/MsSelectTree";
import {listAllProject} from "@/api/project"; import {getProject} from "@/api/project";
import {getCurrentWorkspaceId} from "metersphere-frontend/src/utils/token"; import {getCurrentProjectID} from "metersphere-frontend/src/utils/token";
import {selectTestCaseNodeList, selectUserProjectMember} from "@/api/resource"; import {selectTestCaseNodeList, selectUserProjectMember} from "@/api/resource";
export default { export default {
@ -147,15 +147,13 @@ export default {
} }
}, },
init: function () { init: function () {
let workspaceId = getCurrentWorkspaceId(); let projectId = getCurrentProjectID();
this.loading = listAllProject(workspaceId).then(response => { this.loading = getProject(projectId).then(response => {
let projects = response.data; let project = response.data;
if (projects) { if (project) {
this.items = []; this.items = [];
projects.forEach(item => { let data = {id: project.id, label: project.name};
let data = {id: item.id, label: item.name}; this.items.push(data);
this.items.push(data);
})
} }
}).catch(() => { }).catch(() => {
this.loading = false; this.loading = false;
@ -178,9 +176,6 @@ export default {
}); });
}, },
setProjects(key, data, data2) {// setProjects(key, data, data2) {//
let selectNodeIds = this.$refs.projectSelector.selectNodeIds;
if (!key || key === "") { if (!key || key === "") {
key = []; key = [];
} }
@ -192,19 +187,13 @@ export default {
} else { } else {
this.disabled = false; this.disabled = false;
} }
if (this.syncReport) { if (this.syncReport) {
this.$emit('filterCharts', this.option); this.$emit('filterCharts', this.option);
} }
this.$nextTick(() => { this.$nextTick(() => {
console.info("------>");
console.info(this.option.projects);
console.info("<------");
if (this.option.projects && this.option.projects.length == 1) { if (this.option.projects && this.option.projects.length == 1) {
this.initModule(); this.initModule();
} }
}) })
}, },