From 78b1d7b92196cee2ef72f092c245553f460c5531 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 4 Aug 2022 11:38:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=8A=B6=E6=80=81=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E5=AF=BC=E5=87=BA=E5=90=8E=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015649 --user=陈建星 【测试跟踪】功能用例,用例状态字段值修改为自定义内容后,导出文件里显示的编码 https://www.tapd.cn/55049933/s/1219125 --- .../io/metersphere/dto/CustomFieldOption.java | 11 +++ .../excel/domain/TestCaseExcelData.java | 29 +------- .../excel/domain/TestCaseExcelDataCn.java | 25 ++----- .../excel/domain/TestCaseExcelDataTw.java | 27 ++----- .../excel/domain/TestCaseExcelDataUs.java | 27 ++----- .../listener/TestCaseNoModelDataListener.java | 43 +++++++++-- .../track/service/TestCaseService.java | 71 ++++++------------- .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + .../track/case/components/TestCaseList.vue | 2 - frontend/src/common/js/tableUtils.js | 14 ++++ 12 files changed, 109 insertions(+), 143 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/dto/CustomFieldOption.java diff --git a/backend/src/main/java/io/metersphere/dto/CustomFieldOption.java b/backend/src/main/java/io/metersphere/dto/CustomFieldOption.java new file mode 100644 index 0000000000..d3d9b2ef35 --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/CustomFieldOption.java @@ -0,0 +1,11 @@ +package io.metersphere.dto; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class CustomFieldOption { + private String text; + private String value; +} diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java index 2e7e8dfd88..e67d9ca299 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java @@ -4,7 +4,6 @@ import com.alibaba.excel.annotation.ExcelIgnore; import io.metersphere.dto.CustomFieldDao; import lombok.Getter; import lombok.Setter; -import org.apache.commons.lang3.StringUtils; import java.util.*; @@ -46,33 +45,9 @@ public class TestCaseExcelData { @ExcelIgnore private String priority; @ExcelIgnore - Map customDatas = new LinkedHashMap<>(); + Map customDatas = new LinkedHashMap<>(); - public Set getExcludeColumnFiledNames(boolean needNum){ - Set excludeColumnFiledNames = new HashSet<>(); - if(!needNum){ - excludeColumnFiledNames.add("customNum"); - } - excludeColumnFiledNames.add("id"); - excludeColumnFiledNames.add("num"); - return excludeColumnFiledNames; - } - - public String parseStatus(String parseStatus){ - String caseStatusValue = ""; - if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Underway","进行中","進行中")){ - caseStatusValue = "Underway"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Prepare","未开始","未開始")){ - caseStatusValue = "Prepare"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Completed","已完成","已完成")){ - caseStatusValue = "Completed"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Trash")){ - caseStatusValue = "Trash"; - } - return caseStatusValue; - } - - public List> getHead(boolean needNum, List customFields){ + public List> getHead(boolean needNum, List customFields) { return new ArrayList<>(); } } diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java index d27e886320..9b86142316 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java @@ -85,9 +85,9 @@ public class TestCaseExcelDataCn extends TestCaseExcelData { private String priority; @Override - public List> getHead(boolean needNum, List customFields){ + public List> getHead(boolean needNum, List customFields) { List> returnList = new ArrayList<>(); - if(needNum){ + if (needNum) { List list = new ArrayList<>(); list.add("ID"); returnList.add(list); @@ -129,9 +129,9 @@ public class TestCaseExcelDataCn extends TestCaseExcelData { list9.add("用例等级"); returnList.add(list9); - if(CollectionUtils.isNotEmpty(customFields)){ - for (CustomFieldDao dto:customFields) { - if(StringUtils.equals(dto.getName(),"用例等级")){ + if (CollectionUtils.isNotEmpty(customFields)) { + for (CustomFieldDao dto : customFields) { + if (StringUtils.equals(dto.getName(), "用例等级")) { continue; } List list = new ArrayList<>(); @@ -145,19 +145,4 @@ public class TestCaseExcelDataCn extends TestCaseExcelData { } return returnList; } - - @Override - public String parseStatus(String parseStatus){ - String caseStatusValue = ""; - if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Underway","进行中","進行中")){ - caseStatusValue = "进行中"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Prepare","未开始","未開始")){ - caseStatusValue = "未开始"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Completed","已完成","已完成")){ - caseStatusValue = "已完成"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Trash","废弃","廢棄")){ - caseStatusValue = "废弃"; - } - return caseStatusValue; - } } diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java index 889a695ad8..314e885af5 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java @@ -85,9 +85,9 @@ public class TestCaseExcelDataTw extends TestCaseExcelData { private String maintainer; @Override - public List> getHead(boolean needNum, List customFields){ + public List> getHead(boolean needNum, List customFields) { List> returnList = new ArrayList<>(); - if(needNum){ + if (needNum) { List list = new ArrayList<>(); list.add("ID"); returnList.add(list); @@ -133,12 +133,12 @@ public class TestCaseExcelDataTw extends TestCaseExcelData { list10.add("用例狀態"); returnList.add(list10); - if(CollectionUtils.isNotEmpty(customFields)){ - for (CustomFieldDao dto:customFields) { - if(StringUtils.equals(dto.getName(),"用例等級")){ + if (CollectionUtils.isNotEmpty(customFields)) { + for (CustomFieldDao dto : customFields) { + if (StringUtils.equals(dto.getName(), "用例等級")) { continue; } - if(StringUtils.equals(dto.getName(),"用例状态")){ + if (StringUtils.equals(dto.getName(), "用例状态")) { continue; } List list = new ArrayList<>(); @@ -152,19 +152,4 @@ public class TestCaseExcelDataTw extends TestCaseExcelData { } return returnList; } - - @Override - public String parseStatus(String parseStatus){ - String caseStatusValue = ""; - if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Underway","进行中","進行中")){ - caseStatusValue = "進行中"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Prepare","未开始","未開始")){ - caseStatusValue = "未開始"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Completed","已完成","已完成")){ - caseStatusValue = "已完成"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Trash","废弃","廢棄")){ - caseStatusValue = "廢棄"; - } - return caseStatusValue; - } } diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java index d2dc5aef3d..eabe9bd213 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java @@ -85,9 +85,9 @@ public class TestCaseExcelDataUs extends TestCaseExcelData { private String maintainer; @Override - public List> getHead(boolean needNum, List customFields){ + public List> getHead(boolean needNum, List customFields) { List> returnList = new ArrayList<>(); - if(needNum){ + if (needNum) { List list = new ArrayList<>(); list.add("ID"); returnList.add(list); @@ -133,12 +133,12 @@ public class TestCaseExcelDataUs extends TestCaseExcelData { list10.add("Case status"); returnList.add(list10); - if(CollectionUtils.isNotEmpty(customFields)){ - for (CustomFieldDao dto:customFields) { - if(StringUtils.equals(dto.getName(),"用例等级")){ + if (CollectionUtils.isNotEmpty(customFields)) { + for (CustomFieldDao dto : customFields) { + if (StringUtils.equals(dto.getName(), "用例等级")) { continue; } - if(StringUtils.equals(dto.getName(),"用例状态")){ + if (StringUtils.equals(dto.getName(), "用例状态")) { continue; } List list = new ArrayList<>(); @@ -152,19 +152,4 @@ public class TestCaseExcelDataUs extends TestCaseExcelData { } return returnList; } - - @Override - public String parseStatus(String parseStatus){ - String caseStatusValue = ""; - if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Underway","进行中","進行中")){ - caseStatusValue = "Underway"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Prepare","未开始","未開始")){ - caseStatusValue = "Prepare"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Completed","已完成","已完成")){ - caseStatusValue = "Completed"; - }else if(StringUtils.equalsAnyIgnoreCase(parseStatus,"Trash")){ - caseStatusValue = "Trash"; - } - return caseStatusValue; - } } diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java index 393fedb216..20c8efd916 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseNoModelDataListener.java @@ -11,6 +11,7 @@ import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.dto.CustomFieldDao; +import io.metersphere.dto.CustomFieldOption; import io.metersphere.excel.annotation.NotRequired; import io.metersphere.excel.domain.ExcelErrData; import io.metersphere.excel.domain.TestCaseExcelData; @@ -207,10 +208,14 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener valueMap = new HashMap<>() {{ + put("Prepare", Translator.get("test_case_status_prepare")); + put("Underway", Translator.get("test_case_status_running")); + put("Completed", Translator.get("test_case_status_finished")); + }}; + value = getCustomFieldValue(Translator.get("test_case_status"), data.getStatus(), field.getOptions(), + stringBuilder, valueMap); + data.setStatus(value); } else if (StringUtils.equals(customName, "priority")) { value = data.getPriority(); } else if (StringUtils.equals(customName, "maintainer")) { @@ -313,6 +318,36 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener systemValueMap) { + List textList = new ArrayList<>(); + if (StringUtils.isNotEmpty(optionsStr)) { + List options = JSONObject.parseArray(optionsStr, CustomFieldOption.class); + for (CustomFieldOption option : options) { + // 系统字段需要翻译 + String i18nText = systemValueMap.get(option.getValue()); + if (i18nText != null) { + option.setText(i18nText); + } + if (StringUtils.equals(option.getValue(), text) || + // 系统字段填写对应内容,而不是key的情况,比如用例状态填未开始而不是 Prepare + StringUtils.equals(option.getText(), text)) { + return option.getValue(); + } + textList.add(option.getText()); + } + } + error.append(String.format(Translator.get("custom_field_option_not_exist"), name, textList.toString())); + return text; + } + public List getNames() { return this.names; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 9ed9bbc813..aa60bf5a7c 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -730,7 +730,6 @@ public class TestCaseService { buildProjectInfoWidthoutProject(list); } buildCustomField(list); - list = this.parseStatus(list); } return list; } @@ -780,7 +779,6 @@ public class TestCaseService { ServiceUtils.buildVersionInfo(returnList); ServiceUtils.buildProjectInfo(returnList); buildUserInfo(returnList); - returnList = this.parseStatus(returnList); return returnList; } @@ -791,41 +789,6 @@ public class TestCaseService { request.setOrders(orders); } - private List parseStatus(List returnList) { - if (CollectionUtils.isNotEmpty(returnList)) { - TestCaseExcelData excelData = new TestCaseExcelDataFactory().getTestCaseExcelDataLocal(); - List testCaseIdList = new ArrayList<>(); - returnList.forEach(item -> { - testCaseIdList.add(item.getId()); - }); - - for (TestCaseDTO data : returnList) { - String dataStatus = excelData.parseStatus(data.getStatus()); - if (StringUtils.equalsAnyIgnoreCase(data.getStatus(), "Trash")) { - try { - JSONArray arr = JSONArray.parseArray(data.getCustomFields()); - JSONArray newArr = new JSONArray(); - for (int i = 0; i < arr.size(); i++) { - JSONObject obj = arr.getJSONObject(i); - if (obj.containsKey("name") && obj.containsKey("value")) { - String name = obj.getString("name"); - if (StringUtils.equalsAny(name, "用例状态", "用例狀態", "Case status")) { - obj.put("value", dataStatus); - } - } - newArr.add(obj); - } - data.setCustomFields(newArr.toJSONString()); - } catch (Exception e) { - LogUtil.error("Parse case exec status error:" + e.getMessage()); - } - } - data.setStatus(dataStatus); - } - } - return returnList; - } - /** * 初始化部分参数 * @@ -1166,7 +1129,9 @@ public class TestCaseService { } num++; testCase.setReviewStatus(TestCaseReviewStatus.Prepare.name()); - testCase.setStatus(TestCaseReviewStatus.Prepare.name()); + if (StringUtils.isBlank(testCase.getStatus())) { + testCase.setStatus(TestCaseReviewStatus.Prepare.name()); + } testCase.setOrder(Long.valueOf(testCases.size() - (num - beforeInsertId)) * ServiceUtils.ORDER_STEP); testCase.setRefId(testCase.getId()); testCase.setVersionId(request.getVersionId()); @@ -1414,24 +1379,18 @@ public class TestCaseService { public void testCaseExport(HttpServletResponse response, TestCaseBatchRequest request) { try { -// EasyExcelExporter easyExcelExporter = new EasyExcelExporter(new TestCaseExcelDataFactory().getExcelDataByLocal()); -// List datas = generateTestCaseExcel(request); -// easyExcelExporter.export(response,datas,Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet")); TestCaseExcelData testCaseExcelData = new TestCaseExcelDataFactory().getTestCaseExcelDataLocal(); - List datas = generateTestCaseExcel(request); - boolean importFileNeedNum = true; TestCaseTemplateService testCaseTemplateService = CommonBeanFactory.getBean(TestCaseTemplateService.class); TestCaseTemplateDao testCaseTemplate = testCaseTemplateService.getTemplate(request.getProjectId()); List customFields = Optional.ofNullable(testCaseTemplate.getCustomFields()).orElse(new ArrayList<>()); - List> headList = testCaseExcelData.getHead(importFileNeedNum, customFields); - List> testCaseDataByExcelList = this.generateTestCaseExcel(headList, datas); + List> headList = testCaseExcelData.getHead(true, customFields); + List> testCaseDataByExcelList = this.generateTestCaseExcel(headList, generateTestCaseExcel(request)); EasyExcelExporter easyExcelExporter = new EasyExcelExporter(testCaseExcelData.getClass()); easyExcelExporter.exportByCustomWriteHandler(response, headList, testCaseDataByExcelList, Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet")); - } catch (Exception e) { LogUtil.error(e.getMessage(), e); MSException.throwException(e); @@ -1572,8 +1531,8 @@ public class TestCaseService { List testCaseList = this.getExportData(request); boolean isUseCustomId = projectService.useCustomNum(request.getProjectId()); List list = new ArrayList<>(); - StringBuilder step = new StringBuilder(""); - StringBuilder result = new StringBuilder(""); + StringBuilder step = new StringBuilder(); + StringBuilder result = new StringBuilder(); Map> customSelectValueMap = new HashMap<>(); Map customNameMap = new HashMap<>(); @@ -1617,6 +1576,7 @@ public class TestCaseService { testCaseList.forEach(t -> { + setExportSystemField(t, customNameMap, customSelectValueMap); TestCaseExcelData data = new TestCaseExcelData(); data.setNum(t.getNum()); data.setName(t.getName()); @@ -1723,6 +1683,21 @@ public class TestCaseService { return list; } + public void setExportSystemField(TestCaseDTO testCase, Map customNameMap, + Map> customSelectValueMap) { + String statusKey = null; + for (String k : customNameMap.keySet()) { + String v = customNameMap.get(k); + if (StringUtils.equals(v, "用例状态")) { + statusKey = k; + } + } + if (StringUtils.isNotEmpty(statusKey)) { + Map valueMap = customSelectValueMap.get(statusKey); + testCase.setStatus(valueMap.get(testCase.getStatus())); + } + } + /** * 更新自定义字段 * diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 10bc0dc2f0..1b3d3e7c2a 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -172,6 +172,7 @@ id_required=ID required id_repeat_in_table=ID is repeat in table step_model_tip=Step description fill in STEP, text description please fill in TEXT (not required) case_status_not_exist=The use case status must be Prepare, Underway way and Completed +custom_field_option_not_exist=%s must be %s issue_project_not_exist=ID does not exist or other errors tapd_project_not_exist=The associated TAPD item ID does not exist zentao_get_project_builds_fail=Get Affecting Version Errors diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 11018d3453..fc2c639b43 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -172,6 +172,7 @@ id_required=ID必填 id_repeat_in_table=表格内ID重复 step_model_tip=步骤描述填写 STEP,文本描述请填写 TEXT (非必填) case_status_not_exist=用例状态必须为未开始(Prepare)、进行中(Underway)、已完成(Completed) +custom_field_option_not_exist=%s必须为%s issue_project_not_exist=ID不存在或其它错误 tapd_project_not_exist=关联的TAPD项目ID不存在 zentao_get_project_builds_fail=获取影响版本错误 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 96adb9ba8c..765b9a92f7 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -172,6 +172,7 @@ id_required=ID必填 id_repeat_in_table=表格內ID重復 step_model_tip=步驟描述填寫 STEP,文本描述請填寫 TEXT (非必填) case_status_not_exist=用例狀態必須為未開始(Prepare)、進行中(Underway)、已完成(Completed) +custom_field_option_not_exist=%s必須為%s issue_project_not_exist=ID不存在或其它錯誤 tapd_project_not_exist=關聯的TAPD項目ID不存在 zentao_get_project_builds_fail=獲取影響版本錯誤 diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index cd84a43e12..bac2be4610 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -698,8 +698,6 @@ export default { return row.priority; } else if (field.name === '责任人') { return row.maintainerName; - } else if (field.name === '用例状态') { - return row.status; } return value ? value : defaultVal; }, diff --git a/frontend/src/common/js/tableUtils.js b/frontend/src/common/js/tableUtils.js index 1598165840..d6a41786ab 100644 --- a/frontend/src/common/js/tableUtils.js +++ b/frontend/src/common/js/tableUtils.js @@ -448,6 +448,17 @@ export function saveCustomTableWidth(key, fieldKey, colWith) { localStorage.setItem(key + '_WITH', JSON.stringify(fields)); } +function parseStatus(row, options) { + if (options) { + for (let option of options) { + if (option.value === row.status) { + return option.system ? i18n.t(option.text) : option.text; + } + } + } + return row.status; +} + /** * 获取列表的自定义字段的显示值 * @param row @@ -456,6 +467,9 @@ export function saveCustomTableWidth(key, fieldKey, colWith) { * @returns {VueI18n.TranslateResult|*} */ export function getCustomFieldValue(row, field, members) { + if (field.name === '用例状态' && field.system) { + return parseStatus(row, field.options); + } if (row.fields) { for (let i = 0; i < row.fields.length; i++) { let item = row.fields[i];