mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-05 05:29:29 +08:00
测试用例导出
This commit is contained in:
parent
d9ab83afa0
commit
cd60ef9be8
@ -15,4 +15,6 @@ public interface ExtTestCaseMapper {
|
||||
|
||||
List<TestCaseDTO> listByMethod(@Param("request") QueryTestCaseRequest request);
|
||||
|
||||
List<TestCaseDTO> listBytestCaseIds(@Param("request") QueryTestCaseRequest request);
|
||||
|
||||
}
|
||||
|
@ -80,4 +80,15 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="listBytestCaseIds" resultType="io.metersphere.track.dto.TestCaseDTO">
|
||||
select test_case.*,api_test.name as apiName,load_test.name AS performName from test_case left join api_test on test_case.test_id=api_test.id left join load_test on test_case.test_id=load_test.id
|
||||
<where>
|
||||
<if test="request.testCaseIds!=null and request.testCaseIds.size() > 0">
|
||||
and test_case.id in
|
||||
<foreach collection="request.testCaseIds" open="(" close=")" separator="," item="id">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
@ -109,6 +109,11 @@ public class TestCaseController {
|
||||
public void testCaseTemplateExport(HttpServletResponse response){
|
||||
testCaseService.testCaseTemplateExport(response);
|
||||
}
|
||||
@GetMapping("/export/testCase/{testCaseIds}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public void testCaseExport(HttpServletResponse response,QueryTestCaseRequest request){
|
||||
testCaseService.testCaseExport(response,request);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/edit")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
|
@ -6,8 +6,10 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TestCaseDTO extends TestCaseWithBLOBs{
|
||||
public class TestCaseDTO extends TestCaseWithBLOBs {
|
||||
|
||||
private String maintainerName;
|
||||
private String apiName;
|
||||
private String performName;
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ public class QueryTestCaseRequest extends TestCase {
|
||||
|
||||
private List<String> nodeIds;
|
||||
|
||||
private List<String> testCaseIds;
|
||||
|
||||
private List<OrderRequest> orders;
|
||||
|
||||
private Map<String, List<String>> filters;
|
||||
|
@ -2,6 +2,8 @@ package io.metersphere.track.service;
|
||||
|
||||
|
||||
import com.alibaba.excel.EasyExcelFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
@ -101,7 +103,7 @@ public class TestCaseService {
|
||||
return testCaseMapper.updateByPrimaryKeySelective(testCase);
|
||||
}
|
||||
|
||||
private void checkTestCaseExist (TestCaseWithBLOBs testCase) {
|
||||
private void checkTestCaseExist(TestCaseWithBLOBs testCase) {
|
||||
if (testCase.getName() != null) {
|
||||
TestCaseExample example = new TestCaseExample();
|
||||
example.createCriteria()
|
||||
@ -154,7 +156,7 @@ public class TestCaseService {
|
||||
|
||||
List<TestCase> testCaseNames = extTestCaseMapper.getTestCaseNames(request);
|
||||
|
||||
if ( StringUtils.isNotBlank(request.getPlanId()) ) {
|
||||
if (StringUtils.isNotBlank(request.getPlanId())) {
|
||||
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
||||
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(request.getPlanId());
|
||||
List<String> relevanceIds = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample).stream()
|
||||
@ -284,9 +286,9 @@ public class TestCaseService {
|
||||
data.setName(Translator.get("test_case") + i);
|
||||
path.append("/" + Translator.get("module") + i);
|
||||
data.setNodePath(path.toString());
|
||||
data.setPriority("P" + i%4);
|
||||
data.setType(types.get(i%3));
|
||||
data.setMethod(methods.get(i%2));
|
||||
data.setPriority("P" + i % 4);
|
||||
data.setType(types.get(i % 3));
|
||||
data.setMethod(methods.get(i % 2));
|
||||
data.setPrerequisite(Translator.get("preconditions_optional"));
|
||||
data.setStepDesc("1. " + Translator.get("step_tip_separate") +
|
||||
"\n2. " + Translator.get("step_tip_order") + "\n3. " + Translator.get("step_tip_optional"));
|
||||
@ -309,6 +311,73 @@ public class TestCaseService {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void testCaseExport(HttpServletResponse response, QueryTestCaseRequest request) {
|
||||
EasyExcelExporter easyExcelExporter = null;
|
||||
try {
|
||||
easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class);
|
||||
easyExcelExporter.export(response, generateTestCaseExcel(request),
|
||||
Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet"));
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
} finally {
|
||||
easyExcelExporter.close();
|
||||
}
|
||||
}
|
||||
|
||||
private List<TestCaseExcelData> generateTestCaseExcel(QueryTestCaseRequest request) {
|
||||
List<TestCaseDTO> TestCaseList = extTestCaseMapper.listBytestCaseIds(request);
|
||||
List<TestCaseExcelData> list = new ArrayList<>();
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
StringBuilder step = new StringBuilder("");
|
||||
StringBuilder result = new StringBuilder("");
|
||||
for (int i = 0; i < TestCaseList.size(); i++) {
|
||||
TestCaseExcelData data = new TestCaseExcelData();
|
||||
data.setName(TestCaseList.get(i).getName());
|
||||
data.setNodePath(TestCaseList.get(i).getNodePath());
|
||||
data.setPriority(TestCaseList.get(i).getPriority());
|
||||
data.setType(TestCaseList.get(i).getType());
|
||||
data.setMethod(TestCaseList.get(i).getMethod());
|
||||
data.setPrerequisite(TestCaseList.get(i).getPrerequisite());
|
||||
if (TestCaseList.get(i).getMethod().equals("manual")) {
|
||||
String steps = TestCaseList.get(i).getSteps();
|
||||
JSONArray jsonArray = JSON.parseArray(steps);
|
||||
for (int j = 0; j <jsonArray.size(); j++) {
|
||||
int num=j+1;
|
||||
step.append(num + ":" + jsonArray.getJSONObject(j).getString("desc"));
|
||||
step.append("\n");
|
||||
data.setStepDesc(step.toString());
|
||||
result.append(num + ":" + jsonArray.getJSONObject(j).getString("result"));
|
||||
result.append("\n");
|
||||
data.setStepResult(result.toString());
|
||||
}
|
||||
data.setRemark(TestCaseList.get(i).getRemark());
|
||||
} else if(TestCaseList.get(i).getMethod().equals("auto")&&TestCaseList.get(i).getType().equals("api")){
|
||||
data.setStepDesc("");
|
||||
data.setStepResult("");
|
||||
data.setRemark(TestCaseList.get(i).getApiName());
|
||||
}else if(TestCaseList.get(i).getMethod().equals("auto")&&TestCaseList.get(i).getType().equals("performance")){
|
||||
data.setStepDesc("");
|
||||
data.setStepResult("");
|
||||
data.setRemark(TestCaseList.get(i).getPerformName());
|
||||
}
|
||||
data.setMaintainer(user.getId());
|
||||
list.add(data);
|
||||
}
|
||||
|
||||
list.add(new TestCaseExcelData());
|
||||
TestCaseExcelData explain = new TestCaseExcelData();
|
||||
explain.setName(Translator.get("do_not_modify_header_order"));
|
||||
explain.setNodePath(Translator.get("module_created_automatically"));
|
||||
explain.setType(Translator.get("options") + "(functional、performance、api)");
|
||||
explain.setMethod(Translator.get("options") + "(manual、auto)");
|
||||
explain.setPriority(Translator.get("options") + "(P0、P1、P2、P3)");
|
||||
explain.setMaintainer(Translator.get("please_input_workspace_member"));
|
||||
|
||||
list.add(explain);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public void editTestCaseBath(TestCaseBatchRequest request) {
|
||||
TestCaseExample testCaseExample = new TestCaseExample();
|
||||
testCaseExample.createCriteria().andIdIn(request.getIds());
|
||||
|
@ -1,15 +1,25 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-tooltip class="item" effect="dark" :content="$t('test_track.case.export.export')" placement="right">
|
||||
<el-button type="info" icon="el-icon-download" size="mini" circle></el-button>
|
||||
</el-tooltip>
|
||||
<el-row>
|
||||
<el-link type="primary" class="download-case"
|
||||
@click="downloadCase"
|
||||
>{{$t('test_track.case.import.download_case')}}
|
||||
</el-link>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "TestCaseImport"
|
||||
export default {
|
||||
name: "TestCaseExport",
|
||||
methods: {
|
||||
downloadCase() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
@ -11,6 +11,8 @@
|
||||
</template>
|
||||
<template v-slot:button>
|
||||
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2" :content="$t('test_track.case.import.import')" @click="importTestCase"/>
|
||||
<ms-table-button :is-tester-permission="true" icon="el-icon-download"
|
||||
:content="$t('test_track.case.export.export')" @click="handleBatch('export')"/>
|
||||
<ms-table-button :is-tester-permission="true" icon="el-icon-right" :content="$t('test_track.case.move')" @click="handleBatch('move')"/>
|
||||
<ms-table-button :is-tester-permission="true" icon="el-icon-delete" :content="$t('test_track.case.delete')" @click="handleBatch('delete')"/>
|
||||
<!--<test-case-export/>-->
|
||||
@ -116,7 +118,7 @@
|
||||
import MsTableOperator from "../../../common/components/MsTableOperator";
|
||||
import MsTableOperatorButton from "../../../common/components/MsTableOperatorButton";
|
||||
import MsTableButton from "../../../common/components/MsTableButton";
|
||||
import {_filter, _sort, humpToLine} from "../../../../../common/js/utils";
|
||||
import {_filter, _sort, downloadFile, humpToLine} from "../../../../../common/js/utils";
|
||||
|
||||
export default {
|
||||
name: "TestCaseList",
|
||||
@ -254,7 +256,7 @@
|
||||
}
|
||||
},
|
||||
handleSelectionChange(selection, row) {
|
||||
if(this.selectIds.has(row.id)){
|
||||
if (this.selectIds.has(row.id)) {
|
||||
this.selectIds.delete(row.id);
|
||||
} else {
|
||||
this.selectIds.add(row.id);
|
||||
@ -263,15 +265,37 @@
|
||||
importTestCase() {
|
||||
this.$refs.testCaseImport.open();
|
||||
},
|
||||
handleBatch(type){
|
||||
exportTestCase() {
|
||||
let config = {
|
||||
url: '/test/case/export/testCase/' + [...this.selectIds],
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
};
|
||||
this.result = this.$request(config).then(response => {
|
||||
const filename = '测试用例.xlsx'
|
||||
const blob = new Blob([response.data]);
|
||||
if ("download" in document.createElement("a")) {
|
||||
let aTag = document.createElement('a');
|
||||
aTag.download = filename;
|
||||
aTag.href = URL.createObjectURL(blob);
|
||||
aTag.click();
|
||||
URL.revokeObjectURL(aTag.href)
|
||||
} else {
|
||||
navigator.msSaveBlob(blob, filename);
|
||||
}
|
||||
});
|
||||
},
|
||||
handleBatch(type) {
|
||||
if (this.selectIds.size < 1) {
|
||||
this.$warning(this.$t('test_track.plan_view.select_manipulate'));
|
||||
return;
|
||||
}
|
||||
if (type === 'move'){
|
||||
if (type === 'move') {
|
||||
this.$emit('moveToNode', this.selectIds);
|
||||
} else if (type === 'delete'){
|
||||
} else if (type === 'delete') {
|
||||
this.handleDeleteBatch();
|
||||
} else {
|
||||
this.exportTestCase();
|
||||
}
|
||||
},
|
||||
filter(filters) {
|
||||
|
Loading…
Reference in New Issue
Block a user