generated from root/miduo_server
流水修改
parent
88dff608d0
commit
917020b609
9
pom.xml
9
pom.xml
|
|
@ -107,11 +107,6 @@
|
||||||
<artifactId>libthrift</artifactId>
|
<artifactId>libthrift</artifactId>
|
||||||
<version>0.9.2</version>
|
<version>0.9.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>fastjson</artifactId>
|
|
||||||
<version>1.2.35</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
|
|
@ -120,12 +115,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi</artifactId>
|
<artifactId>poi</artifactId>
|
||||||
<version>3.14</version>
|
<version>3.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi-ooxml</artifactId>
|
<artifactId>poi-ooxml</artifactId>
|
||||||
<version>3.14</version>
|
<version>3.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.jmfy.WebSecurityConfig;
|
import com.jmfy.WebSecurityConfig;
|
||||||
import com.jmfy.dao.*;
|
import com.jmfy.dao.*;
|
||||||
import com.jmfy.model.*;
|
import com.jmfy.model.*;
|
||||||
|
|
@ -10,10 +8,10 @@ import com.jmfy.model.vo.OrderExcelVo;
|
||||||
import com.jmfy.redisProperties.RedisUserKey;
|
import com.jmfy.redisProperties.RedisUserKey;
|
||||||
import com.jmfy.utils.*;
|
import com.jmfy.utils.*;
|
||||||
import com.jmfy.utils.DateUtil;
|
import com.jmfy.utils.DateUtil;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||||
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -31,9 +29,6 @@ import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -316,53 +311,48 @@ public class OrderInfoController {
|
||||||
long start = DateUtil.now();
|
long start = DateUtil.now();
|
||||||
LOGGER.info("开始导出订单,写入文件,name:{},订单数:{}",name, cgPayOrders.size());
|
LOGGER.info("开始导出订单,写入文件,name:{},订单数:{}",name, cgPayOrders.size());
|
||||||
try (FileOutputStream fOut = new FileOutputStream(getExcelFilePath(name, start))) {
|
try (FileOutputStream fOut = new FileOutputStream(getExcelFilePath(name, start))) {
|
||||||
try (Workbook workbook = new XSSFWorkbook()) {
|
SXSSFWorkbook workbook = new SXSSFWorkbook(); // 使用SXSSFWorkbook代替XSSFWorkbook
|
||||||
CellStyle contextStyle = workbook.createCellStyle();
|
|
||||||
int rowIndex = 1, cellIndex = 0;
|
|
||||||
Field[] fields = cgPayOrders.get(0).getClass().getDeclaredFields();
|
|
||||||
Sheet sheet = workbook.createSheet();
|
|
||||||
Row headerRow = sheet.createRow(0);
|
|
||||||
while (cellIndex < fields.length) {
|
|
||||||
Cell cell = headerRow.createCell(cellIndex);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
cell.setCellValue(fields[cellIndex].getAnnotation(Fields.class).value());
|
|
||||||
cellIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Corder cgPayOrder : cgPayOrders) {
|
CellStyle contextStyle = workbook.createCellStyle();
|
||||||
if (rowIndex > 65535) {
|
int rowIndex = 1, cellIndex = 0;
|
||||||
// 超过行数限制,创建新的工作表
|
Field[] fields = cgPayOrders.get(0).getClass().getDeclaredFields();
|
||||||
sheet = workbook.createSheet();
|
SXSSFSheet sheet = workbook.createSheet();
|
||||||
headerRow = sheet.createRow(0);
|
Row headerRow = sheet.createRow(0);
|
||||||
cellIndex = 0;
|
while (cellIndex < fields.length) {
|
||||||
while (cellIndex < fields.length) {
|
Cell cell = headerRow.createCell(cellIndex);
|
||||||
Cell cell = headerRow.createCell(cellIndex);
|
cell.setCellType(CellType.STRING);
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
cell.setCellValue(fields[cellIndex].getAnnotation(Fields.class).value());
|
||||||
cell.setCellValue(fields[cellIndex].getAnnotation(Fields.class).value());
|
cellIndex++;
|
||||||
cellIndex++;
|
}
|
||||||
}
|
|
||||||
rowIndex = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int batchSize = 1000; // 每批写入的数据量
|
||||||
|
int batchCount = (int) Math.ceil((double) cgPayOrders.size() / batchSize);
|
||||||
|
for (int batch = 0; batch < batchCount; batch++) {
|
||||||
|
int startIndex = batch * batchSize;
|
||||||
|
int endIndex = Math.min(startIndex + batchSize, cgPayOrders.size());
|
||||||
|
for (int i = startIndex; i < endIndex; i++) {
|
||||||
|
Corder cgPayOrder = cgPayOrders.get(i);
|
||||||
cellIndex = 0;
|
cellIndex = 0;
|
||||||
Row currentRow = sheet.createRow(rowIndex);
|
Row currentRow = sheet.createRow(rowIndex);
|
||||||
while (cellIndex < fields.length) {
|
while (cellIndex < fields.length) {
|
||||||
Cell cell = currentRow.createCell(cellIndex);
|
Cell cell = currentRow.createCell(cellIndex);
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
cell.setCellType(CellType.STRING);
|
||||||
Object value = getFieldValueByName(fields[cellIndex].getName(), cgPayOrder);
|
Object value = getFieldValueByName(fields[cellIndex].getName(), cgPayOrder);
|
||||||
setCellValue(cell, value, contextStyle);
|
setCellValue(cell, value, contextStyle);
|
||||||
cellIndex++;
|
cellIndex++;
|
||||||
}
|
}
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
}
|
}
|
||||||
workbook.write(fOut);
|
|
||||||
}catch (Exception e){
|
sheet.flushRows(); // 刷新行数据到磁盘,释放内存
|
||||||
LOGGER.error("导出订单报错1:{}", e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workbook.write(fOut);
|
||||||
|
workbook.dispose(); // 释放临时文件资源
|
||||||
|
LOGGER.info("导出订单操作,excel文件写入耗时:{}毫秒", DateUtil.now() - start);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("导出订单报错2:{}", e.getMessage(), e);
|
LOGGER.error("导出订单报错:{}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
LOGGER.info("导出订单操作,excel文件写入耗时:{}毫秒", DateUtil.now() - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getExcelFilePath(String name, long start) throws Exception {
|
private static String getExcelFilePath(String name, long start) throws Exception {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue