Browse Source

Merge branch 'pre'

dzx 1 month ago
parent
commit
2161bdf806

+ 2 - 2
src/main/java/com/xjrsoft/module/schedule/controller/ScheduleController.java

@@ -161,7 +161,7 @@ public class ScheduleController {
     public RT<Integer> currentWeek(CourseTableDto dto){
         BaseSemester baseSemester = semesterService.getCurrentSemester();
         if(baseSemester == null){
-            return RT.error("未能查询到当前周次");
+            return RT.ok();
         }
         LocalDateTime now = LocalDateTime.now();
         if(dto.getScheduleDate() != null){
@@ -183,7 +183,7 @@ public class ScheduleController {
             }
         }
 
-        return RT.error("未能查询到当前周次");
+        return RT.ok();
     }
 
 

+ 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;
+
 }

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

@@ -1,6 +1,8 @@
 package com.xjrsoft.module.xycxedu.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.dev33.satoken.stp.StpUtil;
+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,13 +21,16 @@ 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.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 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 +97,17 @@ public class ExamSubjectScoreController {
     @GetMapping(value = "/class-student-page")
     @ApiOperation(value="班级成绩查询(分页)")
     @SaCheckPermission("examsubjectscore:detail")
-    @XjrLog("查询考试成绩")
+    @XjrLog("班级成绩查询(分页)")
     public RT<PageOutput<ClassStudentScorePageVo>> classStudentScorePage(@Valid ClassStudentScorePageDto dto){
+        List<String> roleList = StpUtil.getRoleList();
+        if(roleList.size() == 2 && roleList.contains("TEACHER") && roleList.contains("CLASSTE")){
+            dto.setTeacherId(StpUtil.getLoginIdAsLong());
+        }else{
+            if((dto.getTreeType() != null && dto.getTreeType() != 4) || dto.getTreeId() == null ){
+                return RT.ok(new PageOutput<>());
+            }
+        }
+
         PageOutput<ClassStudentScorePageVo> pageOutput = scoreService.getClassStudentScorePage(dto);
         return RT.ok(pageOutput);
     }
@@ -101,12 +115,32 @@ 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);
     }
 
+    @PostMapping(value = "/class-student-export-query")
+    @ApiOperation(value="班级成绩查询导出")
+    @SaCheckPermission("examsubjectscore:detail")
+    @XjrLog("导出考试成绩")
+    public ResponseEntity<byte[]> classStudentScoreExportQuery(@Valid @RequestBody ClassStudentScorePageDto dto) throws IOException {
+        String fileName = "class-student-export-query" + ExcelTypeEnum.XLSX.getValue();
+
+        List<String> roleList = StpUtil.getRoleList();
+        if(roleList.size() == 2 && roleList.contains("TEACHER") && roleList.contains("CLASSTE")){
+            dto.setTeacherId(StpUtil.getLoginIdAsLong());
+        }else{
+            if((dto.getTreeType() != null && dto.getTreeType() != 4) || dto.getTreeId() == null ){
+                return RT.fileStream(new byte[0], fileName);
+            }
+        }
+        //查询列头
+        byte[] bytes = scoreService.getClassStudentScoreExportQuery(dto);
+        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;
 }

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

@@ -1,5 +1,6 @@
 package com.xjrsoft.module.xycxedu.service.impl;
 
+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;
@@ -9,6 +10,8 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
 import com.xjrsoft.module.base.entity.BaseClass;
+import com.xjrsoft.module.base.entity.BaseSemester;
+import com.xjrsoft.module.base.service.IBaseSemesterService;
 import com.xjrsoft.module.organization.entity.User;
 import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
 import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
@@ -18,8 +21,10 @@ import com.xjrsoft.module.xycxedu.dto.ClassStudentScorePageDto;
 import com.xjrsoft.module.xycxedu.dto.ExamStatisticsPageDto;
 import com.xjrsoft.module.xycxedu.dto.ExamSubjectScoreDto;
 import com.xjrsoft.module.xycxedu.dto.ExamSubjectScoreEnterDto;
+import com.xjrsoft.module.xycxedu.entity.ExamPlan;
 import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
 import com.xjrsoft.module.xycxedu.mapper.ExamSubjectScoreMappper;
+import com.xjrsoft.module.xycxedu.service.IExamPlanService;
 import com.xjrsoft.module.xycxedu.service.IExamSubjectScoreService;
 import com.xjrsoft.module.xycxedu.vo.ClassStudentScorePageVo;
 import com.xjrsoft.module.xycxedu.vo.ClassStudentScoreTitleVo;
@@ -27,8 +32,21 @@ 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.ss.util.CellRangeAddress;
+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;
@@ -46,6 +64,8 @@ import java.util.stream.Collectors;
 public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectScoreMappper, ExamSubjectScore> implements IExamSubjectScoreService {
 
     private final IStudentManagerService studentManagerService;
+    private final IBaseSemesterService semesterService;
+    private final IExamPlanService examPlanService;
 
     @Override
     public Long getUserIdByIdNumber(String idNumber) {
@@ -124,8 +144,10 @@ public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectS
 
     @Override
     public PageOutput<ClassStudentScorePageVo> getClassStudentScorePage(ClassStudentScorePageDto dto) {
-
         BaseStudentUserPageDto studentDto = BeanUtil.toBean(dto, BaseStudentUserPageDto.class);
+        if(dto.getTreeType() != null && dto.getTreeType() == 4){
+            studentDto.setQueryId(dto.getTreeId());
+        }
         Page<BaseStudentUserPageVo> studentPage = studentManagerService.getStudentPage(new Page<>(dto.getLimit(), dto.getSize()), studentDto);
 
         Set<Long> userIdSet = studentPage.getRecords().stream().map(x -> Long.parseLong(x.getId())).collect(Collectors.toSet());
@@ -161,4 +183,195 @@ 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);
+
+        createFirstTitle(workbook, sheet, semesterService.getById(dto.getSemesterId()), examPlanService.getById(dto.getExamPlanId()), titleList);
+
+        createTitle(workbook, sheet, titleList);
+
+        //查询数据
+        dto.setSize(1000);
+        dto.setLimit(1);
+        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();
+            if(scoreList == null){
+                for (ClassStudentScoreTitleVo scoreTitleVo : titleList) {
+                    rowData.add("");
+                }
+                excelDataList.add(rowData);
+                sortCode ++;
+                continue;
+            }
+            BigDecimal reduce = scoreList.stream().filter(x -> StrUtil.isNotEmpty(x.getScore())).map(x -> new BigDecimal(x.getScore())).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal totalSocre = reduce
+                    .setScale(2, BigDecimal.ROUND_HALF_UP);
+            if(!totalSocre.equals(BigDecimal.ZERO)){
+                totalSocre = totalSocre.stripTrailingZeros();
+                if (totalSocre.scale() <= 0) { // 如果是整数
+                    rowData.add(totalSocre.toBigInteger().toString());
+                } else {
+                    rowData.add(totalSocre.toPlainString());
+                }
+            }else{
+                rowData.add("");
+            }
+
+            Map<String, String> scoreMap = scoreList.stream().filter(x -> StrUtil.isNotEmpty(x.getScore())).collect(Collectors.toMap(ClassStudentScoreTitleVo::getCourseId, ClassStudentScoreTitleVo::getScore));
+
+            for (ClassStudentScoreTitleVo scoreTitleVo : titleList) {
+                String score = scoreMap.get(scoreTitleVo.getCourseId());
+                if(StrUtil.isEmpty(score)){
+                    rowData.add("");
+                    continue;
+                }
+                BigDecimal scorebd = new BigDecimal(score);
+                scorebd = scorebd.stripTrailingZeros();
+                if (scorebd.scale() <= 0) { // 如果是整数
+                    rowData.add(scorebd.toBigInteger().toString());
+                } else {
+                    rowData.add(scorebd.toPlainString());
+                }
+            }
+            excelDataList.add(rowData);
+            sortCode ++;
+        }
+
+        createData(workbook, sheet, excelDataList);
+
+        ByteArrayOutputStream bot = new ByteArrayOutputStream();
+        workbook.write(bot);
+        return bot.toByteArray();
+    }
+
+    void createFirstTitle(Workbook workbook, Sheet sheet, BaseSemester semester, ExamPlan examPlan, 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);
+
+        int cellNumber = 0;
+        Cell cell = row.createCell(cellNumber);
+        cell.setCellValue(semester.getName() + "-" + examPlan.getName());
+        cell.setCellStyle(cellStyle);
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, cellNumber, cellNumber + 8 + titleList.size() - 1));
+    }
+
+    void createTitle(Workbook workbook, Sheet sheet, List<ClassStudentScoreTitleVo> titleList) {
+        int rowNumber = 1;
+        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);
+
+        int cellNumber = 0;
+        Cell cell = row.createCell(cellNumber);
+        cell.setCellValue("序号");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("班级");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("姓名");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("性别");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("身份证号");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("手机号");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("班主任");
+        cell.setCellStyle(cellStyle);
+
+        cellNumber ++;
+        cell = row.createCell(cellNumber);
+        cell.setCellValue("总分");
+        cell.setCellStyle(cellStyle);
+
+
+        cellNumber ++;
+        for(int i = 0; i < titleList.size(); i ++){
+            ClassStudentScoreTitleVo titleVo = titleList.get(i);
+            cell = row.createCell(cellNumber + i);
+            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);
+        int rowNumber = 2;
+        for (ArrayList<String> rowData : excelDataList) {
+            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);
+            }
+            rowNumber ++;
+        }
+    }
 }

+ 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>

+ 14 - 2
src/main/resources/mapper/xycxedu/ExamSubjectScoreMappper.xml

@@ -48,10 +48,16 @@
         INNER JOIN exam_plan t2 ON (t1.exam_plan_id = t2.id OR t2.milexamids LIKE CONCAT('%', t1.milexamid, '%'))
         INNER JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
         LEFT JOIN base_course_subject t4 ON t1.course_subject_id = t4.id
+        LEFT JOIN base_class t5 ON t3.class_id = t5.id
         WHERE t1.delete_mark = 0
         AND t1.semester_id = #{dto.semesterId}
         AND t2.id = #{dto.examPlanId}
-        AND t3.class_id = #{dto.treeId}
+        <if test="dto.treeId != null">
+            AND t3.class_id = #{dto.treeId}
+        </if>
+        <if test="dto.teacherId != null">
+            AND t5.teacher_id = #{dto.teacherId}
+        </if>
         order by t4.name
     </select>
     <select id="getClassStudentScoreList" parameterType="com.xjrsoft.module.xycxedu.dto.ClassStudentScorePageDto" resultType="com.xjrsoft.module.xycxedu.entity.ExamSubjectScore">
@@ -59,10 +65,16 @@
         INNER JOIN exam_plan t2 ON (t1.exam_plan_id = t2.id OR t2.milexamids LIKE CONCAT('%', t1.milexamid, '%'))
         INNER JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
         LEFT JOIN base_course_subject t4 ON t1.course_subject_id = t4.id
+        LEFT JOIN base_class t5 ON t3.class_id = t5.id
         WHERE t1.delete_mark = 0
         AND t1.semester_id = #{dto.semesterId}
         AND t2.id = #{dto.examPlanId}
-        AND t3.class_id = #{dto.treeId}
+        <if test="dto.treeId != null">
+            AND t3.class_id = #{dto.treeId}
+        </if>
+        <if test="dto.teacherId != null">
+            AND t5.teacher_id = #{dto.teacherId}
+        </if>
         <if test="dto.userIdList != null and dto.userIdList.size() > 0">
             AND t1.user_id in
             <foreach item="userId" index="index" collection="dto.userIdList" open="(" separator="," close=")">