fix:saveQCCheck异常
This commit is contained in:
parent
bc79da2cd0
commit
0b17702d43
|
@ -1093,7 +1093,7 @@ public class Sample_G_Analysis {
|
|||
return gardsAnalyses;
|
||||
}
|
||||
|
||||
public <T1,T2> List<T2> mapFields(T1 source, T2 tartget, String baseLine, Map<String,String> fieldMap) {
|
||||
/* public <T1,T2> List<T2> mapFields(T1 source, T2 tartget, String baseLine, Map<String,String> fieldMap) {
|
||||
try {
|
||||
List<T2> result = new ArrayList<>();
|
||||
Class<?> sourceClass = source.getClass();
|
||||
|
@ -1147,6 +1147,66 @@ public class Sample_G_Analysis {
|
|||
e.printStackTrace();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}*/
|
||||
|
||||
public <T1,T2> List<T2> mapFields(T1 source, T2 tartget, String baseLine, Map<String,String> fieldMap) {
|
||||
try {
|
||||
List<T2> result = new ArrayList<>();
|
||||
Class<?> sourceClass = source.getClass();
|
||||
boolean isNumber = NumberUtil.isNumber(baseLine);
|
||||
int total;
|
||||
if (isNumber){
|
||||
total = Integer.parseInt(baseLine);
|
||||
}else {
|
||||
Field declaredField = sourceClass.getDeclaredField(baseLine);
|
||||
declaredField.setAccessible(true);
|
||||
List<String> baseList = (List<String>) declaredField.get(source);
|
||||
if (CollUtil.isEmpty(baseList))
|
||||
return result;
|
||||
total = baseList.size();
|
||||
}
|
||||
Class<T2> tartgetClass = (Class<T2>) tartget.getClass();
|
||||
Field[] sourceFields = sourceClass.getDeclaredFields();
|
||||
for (int i = 0; i < total; i++) {
|
||||
tartget = tartgetClass.newInstance();
|
||||
for (Field sourceField : sourceFields) {
|
||||
try {
|
||||
sourceField.setAccessible(true);
|
||||
List<String> sourceList = (List<String>) sourceField.get(source);
|
||||
if (CollUtil.isEmpty(sourceList))
|
||||
continue;
|
||||
if (sourceList.size() <= i)
|
||||
continue;
|
||||
String value = sourceList.get(i);
|
||||
if (StrUtil.isNotBlank(value)){
|
||||
String sourceFieldName = sourceField.getName();
|
||||
String targetFieldName = fieldMap.get(sourceFieldName);
|
||||
targetFieldName = StrUtil.isBlank(targetFieldName) ? sourceFieldName : targetFieldName;
|
||||
Field tartgetField = tartgetClass.getDeclaredField(targetFieldName);
|
||||
tartgetField.setAccessible(true);
|
||||
Class<?> type = tartgetField.getType();
|
||||
if (type == String.class) {
|
||||
tartgetField.set(tartget, value);
|
||||
} else if (type == Integer.class || type == int.class) {
|
||||
// 避免类似0.000的String值转Integer时NumberFormatException
|
||||
tartgetField.set(tartget, Double.valueOf(value).intValue());
|
||||
} else if (type == Double.class || type == double.class) {
|
||||
tartgetField.set(tartget, Double.valueOf(value));
|
||||
} else if (type == Boolean.class || type == boolean.class) {
|
||||
tartgetField.set(tartget, Boolean.valueOf(value));
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("Sample_G_Analysis.mapFields()值映射异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
result.add(tartget);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
private void setPHDFile(PHDFile phdFile, EnergySpectrumStruct spectrumStruct) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user