Quellcode durchsuchen

3.4.2 成绩导出按班级拆分

xiaofei vor 8 Monaten
Ursprung
Commit
86decbb6bb

+ 8 - 1
distributed-print/install/nginx/teachcloud.conf

@@ -20,7 +20,14 @@ server {
                 try_files $uri $uri/ /mark/index.html;
         }
 		
-        location ~ ^/(api|fss)/ {
+        location ^~ /api/ {
+                proxy_pass http://127.0.0.1:7410;
+                proxy_set_header Host   $http_host;
+                proxy_set_header X-Real-IP $remote_addr;
+                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        }
+
+        location ^~ /fss/ {
                 proxy_pass http://127.0.0.1:7410;
                 proxy_set_header Host   $http_host;
                 proxy_set_header X-Real-IP $remote_addr;

+ 1 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/mark/MarkArchiveController.java

@@ -73,8 +73,7 @@ public class MarkArchiveController {
     public void scoreExport(@Validated ArchiveStudentQuery query, HttpServletResponse response) throws IOException {
         response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode("成绩导出", SystemConstant.CHARSET_NAME) + ".xlsx");
         response.setContentType("application/vnd.ms-excel");
-        ServletOutputStream outputStream = response.getOutputStream();
-        markStudentService.scoreExport(query, outputStream);
+        markStudentService.scoreExport(query, response);
     }
 
     @ApiOperation(value = "成绩下载")

+ 1 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/mark/MarkDocumentController.java

@@ -108,8 +108,7 @@ public class MarkDocumentController {
             response.setHeader("Content-Disposition",
                     "inline;filename=" + URLEncoder.encode("成绩导出", SystemConstant.CHARSET_NAME) + ".xlsx");
             response.setContentType("application/vnd.ms-excel");
-            ServletOutputStream outputStream = response.getOutputStream();
-            markStudentService.scoreExport(query, outputStream);
+            markStudentService.scoreExport(query, response);
         }
         MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(document.getExamId(), document.getPaperNumber());
         if (markPaper == null) {

+ 4 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -1306,12 +1306,14 @@ public class SystemConstant {
     }
 
     public static String readJson(InputStream inputStream) {
+        InputStreamReader reader = null;
         try {
+            reader = new InputStreamReader(inputStream, "UTF-8");
             // 读取目标文件的内容
             StringBuilder content = new StringBuilder();
-            byte[] buffer = new byte[1024];
+            char[] buffer = new char[1024];
             int length;
-            while ((length = inputStream.read(buffer)) > 0) {
+            while ((length = reader.read(buffer)) > 0) {
                 content.append(new String(buffer, 0, length));
             }
             return content.toString();

+ 1 - 1
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/MarkStudentService.java

@@ -159,7 +159,7 @@ public interface MarkStudentService extends IService<MarkStudent> {
 
     IPage<ArchiveStudentVo> studentList(ArchiveStudentQuery query);
 
-    void scoreExport(ArchiveStudentQuery query, OutputStream outputStream);
+    void scoreExport(ArchiveStudentQuery query, HttpServletResponse response);
 
     ScoreReportVo scoreReport(ArchiveStudentQuery query);
 

+ 1 - 1
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkDocumentServiceImpl.java

@@ -267,7 +267,7 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
                     filePath = tempFile.getPath() + File.separator + name + SystemConstant.EXCEL_PREFIX;
                     File file = new File(filePath);
                     OutputStream outputStream = new FileOutputStream(file);
-                    markStudentService.scoreExport(query, outputStream);
+                    markStudentService.scoreExport(query, response);
                     writer.write(file, file.getName());
                     file.delete();
                     break;

+ 44 - 20
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkStudentServiceImpl.java

@@ -1139,7 +1139,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     }
 
     @Override
-    public void scoreExport(ArchiveStudentQuery query, OutputStream outputStream) {
+    public void scoreExport(ArchiveStudentQuery query, HttpServletResponse response) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         //生成表头
         String[] columnName = new String[]{"学生姓名", "学号", "学院", "教学班", "行政班", "课程代码", "课程名称", "状态", "客观分", "主观分", "成绩"};
@@ -1187,27 +1187,51 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
             String[] columnValue = valueList.toArray(new String[0]);
             columnValues.add(columnValue);
         }
+
+        String rootPath = null;
         try {
+            // 本地保存目录
+            File tempFile = SystemConstant.getFileTempParentDirVar(SystemConstant.TEMP_PREFIX);
+            rootPath = tempFile.getPath() + File.separator + SystemConstant.getNanoId();
+
+            // 下载文件保存目录(用uuid命名)
+            String downloadFilePath = rootPath + File.separator + query.getPaperNumber();
+            File downloadPathFile = new File(downloadFilePath);
+            if (!downloadPathFile.exists()) {
+                downloadPathFile.mkdirs();
+            }
+
             log.debug("导出Excel开始...");
             ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
-
-//            CellStyle cellStyle = writer.createCellStyle();
-//            cellStyle.setDataFormat((short) 1);
-//            org.apache.poi.ss.usermodel.Font font1 = writer.createFont();
-//            font1.setBold(true);
-//            font1.setFontHeightInPoints((short) 20);
-//            cellStyle.setFont(font1);
-//            cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
-//            cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
-//            writer.setCellStyle("成绩导出", cellStyle, 1, new int[]{8, 9, 10, 12, 14});
-
             writer.writeDataArrays("成绩导出", null, columnNames, columnValues.listIterator());
-            writer.output(outputStream);
-            outputStream.flush();
-            outputStream.close();
+            FileOutputStream fileOut = new FileOutputStream(downloadFilePath + File.separator + "成绩导出" + SystemConstant.EXCEL_PREFIX);
+            writer.output(fileOut);
+            fileOut.flush();
+            fileOut.close();
+
+            // 通过教学班聚合
+            Map<String, List<String[]>> listMap = columnValues.stream().collect(Collectors.groupingBy(m -> m[3]));
+            Set<Map.Entry<String, List<String[]>>> entrySet = listMap.entrySet();
+            if (entrySet.size() > 1) {
+                for (Map.Entry<String, List<String[]>> entry : entrySet) {
+                    writer = ExcelWriter.create(ExcelType.XLSX);
+                    writer.writeDataArrays("成绩导出", null, columnNames, entry.getValue().listIterator());
+                    FileOutputStream classFileOut = new FileOutputStream(downloadFilePath + File.separator + "成绩导出-" + entry.getKey() + SystemConstant.EXCEL_PREFIX);
+                    writer.output(classFileOut);
+                    classFileOut.flush();
+                    classFileOut.close();
+                }
+            }
             log.debug("导出Excel结束");
+
+            String zipFileName = downloadPathFile.getName() + SystemConstant.ZIP_PREFIX;
+            FileUtil.downloadEncryptZip(response, downloadPathFile, zipFileName);
         } catch (Exception e) {
             throw new RuntimeException(e);
+        } finally {
+            if (Objects.nonNull(rootPath)) {
+                FileUtil.deleteDirectory(rootPath);
+            }
         }
     }
 
@@ -1502,10 +1526,10 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     /**
      * 填充大题分析
      *
-     * @param ret           ret
-     * @param studentList   涉及的考生集合
-     * @param examId        考试id
-     * @param paperNumber   试卷编号
+     * @param ret         ret
+     * @param studentList 涉及的考生集合
+     * @param examId      考试id
+     * @param paperNumber 试卷编号
      */
     private void fillMainQuestionAnalysis(ScoreReportVo ret, List<ArchiveStudentVo> studentList, Long examId, String paperNumber) {
         // 试卷结构数据
@@ -1616,7 +1640,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         ret.setMainQuestionAnalysis(questionVoList);
     }
 
-    private String getMainQuestionMapKey(Integer mainNumber, boolean objective){
+    private String getMainQuestionMapKey(Integer mainNumber, boolean objective) {
         return mainNumber + "-" + objective;
     }