|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.boot.tools.excel.ExcelWriter;
|
|
|
+import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
import com.qmth.eds.bean.dto.ExamAssignDto;
|
|
|
import com.qmth.eds.bean.dto.ScoreDownloadDto;
|
|
|
import com.qmth.eds.bean.result.AssignResultPreviewResult;
|
|
@@ -20,6 +22,9 @@ import com.qmth.eds.mapper.ExamAssignMapper;
|
|
|
import com.qmth.eds.service.*;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
+import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -27,6 +32,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -245,23 +252,37 @@ public class ExamAssignServiceImpl extends ServiceImpl<ExamAssignMapper, ExamAss
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void download(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response) {
|
|
|
+ public void download(Long id, Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response) {
|
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
- File file = null;
|
|
|
try {
|
|
|
- List<ScoreDownloadDto> scoreDownloadDtoList = cloudMarkingScoreService.listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(semesterId, examTypeId, collegeId, courseCode, openCollege);
|
|
|
- String fileName = "file-folder" + File.separator + schoolId + File.separator + System.currentTimeMillis() + ".xlsx";
|
|
|
- file = new File(fileName);
|
|
|
- if (!file.exists()) {
|
|
|
- file.getParentFile().mkdirs();
|
|
|
- }
|
|
|
- EasyExcel.write(fileName, ScoreDownloadDto.class).sheet("赋分成绩数据").doWrite(scoreDownloadDtoList);
|
|
|
- FileUtil.outputFile(response, file, file.getName());
|
|
|
- } finally {
|
|
|
- if (file != null && file.exists()) {
|
|
|
- file.delete();
|
|
|
+ String fileNamePrefix = "批量导出" + System.currentTimeMillis();
|
|
|
+ if (id != null) {
|
|
|
+ ExamAssign examAssign = this.getById(id);
|
|
|
+ if (examAssign != null) {
|
|
|
+ fileNamePrefix = examAssign.getCourseName() + "(" + examAssign.getCourseCode() + ")";
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ List<ScoreDownloadDto> scoreDownloadDtoList = cloudMarkingScoreService.listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(semesterId, examTypeId, collegeId, courseCode, openCollege);
|
|
|
+ response.setHeader("Content-Disposition",
|
|
|
+ "inline;filename=" + URLEncoder.encode(fileNamePrefix, SystemConstant.CHARSET_NAME) + ".xlsx");
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
|
|
|
+
|
|
|
+ String sheetName = "赋分成绩数据";
|
|
|
+ // 设置样式
|
|
|
+ CellStyle cellStyle1 = writer.createCellStyle();
|
|
|
+ org.apache.poi.ss.usermodel.Font font1 = writer.createFont();
|
|
|
+ font1.setBold(true);
|
|
|
+ font1.setFontHeightInPoints((short) 18);
|
|
|
+ cellStyle1.setFont(font1);
|
|
|
+ cellStyle1.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
+// cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ writer.setCellStyle(sheetName, cellStyle1, 0, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
|
|
|
|
|
|
+ writer.writeObjects(sheetName, null, ScoreDownloadDto.class, scoreDownloadDtoList.listIterator());
|
|
|
+ writer.output(response.getOutputStream());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|