Commit 4c3e5a68 by fudahua

feat: 新版本的下载

parent 2980fe23
...@@ -53,6 +53,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; ...@@ -53,6 +53,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** 自助指标查询服务实现 /** 自助指标查询服务实现
...@@ -878,8 +880,11 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -878,8 +880,11 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
xlsxFiles.add(currentFile.get().filepath); xlsxFiles.add(currentFile.get().filepath);
} }
saveXlsSplitNew(currentFile.get().filepath,cells,titles,currentFile.get(),count); saveXlsSplitNew(currentFile.get().filepath,cells,titles,currentFile.get(),count,false);
}); });
//结束
saveXlsSplitNew(currentFile.get().filepath,null,null,currentFile.get(),count,true);
//是否压缩 //是否压缩
boolean zipFlag = (xlsxFiles.size() > 1) ? true : false; boolean zipFlag = (xlsxFiles.size() > 1) ? true : false;
String cloudFileUrl=null; String cloudFileUrl=null;
...@@ -921,7 +926,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -921,7 +926,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
* @param dirName * @param dirName
* @param func * @param func
*/ */
private void readCsvFile(String tableId,String dirName,DownloadFunc func){ private void readCsvFile(String tableId, String dirName, DownloadFunc func){
File file = new File(SAVE_FOLDER+"/"+dirName); File file = new File(SAVE_FOLDER+"/"+dirName);
File[] files = file.listFiles(); File[] files = file.listFiles();
List<ColumnInfo> titles=null; List<ColumnInfo> titles=null;
...@@ -945,6 +950,9 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -945,6 +950,9 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
titles.add(columnInfoMap.get(cell)); titles.add(columnInfoMap.get(cell));
} }
} }
if (first) {
continue;
}
func.deal(cells,titles,first); func.deal(cells,titles,first);
first=false; first=false;
}while ((cells = csvReader.readNext())!=null); }while ((cells = csvReader.readNext())!=null);
...@@ -1146,7 +1154,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1146,7 +1154,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
* @param originalFilePath * @param originalFilePath
* @param cells * @param cells
*/ */
private void saveXlsSplitNew(String originalFilePath, String[] cells, List<ColumnInfo> titles, XlsxFileInfo xlsxFileInfo, AtomicInteger count){ private void saveXlsSplitNew(String originalFilePath, String[] cells, List<ColumnInfo> titles, XlsxFileInfo xlsxFileInfo, AtomicInteger count,boolean endFlag){
try { try {
if (xlsxFileInfo.workbook==null) { if (xlsxFileInfo.workbook==null) {
xlsxFileInfo.workbook=new SXSSFWorkbook(100); xlsxFileInfo.workbook=new SXSSFWorkbook(100);
...@@ -1160,7 +1168,10 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1160,7 +1168,10 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} }
return; return;
} }
SXSSFWorkbook wb = xlsxFileInfo.workbook; // 内存中保留 100 行 SXSSFWorkbook wb = xlsxFileInfo.workbook; // 内存中保留 100 行
if (!endFlag) {
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
//日期 //日期
CellStyle yyyyMMddhhmmss = wb.createCellStyle(); CellStyle yyyyMMddhhmmss = wb.createCellStyle();
...@@ -1173,7 +1184,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1173,7 +1184,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
yyyyMMdd.setDataFormat(yyyyMMddDataFormat.getFormat("yyyy-MM-dd")); yyyyMMdd.setDataFormat(yyyyMMddDataFormat.getFormat("yyyy-MM-dd"));
Row row = sheet.createRow(count.get()); Row row = sheet.createRow(count.get());
for(int j=0; j<cells.length; j++){ for (int j = 0; j < cells.length; j++) {
String type = titles.get(j).getType(); String type = titles.get(j).getType();
Cell midCell = row.createCell(j); Cell midCell = row.createCell(j);
String columnValue = cells[j]; String columnValue = cells[j];
...@@ -1183,18 +1194,18 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1183,18 +1194,18 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} }
switch (type) { switch (type) {
case FlatQueryFieldType.DATE: case FlatQueryFieldType.DATE:
if (columnValue.length()==10) { if (columnValue.length() == 10) {
midCell.setCellStyle(yyyyMMdd); midCell.setCellStyle(yyyyMMdd);
midCell.setCellValue(DateUtils.parseDate(columnValue,new String[]{"yyyy-MM-dd"})); midCell.setCellValue(DateUtils.parseDate(columnValue, new String[]{"yyyy-MM-dd"}));
}else { } else {
midCell.setCellStyle(yyyyMMddhhmmss); midCell.setCellStyle(yyyyMMddhhmmss);
midCell.setCellValue(DateUtils.parseDate(columnValue, new String[]{"yyyy-MM-dd HH:mm:ss"})); midCell.setCellValue(DateUtils.parseDate(columnValue, new String[]{"yyyy-MM-dd HH:mm:ss"}));
} }
break; break;
case FlatQueryFieldType.NUMBER: case FlatQueryFieldType.NUMBER:
if (columnValue.indexOf(".")>0) { if (columnValue.indexOf(".") > 0) {
midCell.setCellValue(Double.valueOf(columnValue)); midCell.setCellValue(Double.valueOf(columnValue));
}else { } else {
midCell.setCellValue(Long.valueOf(columnValue)); midCell.setCellValue(Long.valueOf(columnValue));
} }
break; break;
...@@ -1202,9 +1213,10 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1202,9 +1213,10 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
midCell.setCellValue(columnValue); midCell.setCellValue(columnValue);
} }
} }
}
Integer limitSize = FileUtil.getLimitSize(); Integer limitSize = FileUtil.getLimitSize();
int c = count.incrementAndGet(); int c = count.incrementAndGet();
if (c>=limitSize) { if (c>=limitSize||endFlag) {
FileOutputStream fileOut = new FileOutputStream(originalFilePath); FileOutputStream fileOut = new FileOutputStream(originalFilePath);
wb.write(fileOut); wb.write(fileOut);
//fileOut.flush(); // SXSSFWorkbook 使用 auto-flush 模式 //fileOut.flush(); // SXSSFWorkbook 使用 auto-flush 模式
......
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