修复:综合浏览导出数据时,因数据表数据包含null值时,导致后台报错的问题

master
Guo XIn 1 year ago
parent f6b3041dfa
commit a5113a829c
  1. 17
      shandan-browser/src/main/java/com/keyware/shandan/browser/service/ExportComponent.java

@ -21,14 +21,12 @@ import com.keyware.shandan.system.service.SysFileService;
import com.keyware.shandan.system.utils.SysSettingUtil;
import lombok.AllArgsConstructor;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ExportComponent {
private final String exportId;
@ -107,9 +105,8 @@ public class ExportComponent {
JSONObject col = (JSONObject) json;
String comment = col.getString("comment");
String colName = col.getString("columnName");
String name = StringUtils.hasTextByDefault(comment, colName);
colNameList.add(colName);
return name;
return colName + (StringUtils.hasText(comment) ? "[" + comment + "]" : "");
}).toList();
// 添加第一行
@ -118,7 +115,13 @@ public class ExportComponent {
// 遍历数据
datas.forEach(data -> {
// 遍历字段列名,获取对应数据并拼接成列的集合
List<String> cells = StreamUtil.as(colNameList).map(col -> data.get(col).toString()).toList();
List<String> cells = colNameList.stream().map(col -> {
Object value = data.get(col);
if (value == null) {
return "";
}
return String.valueOf(value);
}).collect(Collectors.toList());
rowList.add(cells);
});
@ -189,7 +192,7 @@ public class ExportComponent {
private void delete(String path) {
File file = new File(path);
if(file.exists()){
if (file.exists()) {
file.delete();
}
}