Browse Source

成绩导出标准版本加入缺考考生

wangliang 2 years ago
parent
commit
a96e1c7f79

+ 1 - 1
themis-admin/src/main/resources/application.properties

@@ -98,7 +98,7 @@ sys.config.oss=true
 # \u914D\u7F6Erocketmq
 #============================================================================
 #namesrv\u5730\u5740
-rocketmq.name-server=127.0.0.1:9876
+rocketmq.name-server=192.168.10.36:9876
 #\u53D1\u9001\u6D88\u606F\u8D85\u65F6\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\u3002\u9ED8\u8BA410000
 rocketmq.producer.send-message-timeout=300000
 #Producer\u7EC4\u540D\uFF0C\u591A\u4E2AProducer\u5982\u679C\u5C5E\u4E8E\u4E00\u4E2A\u5E94\u7528\uFF0C\u53D1\u9001\u540C\u6837\u7684\u6D88\u606F\uFF0C\u5219\u5E94\u8BE5\u5C06\u5B83\u4EEC\u5F52\u4E3A\u540C\u4E00\u7EC4\u3002\u9ED8\u8BA4DEFAULT_PRODUCER

+ 0 - 9
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -816,15 +816,6 @@ public class SystemConstant {
         }
     }
 
-    /**
-     * 获取全局uuid
-     *
-     * @return
-     */
-    public static String getUuid() {
-        return String.valueOf(UUID.randomUUID()).replaceAll("-", "");
-    }
-
     /**
      * 获取全局uuid
      *

+ 270 - 144
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskMarkResultStandardExportTemplete.java

@@ -101,8 +101,7 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
         String zipPath = null;
         File zip = null;
         List<File> files = null;
-        int finalSize = 0;
-        int min = 0, line = 0;
+        int finalSize = 0, min = 0, line = 0;
         try {
             taskExportCommon.getTxtList()
                     .add(DateUtil.format(new Date(), Constants.DEFAULT_DATE_PATTERN) + "->开始准备处理导出的成绩标准版数据");
@@ -204,13 +203,12 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
             Map<Long, Map<String, Integer>> paperObjectiveAnswerMap = new HashMap<>();
             LinkedMultiValueMap<Long, ExcelDto> dynamicExcelHead = new LinkedMultiValueMap<>();
             LinkedMultiValueMap<Long, MarkResultStandardExportDto> markResultStandardExportDtoLinkedMultiValueMap = new LinkedMultiValueMap<>();
+            List<MarkResultStandardExportDto> missMarkResultStandardExportDtoList = new LinkedList<>();
             if (!CollectionUtils.isEmpty(markResultStandardExportDtoList)) {
-                Long currentPaperId = null;
                 for (MarkResultStandardExportDto m : markResultStandardExportDtoList) {
                     excelDtoMap = new HashMap<>();
                     Map<String, Integer> objectiveAnswerCacheBeanMap = null;
                     if (Objects.nonNull(m.getPaperId())) {//处理试卷
-                        currentPaperId = m.getPaperId();
                         if (!paperObjectiveAnswerMap.containsKey(m.getPaperId())) {
                             objectiveAnswerCacheBeanMap = teExamPaperService.getPaperStructCacheBean(m.getPaperId());
                             paperObjectiveAnswerMap.put(m.getPaperId(), objectiveAnswerCacheBeanMap);
@@ -232,18 +230,7 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
                             objectiveAnswerCacheBeanMap = paperObjectiveAnswerMap.get(m.getPaperId());
                         }
                     } else {
-                        if (Objects.nonNull(currentPaperId)) {//有答题数据的
-                            markResultStandardExportDtoLinkedMultiValueMap.add(currentPaperId, m);
-                            List<MarkResultStandardExportDto> markResultStandardExportDtos = markResultStandardExportDtoLinkedMultiValueMap.get(-1L);
-                            if (!CollectionUtils.isEmpty(markResultStandardExportDtos)) {
-                                for (MarkResultStandardExportDto markResultStandardExportDto : markResultStandardExportDtos) {
-                                    markResultStandardExportDtoLinkedMultiValueMap.add(currentPaperId, markResultStandardExportDto);
-                                }
-                                markResultStandardExportDtoLinkedMultiValueMap.remove(-1L);
-                            }
-                        } else {
-                            markResultStandardExportDtoLinkedMultiValueMap.add(-1L, m);
-                        }
+                        missMarkResultStandardExportDtoList.add(m);
                         continue;
                     }
                     if (Objects.nonNull(m.getRecordId())) {//处理考生答案
@@ -327,136 +314,17 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
                     .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
                     .add(String.format("%02d", nowTime.getDayOfMonth()));
 
-            SXSSFWorkbook wb = null;
-            InputStream inputStream = null;
-            ByteArrayOutputStream out = null;
-            //开始根据卷型生成多个excel
-            for (Map.Entry<Long, List<ExcelDto>> entry : dynamicExcelHead.entrySet()) {
-                try {
-                    //创建excel
-                    wb = new SXSSFWorkbook();
-                    Sheet sheet = wb.createSheet("成绩统计标准版");
-                    CellStyle style = wb.createCellStyle();
-                    style.setAlignment(HorizontalAlignment.CENTER); // 水平居中格式
-                    style.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
-                    Row row = sheet.createRow(0);
-                    Field[] fields = MarkResultStandardExportDto.class.getDeclaredFields();
-                    int num = 0;
-                    //绘制表头
-                    for (int i = 0; i < fields.length; i++) {
-                        Field field = fields[i];
-                        field.setAccessible(true);
-                        Annotation annotation = field.getAnnotation(ExcelNote.class);
-                        if (Objects.nonNull(annotation)) {
-                            Cell cell = row.createCell(i);
-                            cell.setCellValue(field.getAnnotation(ExcelNote.class).value());
-                            cell.setCellStyle(style);
-                            num = i;
-                        }
-                    }
-                    num++;
-                    Map<String, Integer> position = new LinkedHashMap<>();
-
-                    //动态表头
-                    for (ExcelDto excelDto : entry.getValue()) {
-                        Cell cell = row.createCell(num);
-                        cell.setCellValue(excelDto.getTitle());
-                        cell.setCellStyle(style);
-                        sheet.setColumnWidth(num, 15 * 256);
-                        position.put(excelDto.getTitle(), num);
-                        num++;
-                    }
-                    List<MarkResultStandardExportDto> markResultStandardExportDtoTempList = markResultStandardExportDtoLinkedMultiValueMap.get(entry.getKey());
-                    int rowIndex = 0, cellIndex = 0, max = SystemConstant.MAX_EXPORT_SIZE, size = markResultStandardExportDtoTempList
-                            .size();
-                    if (max >= size) {
-                        max = size;
-                    }
-                    while (max <= size) {
-                        List subList = markResultStandardExportDtoTempList.subList(min, max);
-                        //绘制数据
-                        for (int y = 0; y < subList.size(); y++) {
-                            finalSize++;
-                            line++;
-                            rowIndex++;
-                            MarkResultStandardExportDto markResultStandardExportDto = (MarkResultStandardExportDto) subList
-                                    .get(y);
-                            cellIndex = 0;
-                            Row sxssfRow = sheet.createRow(rowIndex);
-                            for (Field field : fields) {
-                                field.setAccessible(true);
-                                Annotation annotation = field.getAnnotation(ExcelNotExport.class);
-                                if (Objects.isNull(annotation)) {
-                                    Annotation dynamicExport = field.getAnnotation(ExcelDynamicExport.class);
-                                    if (Objects.nonNull(dynamicExport)) {
-                                        Map<Long, List<ExcelDto>> answerExcetDto = markResultStandardExportDto
-                                                .getAnswerExcetDto();
-                                        if (Objects.nonNull(answerExcetDto)) {
-                                            List<ExcelDto> excelDtoList = answerExcetDto
-                                                    .get(markResultStandardExportDto.getExamStudentId());
-                                            if (Objects.nonNull(excelDtoList) && excelDtoList.size() > 0) {
-                                                excelDtoList.forEach(s -> {
-                                                    if (Objects.nonNull(s) && Objects.nonNull(s.getTitle()) && Objects.nonNull(position.get(s.getTitle()))) {
-                                                        taskExportCommon.createExcelCell(sxssfRow, position.get(s.getTitle()),
-                                                                s.getContent(), style);
-                                                    }
-                                                });
-                                            }
-                                        }
-                                    } else {
-                                        taskExportCommon
-                                                .createExcelCell(sxssfRow, cellIndex, field.get(markResultStandardExportDto),
-                                                        style);
-                                        cellIndex++;
-                                    }
-                                }
-                            }
-                        }
-                        map.put("max", max);
-                        map.put("min", min);
-                        map.put("size", size);
-                        map = templeteLogicService.execExportMarkResultSimpleLogic(map);
-                        if (max == size) {
-                            break;
-                        }
-                        min = max;
-                        max += SystemConstant.MAX_EXPORT_SIZE;
-                        if (max >= size) {
-                            max = size;
-                        }
-                    }
-                    //临时缓冲区
-                    out = new ByteArrayOutputStream();
-                    wb.write(out);
-                    byte[] bookByteAry = out.toByteArray();
-                    inputStream = new ByteArrayInputStream(bookByteAry);
-                    StringBuilder stringBuilder = new StringBuilder(excelSj.toString());
-                    File finalFile = new File(stringBuilder.append(File.separator).append(markResultStandardExportDtoTempList.get(0).getPaperId() + "_" + markResultStandardExportDtoTempList.get(0).getPaperName() + "_" + markResultStandardExportDtoTempList.get(0).getCourseName() + "_" + markResultStandardExportDtoTempList.get(0).getCourseCode()).append(SystemConstant.EXCEL_PREFIX).toString());
-                    if (!finalFile.exists()) {
-                        finalFile.getParentFile().mkdirs();
-                        finalFile.createNewFile();
-                    }
-                    FileUtils.copyInputStreamToFile(inputStream, finalFile);
-                    files.add(finalFile);
-                } catch (Exception e) {
-                    log.error("生成excel报错", e);
-                    e.printStackTrace();
-                } finally {
-                    if (Objects.nonNull(wb)) {
-                        wb.dispose();
-                    }
-                    if (Objects.nonNull(inputStream)) {
-                        inputStream.close();
-                    }
-                    if (Objects.nonNull(out)) {
-                        out.flush();
-                        out.close();
-                    }
-                }
-            }
+            map = createExamStudentExcel(dynamicExcelHead, markResultStandardExportDtoLinkedMultiValueMap, map, files, taskExportCommon, excelSj);
+            finalSize = Integer.parseInt(String.valueOf(map.get("finalSize")));
+            min = Integer.parseInt(String.valueOf(map.get("min")));
+            line = Integer.parseInt(String.valueOf(map.get("line")));
+            map = createMissExamStudentExcel(missMarkResultStandardExportDtoList, finalSize, min, line, map, files, taskExportCommon, excelSj);
+            finalSize = Integer.parseInt(String.valueOf(map.get("finalSize")));
+            min = Integer.parseInt(String.valueOf(map.get("min")));
+            line = Integer.parseInt(String.valueOf(map.get("line")));
             if (files.size() > 0) {
                 StringBuilder stringBuilder = new StringBuilder(excelSj.toString());
-                String uuid = SystemConstant.getUuid();
+                String uuid = SystemConstant.getNanoId();
                 StringBuilder zipStringBuilder = new StringBuilder(stringJoiner.toString());
                 zipPath = zipStringBuilder.append(File.separator).append(uuid).toString();
                 zip = new File(stringBuilder.append(File.separator).append(uuid).append(".zip").toString());
@@ -485,4 +353,262 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
         }
         return ResultUtil.ok(true);
     }
+
+    /**
+     * 创建非缺考考生excel
+     *
+     * @param dynamicExcelHead
+     * @param markResultStandardExportDtoLinkedMultiValueMap
+     * @param map
+     * @param files
+     * @param taskExportCommon
+     * @param excelSj
+     * @return
+     * @throws IOException
+     */
+    public Map<String, Object> createExamStudentExcel(LinkedMultiValueMap<Long, ExcelDto> dynamicExcelHead,
+                                                      LinkedMultiValueMap<Long, MarkResultStandardExportDto> markResultStandardExportDtoLinkedMultiValueMap,
+                                                      Map<String, Object> map, List<File> files,
+                                                      TaskExportCommon taskExportCommon, StringJoiner excelSj) throws IOException {
+        int finalSize = 0, min = 0, line = 0;
+        SXSSFWorkbook wb = null;
+        InputStream inputStream = null;
+        ByteArrayOutputStream out = null;
+        //开始根据卷型生成多个excel
+        for (Map.Entry<Long, List<ExcelDto>> entry : dynamicExcelHead.entrySet()) {
+            try {
+                //创建excel
+                wb = new SXSSFWorkbook();
+                Sheet sheet = wb.createSheet("成绩统计标准版");
+                CellStyle style = wb.createCellStyle();
+                style.setAlignment(HorizontalAlignment.CENTER); // 水平居中格式
+                style.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
+                Row row = sheet.createRow(0);
+                Field[] fields = MarkResultStandardExportDto.class.getDeclaredFields();
+                int num = 0;
+                //绘制表头
+                for (int i = 0; i < fields.length; i++) {
+                    Field field = fields[i];
+                    field.setAccessible(true);
+                    Annotation annotation = field.getAnnotation(ExcelNote.class);
+                    if (Objects.nonNull(annotation)) {
+                        Cell cell = row.createCell(i);
+                        cell.setCellValue(field.getAnnotation(ExcelNote.class).value());
+                        cell.setCellStyle(style);
+                        num = i;
+                    }
+                }
+                num++;
+                Map<String, Integer> position = new LinkedHashMap<>();
+
+                //动态表头
+                for (ExcelDto excelDto : entry.getValue()) {
+                    Cell cell = row.createCell(num);
+                    cell.setCellValue(excelDto.getTitle());
+                    cell.setCellStyle(style);
+                    sheet.setColumnWidth(num, 15 * 256);
+                    position.put(excelDto.getTitle(), num);
+                    num++;
+                }
+                List<MarkResultStandardExportDto> markResultStandardExportDtoTempList = markResultStandardExportDtoLinkedMultiValueMap.get(entry.getKey());
+                int rowIndex = 0, cellIndex = 0, max = SystemConstant.MAX_EXPORT_SIZE, size = markResultStandardExportDtoTempList
+                        .size();
+                if (max >= size) {
+                    max = size;
+                }
+                while (max <= size) {
+                    List subList = markResultStandardExportDtoTempList.subList(min, max);
+                    //绘制数据
+                    for (int y = 0; y < subList.size(); y++) {
+                        finalSize++;
+                        line++;
+                        rowIndex++;
+                        MarkResultStandardExportDto markResultStandardExportDto = (MarkResultStandardExportDto) subList.get(y);
+                        cellIndex = 0;
+                        Row sxssfRow = sheet.createRow(rowIndex);
+                        for (Field field : fields) {
+                            field.setAccessible(true);
+                            Annotation annotation = field.getAnnotation(ExcelNotExport.class);
+                            if (Objects.isNull(annotation)) {
+                                Annotation dynamicExport = field.getAnnotation(ExcelDynamicExport.class);
+                                if (Objects.nonNull(dynamicExport)) {
+                                    Map<Long, List<ExcelDto>> answerExcetDto = markResultStandardExportDto
+                                            .getAnswerExcetDto();
+                                    if (Objects.nonNull(answerExcetDto)) {
+                                        List<ExcelDto> excelDtoList = answerExcetDto
+                                                .get(markResultStandardExportDto.getExamStudentId());
+                                        if (Objects.nonNull(excelDtoList) && excelDtoList.size() > 0) {
+                                            excelDtoList.forEach(s -> {
+                                                if (Objects.nonNull(s) && Objects.nonNull(s.getTitle()) && Objects.nonNull(position.get(s.getTitle()))) {
+                                                    taskExportCommon.createExcelCell(sxssfRow, position.get(s.getTitle()), s.getContent(), style);
+                                                }
+                                            });
+                                        }
+                                    }
+                                } else {
+                                    taskExportCommon.createExcelCell(sxssfRow, cellIndex, field.get(markResultStandardExportDto), style);
+                                    cellIndex++;
+                                }
+                            }
+                        }
+                    }
+                    map.put("max", max);
+                    map.put("min", min);
+                    map.put("size", size);
+                    map = templeteLogicService.execExportMarkResultSimpleLogic(map);
+                    if (max == size) {
+                        break;
+                    }
+                    min = max;
+                    max += SystemConstant.MAX_EXPORT_SIZE;
+                    if (max >= size) {
+                        max = size;
+                    }
+                }
+                //临时缓冲区
+                out = new ByteArrayOutputStream();
+                wb.write(out);
+                byte[] bookByteAry = out.toByteArray();
+                inputStream = new ByteArrayInputStream(bookByteAry);
+                StringBuilder stringBuilder = new StringBuilder(excelSj.toString());
+                File finalFile = new File(stringBuilder.append(File.separator).append(markResultStandardExportDtoTempList.get(0).getPaperId() + "_" + markResultStandardExportDtoTempList.get(0).getPaperName() + "_" + markResultStandardExportDtoTempList.get(0).getCourseName() + "_" + markResultStandardExportDtoTempList.get(0).getCourseCode()).append(SystemConstant.EXCEL_PREFIX).toString());
+                if (!finalFile.exists()) {
+                    finalFile.getParentFile().mkdirs();
+                    finalFile.createNewFile();
+                }
+                FileUtils.copyInputStreamToFile(inputStream, finalFile);
+                files.add(finalFile);
+            } catch (Exception e) {
+                log.error("生成excel报错", e);
+                e.printStackTrace();
+            } finally {
+                if (Objects.nonNull(wb)) {
+                    wb.dispose();
+                }
+                if (Objects.nonNull(inputStream)) {
+                    inputStream.close();
+                }
+                if (Objects.nonNull(out)) {
+                    out.flush();
+                    out.close();
+                }
+            }
+        }
+        map.put("finalSize", finalSize);
+        map.put("line", line);
+        return map;
+    }
+
+    /**
+     * 创建缺考考生excel
+     *
+     * @param missMarkResultStandardExportDtoList
+     * @param finalSize
+     * @param min
+     * @param line
+     * @param map
+     * @param files
+     * @param taskExportCommon
+     * @param excelSj
+     * @return
+     * @throws IOException
+     */
+    public Map<String, Object> createMissExamStudentExcel(List<MarkResultStandardExportDto> missMarkResultStandardExportDtoList,
+                                                          int finalSize, int min, int line,
+                                                          Map<String, Object> map, List<File> files,
+                                                          TaskExportCommon taskExportCommon, StringJoiner excelSj) throws IOException {
+        SXSSFWorkbook wb = null;
+        InputStream inputStream = null;
+        ByteArrayOutputStream out = null;
+        //开始生成缺考excel
+        if (!CollectionUtils.isEmpty(missMarkResultStandardExportDtoList)) {
+            try {
+                //创建excel
+                wb = new SXSSFWorkbook();
+                Sheet sheet = wb.createSheet("成绩统计标准版_缺考考生");
+                CellStyle style = wb.createCellStyle();
+                style.setAlignment(HorizontalAlignment.CENTER); // 水平居中格式
+                style.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
+                Row row = sheet.createRow(0);
+                Field[] fields = MarkResultStandardExportDto.class.getDeclaredFields();
+                //绘制表头
+                for (int i = 0; i < fields.length; i++) {
+                    Field field = fields[i];
+                    field.setAccessible(true);
+                    Annotation annotation = field.getAnnotation(ExcelNote.class);
+                    if (Objects.nonNull(annotation)) {
+                        Cell cell = row.createCell(i);
+                        cell.setCellValue(field.getAnnotation(ExcelNote.class).value());
+                        cell.setCellStyle(style);
+                    }
+                }
+                int rowIndex = 0, cellIndex = 0, max = SystemConstant.MAX_EXPORT_SIZE, size = missMarkResultStandardExportDtoList.size();
+                if (max >= size) {
+                    max = size;
+                }
+                while (max <= size) {
+                    List subList = missMarkResultStandardExportDtoList.subList(min, max);
+                    //绘制数据
+                    for (int y = 0; y < subList.size(); y++) {
+                        finalSize++;
+                        line++;
+                        rowIndex++;
+                        MarkResultStandardExportDto markResultStandardExportDto = (MarkResultStandardExportDto) subList.get(y);
+                        cellIndex = 0;
+                        Row sxssfRow = sheet.createRow(rowIndex);
+                        for (Field field : fields) {
+                            field.setAccessible(true);
+                            Annotation annotation = field.getAnnotation(ExcelNotExport.class);
+                            if (Objects.isNull(annotation)) {
+                                taskExportCommon.createExcelCell(sxssfRow, cellIndex, field.get(markResultStandardExportDto), style);
+                                cellIndex++;
+                            }
+                        }
+                    }
+                    map.put("max", max);
+                    map.put("min", min);
+                    map.put("size", size);
+                    map = templeteLogicService.execExportMarkResultSimpleLogic(map);
+                    if (max == size) {
+                        break;
+                    }
+                    min = max;
+                    max += SystemConstant.MAX_EXPORT_SIZE;
+                    if (max >= size) {
+                        max = size;
+                    }
+                }
+                //临时缓冲区
+                out = new ByteArrayOutputStream();
+                wb.write(out);
+                byte[] bookByteAry = out.toByteArray();
+                inputStream = new ByteArrayInputStream(bookByteAry);
+                StringBuilder stringBuilder = new StringBuilder(excelSj.toString());
+                File finalFile = new File(stringBuilder.append(File.separator).append(missMarkResultStandardExportDtoList.get(0).getCourseName() + "_" + missMarkResultStandardExportDtoList.get(0).getCourseCode() + "_缺考考生").append(SystemConstant.EXCEL_PREFIX).toString());
+                if (!finalFile.exists()) {
+                    finalFile.getParentFile().mkdirs();
+                    finalFile.createNewFile();
+                }
+                FileUtils.copyInputStreamToFile(inputStream, finalFile);
+                files.add(finalFile);
+            } catch (Exception e) {
+                log.error("生成excel报错", e);
+                e.printStackTrace();
+            } finally {
+                if (Objects.nonNull(wb)) {
+                    wb.dispose();
+                }
+                if (Objects.nonNull(inputStream)) {
+                    inputStream.close();
+                }
+                if (Objects.nonNull(out)) {
+                    out.flush();
+                    out.close();
+                }
+            }
+        }
+        map.put("finalSize", finalSize);
+        map.put("line", line);
+        return map;
+    }
 }