|
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -47,24 +48,20 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
|
|
TaskExportCommon taskExportCommon = new TaskExportCommon(transMap);
|
|
TaskExportCommon taskExportCommon = new TaskExportCommon(transMap);
|
|
taskExportCommon.init();
|
|
taskExportCommon.init();
|
|
FileOutputStream fos = null;
|
|
FileOutputStream fos = null;
|
|
- File mkdir = null;
|
|
|
|
File file = null;
|
|
File file = null;
|
|
-
|
|
|
|
|
|
+ StringJoiner stringJoiner = null;
|
|
|
|
+ String excelFilePath = null;
|
|
boolean oss = (boolean) taskExportCommon.getOssEnv().get(SystemConstant.OSS);
|
|
boolean oss = (boolean) taskExportCommon.getOssEnv().get(SystemConstant.OSS);
|
|
try {
|
|
try {
|
|
- StringJoiner stringJoiner = new StringJoiner("");
|
|
|
|
|
|
+ stringJoiner = new StringJoiner("");
|
|
if (!oss) {
|
|
if (!oss) {
|
|
stringJoiner.add(SystemConstant.FILES_DIR).add(File.separator);
|
|
stringJoiner.add(SystemConstant.FILES_DIR).add(File.separator);
|
|
}
|
|
}
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
stringJoiner.add(String.valueOf(nowTime.getYear()))
|
|
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();
|
|
|
|
- }
|
|
|
|
- file = new File(mkdir.getPath() + "/" + uuid() + SystemConstant.EXCEL_PREFIX);
|
|
|
|
|
|
+ .add(File.separator).add(String.format("%02d", nowTime.getMonthValue()))
|
|
|
|
+ .add(File.separator).add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
|
+ file = new File(SystemConstant.TEMP_FILES_DIR + "/" + uuid() + SystemConstant.EXCEL_PREFIX);
|
|
file.createNewFile();
|
|
file.createNewFile();
|
|
fos = new FileOutputStream(file);
|
|
fos = new FileOutputStream(file);
|
|
Long examId = (Long) transMap.get("examId");
|
|
Long examId = (Long) transMap.get("examId");
|
|
@@ -80,7 +77,7 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
|
|
List<TEExamStudentDto> list = teExamStudentService.examStudentList(examId, activityId, identity, name, roomCode, courseCode, grade,
|
|
List<TEExamStudentDto> list = teExamStudentService.examStudentList(examId, activityId, identity, name, roomCode, courseCode, grade,
|
|
enable, classNo, hasPhoto);
|
|
enable, classNo, hasPhoto);
|
|
ExportUtils.makeExcel(TEExamStudentDto.class, list, fos);
|
|
ExportUtils.makeExcel(TEExamStudentDto.class, list, fos);
|
|
- taskExportCommon.ossUpload(file);
|
|
|
|
|
|
+ excelFilePath = taskExportCommon.ossUpload(new FileInputStream(file), stringJoiner.toString());
|
|
taskExportCommon.getTbTaskHistory().setSummary("处理成功");
|
|
taskExportCommon.getTbTaskHistory().setSummary("处理成功");
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
log.info("导出考生数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
log.info("导出考生数据结束,============耗时============:{}秒", (end - start) / 1000);
|
|
@@ -89,10 +86,6 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
|
|
taskExportCommon.setException(true);
|
|
taskExportCommon.setException(true);
|
|
taskExportCommon.getTbTaskHistory().setSummary("处理出错");
|
|
taskExportCommon.getTbTaskHistory().setSummary("处理出错");
|
|
} finally {
|
|
} finally {
|
|
- if (Objects.nonNull(fos)) {
|
|
|
|
- fos.flush();
|
|
|
|
- fos.close();
|
|
|
|
- }
|
|
|
|
if (oss && file != null) {
|
|
if (oss && file != null) {
|
|
file.delete();
|
|
file.delete();
|
|
}
|
|
}
|
|
@@ -100,7 +93,7 @@ public class TaskExamStudentExportTemplete implements TaskExportTemplete {
|
|
taskExportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
|
|
taskExportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
|
|
taskExportCommon.getTbTaskHistory().setProgress(100.0d);
|
|
taskExportCommon.getTbTaskHistory().setProgress(100.0d);
|
|
//这里写入txt文件
|
|
//这里写入txt文件
|
|
- taskExportCommon.writeExportResultTxt(mkdir.getPath(), "", file);
|
|
|
|
|
|
+ taskExportCommon.writeExportResultTxt(stringJoiner.toString(), "", excelFilePath);
|
|
}
|
|
}
|
|
return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
|
|
return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
|
|
}
|
|
}
|