|
@@ -51,9 +51,8 @@ public class FirstDeliveryValidServiceImpl implements FirstDeliveryValidService
|
|
|
List<FirstDeliveryValidMaterials> dataList = new ArrayList<>();
|
|
|
StringBuffer path = new StringBuffer();
|
|
|
try {
|
|
|
- path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.SHORT_FORMAT)).append("/").append(UUID.randomUUID().toString()).append("/");
|
|
|
- log.info("-------下载到服务器地址:{}", path.toString());
|
|
|
- List<JSONObject> list = this.analysisBIGBIGFile(file, path.toString());
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ List<JSONObject> list = this.analysisFile(file, fileName);
|
|
|
LoadFileUtil.delFile(path.toString());
|
|
|
for (JSONObject object : list) {
|
|
|
FirstDeliveryValidMaterials material = new FirstDeliveryValidMaterials(object);
|
|
@@ -209,64 +208,6 @@ public class FirstDeliveryValidServiceImpl implements FirstDeliveryValidService
|
|
|
page.setTotal(total);
|
|
|
return Result.OK(page);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public List<JSONObject> analysisBIGBIGFile(MultipartFile mfile, String path) throws Exception {
|
|
|
- InputStream is = null;
|
|
|
- String newFileUrl = FileUtil.approvalFile(mfile, path);
|
|
|
- List<JSONObject> list = null;
|
|
|
- try {
|
|
|
- File file = new File(newFileUrl);
|
|
|
- is = new FileInputStream(file);
|
|
|
- Workbook workbook = StreamingReader.builder()
|
|
|
- .rowCacheSize(20000)
|
|
|
- .bufferSize(4096)
|
|
|
- .open(is);
|
|
|
- ExportExcelUtils eeu = new ExportExcelUtils();
|
|
|
- //最后一列(列数)
|
|
|
- int lastCellNum = 0;
|
|
|
- // list存储数据集
|
|
|
- list = new ArrayList<>();
|
|
|
- for (Sheet sheet : workbook) {
|
|
|
- // sheet.getLastRowNum()获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
|
|
|
- int sumPageNum = (sheet.getLastRowNum() + 1) / 20000 + 1; //计算分片数
|
|
|
- for (int i = 1; i <= sumPageNum; i++) { //读取每片范围内的内容
|
|
|
- try {
|
|
|
- int minRowNum = 20000 * (i - 1) + 1; //计算每片读取的行数范围
|
|
|
- int maxRowNum = 20000 * i;
|
|
|
- for (Row row : sheet) {
|
|
|
- if (lastCellNum == 0) {
|
|
|
- lastCellNum = row.getLastCellNum();
|
|
|
- }
|
|
|
- if (row != null) {
|
|
|
- Map<String, Object> columnValueMap = new HashMap<>();
|
|
|
- if (row.getRowNum() >= minRowNum && row.getRowNum() <= maxRowNum) {//控制每片读取的行
|
|
|
- //每行数据对象,按照顺序从0到(lastCellNum-1)记录
|
|
|
- JSONObject cellEntity = new JSONObject();
|
|
|
- for (int k = 0; k < lastCellNum; k++) {
|
|
|
- cellEntity.put(String.valueOf(k), eeu.getCellValue2(row.getCell(k)));
|
|
|
- }
|
|
|
- list.add(cellEntity);
|
|
|
- if (row.getRowNum() == maxRowNum) {//读取到每片最大行数限制,跳出,执行数据写入
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- workbook.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- IOUtils.closeQuietly(is);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
public static List<JSONObject> analysisFile(MultipartFile file, String fileName) throws Exception {
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
Workbook workbook = null;
|