Commit 42cfd23d authored by song-tianyang's avatar song-tianyang Committed by 刘瑞斌
Browse files

fix(接口自动化,功能用例): 修复功能用例的excel模板备注和列对不起来的问题以及接口自动化引用场景接口案例时按钮禁止重复提交

修复功能用例的excel模板备注和列对不起来的问题没有对应的tapd链接     --bug=1004928 --user=宋天阳
【接口测试-接口自动化】新建场景后选择接口或场景时多次点击可生成多个(按键未添加保护)
https://www.tapd.cn/55049933/s/1025330
parent 2c2a65b8
Showing with 165 additions and 68 deletions
+165 -68
......@@ -4,12 +4,17 @@ import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author song.tianyang
......@@ -19,9 +24,36 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString;
public class FunctionCaseTemplateWriteHandler extends AbstractRowHeightStyleStrategy {
private boolean isNeedId;
public FunctionCaseTemplateWriteHandler(boolean isNeedId){
List<List<String>> headList = new ArrayList<>();
Map<String,Integer> rowDispseIndexMap;
public FunctionCaseTemplateWriteHandler(boolean isNeedId,List<List<String>> headList){
this.isNeedId = isNeedId;
rowDispseIndexMap = this.buildFiledMap(headList);
}
private Map<String, Integer> buildFiledMap(List<List<String>> headList) {
Map<String,Integer> returnMap = new HashMap<>();
int index = 0;
for (List<String> list:headList) {
for (String head : list) {
if(StringUtils.equalsAnyIgnoreCase(head,"id")){
returnMap.put("ID",index);
}else if(StringUtils.equalsAnyIgnoreCase(head,"所属模块","所屬模塊","Module")){
returnMap.put("Module",index);
}else if(StringUtils.equalsAnyIgnoreCase(head,"责任人","維護人","Maintainer")){
returnMap.put("Maintainer",index);
}else if(StringUtils.equalsAnyIgnoreCase(head,"用例等级","用例等級","Priority")){
returnMap.put("Priority",index);
}else if(StringUtils.equalsAnyIgnoreCase(head,"标签","標簽","Tag")){
returnMap.put("Tag",index);
}
index ++;
}
}
return returnMap;
}
@Override
public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex, Integer relativeRowIndex, Boolean isHead) {
......@@ -39,71 +71,97 @@ public class FunctionCaseTemplateWriteHandler extends AbstractRowHeightStyleStra
Sheet sheet = writeSheetHolder.getSheet();
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
if(isNeedId){
// 在第一行 第1列创建一个批注
Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 0, 0, (short) 3, 1));
// 输入批注信息
comment1.setString(new XSSFRichTextString(Translator.get("do_not_modify_header_order")+","+Translator.get("id_required")));
if(rowDispseIndexMap != null){
if(isNeedId){
Integer idIndex = rowDispseIndexMap.get("ID");
if(idIndex != null){
Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, idIndex, 0, (short) 3, 1));
comment1.setString(new XSSFRichTextString(Translator.get("do_not_modify_header_order")+","+Translator.get("id_required")));
sheet.getRow(0).getCell(1).setCellComment(comment1);
}
}
for (Map.Entry<String, Integer> entry:rowDispseIndexMap.entrySet()){
String coloum = entry.getKey();
Integer index = entry.getValue();
if(StringUtils.equalsAnyIgnoreCase(coloum,"Module")){
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, index, 0, (short) 3, 1));
comment.setString(new XSSFRichTextString(Translator.get("module_created_automatically")));
sheet.getRow(0).getCell(1).setCellComment(comment);
}else if(StringUtils.equalsAnyIgnoreCase(coloum,"Maintainer")){
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, index, 0, (short) 3, 1));
comment.setString(new XSSFRichTextString(Translator.get("please_input_workspace_member")));
sheet.getRow(0).getCell(1).setCellComment(comment);
}else if(StringUtils.equalsAnyIgnoreCase(coloum,"Priority")){
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, index, 0, (short) 3, 1));
comment.setString(new XSSFRichTextString(Translator.get("options") + "(P0、P1、P2、P3)"));
sheet.getRow(0).getCell(1).setCellComment(comment);
}else if(StringUtils.equalsAnyIgnoreCase(coloum,"Tag")){
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, index, 0, (short) 3, 1));
comment.setString(new XSSFRichTextString(Translator.get("tag_tip_pattern")));
sheet.getRow(0).getCell(1).setCellComment(comment);
}
}
}
// 在第一行 第3列创建一个批注
Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 2, 0, (short) 3, 1));
// 输入批注信息
comment2.setString(new XSSFRichTextString(Translator.get("module_created_automatically")));
// if(isNeedId){
// // 在第一行 第1列创建一个批注
// Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 0, 0, (short) 3, 1));
// // 输入批注信息
// comment1.setString(new XSSFRichTextString(Translator.get("do_not_modify_header_order")+","+Translator.get("id_required")));
// // 在第一行 第3列创建一个批注
// Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 2, 0, (short) 3, 1));
// // 输入批注信息
// comment2.setString(new XSSFRichTextString(Translator.get("module_created_automatically")));
// // 在第一行 第4列创建一个批注
// Comment comment4 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 0, (short) 3, 1));
// // 输入批注信息
// comment4.setString(new XSSFRichTextString(Translator.get("please_input_workspace_member")));
//
// // 在第一行 第5列创建一个批注
// Comment comment3 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 0, (short) 3, 1));
// Comment comment5 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 0, (short) 3, 1));
// // 输入批注信息
// comment3.setString(new XSSFRichTextString(Translator.get("options") + "(functional、performance、api)"));
// 在第一行 第4列创建一个批注
Comment comment4 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 0, (short) 3, 1));
// 输入批注信息
comment4.setString(new XSSFRichTextString(Translator.get("please_input_workspace_member")));
// 在第一行 第5列创建一个批注
Comment comment5 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 0, (short) 3, 1));
// 输入批注信息
comment5.setString(new XSSFRichTextString(Translator.get("options") + "(P0、P1、P2、P3)"));
// 在第一行 第6列创建一个批注
Comment comment6 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 5, 0, (short) 3, 1));
// 输入批注信息
comment6.setString(new XSSFRichTextString(Translator.get("tag_tip_pattern")));
// 将批注添加到单元格对象中
sheet.getRow(0).getCell(1).setCellComment(comment1);
sheet.getRow(0).getCell(1).setCellComment(comment2);
sheet.getRow(0).getCell(1).setCellComment(comment4);
sheet.getRow(0).getCell(1).setCellComment(comment5);
sheet.getRow(0).getCell(1).setCellComment(comment6);
}else {
// 在第一行 第2列创建一个批注
Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 1, 0, (short) 3, 1));
// 输入批注信息
comment2.setString(new XSSFRichTextString(Translator.get("do_not_modify_header_order") + ","+Translator.get("module_created_automatically")));
// 在第一行 第3列创建一个批注
Comment comment4 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 2, 0, (short) 3, 1));
// 输入批注信息
comment4.setString(new XSSFRichTextString(Translator.get("please_input_workspace_member")));
// 在第一行 第4列创建一个批注
Comment comment5 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 0, (short) 3, 1));
// 输入批注信息
comment5.setString(new XSSFRichTextString(Translator.get("options") + "(P0、P1、P2、P3)"));
// 在第一行 第5列创建一个批注
Comment comment6 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 0, (short) 3, 1));
// 输入批注信息
comment6.setString(new XSSFRichTextString(Translator.get("tag_tip_pattern")));
// 将批注添加到单元格对象中
sheet.getRow(0).getCell(1).setCellComment(comment2);
sheet.getRow(0).getCell(1).setCellComment(comment4);
sheet.getRow(0).getCell(1).setCellComment(comment5);
sheet.getRow(0).getCell(1).setCellComment(comment6);
}
// comment5.setString(new XSSFRichTextString(Translator.get("options") + "(P0、P1、P2、P3)"));
//
// // 在第一行 第6列创建一个批注
// Comment comment6 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 5, 0, (short) 3, 1));
// // 输入批注信息
// comment6.setString(new XSSFRichTextString(Translator.get("tag_tip_pattern")));
// // 将批注添加到单元格对象中
// sheet.getRow(0).getCell(1).setCellComment(comment1);
// sheet.getRow(0).getCell(1).setCellComment(comment2);
// sheet.getRow(0).getCell(1).setCellComment(comment4);
// sheet.getRow(0).getCell(1).setCellComment(comment5);
// sheet.getRow(0).getCell(1).setCellComment(comment6);
// }else {
// // 在第一行 第2列创建一个批注
// Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 1, 0, (short) 3, 1));
// // 输入批注信息
// comment2.setString(new XSSFRichTextString(Translator.get("do_not_modify_header_order") + ","+Translator.get("module_created_automatically")));
//
// // 在第一行 第3列创建一个批注
// Comment comment4 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 2, 0, (short) 3, 1));
// // 输入批注信息
// comment4.setString(new XSSFRichTextString(Translator.get("please_input_workspace_member")));
//
// // 在第一行 第4列创建一个批注
// Comment comment5 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 0, (short) 3, 1));
// // 输入批注信息
// comment5.setString(new XSSFRichTextString(Translator.get("options") + "(P0、P1、P2、P3)"));
//
// // 在第一行 第5列创建一个批注
// Comment comment6 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 0, (short) 3, 1));
// // 输入批注信息
// comment6.setString(new XSSFRichTextString(Translator.get("tag_tip_pattern")));
//
// // 将批注添加到单元格对象中
// sheet.getRow(0).getCell(1).setCellComment(comment2);
// sheet.getRow(0).getCell(1).setCellComment(comment4);
// sheet.getRow(0).getCell(1).setCellComment(comment5);
// sheet.getRow(0).getCell(1).setCellComment(comment6);
// }
}
}
......
......@@ -701,7 +701,7 @@ public class TestCaseService {
List<List<String>> headList = testCaseExcelData.getHead(importFileNeedNum,customFields);
EasyExcelExporter easyExcelExporter = new EasyExcelExporter(testCaseExcelData.getClass());
FunctionCaseTemplateWriteHandler handler = new FunctionCaseTemplateWriteHandler(importFileNeedNum);
FunctionCaseTemplateWriteHandler handler = new FunctionCaseTemplateWriteHandler(importFileNeedNum,headList);
easyExcelExporter.exportByCustomWriteHandler(response,headList, generateExportDatas(importFileNeedNum),
Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet"), handler);
......
......@@ -601,6 +601,8 @@ export default {
this.currentScenario.modulePath = data.path;
},
setHideBtn() {
this.$refs.scenarioRelevance.changeButtonLoadingType();
this.$refs.scenarioApiRelevance.changeButtonLoadingType();
this.isBtnHide = false;
},
// 打开引用的场景
......@@ -781,6 +783,7 @@ export default {
arr.forEach(item => {
if (item.id === this.currentScenario.id) {
this.$error("不能引用或复制自身!");
this.$refs.scenarioRelevance.changeButtonLoadingType();
return;
}
if (!item.hashTree) {
......@@ -836,6 +839,7 @@ export default {
this.setApiParameter(item, refType, referenced);
});
this.isBtnHide = false;
this.$refs.scenarioApiRelevance.changeButtonLoadingType();
this.sort();
this.reload();
},
......
......@@ -33,8 +33,8 @@
ref="apiCaseList"/>
<template v-slot:footer>
<el-button type="primary" @click="copy" @keydown.enter.native.prevent>{{ $t('commons.copy') }}</el-button>
<el-button v-if="!isApiListEnable" type="primary" @click="reference" @keydown.enter.native.prevent>
<el-button type="primary" @click="copy" :loading="buttonIsWorking" @keydown.enter.native.prevent>{{ $t('commons.copy') }}</el-button>
<el-button v-if="!isApiListEnable" type="primary" :loading="buttonIsWorking" @click="reference" @keydown.enter.native.prevent>
{{ $t('api_test.scenario.reference') }}
</el-button>
</template>
......@@ -62,6 +62,7 @@ export default {
},
data() {
return {
buttonIsWorking:false,
result: {},
currentProtocol: null,
selectNodeIds: [],
......@@ -77,10 +78,15 @@ export default {
}
},
methods: {
changeButtonLoadingType(){
this.buttonIsWorking = false;
},
reference() {
this.buttonIsWorking = true;
this.save('REF');
},
copy() {
this.buttonIsWorking = true;
this.save('Copy');
},
save(reference) {
......@@ -94,10 +100,13 @@ export default {
let apis = response.data;
if(apis.length === 0){
this.$warning('请选择接口');
this.buttonIsWorking = false;
}else {
this.$emit('save', apis, 'API', reference);
this.$refs.baseRelevance.close();
}
},(error) => {
this.buttonIsWorking = false;
});
} else {
......@@ -106,11 +115,13 @@ export default {
let apiCases = response.data;
if(apiCases.length === 0) {
this.$warning('请选择案例');
this.buttonIsWorking = false;
}else{
this.$emit('save', apiCases, 'CASE', reference);
this.$refs.baseRelevance.close();
}
},(error) => {
this.buttonIsWorking = false;
});
}
},
......@@ -120,6 +131,7 @@ export default {
this.$refs.relevanceDialog.close();
},
open() {
this.buttonIsWorking = false;
if (this.$refs.apiList) {
this.$refs.apiList.clearSelection();
}
......
......@@ -24,8 +24,8 @@
ref="apiScenarioList"/>
<template v-slot:footer>
<el-button type="primary" @click="copy" @keydown.enter.native.prevent>{{$t('commons.copy')}}</el-button>
<el-button type="primary" @click="reference" @keydown.enter.native.prevent> {{ $t('api_test.scenario.reference') }}</el-button>
<el-button type="primary" @click="copy" :loading="buttonIsWorking" @keydown.enter.native.prevent>{{$t('commons.copy')}}</el-button>
<el-button type="primary" @click="reference" :loading="buttonIsWorking" @keydown.enter.native.prevent> {{ $t('api_test.scenario.reference') }}</el-button>
</template>
</test-case-relevance-base>
</template>
......@@ -51,6 +51,7 @@
},
data() {
return {
buttonIsWorking: false,
result: {},
currentProtocol: null,
selectNodeIds: [],
......@@ -77,7 +78,11 @@
}
},
methods: {
changeButtonLoadingType(){
this.buttonIsWorking = false;
},
reference() {
this.buttonIsWorking = true;
let scenarios = [];
let conditions = this.getConditions();
if (conditions.selectAll) {
......@@ -89,6 +94,7 @@
this.currentScenario = response.data;
if (!this.currentScenario || this.currentScenario.length < 1) {
this.$emit('请选择场景');
this.buttonIsWorking = false;
return;
}
this.currentScenario.forEach(item => {
......@@ -104,10 +110,14 @@
});
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
},(error) => {
this.buttonIsWorking = false;
});
} else {
if (!this.currentScenario || this.currentScenario.length < 1) {
this.$emit('请选择场景');
this.buttonIsWorking = false;
return;
}
this.currentScenario.forEach(item => {
......@@ -123,9 +133,11 @@
});
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
}
},
copy() {
this.buttonIsWorking = true;
let scenarios = [];
let conditions = this.getConditions();
if (conditions.selectAll) {
......@@ -137,6 +149,7 @@
this.currentScenarioIds = response.data;
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$warning('请选择场景');
this.buttonIsWorking = false;
return;
}
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
......@@ -161,12 +174,18 @@
});
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
}
},(error) => {
this.buttonIsWorking = false;
});
},(error) => {
this.buttonIsWorking = false;
});
} else {
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$warning('请选择场景');
this.buttonIsWorking = false;
return;
}
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
......@@ -191,7 +210,10 @@
});
this.$emit('save', scenarios);
this.$refs.baseRelevance.close();
this.buttonIsWorking = false;
}
},(error) => {
this.buttonIsWorking = false;
});
}
},
......@@ -201,6 +223,7 @@
this.$refs.relevanceDialog.close();
},
open() {
this.buttonIsWorking = false;
this.$refs.baseRelevance.open();
if (this.$refs.apiScenarioList) {
this.$refs.apiScenarioList.search(this.projectId);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment