feat(测试跟踪): 资源按照项目查询

This commit is contained in:
shiziyuan9527 2020-12-10 15:16:50 +08:00
parent ab57c77967
commit 239ce6bd5b
18 changed files with 178 additions and 128 deletions

View File

@ -15,6 +15,9 @@
and test_case_review.name like CONCAT('%', #{request.name},'%')
</if>
and project.workspace_id = #{request.workspaceId}
<if test="request.projectId != null">
and test_case_review_project.project_id = #{request.projectId}
</if>
</where>
<if test="request.orders != null and request.orders.size() > 0">
order by
@ -51,6 +54,9 @@
<if test="request.reviewerId != null">
and test_case_review_users.user_id = #{request.reviewerId}
</if>
<if test="request.projectId != null">
and test_case_review_project.project_id = #{request.projectId}
</if>
<if test="request.creator != null">
and (test_case_review.creator = #{request.creator}
<if test="request.reviewIds != null and request.reviewIds.size() > 0">

View File

@ -114,6 +114,9 @@
<if test="request.workspaceId != null">
AND test_plan.workspace_id = #{request.workspaceId}
</if>
<if test="request.projectId != null">
AND test_plan_project.project_id = #{request.projectId}
</if>
<if test="request.id != null">
AND test_plan.id = #{request.id}
</if>
@ -160,16 +163,22 @@
</select>
<select id="listRelate" resultType="io.metersphere.track.dto.TestPlanDTOWithMetric">
select test_plan.* from test_plan
where test_plan.workspace_id = #{request.workspaceId}
and (test_plan.principal = #{request.principal}
<if test="request.planIds != null and request.planIds.size() > 0">
or test_plan.id in
<foreach collection="request.planIds" item="planId" open="(" close=")" separator=",">
#{planId}
</foreach>
</if>
)
select distinct test_plan.* from test_plan
inner join test_plan_project on test_plan.id = test_plan_project.test_plan_id
<where>
test_plan.workspace_id = #{request.workspaceId}
<if test="request.projectId != null">
and test_plan_project.project_id = #{request.projectId}
</if>
and (test_plan.principal = #{request.principal}
<if test="request.planIds != null and request.planIds.size() > 0">
or test_plan.id in
<foreach collection="request.planIds" item="planId" open="(" close=")" separator=",">
#{planId}
</foreach>
</if>
)
</where>
order by test_plan.update_time desc
</select>

View File

@ -19,7 +19,7 @@ public interface ExtTestPlanTestCaseMapper {
List<TestPlanCaseDTO> listByNodes(@Param("request") QueryTestPlanCaseRequest request);
List<String> findRelateTestPlanId(@Param("userId") String userId, @Param("workspaceId") String workspaceId);
List<String> findRelateTestPlanId(@Param("userId") String userId, @Param("workspaceId") String workspaceId, @Param("projectId") String projectId);
List<TestPlanCaseDTO> getRecentTestedTestCase(@Param("request") QueryTestPlanCaseRequest request);

View File

@ -270,8 +270,15 @@
select distinct plan_id from test_plan_test_case
inner join test_plan
on test_plan_test_case.plan_id = test_plan.id
where test_plan_test_case.executor = #{userId}
and test_plan.workspace_id = #{workspaceId}
inner join test_plan_project
on test_plan.id = test_plan_project.test_plan_id
<where>
test_plan_test_case.executor = #{userId}
and test_plan.workspace_id = #{workspaceId}
<if test="projectId != null">
and test_plan_project.project_id = #{projectId}
</if>
</where>
</select>
<select id="getRecentTestedTestCase" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
select test_plan_test_case.*, test_case.*

View File

@ -11,7 +11,7 @@ public interface ExtTestReviewCaseMapper {
List<TestReviewCaseDTO> list(@Param("request") QueryCaseReviewRequest request);
List<String> getStatusByReviewId(String reviewId);
List<String> findRelateTestReviewId(@Param("userId") String userId, @Param("workspaceId") String workspaceId);
List<String> findRelateTestReviewId(@Param("userId") String userId, @Param("workspaceId") String workspaceId, @Param("projectId") String projectId);
/**
* 根据项目 ids 查询 TestReviewCaseDTO 列表

View File

@ -206,6 +206,7 @@
inner join project on project.id = test_case_review_project.project_id
where test_case_review_test_case.review_id = #{userId}
and project.workspace_id = #{workspaceId}
and test_case_review_project.project_id = #{projectId}
</select>
<select id="listTestCaseByProjectIds" resultType="io.metersphere.track.dto.TestReviewCaseDTO">
select distinct * from test_case_review_test_case, test_case

View File

@ -68,4 +68,8 @@ public class SessionUtils {
public static String getCurrentOrganizationId() {
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastOrganizationId();
}
public static String getCurrentProjectId() {
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastProjectId();
}
}

View File

@ -81,8 +81,7 @@ public class TestCaseReviewController {
@PostMapping("/list/all")
public List<TestCaseReview> listAll() {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
return testCaseReviewService.listCaseReviewAll(currentWorkspaceId);
return testCaseReviewService.listCaseReviewAll();
}
@PostMapping("/relevance")

View File

@ -35,4 +35,6 @@ public class QueryCaseReviewRequest extends TestCaseReviewTestCase {
private String method;
private Map<String, Object> combine;
private String projectId;
}

View File

@ -156,6 +156,7 @@ public class TestCaseReviewService {
public List<TestCaseReviewDTO> listCaseReview(QueryCaseReviewRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extTestCaseReviewMapper.list(request);
}
@ -346,21 +347,16 @@ public class TestCaseReviewService {
testCaseReviewTestCaseMapper.deleteByExample(testCaseReviewTestCaseExample);
}
public List<TestCaseReview> listCaseReviewAll(String currentWorkspaceId) {
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(currentWorkspaceId);
List<Project> projects = projectMapper.selectByExample(projectExample);
List<String> projectIds = projects.stream().map(Project::getId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(projectIds)) {
TestCaseReviewProjectExample testCaseReviewProjectExample = new TestCaseReviewProjectExample();
testCaseReviewProjectExample.createCriteria().andProjectIdIn(projectIds);
List<TestCaseReviewProject> testCaseReviewProjects = testCaseReviewProjectMapper.selectByExample(testCaseReviewProjectExample);
List<String> reviewIds = testCaseReviewProjects.stream().map(TestCaseReviewProject::getReviewId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(reviewIds)) {
public List<TestCaseReview> listCaseReviewAll() {
TestCaseReviewProjectExample reviewProjectExample = new TestCaseReviewProjectExample();
TestCaseReviewProjectExample.Criteria criteria = reviewProjectExample.createCriteria();
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) {
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
List<TestCaseReviewProject> testCaseReviewProjects = testCaseReviewProjectMapper.selectByExample(reviewProjectExample);
if (!CollectionUtils.isEmpty(testCaseReviewProjects)) {
List<String> caseReviewIds = testCaseReviewProjects.stream().map(TestCaseReviewProject::getReviewId).collect(Collectors.toList());
TestCaseReviewExample testCaseReviewExample = new TestCaseReviewExample();
testCaseReviewExample.createCriteria().andIdIn(reviewIds);
testCaseReviewExample.createCriteria().andIdIn(caseReviewIds);
return testCaseReviewMapper.selectByExample(testCaseReviewExample);
}
}
@ -481,7 +477,8 @@ public class TestCaseReviewService {
request.setReviewerId(user.getId());
}
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setReviewIds(extTestReviewCaseMapper.findRelateTestReviewId(user.getId(), SessionUtils.getCurrentWorkspaceId()));
request.setProjectId(SessionUtils.getCurrentProjectId());
request.setReviewIds(extTestReviewCaseMapper.findRelateTestReviewId(user.getId(), SessionUtils.getCurrentWorkspaceId(), user.getLastProjectId()));
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(SessionUtils.getCurrentWorkspaceId());
@ -545,9 +542,11 @@ public class TestCaseReviewService {
if (userIds.size() > 0) {
for (String id : userIds) {
stringBuilder.append(userMap.get(id)).append("");
if (StringUtils.isNotBlank(userMap.get(id))) {
stringBuilder.append(userMap.get(id)).append("");
}
}
name = stringBuilder.toString().substring(0, stringBuilder.length() - 1);
name = stringBuilder.substring(0, stringBuilder.length() - 1);
}
return name;
}

View File

@ -327,6 +327,10 @@ public class TestPlanService {
public List<TestPlanDTOWithMetric> listTestPlan(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
String projectId = SessionUtils.getCurrentProjectId();
if (StringUtils.isNotBlank(projectId)) {
request.setProjectId(projectId);
}
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request);
calcTestPlanRate(testPlans);
return testPlans;
@ -400,9 +404,22 @@ public class TestPlanService {
}
public List<TestPlan> listTestAllPlan(String currentWorkspaceId) {
TestPlanExample testPlanExample = new TestPlanExample();
testPlanExample.createCriteria().andWorkspaceIdEqualTo(currentWorkspaceId);
return testPlanMapper.selectByExample(testPlanExample);
TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample();
TestPlanProjectExample.Criteria criteria = testPlanProjectExample.createCriteria();
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) {
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
List<TestPlanProject> testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample);
if (!CollectionUtils.isEmpty(testPlanProjects)) {
List<String> testPlanIds = testPlanProjects.stream().map(TestPlanProject::getTestPlanId).collect(Collectors.toList());
TestPlanExample testPlanExample = new TestPlanExample();
TestPlanExample.Criteria testPlanCriteria = testPlanExample.createCriteria();
testPlanCriteria.andWorkspaceIdEqualTo(currentWorkspaceId);
testPlanCriteria.andIdIn(testPlanIds);
return testPlanMapper.selectByExample(testPlanExample);
}
}
return new ArrayList<>();
}
public List<TestPlanDTOWithMetric> listRelateAllPlan() {
@ -410,7 +427,8 @@ public class TestPlanService {
QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setPrincipal(user.getId());
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId()));
request.setProjectId(SessionUtils.getCurrentProjectId());
request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId(), SessionUtils.getCurrentProjectId()));
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.listRelate(request);
calcTestPlanRate(testPlans);
return testPlans;

View File

@ -123,7 +123,7 @@ public class TestPlanTestCaseService {
public void buildQueryRequest(QueryTestPlanCaseRequest request, int count) {
SessionUser user = SessionUtils.getUser();
List<String> relateTestPlanIds = extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId());
List<String> relateTestPlanIds = extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId(), SessionUtils.getCurrentProjectId());
PageHelper.startPage(1, count, true);
request.setPlanIds(relateTestPlanIds);
request.setExecutor(user.getId());

View File

@ -2,11 +2,6 @@
<ms-container>
<ms-aside-container>
<select-menu
:data="projects"
:current-data="currentProject"
:title="$t('test_track.project')"
@dataChange="changeProject"/>
<node-tree
class="node-tree"
v-loading="result.loading"
@ -17,13 +12,13 @@
:draggable="nodeTreeDraggable"
:select-node.sync="selectNode"
@refreshTable="refreshTable"
:current-project="currentProject"
:current-project="{id:currentProject}"
ref="nodeTree"/>
</ms-aside-container>
<ms-main-container>
<test-case-list
:current-project="currentProject"
:current-project="{id:currentProject}"
:select-node-ids="selectNodeIds"
:select-parent-nodes="selectParentNodes"
@testCaseEdit="editTestCase"
@ -41,7 +36,7 @@
:read-only="testCaseReadOnly"
:tree-nodes="treeNodes"
:select-node="selectNode"
:current-project="currentProject"
:current-project="{id:currentProject}"
ref="testCaseEditDialog">
</test-case-edit>
@ -57,7 +52,7 @@
import NodeTree from '../common/NodeTree';
import TestCaseEdit from './components/TestCaseEdit';
import {CURRENT_PROJECT, ROLE_TEST_MANAGER, ROLE_TEST_USER} from '../../../../common/js/constants';
import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER} from '../../../../common/js/constants';
import TestCaseList from "./components/TestCaseList";
import SelectMenu from "../common/SelectMenu";
import TestCaseMove from "./components/TestCaseMove";
@ -90,11 +85,15 @@ export default {
nodeTreeDraggable: true,
}
},
activated() {
this.currentProject = localStorage.getItem(PROJECT_ID);
},
mounted() {
this.init(this.$route);
},
watch: {
'$route'(to, from) {
// console.log(this.$route.params.projectId)
this.init(to);
},
currentProject() {
@ -105,7 +104,7 @@ export default {
init(route) {
let path = route.path;
if (path.indexOf("/track/case/edit") >= 0 || path.indexOf("/track/case/create") >= 0) {
this.getProjects();
// this.getProjects();
this.testCaseReadOnly = false;
if (!checkoutTestManagerOrTestUser()) {
this.testCaseReadOnly = true;
@ -113,48 +112,49 @@ export default {
let caseId = this.$route.params.caseId;
this.openRecentTestCaseEditDialog(caseId);
this.$router.push('/track/case/all');
} else if (route.params.projectId) {
this.getProjects();
this.getProjectById(route.params.projectId);
}
// else if (route.params.projectId) {
// this.getProjects();
// this.getProjectById(route.params.projectId);
// }
},
getProjects() {
this.$get("/project/listAll", (response) => {
this.projects = response.data;
let lastProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT));
if (lastProject) {
let hasCurrentProject = false;
for (let i = 0; i < this.projects.length; i++) {
if (this.projects[i].id == lastProject.id) {
this.currentProject = lastProject;
hasCurrentProject = true;
break;
}
}
if (!hasCurrentProject) {
this.setCurrentProject(this.projects[0]);
}
} else {
if (this.projects.length > 0) {
this.setCurrentProject(this.projects[0]);
}
}
// this.checkProject();
});
},
checkProject() {
if (this.currentProject === null) {
this.$alert(this.$t('test_track.case.no_project'), {
confirmButtonText: this.$t('project.create'),
callback: action => {
this.$router.push("/track/project/create");
}
});
}
},
changeProject(project) {
this.setCurrentProject(project);
},
// getProjects() {
// this.$get("/project/listAll", (response) => {
// this.projects = response.data;
// let lastProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT));
// if (lastProject) {
// let hasCurrentProject = false;
// for (let i = 0; i < this.projects.length; i++) {
// if (this.projects[i].id == lastProject.id) {
// this.currentProject = lastProject;
// hasCurrentProject = true;
// break;
// }
// }
// if (!hasCurrentProject) {
// this.setCurrentProject(this.projects[0]);
// }
// } else {
// if (this.projects.length > 0) {
// this.setCurrentProject(this.projects[0]);
// }
// }
// // this.checkProject();
// });
// },
// checkProject() {
// if (this.currentProject === null) {
// this.$alert(this.$t('test_track.case.no_project'), {
// confirmButtonText: this.$t('project.create'),
// callback: action => {
// this.$router.push("/track/project/create");
// }
// });
// }
// },
// changeProject(project) {
// this.setCurrentProject(project);
// },
nodeChange(nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
this.selectParentNodes = pNodes;
@ -182,21 +182,21 @@ export default {
this.testCaseReadOnly = true;
this.$refs.testCaseEditDialog.open(testCase);
},
getProjectByCaseId(caseId) {
return this.$get('/test/case/project/' + caseId, async response => {
this.setCurrentProject(response.data);
});
},
// getProjectByCaseId(caseId) {
// return this.$get('/test/case/project/' + caseId, async response => {
// this.setCurrentProject(response.data);
// });
// },
refresh() {
this.selectNodeIds = [];
this.selectParentNodes = [];
this.selectNode = {};
this.$refs.testCaseList.initTableData();
this.refreshTable();
this.getNodeTree();
},
openRecentTestCaseEditDialog(caseId) {
if (caseId) {
this.getProjectByCaseId(caseId);
// this.getProjectByCaseId(caseId);
this.$get('/test/case/get/' + caseId, response => {
if (response.data) {
this.$refs.testCaseEditDialog.open(response.data);
@ -206,31 +206,31 @@ export default {
this.$refs.testCaseEditDialog.open();
}
},
getProjectById(id) {
if (id && id != 'all') {
this.$get('/project/get/' + id, response => {
let project = response.data;
this.setCurrentProject(project);
// this.$router.push('/track/case/all');
});
}
if (id === 'all') {
this.refresh();
}
},
setCurrentProject(project) {
if (project) {
this.currentProject = project;
localStorage.setItem(CURRENT_PROJECT, JSON.stringify(project));
}
this.refresh();
},
// getProjectById(id) {
// if (id && id != 'all') {
// this.$get('/project/get/' + id, response => {
// let project = response.data;
// this.setCurrentProject(project);
// // this.$router.push('/track/case/all');
// });
// }
// if (id === 'all') {
// this.refresh();
// }
// },
// setCurrentProject(project) {
// if (project) {
// this.currentProject = project;
// localStorage.setItem(CURRENT_PROJECT, JSON.stringify(project));
// }
// this.refresh();
// },
getNodeTree() {
if (!hasRoles(ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.nodeTreeDraggable = false;
}
if (this.currentProject) {
this.result = this.$get("/case/node/list/" + this.currentProject.id, response => {
this.result = this.$get("/case/node/list/" + this.currentProject, response => {
this.treeNodes = response.data;
});
}

View File

@ -489,7 +489,7 @@ export default {
param.nodePath = item.path;
}
});
if (this.currentProject) {
if (this.currentProject.id) {
param.projectId = this.currentProject.id;
}
param.name = param.name.trim();
@ -563,7 +563,7 @@ export default {
},
getTestOptions() {
this.testOptions = [];
if (this.currentProject && this.form.type != '' && this.form.type != 'functional') {
if (this.currentProject.id && this.form.type != '' && this.form.type != 'functional') {
this.result = this.$get('/' + this.form.type + '/list/' + this.currentProject.id, response => {
this.testOptions = response.data;
this.testOptions.unshift({id: 'other', name: this.$t('test_track.case.other')})

View File

@ -302,7 +302,9 @@ export default {
// param.nodeIds = this.selectNodeIds;
this.condition.nodeIds = this.selectNodeIds;
}
this.getData();
if (this.currentProject.id) {
this.getData();
}
},
getData() {
if (this.currentProject) {

View File

@ -135,14 +135,14 @@ export default {
},
init() {
let path = this.$route.path;
if (path.indexOf("/track/case") >= 0 && !!this.$route.params.projectId) {
this.testCaseProjectPath = path;
//
this.isProjectActivation = false;
this.reload();
} else {
this.isProjectActivation = true;
}
// if (path.indexOf("/track/case") >= 0 && !!this.$route.params.projectId) {
// this.testCaseProjectPath = path;
// //
// this.isProjectActivation = false;
// this.reload();
// } else {
// this.isProjectActivation = true;
// }
if (path.indexOf("/track/plan/view") >= 0) {
this.testPlanViewPath = path;
this.reload();
@ -151,6 +151,10 @@ export default {
this.testCaseEditPath = path;
this.reload();
}
if (path.indexOf("/track/review/view") >= 0) {
this.testCaseReviewEditPath = path;
this.reload();
}
},
registerEvents() {
TrackEvent.$on(LIST_CHANGE, () => {

View File

@ -1,4 +1,3 @@
import MsProject from "@/business/components/settings/project/MsProject";
const TestTrack = () => import('@/business/components/track/TestTrack')
const TrackHome = () => import('@/business/components/track/home/TrackHome')

@ -1 +1 @@
Subproject commit 8a972a198775b3783ed6e4cef27197e53d1ebdc8
Subproject commit a22a3005d9bd254793fcf634d72539cbdf31be3a