diff --git a/test-track/backend/src/main/java/io/metersphere/excel/handler/IssueTemplateHeadWriteHandler.java b/test-track/backend/src/main/java/io/metersphere/excel/handler/IssueTemplateHeadWriteHandler.java index 387a9aef89..93a164ce65 100644 --- a/test-track/backend/src/main/java/io/metersphere/excel/handler/IssueTemplateHeadWriteHandler.java +++ b/test-track/backend/src/main/java/io/metersphere/excel/handler/IssueTemplateHeadWriteHandler.java @@ -118,8 +118,8 @@ public class IssueTemplateHeadWriteHandler implements RowWriteHandler, SheetWrit Translator.get("options").concat(memberMap.keySet().toString())); } if (StringUtils.equalsAnyIgnoreCase(field.getType(), CustomFieldType.CASCADING_SELECT.getValue())) { - commentText = Translator.get("multiple_input_import_cell_format_comment").concat(", " + - Translator.get("options_tips").concat(JSON.toJSONString(getCascadSelect(field.getOptions())))); + commentText = Translator.get("cascading_select_import_cell_format_comment").concat(", " + + Translator.get("options_key_tips").concat(JSON.toJSONString(getCascadSelect(field.getOptions())))); } return field.getRequired() ? Translator.get("required").concat("; " + commentText) : commentText; } diff --git a/test-track/backend/src/main/java/io/metersphere/excel/listener/IssueExcelListener.java b/test-track/backend/src/main/java/io/metersphere/excel/listener/IssueExcelListener.java index 349cff7775..5d548fe309 100644 --- a/test-track/backend/src/main/java/io/metersphere/excel/listener/IssueExcelListener.java +++ b/test-track/backend/src/main/java/io/metersphere/excel/listener/IssueExcelListener.java @@ -5,6 +5,7 @@ import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.util.DateUtils; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.Issues; import io.metersphere.commons.constants.CustomFieldType; import io.metersphere.commons.exception.MSException; @@ -340,25 +341,33 @@ public class IssueExcelListener extends AnalysisEventListener values = new ArrayList<>(); + if (StringUtils.isEmpty(cascadingOption)) { + return StringUtils.EMPTY; + } + JSONArray options = JSONArray.parseArray(cascadingOption); + JSONArray talVals = JSONArray.parseArray(tarVal); + if (options.size() == 0 || talVals.size() == 0) { + return StringUtils.EMPTY; + } + for (int i = 0; i < talVals.size(); i++) { + String val = talVals.get(i).toString(); + JSONObject jsonOption = this.findJsonOption(options, val); + if (jsonOption == null) { + return StringUtils.EMPTY; + } else { + values.add("\"" + jsonOption.get("value").toString() + "\""); + options = jsonOption.getJSONArray("children"); + } + } + return values.toString(); + } + + private JSONObject findJsonOption(JSONArray options, String tarVal) { + if (options.size() == 0) { + return null; + } + List jsonObjects = options.stream().map(option -> (JSONObject) option).filter(option -> StringUtils.equals(tarVal, option.get("text").toString())).toList(); + if (jsonObjects.size() == 0) { + return null; + } else { + return jsonObjects.get(0); + } + } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index ad897f9806..728c7fd002 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -823,6 +823,9 @@ public class IssuesService { && !StringUtils.equalsAnyIgnoreCase(customField.getName(), SystemCustomField.ISSUE_STATUS)) { fieldDao.setValue(parseOptionValue(customField.getOptions(), fieldDao.getValue())); } + if (StringUtils.equalsAnyIgnoreCase(customField.getType(), CustomFieldType.CASCADING_SELECT.getValue())) { + fieldDao.setValue(parseCascadingOptionValue(customField.getOptions(), fieldDao.getValue())); + } } } } @@ -1936,6 +1939,41 @@ public class IssuesService { return tarVal; } + public String parseCascadingOptionValue(String cascadingOption, String tarVal) { + List values = new ArrayList<>(); + if (StringUtils.isEmpty(cascadingOption)) { + return StringUtils.EMPTY; + } + JSONArray options = JSONArray.parseArray(cascadingOption); + JSONArray talVals = JSONArray.parseArray(tarVal); + if (options.size() == 0 || talVals.size() == 0) { + return StringUtils.EMPTY; + } + for (int i = 0; i < talVals.size(); i++) { + String val = talVals.get(i).toString(); + JSONObject jsonOption = this.findJsonOption(options, val); + if (jsonOption == null) { + return StringUtils.EMPTY; + } else { + values.add("\"" + jsonOption.get("text").toString() + "\""); + options = jsonOption.getJSONArray("children"); + } + } + return values.toString(); + } + + private JSONObject findJsonOption(JSONArray options, String tarVal) { + if (options.size() == 0) { + return null; + } + List jsonObjects = options.stream().map(option -> (JSONObject) option).filter(option -> StringUtils.equals(tarVal, option.get("value").toString())).toList(); + if (jsonObjects.size() == 0) { + return null; + } else { + return jsonObjects.get(0); + } + } + public Issues checkIssueExist(Integer num, String projectId) { IssuesExample example = new IssuesExample(); example.createCriteria().andNumEqualTo(num).andProjectIdEqualTo(projectId); diff --git a/test-track/backend/src/main/resources/i18n/messages_en_US.properties b/test-track/backend/src/main/resources/i18n/messages_en_US.properties index 20b3835de2..3954ec7e02 100644 --- a/test-track/backend/src/main/resources/i18n/messages_en_US.properties +++ b/test-track/backend/src/main/resources/i18n/messages_en_US.properties @@ -51,7 +51,9 @@ datetime_import_cell_format_comment=The date and time cell format is YYYY/MM/DD int_import_cell_format_comment=cell format: 100001 float_import_cell_format_comment=cell format: 24 multiple_input_import_cell_format_comment=This field has multiple values. Separate multiple values with commas or semicolons +cascading_select_import_cell_format_comment=This cell is a cascade selection. Please separate the child options under the parent option with a comma or semicolon (v; v1; v11) options_tips=(format{key:value}, please fill in the corresponding value)Option value: +options_key_tips=(format{key:value},please fill in the corresponding key)Option value: # issue import and issue export title==Title description=Description diff --git a/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties b/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties index e5644fca8e..4a8a3a56ba 100644 --- a/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -28,7 +28,9 @@ datetime_import_cell_format_comment=日期时间类型单元格格式为: YYYY/M int_import_cell_format_comment=整型单元格格式为: 100001 float_import_cell_format_comment=浮点单元格格式为: 24 multiple_input_import_cell_format_comment=该单元格可输入多个值,多个值请用逗号或分号隔开(v1;v2) +cascading_select_import_cell_format_comment=该单元格为级联选择,选择父级选项下的子级选项请用逗号或者分号隔开(v;v1;v11) options_tips=(格式{key:value},请填写对应的value)选项: +options_key_tips=(格式{key:value},请填写对应的key)选项: # issue import and issue export title=缺陷标题 description=缺陷描述 diff --git a/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties b/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties index 50ceb3f8b1..fa70984be0 100644 --- a/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -28,7 +28,9 @@ datetime_import_cell_format_comment=日期時間單元格格式爲: YYYY/MM/DD H int_import_cell_format_comment=單元格格式: 100001 float_import_cell_format_comment=單元格格式: 24 multiple_input_import_cell_format_comment=該單元格可輸入多個值,多個值請用逗號或分號隔開(v1;v2) +cascading_select_import_cell_format_comment=該單元格爲級聯選擇,選擇父級選項下的子級選項請用逗號或者分號隔開(v;v1;v11) options_tips=(格式{key:value},請填寫對應value)選項: +options_key_tips=(格式{key:value},請填寫對應key)選項: # issue import and issue export title=缺陷標題 description=缺陷描述