浏览代码

平时成绩导出

wangliang 10 月之前
父节点
当前提交
15db31754d
共有 1 个文件被更改,包括 142 次插入48 次删除
  1. 142 48
      distributed-print/src/main/java/com/qmth/distributed/print/api/obe/TRBasicInfoController.java

+ 142 - 48
distributed-print/src/main/java/com/qmth/distributed/print/api/obe/TRBasicInfoController.java

@@ -48,6 +48,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.RegionUtil;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -480,13 +481,20 @@ public class TRBasicInfoController {
             throw ExceptionResultEnum.ERROR.exception("未找到学生信息");
         }
 
+        Map<Long, BigDecimal> examStudentMatrixDegree = new LinkedHashMap<>(),
+                examStudentSumMatrixDegree = new LinkedHashMap<>();
+        BigDecimal examStudentSumTargetWeight = new BigDecimal(0);
         LinkedMultiValueMap<String, String> courseTargetMap = new LinkedMultiValueMap<>();
-        for (TRExamStudent t : trExamStudentList) {
+        LinkedMultiValueMap<Long, BigDecimal> examStudentMatrixDegreeMap = new LinkedMultiValueMap<>();
+        for (int y = 0; y < trExamStudentList.size(); y++) {
+            TRExamStudent t = trExamStudentList.get(y);
             if (Objects.nonNull(t.getResultDetail())) {
                 List<ReportExamStudentTargetDto> reportExamStudentTargetDtoList = JSONArray.parseArray(t.getResultDetail(), ReportExamStudentTargetDto.class);
                 for (ReportExamStudentTargetDto r : reportExamStudentTargetDtoList) {
                     if (Objects.nonNull(r.getUsualScore()) && CollectionUtils.isNotEmpty(r.getUsualScore().getScoreList())) {
-                        for (ReportExamStudentUsualScoreObjDto reportExamStudentUsualScoreObjDto : r.getUsualScore().getScoreList()) {
+                        for (int i = 0; i < r.getUsualScore().getScoreList().size(); i++) {
+                            ReportExamStudentUsualScoreObjDto reportExamStudentUsualScoreObjDto = r.getUsualScore().getScoreList().get(i);
+                            //课程目标有几个
                             if (!courseTargetMap.containsKey(r.getTargetName())) {
                                 courseTargetMap.add(r.getTargetName(), reportExamStudentUsualScoreObjDto.getEvaluation());
                             } else {
@@ -495,45 +503,68 @@ public class TRBasicInfoController {
                                     courseTargetMap.add(r.getTargetName(), reportExamStudentUsualScoreObjDto.getEvaluation());
                                 }
                             }
+                            //课程目标有几个
+                            examStudentMatrixDegreeMap.add(t.getId(), reportExamStudentUsualScoreObjDto.getMatrixScore());
+                            //各个学生的换算分数
+                            if (!examStudentMatrixDegree.containsKey(t.getId())) {
+                                examStudentMatrixDegree.put(t.getId(), reportExamStudentUsualScoreObjDto.getMatrixScore());
+                            } else {
+                                BigDecimal matrixDegree = examStudentMatrixDegree.get(t.getId());
+                                matrixDegree = matrixDegree.add(reportExamStudentUsualScoreObjDto.getMatrixScore());
+                                examStudentMatrixDegree.put(t.getId(), matrixDegree);
+                            }
+                            //权重
+                            if (y == 0) {
+                                examStudentSumTargetWeight = examStudentSumTargetWeight.add(reportExamStudentUsualScoreObjDto.getTargetWeight());
+                            }
+                            if (i == r.getUsualScore().getScoreList().size() - 1) {
+                                BigDecimal matrixDegree = examStudentMatrixDegree.get(t.getId());
+                                matrixDegree = matrixDegree.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                examStudentMatrixDegree.put(t.getId(), matrixDegree);
+
+                                examStudentSumTargetWeight = examStudentSumTargetWeight.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                BigDecimal sumMatrixDegree = SystemConstant.PERCENT.multiply(matrixDegree).divide(examStudentSumTargetWeight, 2, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
+                                examStudentSumMatrixDegree.put(t.getId(), sumMatrixDegree);
+                            }
                         }
                     }
                 }
             }
         }
 
+        SXSSFWorkbook wb = new SXSSFWorkbook();
+        Sheet sheet = wb.createSheet("过程考核");
+        CellStyle headerStyle = wb.createCellStyle();
+        headerStyle.setAlignment(HorizontalAlignment.CENTER); // 水平居中格式
+        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
+        headerStyle.setBorderRight(BorderStyle.THIN);
+        headerStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
+        headerStyle.setBorderLeft(BorderStyle.THIN);
+        headerStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
+        headerStyle.setBorderTop(BorderStyle.THIN);
+        headerStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
+        headerStyle.setBorderBottom(BorderStyle.THIN);
+        headerStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
+        // 背景颜色
+        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+
+        Font defaultFont = wb.createFont();
+        defaultFont.setFontHeightInPoints((short) 12);
+        defaultFont.setBold(true);
+        headerStyle.setFont(defaultFont);
+
+        Row rowHeadOne = sheet.createRow(0);
+        Row rowHeadTwo = sheet.createRow(1);
+        Row rowOne = sheet.createRow(2);
+        Row rowTwo = sheet.createRow(3);
+
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
         String fileName = Objects.nonNull(basicSchool) ? basicSchool.getName() + "_" + trBasicInfo.getOpenTime() + "《" + trBasicInfo.getCourseName() + "》_平时成绩" : trBasicInfo.getOpenTime() + "《" + trBasicInfo.getCourseName() + "》_平时成绩";
 
-        SXSSFWorkbook wb = new SXSSFWorkbook();
-        Sheet sheet = wb.createSheet("过程考核");
-        CellStyle style = wb.createCellStyle();
-        style.setAlignment(HorizontalAlignment.CENTER); // 水平居中格式
-        style.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
-        Row row1 = sheet.createRow(0);
-        Row row2 = sheet.createRow(1);
-
-        Cell cell = row1.createCell(0);
-        cell.setCellValue("姓名");
-        cell.setCellStyle(style);
-        CellRangeAddress region = new CellRangeAddress(0, 1, (short) 0, (short) 0);
-        sheet.addMergedRegion(region);
-        sheet.setColumnWidth(0, sheet.getColumnWidth(0) * 17 / 10);
-
-//        courseTargetMap.add("测试1", "1");
-//        courseTargetMap.add("测试1", "2");
-//        courseTargetMap.add("测试1", "3");
-//        courseTargetMap.add("测试1", "4");
-//        courseTargetMap.add("测试2", "5");
-//        courseTargetMap.add("测试2", "6");
-//        courseTargetMap.add("测试3", "7");
-//        courseTargetMap.add("测试4", "8");
-//        courseTargetMap.add("测试5", "9");
-//        courseTargetMap.add("测试5", "10");
-//        courseTargetMap.add("测试5", "11");
-//        courseTargetMap.add("测试5", "12");
-//        courseTargetMap.add("测试5", "13");
-//        courseTargetMap.add("测试5", "14");
+        //姓名
+        this.drawExcelFixedHead(rowOne, headerStyle, sheet, "姓名", 0, 2, 3, 0, 0, sheet.getColumnWidth(0) * 17 / 10);
 
         AtomicInteger cellOneIndex = new AtomicInteger(1);
         AtomicInteger oneFirst = new AtomicInteger(1);
@@ -542,41 +573,104 @@ public class TRBasicInfoController {
         for (Map.Entry<String, List<String>> entry : courseTargetMap.entrySet()) {
             List<String> childKeys = entry.getValue();
             String key = entry.getKey();
-            Cell cell1 = row1.createCell(cellOneIndex.get());
-            cell1.setCellValue(key);
-            cell1.setCellStyle(style);
+            Cell cell = rowOne.createCell(cellOneIndex.get());
+            cell.setCellValue(key);
+            cell.setCellStyle(headerStyle);
             oneLast.compareAndSet(oneLast.get(), oneLast.get() + childKeys.size());
             if (oneFirst.get() != oneLast.get()) {
-                CellRangeAddress region1 = new CellRangeAddress(0, 0, (short) oneFirst.get(), (short) oneLast.get());
-                sheet.addMergedRegion(region1);
+                CellRangeAddress region = new CellRangeAddress(2, 2, (short) oneFirst.get(), (short) oneLast.get());
+                this.setRegionBorder(region, sheet);
+                sheet.addMergedRegion(region);
             }
             sheet.setColumnWidth(cellOneIndex.get(), sheet.getColumnWidth(cellOneIndex.get()) * 17 / 10);
-
             cellOneIndex.compareAndSet(cellOneIndex.get(), cellOneIndex.get() + childKeys.size());
             oneFirst.compareAndSet(oneFirst.get(), cellOneIndex.get());
-
             for (String s : childKeys) {
-                Cell cell2 = row2.createCell(cellTwoIndex.get());
-                cell2.setCellValue(s);
-                cell2.setCellStyle(style);
-                sheet.setColumnWidth(cellTwoIndex.get(), sheet.getColumnWidth(cellTwoIndex.get()) * 17 / 10);
+                this.drawExcelFixedHead(rowTwo, headerStyle, sheet, s, cellTwoIndex.get(), sheet.getColumnWidth(cellTwoIndex.get()) * 17 / 10);
                 cellTwoIndex.incrementAndGet();
             }
         }
 
-        //绘制固定表头
-//        sheet = drawExcelFixedHead(scoreInterval, sheet, style, row, subjectMap, workId);
+        this.drawExcelFixedHead(rowOne, headerStyle, sheet, "平时成绩总分(满分" + SystemConstant.df.format(examStudentSumTargetWeight) + "分)", cellTwoIndex.get(), 2, 3, cellTwoIndex.get(), cellTwoIndex.get(), sheet.getColumnWidth(cellTwoIndex.get()) * 17 / 5);
+        cellTwoIndex.incrementAndGet();
+        this.drawExcelFixedHead(rowOne, headerStyle, sheet, "平时成绩总分(满分100分)", cellTwoIndex.get(), 2, 3, cellTwoIndex.get(), cellTwoIndex.get(), sheet.getColumnWidth(cellTwoIndex.get()) * 17 / 5);
+        cellTwoIndex.incrementAndGet();
+
+        //第一行
+        this.drawExcelFixedHead(rowHeadOne, headerStyle, sheet, "《" + trBasicInfo.getCourseName() + "》课程过程考核原始记录", 0, 0, 0, 0, cellTwoIndex.get() - 1, sheet.getColumnWidth(cellTwoIndex.get()) * 17);
+        //第二行
+        this.drawExcelFixedHead(rowHeadTwo, headerStyle, sheet, "课程:" + trBasicInfo.getCourseName() + "     班级:" + (Objects.nonNull(trBasicInfo.getTeachingObject()) ? trBasicInfo.getTeachingObject() : "无") + "     任课教师:" + (Objects.nonNull(trBasicInfo.getTeacher()) ? trBasicInfo.getTeacher() : "无") + "     学期:" + trBasicInfo.getOpenTime(), 0, 1, 1, 0, cellTwoIndex.get() - 1, sheet.getColumnWidth(cellTwoIndex.get()) * 17);
 
-        for (int i = 0; i < trExamStudentList.size(); i++) {
-            TRExamStudent trExamStudent = trExamStudentList.get(i);
-            if (Objects.nonNull(trExamStudent.getResultDetail())) {
-                List<ReportExamStudentTargetDto> reportExamStudentTargetDtoList = JSONArray.parseArray(trExamStudent.getResultDetail(), ReportExamStudentTargetDto.class);
+        CellStyle styleExamStudent = wb.createCellStyle();
+        styleExamStudent.setAlignment(HorizontalAlignment.LEFT);
+        styleExamStudent.setVerticalAlignment(VerticalAlignment.CENTER);
+        AtomicInteger rowStudentIndex = new AtomicInteger(4);
+        for (TRExamStudent t : trExamStudentList) {
+            Row rowStudent = sheet.createRow(rowStudentIndex.get());
+            this.drawExcelFixedHead(rowStudent, styleExamStudent, sheet, t.getName(), 0, sheet.getColumnWidth(2) * 17 / 10);
 
+            List<BigDecimal> bigDecimalList = examStudentMatrixDegreeMap.get(t.getId());
+            if (CollectionUtils.isNotEmpty(bigDecimalList)) {
+                for (int i = 0; i < bigDecimalList.size(); i++) {
+                    this.drawExcelFixedHead(rowStudent, styleExamStudent, sheet, SystemConstant.df.format(bigDecimalList.get(i)), i + 1, sheet.getColumnWidth(i + 1) * 17 / 10);
+                }
+                this.drawExcelFixedHead(rowStudent, styleExamStudent, sheet, SystemConstant.df.format(!org.springframework.util.CollectionUtils.isEmpty(examStudentMatrixDegree) && examStudentMatrixDegree.containsKey(t.getId()) ? examStudentMatrixDegree.get(t.getId()) : 0), bigDecimalList.size() + 1, sheet.getColumnWidth(bigDecimalList.size() + 1) * 17 / 10);
+                this.drawExcelFixedHead(rowStudent, styleExamStudent, sheet, SystemConstant.df.format(!org.springframework.util.CollectionUtils.isEmpty(examStudentSumMatrixDegree) && examStudentSumMatrixDegree.containsKey(t.getId()) ? examStudentSumMatrixDegree.get(t.getId()) : 0), bigDecimalList.size() + 2, sheet.getColumnWidth(bigDecimalList.size() + 2) * 17 / 10);
             }
+            rowStudentIndex.incrementAndGet();
         }
         ExcelUtil.exportEXCEL(fileName, wb, ServletUtil.getResponse());
     }
 
+    /**
+     * 创建固定行表头
+     *
+     * @param row
+     * @param style
+     * @param sheet
+     * @param cellName
+     * @param cellIndex
+     * @param firstRow
+     * @param lastRow
+     * @param firstCol
+     * @param lastCol
+     * @param columnWidth
+     */
+    protected void drawExcelFixedHead(Row row, CellStyle style, Sheet sheet, String cellName, int cellIndex,
+                                      int firstRow, int lastRow, int firstCol, int lastCol, int columnWidth) {
+        Cell cell = row.createCell(cellIndex);
+        cell.setCellValue(cellName);
+        cell.setCellStyle(style);
+        CellRangeAddress region = new CellRangeAddress(firstRow, lastRow, (short) firstCol, (short) lastCol);
+        sheet.addMergedRegion(region);
+        this.setRegionBorder(region, sheet);
+        sheet.setColumnWidth(cellIndex, columnWidth);
+    }
+
+    protected void setRegionBorder(CellRangeAddress region, Sheet sheet) {
+        RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);//设置左边框
+        RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);//设置下边框
+        RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);//设置右边框
+        RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);//设置左边框
+    }
+
+    /**
+     * 创建动态固定行表头
+     *
+     * @param row
+     * @param style
+     * @param sheet
+     * @param cellName
+     * @param cellIndex
+     * @param columnWidth
+     */
+    protected void drawExcelFixedHead(Row row, CellStyle style, Sheet sheet, String cellName, int cellIndex, int columnWidth) {
+        Cell cell = row.createCell(cellIndex);
+        cell.setCellValue(cellName);
+        cell.setCellStyle(style);
+        sheet.setColumnWidth(cellIndex, columnWidth > 10000 ? (int) Math.abs(columnWidth / 2) : columnWidth);
+    }
+
     @Resource
     WordToPdfUtil wordToPdfUtil;