|
@@ -17,9 +17,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
@@ -55,9 +53,11 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
|
|
|
taskExportCommon.init();
|
|
|
String timeFormat = taskExportCommon.getTimeFormat();
|
|
|
taskExportCommon.setTxtList(new ArrayList());
|
|
|
- FileOutputStream fos = null;
|
|
|
SXSSFWorkbook wb = null;
|
|
|
- File mkdir = null, file = null;
|
|
|
+ StringJoiner stringJoiner = null;
|
|
|
+ String excelFilePath = null;
|
|
|
+ InputStream inputStream = null;
|
|
|
+ ByteArrayOutputStream out = null;
|
|
|
int y = 0, min = 0;
|
|
|
try {
|
|
|
taskExportCommon.getTxtList().add(DateUtil.format(new Date(), timeFormat) + "->开始准备处理导出的考场数据");
|
|
@@ -67,18 +67,14 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
|
|
|
List<RoomCodeExportDto> roomCodeExportDtoList = tbExamInvigilateUserService.examInvigilateUserExport(examId, roomCode, userId, taskExportCommon.getOrgId());
|
|
|
|
|
|
boolean oss = (boolean) taskExportCommon.getOssEnv().get(SystemConstant.OSS);
|
|
|
- StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ stringJoiner = new StringJoiner("");
|
|
|
if (!oss) {
|
|
|
stringJoiner.add(SystemConstant.FILES_DIR).add(File.separator);
|
|
|
}
|
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
|
stringJoiner.add(String.valueOf(nowTime.getYear()))
|
|
|
- .add(File.separator).add(String.valueOf(nowTime.getMonthValue()))
|
|
|
- .add(File.separator).add(String.valueOf(nowTime.getDayOfMonth()));
|
|
|
- mkdir = new File(stringJoiner.toString());
|
|
|
- if (!mkdir.exists()) {
|
|
|
- mkdir.mkdirs();
|
|
|
- }
|
|
|
+ .add(File.separator).add(String.format("%02d", nowTime.getMonthValue()))
|
|
|
+ .add(File.separator).add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
//创建excel
|
|
|
wb = new SXSSFWorkbook();
|
|
|
Sheet sheet = wb.createSheet("考场导出");
|
|
@@ -127,11 +123,12 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
|
|
|
max = size;
|
|
|
}
|
|
|
}
|
|
|
- file = taskExportCommon.createExcel(mkdir.getPath());
|
|
|
- //写入excel并上传附件
|
|
|
- fos = new FileOutputStream(file);
|
|
|
- wb.write(fos);
|
|
|
- taskExportCommon.ossUpload(file);
|
|
|
+ //临时缓冲区
|
|
|
+ out = new ByteArrayOutputStream();
|
|
|
+ wb.write(out);
|
|
|
+ byte[] bookByteAry = out.toByteArray();
|
|
|
+ inputStream = new ByteArrayInputStream(bookByteAry);
|
|
|
+ excelFilePath = taskExportCommon.ossUpload(inputStream, stringJoiner.toString());
|
|
|
long end = System.currentTimeMillis();
|
|
|
log.info("导出考场数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
|
} catch (Exception e) {
|
|
@@ -141,12 +138,15 @@ public class TaskRoomCodeExportTemplete implements TaskExportTemplete {
|
|
|
if (Objects.nonNull(wb)) {
|
|
|
wb.dispose();
|
|
|
}
|
|
|
- if (Objects.nonNull(fos)) {
|
|
|
- fos.flush();
|
|
|
- fos.close();
|
|
|
+ if (Objects.nonNull(inputStream)) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(out)) {
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
}
|
|
|
//这里写入txt文件
|
|
|
- taskExportCommon.writeExportResultTxt(mkdir.getPath(), taskExportCommon.getTxtList().toString(), file);
|
|
|
+ taskExportCommon.writeExportResultTxt(stringJoiner.toString(), taskExportCommon.getTxtList().toString(), excelFilePath);
|
|
|
}
|
|
|
return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
|
|
|
}
|