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,51 +1168,55 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService { ...@@ -1160,51 +1168,55 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
} }
return; return;
} }
SXSSFWorkbook wb = xlsxFileInfo.workbook; // 内存中保留 100 行
Sheet sheet = wb.getSheetAt(0);
//日期
CellStyle yyyyMMddhhmmss = wb.createCellStyle();
DataFormat dataFormat = wb.createDataFormat();
yyyyMMddhhmmss.setDataFormat(dataFormat.getFormat("yyyy-MM-dd HH:mm:ss"));
//日期
CellStyle yyyyMMdd = wb.createCellStyle();
DataFormat yyyyMMddDataFormat = wb.createDataFormat();
yyyyMMdd.setDataFormat(yyyyMMddDataFormat.getFormat("yyyy-MM-dd"));
Row row = sheet.createRow(count.get()); SXSSFWorkbook wb = xlsxFileInfo.workbook; // 内存中保留 100 行
for(int j=0; j<cells.length; j++){ if (!endFlag) {
String type = titles.get(j).getType(); Sheet sheet = wb.getSheetAt(0);
Cell midCell = row.createCell(j); //日期
String columnValue = cells[j]; CellStyle yyyyMMddhhmmss = wb.createCellStyle();
if (StringUtils.isBlank(columnValue)) { DataFormat dataFormat = wb.createDataFormat();
midCell.setCellValue(columnValue); yyyyMMddhhmmss.setDataFormat(dataFormat.getFormat("yyyy-MM-dd HH:mm:ss"));
continue;
} //日期
switch (type) { CellStyle yyyyMMdd = wb.createCellStyle();
case FlatQueryFieldType.DATE: DataFormat yyyyMMddDataFormat = wb.createDataFormat();
if (columnValue.length()==10) { yyyyMMdd.setDataFormat(yyyyMMddDataFormat.getFormat("yyyy-MM-dd"));
midCell.setCellStyle(yyyyMMdd);
midCell.setCellValue(DateUtils.parseDate(columnValue,new String[]{"yyyy-MM-dd"})); Row row = sheet.createRow(count.get());
}else { for (int j = 0; j < cells.length; j++) {
midCell.setCellStyle(yyyyMMddhhmmss); String type = titles.get(j).getType();
midCell.setCellValue(DateUtils.parseDate(columnValue, new String[]{"yyyy-MM-dd HH:mm:ss"})); Cell midCell = row.createCell(j);
} String columnValue = cells[j];
break; if (StringUtils.isBlank(columnValue)) {
case FlatQueryFieldType.NUMBER:
if (columnValue.indexOf(".")>0) {
midCell.setCellValue(Double.valueOf(columnValue));
}else {
midCell.setCellValue(Long.valueOf(columnValue));
}
break;
default:
midCell.setCellValue(columnValue); midCell.setCellValue(columnValue);
continue;
}
switch (type) {
case FlatQueryFieldType.DATE:
if (columnValue.length() == 10) {
midCell.setCellStyle(yyyyMMdd);
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) {
midCell.setCellValue(Double.valueOf(columnValue));
} else {
midCell.setCellValue(Long.valueOf(columnValue));
}
break;
default:
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