Commit 73ded52f by fudahua

feat: 换成json格式

parent 84c71daf
...@@ -937,7 +937,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -937,7 +937,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
AtomicInteger totalCount=new AtomicInteger(0); AtomicInteger totalCount=new AtomicInteger(0);
AtomicInteger count=new AtomicInteger(0); AtomicInteger count=new AtomicInteger(0);
AtomicReference<XlsxFileInfo> currentFile=new AtomicReference<>(); AtomicReference<XlsxFileInfo> currentFile=new AtomicReference<>();
readCsvFile(condition,dirName,(cells,titles,firstFlag)->{ readJsonFile(condition,dirName,(cells,titles,firstFlag)->{
if (count.get()==0) { if (count.get()==0) {
XlsxFileInfo xlsxFileInfo = new XlsxFileInfo(); XlsxFileInfo xlsxFileInfo = new XlsxFileInfo();
xlsxFileInfo.filepath=SAVE_FOLDER + "/" + task.getId() + xlsxFiles.size() + ".xlsx"; xlsxFileInfo.filepath=SAVE_FOLDER + "/" + task.getId() + xlsxFiles.size() + ".xlsx";
...@@ -1071,6 +1071,58 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1071,6 +1071,58 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} }
/**
* 读物文件
* @param dirName
* @param func
*/
private void readJsonFile(FlatQueryTaskCondition condition, String dirName, DownloadFunc func){
File file = new File(SAVE_FOLDER+"/"+dirName);
File[] files = file.listFiles();
List<FlatQueryCondition> titles=null;
List<FlatQueryCondition> conditions = condition.getConditions();
List<String> keys = conditions.stream().map(mid -> mid.getFieldMark()).collect(Collectors.toList());
Map<String, FlatQueryCondition> columnInfoMap = conditions.stream().collect(Collectors.toMap(mid -> mid.getFieldMark(), mid ->mid));
List<File> fileList = Arrays.stream(files).sorted(Comparator.comparing(File::getName)).collect(Collectors.toList());
for (File midFile : fileList) {
if (!midFile.getName().endsWith("json")) {
continue;
}
try {
BufferedReader reader=new BufferedReader(new FileReader(midFile));
boolean first=true;
Exception exception=null;
try {
String line = reader.readLine();
while (line != null) {
List<String> cellList=new ArrayList<>();
JSONObject jsonObject = JSONObject.parseObject(line);
for (String key : keys) {
String cellVal = jsonObject.getString(key);
cellList.add(cellVal);
}
String[] cells = cellList.toArray(new String[]{});
func.deal(cells,conditions,first);
first=false;
line = reader.readLine();
}
logger.info("读取结束:{}",midFile.getName());
} catch (Exception e) {
exception=e;
}finally {
reader.close();
}
if (exception!=null) {
throw exception;
}
} catch (Exception e) {
logger.info("读取异常:{}",e);
throw new RuntimeException(e);
}
}
}
private void takeFile(FlatQueryTaskCondition condition, Connection conn, int downloadType){ private void takeFile(FlatQueryTaskCondition condition, Connection conn, int downloadType){
if (condition != null) { if (condition != null) {
......
...@@ -11,6 +11,9 @@ import com.gic.cloud.data.hook.service.FileUtil; ...@@ -11,6 +11,9 @@ import com.gic.cloud.data.hook.service.FileUtil;
import com.gic.cloud.data.hook.service.entity.ColumnInfo; import com.gic.cloud.data.hook.service.entity.ColumnInfo;
import com.gic.cloud.data.hook.service.impl.FlatQueryResultServiceImpl; import com.gic.cloud.data.hook.service.impl.FlatQueryResultServiceImpl;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.RFC4180Parser;
import com.opencsv.RFC4180ParserBuilder;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
...@@ -45,9 +48,12 @@ public class ExceTest2 { ...@@ -45,9 +48,12 @@ public class ExceTest2 {
if (!midFile.getName().endsWith("csv")) { if (!midFile.getName().endsWith("csv")) {
continue; continue;
} }
String lastcells=null;
String[] cells=null;
try { try {
CSVReader csvReader = new CSVReader(new FileReader(midFile)); RFC4180Parser rfc4180Parser = new RFC4180ParserBuilder().build();
String[] cells = csvReader.readNext(); CSVReader csvReader = new CSVReaderBuilder(new FileReader(midFile)).build();
cells = csvReader.readNext();
boolean first=true; boolean first=true;
do { do {
if (titles == null) { if (titles == null) {
...@@ -62,10 +68,14 @@ public class ExceTest2 { ...@@ -62,10 +68,14 @@ public class ExceTest2 {
continue; continue;
} }
func.deal(cells,titles,first); func.deal(cells,titles,first);
lastcells=JSONObject.toJSONString(cells);
}while ((cells = csvReader.readNext())!=null); }while ((cells = csvReader.readNext())!=null);
logger.info("读取结束:{}",midFile.getName()); logger.info("读取结束:{}",midFile.getName());
csvReader.close(); csvReader.close();
} catch (Exception e) { } catch (Exception e) {
logger.info("lastcell: {}",lastcells);
logger.info("cells: {}",cells[0]);
logger.info("cells: {},{},{}",cells[1]);
logger.info("读取异常:{}",e); logger.info("读取异常:{}",e);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment