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