فهرست منبع

班级成绩查看导出

dzx 10 ماه پیش
والد
کامیت
f22dabd265

+ 4 - 0
src/main/java/com/xjrsoft/module/student/dto/BaseStudentUserPageDto.java

@@ -1,5 +1,6 @@
 package com.xjrsoft.module.student.dto;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.xjrsoft.common.page.PageInput;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -56,4 +57,7 @@ public class BaseStudentUserPageDto extends PageInput {
     @ApiModelProperty("年级id")
     private Long gradeId;
 
+    @JsonIgnore
+    private Long teacherId;
+
 }

+ 19 - 2
src/main/java/com/xjrsoft/module/xycxedu/controller/ExamSubjectScoreController.java

@@ -1,6 +1,7 @@
 package com.xjrsoft.module.xycxedu.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.alibaba.excel.support.ExcelTypeEnum;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xjrsoft.common.annotation.XjrLog;
 import com.xjrsoft.common.model.result.RT;
@@ -19,6 +20,7 @@ import com.xjrsoft.module.xycxedu.vo.ExamSubjectScorePageVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -26,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -92,8 +95,11 @@ public class ExamSubjectScoreController {
     @GetMapping(value = "/class-student-page")
     @ApiOperation(value="班级成绩查询(分页)")
     @SaCheckPermission("examsubjectscore:detail")
-    @XjrLog("查询考试成绩")
+    @XjrLog("班级成绩查询(分页)")
     public RT<PageOutput<ClassStudentScorePageVo>> classStudentScorePage(@Valid ClassStudentScorePageDto dto){
+        if(dto.getTreeType() != 4 && dto.getTreeId() == null ){
+            return RT.ok(new PageOutput<>());
+        }
         PageOutput<ClassStudentScorePageVo> pageOutput = scoreService.getClassStudentScorePage(dto);
         return RT.ok(pageOutput);
     }
@@ -101,12 +107,23 @@ public class ExamSubjectScoreController {
     @GetMapping(value = "/class-student-page-title")
     @ApiOperation(value="班级成绩查询列头")
     @SaCheckPermission("examsubjectscore:detail")
-    @XjrLog("查询考试成绩")
+    @XjrLog("班级成绩查询列头")
     public RT<List<ClassStudentScoreTitleVo>> classStudentScorePageTitle(@Valid ClassStudentScorePageDto dto){
         //查询列头
         List<ClassStudentScoreTitleVo> list = scoreService.getClassStudentScoreCourse(dto);
         return RT.ok(list);
     }
 
+    @GetMapping(value = "/class-student-export-query")
+    @ApiOperation(value="班级成绩查询导出")
+    @SaCheckPermission("examsubjectscore:detail")
+    @XjrLog("导出考试成绩")
+    public ResponseEntity<byte[]> classStudentScoreExportQuery(@Valid ClassStudentScorePageDto dto) throws IOException {
+        //查询列头
+        byte[] bytes = scoreService.getClassStudentScoreExportQuery(dto);
+        String fileName = "class-student-export-query" + ExcelTypeEnum.XLSX.getValue();
+        return RT.fileStream(bytes, fileName);
+    }
+
 
 }

+ 3 - 0
src/main/java/com/xjrsoft/module/xycxedu/dto/ClassStudentScorePageDto.java

@@ -34,4 +34,7 @@ public class ClassStudentScorePageDto extends PageInput {
 
     @JsonIgnore
     private List<Long> userIdList;
+
+    @JsonIgnore
+    private Long teacherId;
 }

+ 3 - 0
src/main/java/com/xjrsoft/module/xycxedu/service/IExamSubjectScoreService.java

@@ -15,6 +15,7 @@ import com.xjrsoft.module.xycxedu.vo.ExamSubjectScoreEnterImportVo;
 import com.xjrsoft.module.xycxedu.vo.ExamSubjectScorePageVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -43,4 +44,6 @@ public interface IExamSubjectScoreService extends MPJBaseService<ExamSubjectScor
     List<ExamSubjectScore> getClassStudentScoreList(ClassStudentScorePageDto dto);
 
     PageOutput<ClassStudentScorePageVo> getClassStudentScorePage(ClassStudentScorePageDto dto);
+
+    byte[] getClassStudentScoreExportQuery(ClassStudentScorePageDto dto) throws IOException;
 }

+ 121 - 1
src/main/java/com/xjrsoft/module/xycxedu/service/impl/ExamSubjectScoreServiceImpl.java

@@ -1,5 +1,7 @@
 package com.xjrsoft.module.xycxedu.service.impl;
 
+import camundajar.impl.scala.Array;
+import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -27,8 +29,20 @@ import com.xjrsoft.module.xycxedu.vo.ExamStatisticsPageVo;
 import com.xjrsoft.module.xycxedu.vo.ExamSubjectScoreEnterImportVo;
 import com.xjrsoft.module.xycxedu.vo.ExamSubjectScorePageVo;
 import lombok.AllArgsConstructor;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.stereotype.Service;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -124,7 +138,10 @@ public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectS
 
     @Override
     public PageOutput<ClassStudentScorePageVo> getClassStudentScorePage(ClassStudentScorePageDto dto) {
-
+        List<String> roleList = StpUtil.getRoleList();
+        if(roleList.size() == 2 && roleList.contains("TEACHER") && roleList.contains("CLASSTE")){
+            dto.setTeacherId(StpUtil.getLoginIdAsLong());
+        }
         BaseStudentUserPageDto studentDto = BeanUtil.toBean(dto, BaseStudentUserPageDto.class);
         Page<BaseStudentUserPageVo> studentPage = studentManagerService.getStudentPage(new Page<>(dto.getLimit(), dto.getSize()), studentDto);
 
@@ -161,4 +178,107 @@ public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectS
         }
         return pageOutput;
     }
+
+    @Override
+    public byte[] getClassStudentScoreExportQuery(ClassStudentScorePageDto dto) throws IOException {
+        //查询表头
+        List<ClassStudentScoreTitleVo> titleList = this.getClassStudentScoreCourse(dto);
+
+        Workbook workbook = new XSSFWorkbook();
+        // 创建一个工作表(sheet)
+        String sheetName = "数据";
+        Sheet sheet = workbook.createSheet(sheetName);
+
+        createTitle(workbook, sheet, titleList);
+
+        //查询数据
+        dto.setSize(1);
+        dto.setLimit(1000);
+        PageOutput<ClassStudentScorePageVo> studentScorePage = this.getClassStudentScorePage(dto);
+        List<ClassStudentScorePageVo> list = studentScorePage.getList();
+
+        ArrayList<ArrayList<String>> excelDataList = new ArrayList<>();
+        int sortCode = 1;
+        for (ClassStudentScorePageVo studentVo : list) {
+            ArrayList<String> rowData = new ArrayList<>();
+            rowData.add(sortCode + "");
+            rowData.add(studentVo.getClassName());
+            rowData.add(studentVo.getName());
+            rowData.add(studentVo.getGenderCn());
+            rowData.add(studentVo.getCredentialNumber());
+            rowData.add(studentVo.getMobile());
+            rowData.add(studentVo.getTeacherName());
+
+            List<ClassStudentScoreTitleVo> scoreList = studentVo.getScoreList();
+            double totalSocre = scoreList.stream().filter(x -> StrUtil.isNotEmpty(x.getScore())).mapToDouble(x -> Float.parseFloat(x.getScore())).sum();
+            BigDecimal bd = new BigDecimal(totalSocre);
+            if (bd.scale() <= 0) { // 如果是整数
+                rowData.add(bd.toBigInteger().toString());
+            } else {
+                rowData.add(bd.toPlainString());
+            }
+
+            Map<String, String> scoreMap = scoreList.stream().collect(Collectors.toMap(ClassStudentScoreTitleVo::getCourseId, ClassStudentScoreTitleVo::getScore));
+
+            for (ClassStudentScoreTitleVo scoreTitleVo : titleList) {
+                BigDecimal scorebd = new BigDecimal(scoreMap.get(scoreTitleVo.getCourseId()));
+                if (scorebd.scale() <= 0) { // 如果是整数
+                    rowData.add(bd.toBigInteger().toString());
+                } else {
+                    rowData.add(bd.toPlainString());
+                }
+            }
+            excelDataList.add(rowData);
+            sortCode ++;
+        }
+
+        createData(workbook, sheet, excelDataList);
+
+        ByteArrayOutputStream bot = new ByteArrayOutputStream();
+        workbook.write(bot);
+        return bot.toByteArray();
+    }
+
+    void createTitle(Workbook workbook, Sheet sheet, List<ClassStudentScoreTitleVo> titleList) {
+        int rowNumber = 0;
+        Font font = workbook.createFont();
+        font.setBold(true);// 设置为粗体
+        font.setFontName("宋体");
+        //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
+        font.setFontHeightInPoints((short)14);
+
+        CellStyle cellStyle = workbook.createCellStyle();
+        cellStyle.setFont(font); // 将字体应用到样式
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+
+        Row row = sheet.createRow(rowNumber);
+        for(int cellNumber = 0; cellNumber < titleList.size(); cellNumber ++){
+            ClassStudentScoreTitleVo titleVo = titleList.get(cellNumber);
+            Cell cell = row.createCell(cellNumber);
+            cell.setCellValue(titleVo.getName());
+            cell.setCellStyle(cellStyle);
+            sheet.setColumnWidth(cellNumber, 5 * 3 * 256);
+        }
+    }
+
+    void createData(Workbook workbook, Sheet sheet, ArrayList<ArrayList<String>> excelDataList) {
+        Font font = workbook.createFont();
+        font.setFontName("宋体");
+        font.setFontHeightInPoints((short)12);
+
+        CellStyle cellStyle = workbook.createCellStyle();
+        cellStyle.setFont(font); // 将字体应用到样式
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+        for (ArrayList<String> rowData : excelDataList) {
+            int rowNumber = 1;
+            Row row = sheet.createRow(rowNumber);
+            for (int i =0; i < rowData.size(); i ++) {
+                Cell cell = row.createCell(i);
+                cell.setCellValue(rowData.get(i));
+                cell.setCellStyle(cellStyle);
+            }
+        }
+    }
 }

+ 3 - 0
src/main/resources/mapper/student/BaseStudentMapper.xml

@@ -96,6 +96,9 @@
         <if test="dto.gradeId != null">
             and t4.grade_id = #{dto.gradeId}
         </if>
+        <if test="dto.teacherId != null">
+            and t4.teacher_id = #{dto.teacherId}
+        </if>
         <if test="dto.order == null">
             order by t1.id
         </if>