Commit 4c3e5a68 by fudahua

feat: 新版本的下载

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