fix(测试跟踪): 缺陷管理导出自定义字段值有误

--bug=1019768 --user=宋昌昌 【测试跟踪】缺陷管理-导出-自定义字段类型是单/多选下拉列表-导出后和导出前字段值不一致 https://www.tapd.cn/55049933/s/1301398
This commit is contained in:
song-cc-rock 2022-11-22 16:36:30 +08:00 committed by f2c-ci-robot[bot]
parent ac233c4ca6
commit ce61109aae
3 changed files with 66 additions and 12 deletions

View File

@ -87,7 +87,7 @@ public class IssueTemplateHeadWriteHandler implements RowWriteHandler, SheetWrit
StringUtils.equalsAnyIgnoreCase(field.getName(), "状态", "严重程度")) {
commentText = Translator.get("options").concat(JSON.toJSONString(getOptionValues(field)));
} else {
commentText = Translator.get("options_tips").concat(JSON.toJSONString(getOptionsText(field.getOptions())));
commentText = Translator.get("options").concat(JSON.toJSONString(getOptionsText(field.getOptions())));
}
}
if (StringUtils.equalsAnyIgnoreCase(field.getType(), CustomFieldType.MEMBER.getValue())) {
@ -111,7 +111,7 @@ public class IssueTemplateHeadWriteHandler implements RowWriteHandler, SheetWrit
if (StringUtils.equalsAnyIgnoreCase(field.getType(),
CustomFieldType.MULTIPLE_SELECT.getValue(), CustomFieldType.CHECKBOX.getValue())) {
commentText = Translator.get("multiple_input_import_cell_format_comment").concat(", " +
Translator.get("options_tips").concat(JSON.toJSONString(getOptionsText(field.getOptions()))));
Translator.get("options").concat(JSON.toJSONString(getOptionsText(field.getOptions()))));
}
if (StringUtils.equalsAnyIgnoreCase(field.getType(), CustomFieldType.MULTIPLE_MEMBER.getValue())) {
commentText = Translator.get("multiple_input_import_cell_format_comment").concat(", " +
@ -153,10 +153,9 @@ public class IssueTemplateHeadWriteHandler implements RowWriteHandler, SheetWrit
List<String> options = new ArrayList<>();
List<Map> optionMapList = JSON.parseArray(optionStr, Map.class);
optionMapList.forEach(optionMap -> {
StringBuffer option = new StringBuffer("{" + optionMap.get("text") + ":" + optionMap.get("value") + "}");
options.add(option.toString());
String optionText = optionMap.get("text").toString();
options.add(optionText);
});
return options;
}

View File

@ -4,13 +4,11 @@ import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.fastjson.JSONArray;
import io.metersphere.base.domain.Issues;
import io.metersphere.commons.constants.CustomFieldType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.commons.utils.*;
import io.metersphere.dto.CustomFieldDao;
import io.metersphere.dto.CustomFieldItemDTO;
import io.metersphere.dto.CustomFieldResourceDTO;
@ -145,12 +143,12 @@ public class IssueExcelListener extends AnalysisEventListener<Map<Integer, Strin
}
if (CollectionUtils.isNotEmpty(insertList)) {
List<IssuesUpdateRequest> issues = insertList.stream().map(item -> this.convertToIssue(item)).collect(Collectors.toList());
List<IssuesUpdateRequest> issues = insertList.stream().map(this::convertToIssue).collect(Collectors.toList());
issuesService.saveImportData(issues);
}
if (CollectionUtils.isNotEmpty(updateList)) {
List<IssuesUpdateRequest> issues = updateList.stream().map(item -> this.convertToIssue(item)).collect(Collectors.toList());
List<IssuesUpdateRequest> issues = updateList.stream().map(this::convertToIssue).collect(Collectors.toList());
issuesService.updateImportData(issues);
}
}
@ -330,7 +328,15 @@ public class IssueExcelListener extends AnalysisEventListener<Map<Integer, Strin
} else if (StringUtils.equalsAnyIgnoreCase(type, CustomFieldType.FLOAT.getValue())) {
customFieldResourceDTO.setValue(v.toString());
} else if (StringUtils.equalsAnyIgnoreCase(type, CustomFieldType.MULTIPLE_SELECT.getValue(),
CustomFieldType.CHECKBOX.getValue(), CustomFieldType.MULTIPLE_INPUT.getValue(),
CustomFieldType.CHECKBOX.getValue())) {
if (!v.toString().contains("[")) {
v = List.of("\"" + v + "\"");
}
customFieldResourceDTO.setValue(parseOptionText(customFieldDao.getOptions(), v.toString()));
} else if (StringUtils.equalsAnyIgnoreCase(type, CustomFieldType.SELECT.getValue(),
CustomFieldType.RADIO.getValue())) {
customFieldResourceDTO.setValue("\"" + parseOptionText(customFieldDao.getOptions(), v.toString()) + "\"");
} else if (StringUtils.equalsAnyIgnoreCase(type, CustomFieldType.MULTIPLE_INPUT.getValue(),
CustomFieldType.MULTIPLE_MEMBER.getValue(), CustomFieldType.CASCADING_SELECT.getValue())) {
if (!v.toString().contains("[")) {
v = List.of("\"" + v + "\"");
@ -424,4 +430,34 @@ public class IssueExcelListener extends AnalysisEventListener<Map<Integer, Strin
}
return Boolean.FALSE;
}
public String parseOptionText(String options, String tarVal) {
if (StringUtils.isEmpty(options)) {
return StringUtils.EMPTY;
}
List<Map> optionList = JSON.parseArray(options, Map.class);
if (StringUtils.containsAny(tarVal, "[", "]")) {
List<String> parseArr = new ArrayList<>();
List<String> tarArr = JSONArray.parseArray(tarVal, String.class);
for (Map option : optionList) {
String text = option.get("text").toString();
String value = option.get("value").toString();
if (tarArr.contains(text)) {
parseArr.add("\"" + value + "\"");
}
}
return parseArr.toString();
} else {
tarVal = tarVal + ",";
for (Map option : optionList) {
String text = option.get("text").toString();
String value = option.get("value").toString();
if (StringUtils.containsIgnoreCase(tarVal, text + ",")) {
tarVal = tarVal.replaceAll(text, value);
}
}
return tarVal.substring(0, tarVal.length() - 1);
}
}
}

View File

@ -766,6 +766,10 @@ public class IssuesService {
String format = DateUtils.format(date, "yyyy/MM/dd HH:mm:ss");
fieldDao.setValue("\"" + format + "\"");
}
if (StringUtils.equalsAnyIgnoreCase(customField.getType(), CustomFieldType.SELECT.getValue(),
CustomFieldType.MULTIPLE_SELECT.getValue(), CustomFieldType.CHECKBOX.getValue(), CustomFieldType.RADIO.getValue())) {
fieldDao.setValue(parseOptionValue(customField.getOptions(), fieldDao.getValue()));
}
}
}
}
@ -1652,6 +1656,21 @@ public class IssuesService {
return value;
}
private String parseOptionValue(String options, String tarVal) {
if (StringUtils.isEmpty(options) || StringUtils.isEmpty(tarVal)) {
return StringUtils.EMPTY;
}
List<Map> optionList = JSON.parseArray(options, Map.class);
for (Map option : optionList) {
String text = option.get("text").toString();
String value = option.get("value").toString();
if (StringUtils.containsIgnoreCase(tarVal, value)) {
tarVal = tarVal.replaceAll(value, text);
}
}
return tarVal;
}
public Issues checkIssueExist(Integer num, String projectId) {
IssuesExample example = new IssuesExample();
example.createCriteria().andNumEqualTo(num).andProjectIdEqualTo(projectId);