fix(测试跟踪): 用例导出缺少责任人字段

This commit is contained in:
chenjianxing 2022-08-17 11:27:30 +08:00 committed by jianxing
parent 5ff9bd0461
commit c620f5e2dd
3 changed files with 59 additions and 45 deletions

View File

@ -1,28 +1,64 @@
package io.metersphere.excel.constants;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.nacos.common.utils.CollectionUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.excel.domain.TestCaseExcelData;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
public enum TestCaseImportFiled {
ID("ID", "ID", "ID"), NAME("用例名称", "用例名稱", "Name"), MODULE("所属模块", "所屬模塊", "Module"),
TAG("标签", "標簽", "Tag"), PREREQUISITE("前置条件", "前置條件", "Prerequisite"), REMARK("备注", "備註", "Remark"),
STEP_DESC("步骤描述", "步驟描述", "Step description"), STEP_RESULT("预期结果", "預期結果", "Step result"), STEP_MODEL("编辑模式", "編輯模式", "Edit Model"),
STATUS("用例状态", "用例狀態", "Case status"), MAINTAINER("责任人", "責任人", "Maintainer"), PRIORITY("用例等级", "用例等級", "Priority");
ID("ID", "ID", "ID", TestCaseExcelData::getCustomNum),
NAME("用例名称", "用例名稱", "Name", TestCaseExcelData::getName),
MODULE("所属模块", "所屬模塊", "Module", TestCaseExcelData::getNodePath),
TAG("标签", "標簽", "Tag", TestCaseImportFiled::parseTags),
PREREQUISITE("前置条件", "前置條件", "Prerequisite", TestCaseExcelData::getPrerequisite),
REMARK("备注", "備註", "Remark", TestCaseExcelData::getRemark),
STEP_DESC("步骤描述", "步驟描述", "Step description", TestCaseExcelData::getStepDesc),
STEP_RESULT("预期结果", "預期結果", "Step result", TestCaseExcelData::getStepResult),
STEP_MODEL("编辑模式", "編輯模式", "Edit Model", TestCaseExcelData::getStepModel),
STATUS("用例状态", "用例狀態", "Case status", TestCaseExcelData::getStatus),
MAINTAINER("责任人", "責任人", "Maintainer", TestCaseExcelData::getMaintainer),
PRIORITY("用例等级", "用例等級", "Priority", TestCaseExcelData::getPriority);
private Map<Locale, String> filedLangMap;
private Function<TestCaseExcelData, String> parseFunc;
public Map<Locale, String> getFiledLangMap() {
return this.filedLangMap;
}
TestCaseImportFiled(String zn, String chineseTw, String us) {
TestCaseImportFiled(String zn, String chineseTw, String us, Function<TestCaseExcelData, String> parseFunc) {
this.filedLangMap = new HashMap<>() {{
put(Locale.SIMPLIFIED_CHINESE, zn);
put(Locale.TRADITIONAL_CHINESE, chineseTw);
put(Locale.US, us);
put(Locale.SIMPLIFIED_CHINESE, zn);
put(Locale.TRADITIONAL_CHINESE, chineseTw);
put(Locale.US, us);
}};
this.parseFunc = parseFunc;
}
public String parseExcelDataValue(TestCaseExcelData excelData) {
return parseFunc.apply(excelData);
}
private static String parseTags(TestCaseExcelData excelData) {
String tags = "";
try {
if (excelData.getTags() != null) {
JSONArray arr = JSONArray.parseArray(excelData.getTags());
if (CollectionUtils.isNotEmpty(arr)) {
tags = StringUtils.joinWith(",", arr.toArray());
}
}
} catch (Exception e) {
LogUtil.error(e);
}
return tags;
}
}

View File

@ -81,7 +81,7 @@ public class TestCaseExcelData {
if (StringUtils.equalsAny(dto.getName(),
TestCaseImportFiled.PRIORITY.getFiledLangMap().get(Locale.SIMPLIFIED_CHINESE),
TestCaseImportFiled.STATUS.getFiledLangMap().get(Locale.SIMPLIFIED_CHINESE),
TestCaseImportFiled.MAINTAINER.getFiledLangMap().get(Locale.SIMPLIFIED_CHINESE).concat("(ID)"))) {
TestCaseImportFiled.MAINTAINER.getFiledLangMap().get(Locale.SIMPLIFIED_CHINESE))) {
continue;
}
heads.add(new ArrayList<>() {{

View File

@ -24,13 +24,13 @@ import io.metersphere.base.mapper.ext.ExtProjectVersionMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.*;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.controller.request.ProjectVersionRequest;
import io.metersphere.controller.request.ResetOrderRequest;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.dto.*;
import io.metersphere.excel.constants.TestCaseImportFiled;
import io.metersphere.excel.domain.*;
import io.metersphere.excel.handler.FunctionCaseMergeWriteHandler;
import io.metersphere.excel.handler.FunctionCaseTemplateWriteHandler;
@ -1422,46 +1422,24 @@ public class TestCaseService {
for (TestCaseExcelData model : data) {
List<Object> fields = new ArrayList<>();
Map<String, String> customDataMaps = Optional.ofNullable(model.getCustomDatas()).orElse(new HashMap<>());
TestCaseImportFiled[] importFields = TestCaseImportFiled.values();
for (String head : headList) {
if (StringUtils.equalsAnyIgnoreCase(head, "ID")) {
fields.add(model.getCustomNum());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Name", "用例名稱", "用例名称")) {
fields.add(model.getName());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Module", "所屬模塊", "所属模块")) {
fields.add(model.getNodePath());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Tag", "標簽", "标签")) {
String tags = "";
try {
if (model.getTags() != null) {
JSONArray arr = JSONArray.parseArray(model.getTags());
for (int i = 0; i < arr.size(); i++) {
tags += arr.getString(i) + ",";
}
}
} catch (Exception e) {
boolean isSystemField = false;
for (TestCaseImportFiled importFiled : importFields) {
if (importFiled.getFiledLangMap().values().contains(head)) {
fields.add(importFiled.parseExcelDataValue(model));
isSystemField = true;
}
}
if (!isSystemField) {
String value = customDataMaps.get(head);
if (value == null) {
value = "";
}
fields.add(tags);
} else if (StringUtils.equalsAnyIgnoreCase(head, "Prerequisite", "前置條件", "前置条件")) {
fields.add(model.getPrerequisite());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Remark", "備註", "备注")) {
fields.add(model.getRemark());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Step description", "步驟描述", "步骤描述")) {
fields.add(model.getStepDesc());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Step result", "預期結果", "预期结果")) {
fields.add(model.getStepResult());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Edit Model", "編輯模式", "编辑模式")) {
fields.add(model.getStepModel());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Priority", "用例等級", "用例等级")) {
fields.add(model.getPriority());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Case status", "用例状态", "用例狀態")) {
fields.add(model.getStatus());
} else if (StringUtils.equalsAnyIgnoreCase(head, "Maintainer(ID)", "责任人(ID)", "維護人(ID)")) {
fields.add(model.getMaintainer());
} else {
String value = Optional.ofNullable(customDataMaps.get(head)).orElse("");
fields.add(value);
}
}
result.add(fields);
}