This commit is contained in:
chenjianxing 2020-09-14 15:55:24 +08:00
commit 37bf65ce07
6 changed files with 130 additions and 89 deletions

View File

@ -14,6 +14,7 @@ import io.metersphere.track.dto.TestPlanDTOWithMetric;
import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest; import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest;
import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplan.AddTestPlanRequest; import io.metersphere.track.request.testplan.AddTestPlanRequest;
import io.metersphere.track.request.testplancase.TestCaseRelevanceRequest;
import io.metersphere.track.service.TestPlanProjectService; import io.metersphere.track.service.TestPlanProjectService;
import io.metersphere.track.service.TestPlanService; import io.metersphere.track.service.TestPlanService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
@ -111,8 +112,18 @@ public class TestPlanController {
return testPlanService.getProjectNameByPlanId(planId); return testPlanService.getProjectNameByPlanId(planId);
} }
@GetMapping("/project/{planId}") @PostMapping("/project")
public List<Project> getProjectByPlanId(@PathVariable String planId) { public List<Project> getProjectByPlanId(@RequestBody TestCaseRelevanceRequest request) {
return testPlanProjectService.getProjectByPlanId(planId); List<String> projectIds = testPlanProjectService.getProjectIdsByPlanId(request.getPlanId());
request.setProjectIds(projectIds);
return testPlanProjectService.getProjectByPlanId(request);
}
@PostMapping("/project/{goPage}/{pageSize}")
public Pager<List<Project>> getProjectByPlanId(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody TestCaseRelevanceRequest request) {
List<String> projectIds = testPlanProjectService.getProjectIdsByPlanId(request.getPlanId());
request.setProjectIds(projectIds);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testPlanProjectService.getProjectByPlanId(request));
} }
} }

View File

@ -0,0 +1,14 @@
package io.metersphere.track.request.testplancase;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class TestCaseRelevanceRequest {
private String planId;
private String name;
private List<String> projectIds;
}

View File

@ -6,26 +6,25 @@ import io.metersphere.base.domain.TestPlanProject;
import io.metersphere.base.domain.TestPlanProjectExample; import io.metersphere.base.domain.TestPlanProjectExample;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.TestPlanProjectMapper; import io.metersphere.base.mapper.TestPlanProjectMapper;
import org.python.antlr.ast.Str; import io.metersphere.track.request.testplancase.TestCaseRelevanceRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class TestPlanProjectService { public class TestPlanProjectService {
@Resource @Resource
TestPlanProjectMapper testPlanProjectMapper; TestPlanProjectMapper testPlanProjectMapper;
@Resource @Resource
ProjectMapper projectMapper; ProjectMapper projectMapper;
public List<String> getProjectIdsByPlanId(String planId) { public List<String> getProjectIdsByPlanId(String planId) {
TestPlanProjectExample example = new TestPlanProjectExample(); TestPlanProjectExample example = new TestPlanProjectExample();
example.createCriteria().andTestPlanIdEqualTo(planId); example.createCriteria().andTestPlanIdEqualTo(planId);
@ -41,12 +40,14 @@ public class TestPlanProjectService {
return projectIds; return projectIds;
} }
public List<Project> getProjectByPlanId(String planId) { public List<Project> getProjectByPlanId(TestCaseRelevanceRequest request) {
List<String> projectIds = getProjectIdsByPlanId(planId);
ProjectExample projectExample = new ProjectExample(); ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andIdIn(projectIds); ProjectExample.Criteria criteria = projectExample.createCriteria();
List<Project> projects = projectMapper.selectByExample(projectExample); criteria.andIdIn(request.getProjectIds());
return Optional.ofNullable(projects).orElse(new ArrayList<>()); if (StringUtils.isNotBlank(request.getName())) {
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
}
return projectMapper.selectByExample(projectExample);
} }
public void deleteTestPlanProjectByPlanId(String planId) { public void deleteTestPlanProjectByPlanId(String planId) {

View File

@ -1,86 +1,101 @@
<template> <template>
<el-dialog v-loading="result.loading" <el-dialog v-loading="result.loading"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
:close-on-click-modal="false" :close-on-click-modal="false"
> class="ms-switch-project"
<el-table >
:data="tableData" <ms-table-header :condition.sync="condition" @search="initData" title="" :show-create="false"/>
highlight-current-row <el-table
@current-change="handleCurrentChange" :data="tableData"
style="width: 100%"> highlight-current-row
<el-table-column prop="name" :label="$t('commons.name')" show-overflow-tooltip/> @current-change="handleCurrentChange"
<el-table-column prop="description" :label="$t('commons.description')" show-overflow-tooltip> style="width: 100%">
<template v-slot:default="scope"> <el-table-column prop="name" :label="$t('commons.name')" show-overflow-tooltip/>
{{ scope.row.description }} <el-table-column prop="description" :label="$t('commons.description')" show-overflow-tooltip>
</template> <template v-slot:default="scope">
</el-table-column> {{ scope.row.description }}
<el-table-column </template>
sortable </el-table-column>
prop="createTime" <el-table-column
:label="$t('commons.create_time')" prop="createTime"
show-overflow-tooltip> :label="$t('commons.create_time')"
<template v-slot:default="scope"> show-overflow-tooltip>
<span>{{ scope.row.createTime | timestampFormatDate }}</span> <template v-slot:default="scope">
</template> <span>{{ scope.row.createTime | timestampFormatDate }}</span>
</el-table-column> </template>
<el-table-column </el-table-column>
sortable <el-table-column
prop="updateTime" prop="updateTime"
:label="$t('commons.update_time')" :label="$t('commons.update_time')"
show-overflow-tooltip> show-overflow-tooltip>
<template v-slot:default="scope"> <template v-slot:default="scope">
<span>{{ scope.row.updateTime | timestampFormatDate }}</span> <span>{{ scope.row.updateTime | timestampFormatDate }}</span>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<template v-slot:footer> <ms-table-pagination :change="initData" :current-page.sync="currentPage" :page-size.sync="pageSize"
<div class="dialog-footer"> :total="total"/>
<ms-dialog-footer <template v-slot:footer>
@cancel="dialogVisible = false" <div class="dialog-footer">
@confirm="submit()"/> <ms-dialog-footer
</div> @cancel="dialogVisible = false"
</template> @confirm="submit()"/>
</el-dialog> </div>
</template>
</el-dialog>
</template> </template>
<script> <script>
import MsDialogFooter from "../../../common/components/MsDialogFooter"; import MsDialogFooter from "../../../common/components/MsDialogFooter";
import MsTableHeader from "../../../common/components/MsTableHeader";
import MsTablePagination from "../../../common/pagination/TablePagination";
export default { export default {
name: "SwitchProject", name: "SwitchProject",
components: {MsDialogFooter}, components: {MsDialogFooter, MsTableHeader, MsTablePagination},
data() { data() {
return { return {
tableData: [], tableData: [],
result: {}, result: {},
dialogVisible: false, dialogVisible: false,
projectId: '' projectId: '',
planId: '',
condition: {},
currentPage: 1,
pageSize: 5,
total: 0,
}
},
methods: {
open(planId) {
this.dialogVisible = true;
this.planId = planId;
this.initData();
},
initData() {
this.condition.planId = this.planId;
this.result = this.$post("/test/plan/project/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
const data = res.data;
this.total = data.itemCount;
this.tableData = data.listObject;
})
},
handleCurrentChange(currentRow) {
// initData
if (currentRow) {
this.projectId = currentRow.id;
} }
}, },
methods: { submit() {
open(planId) { this.$emit('getProjectNode', this.projectId);
this.dialogVisible = true; this.dialogVisible = false;
this.initData(planId);
},
initData(planId) {
this.result = this.$get("/test/plan/project/" + planId,res => {
this.tableData = res.data;
})
},
handleCurrentChange(currentRow) {
// initData
if (currentRow) {
this.projectId = currentRow.id;
}
},
submit() {
this.$emit('getProjectNode', this.projectId);
this.dialogVisible = false;
}
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.ms-switch-project >>> .el-dialog__body {
padding: 0 15px !important;
}
</style> </style>

View File

@ -192,8 +192,8 @@ export default {
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
for (let i = 0; i < this.tableData.length; i++) { for (let i = 0; i < this.tableData.length; i++) {
let path = "/test/plan/project/" + this.tableData[i].id; let path = "/test/plan/project";
this.$get(path, res => { this.$post(path,{planId: this.tableData[i].id}, res => {
let arr = res.data; let arr = res.data;
let projectName = arr.map(data => data.name).join("、"); let projectName = arr.map(data => data.name).join("、");
let projectIds = arr.map(data => data.id); let projectIds = arr.map(data => data.id);

View File

@ -256,7 +256,7 @@
}, },
getProject() { getProject() {
if (this.planId) { if (this.planId) {
this.$get("/test/plan/project/" + this.planId,res => { this.$post("/test/plan/project/", {planId: this.planId},res => {
let data = res.data; let data = res.data;
if (data) { if (data) {
this.projects = data; this.projects = data;