|
@@ -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();
|
|
|
+
|
|
|
+ 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.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.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 ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|