fix(测试跟踪): 修复功能用例导入小数数值精度问题

--bug=1009890--user=郭雨琦
修复功能用例导入小数数值精度问题
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001009890
This commit is contained in:
guoyuqi 2022-02-23 18:19:24 +08:00 committed by 刘瑞斌
parent d0a1bbc978
commit f871546d2e

View File

@ -23,7 +23,10 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -44,6 +47,8 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
private Map<Integer, String> headMap;
private Map<String,String> excelHeadToFieldNameDic = new HashMap<>();
private static NumberFormat numberFormat = NumberFormat.getNumberInstance();
/**
* 每隔2000条存储数据库然后清理list 方便内存回收
*/
@ -572,8 +577,16 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
private RowInfo parseIndexInRow(String row,int rowIndex) {
RowInfo rowInfo = new RowInfo();
String parseString = row;
if(isNumericzidai(parseString)){
Double aDouble = Double.valueOf(parseString);
parseString = numberFormat.format(aDouble);
}
int index = -1;
String rowMessage = row;
if(isNumericzidai(rowMessage)){
Double aDouble = Double.valueOf(rowMessage);
rowMessage = numberFormat.format(aDouble);
}
String[] indexSplitCharArr = new String[]{")", "", "]", "", ".", ",", "", ""};
if (StringUtils.startsWithAny(row, "(", "", "[", "")) {
parseString = parseString.substring(1);
@ -765,4 +778,13 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
public int index;
public String rowInfo;
}
public static boolean isNumericzidai(String str) {
Pattern pattern = Pattern.compile("-?[0-9]+(\\.[0-9]+)?");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
}