|
@@ -1,17 +1,58 @@
|
|
|
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;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+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;
|
|
|
+import com.xjrsoft.module.student.service.IStudentManagerService;
|
|
|
+import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
|
|
|
+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;
|
|
|
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;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @title: 晓羊策学考试计划表
|
|
|
* @Author dzx
|
|
@@ -21,6 +62,11 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
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) {
|
|
|
return this.baseMapper.getUserIdByIdNumber(idNumber);
|
|
@@ -35,4 +81,297 @@ public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectS
|
|
|
public Page<ExamStatisticsPageVo> getStatisticsPage(Page<ExamStatisticsPageVo> page, ExamStatisticsPageDto dto) {
|
|
|
return this.baseMapper.getStatisticsPage(page, dto);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamSubjectScoreEnterImportVo> getEnterScoreStudentList(ExamSubjectScoreEnterDto dto) {
|
|
|
+ List<ExamSubjectScoreEnterImportVo> result = this.selectJoinList(ExamSubjectScoreEnterImportVo.class,
|
|
|
+ new MPJLambdaWrapper<ExamSubjectScore>()
|
|
|
+ .select(ExamSubjectScore::getId)
|
|
|
+ .selectAs(BaseClass::getName, ExamSubjectScoreEnterImportVo::getClassName)
|
|
|
+ .selectAs(User::getName, ExamSubjectScoreEnterImportVo::getStudentName)
|
|
|
+ .selectAs(User::getCredentialNumber, ExamSubjectScoreEnterImportVo::getCredentialNumber)
|
|
|
+ .select(ExamSubjectScore::getScore)
|
|
|
+ .select(ExamSubjectScore::getClassRanking)
|
|
|
+ .select(ExamSubjectScore::getGradeRanking)
|
|
|
+ .innerJoin(User.class, User::getId, ExamSubjectScore::getUserId)
|
|
|
+ .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, ExamSubjectScore::getUserId)
|
|
|
+ .innerJoin(BaseClass.class, BaseClass::getId, BaseStudentSchoolRoll::getClassId)
|
|
|
+ .eq(dto.getClassId() != null, BaseClass::getId, dto.getClassId())
|
|
|
+ .like(StrUtil.isNotEmpty(dto.getStudentName()), User::getName, dto.getStudentName())
|
|
|
+ .like(StrUtil.isNotEmpty(dto.getCredentialNumber()), User::getCredentialNumber, dto.getCredentialNumber())
|
|
|
+ .isNotNull(dto.getIsEnter() != null && dto.getIsEnter() == 1, ExamSubjectScore::getScore)
|
|
|
+ .isNull(dto.getIsEnter() != null && dto.getIsEnter() == 0, ExamSubjectScore::getScore)
|
|
|
+ .eq(dto.getExamSubjectScoreEnterId() != null, ExamSubjectScore::getExamSubjectScoreEnterId, dto.getExamSubjectScoreEnterId())
|
|
|
+ .orderByAsc(BaseClass::getName)
|
|
|
+ );
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageOutput<ExamSubjectScoreEnterImportVo> getEnterScoreStudentPage(Page<ExamSubjectScoreEnterImportVo> page, ExamSubjectScoreEnterDto dto) {
|
|
|
+ IPage<ExamSubjectScoreEnterImportVo> voIPage = this.selectJoinListPage(page, ExamSubjectScoreEnterImportVo.class,
|
|
|
+ new MPJLambdaWrapper<ExamSubjectScore>()
|
|
|
+ .select(ExamSubjectScore::getId)
|
|
|
+ .selectAs(BaseClass::getName, ExamSubjectScoreEnterImportVo::getClassName)
|
|
|
+ .selectAs(User::getName, ExamSubjectScoreEnterImportVo::getStudentName)
|
|
|
+ .selectAs(User::getCredentialNumber, ExamSubjectScoreEnterImportVo::getCredentialNumber)
|
|
|
+ .select(ExamSubjectScore::getScore)
|
|
|
+ .select(ExamSubjectScore::getClassRanking)
|
|
|
+ .select(ExamSubjectScore::getGradeRanking)
|
|
|
+ .innerJoin(User.class, User::getId, ExamSubjectScore::getUserId)
|
|
|
+ .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, ExamSubjectScore::getUserId)
|
|
|
+ .innerJoin(BaseClass.class, BaseClass::getId, BaseStudentSchoolRoll::getClassId)
|
|
|
+ .eq(dto.getClassId() != null, BaseClass::getId, dto.getClassId())
|
|
|
+ .like(StrUtil.isNotEmpty(dto.getStudentName()), User::getName, dto.getStudentName())
|
|
|
+ .like(StrUtil.isNotEmpty(dto.getCredentialNumber()), User::getCredentialNumber, dto.getCredentialNumber())
|
|
|
+ .isNotNull(dto.getIsEnter() != null && dto.getIsEnter() == 1, ExamSubjectScore::getScore)
|
|
|
+ .isNull(dto.getIsEnter() != null && dto.getIsEnter() == 0, ExamSubjectScore::getScore)
|
|
|
+ .eq(dto.getExamSubjectScoreEnterId() != null, ExamSubjectScore::getExamSubjectScoreEnterId, dto.getExamSubjectScoreEnterId())
|
|
|
+ );
|
|
|
+ PageOutput<ExamSubjectScoreEnterImportVo> pageOutput = ConventPage.getPageOutput(voIPage, ExamSubjectScoreEnterImportVo.class);
|
|
|
+ return pageOutput;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ClassStudentScoreTitleVo> getClassStudentScoreCourse(ClassStudentScorePageDto dto) {
|
|
|
+ return this.baseMapper.getClassStudentScoreCourse(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamSubjectScore> getClassStudentScoreList(ClassStudentScorePageDto dto) {
|
|
|
+ return this.baseMapper.getClassStudentScoreList(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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());
|
|
|
+ dto.setUserIdList(new ArrayList<>(userIdSet));
|
|
|
+ List<ExamSubjectScore> allScoreList = this.baseMapper.getClassStudentScoreList(dto);
|
|
|
+ Map<Long, List<ExamSubjectScore>> listMap = allScoreList.stream().collect(Collectors.groupingBy(ExamSubjectScore::getUserId));
|
|
|
+ PageOutput<ClassStudentScorePageVo> pageOutput = ConventPage.getPageOutput(studentPage, ClassStudentScorePageVo.class);
|
|
|
+
|
|
|
+ for (ClassStudentScorePageVo vo : pageOutput.getList()) {
|
|
|
+ long userId = Long.parseLong(vo.getId());
|
|
|
+ List<ClassStudentScoreTitleVo> scoreList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<ExamSubjectScore> scores = listMap.get(userId);
|
|
|
+ if(scores == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (ExamSubjectScore score : scores) {
|
|
|
+ scoreList.add(
|
|
|
+ new ClassStudentScoreTitleVo(){{
|
|
|
+ if(score.getScore() != null){
|
|
|
+ setScore(Float.toString(score.getScore()));
|
|
|
+ }
|
|
|
+ if(score.getExamPlanId() == null){
|
|
|
+ setCourseId(score.getMilexamid() + "" + score.getCourseSubjectId());
|
|
|
+ }else{
|
|
|
+ setCourseId(score.getExamPlanId() + "" + score.getCourseSubjectId());
|
|
|
+ }
|
|
|
+ setName(score.getCoursename());
|
|
|
+ }}
|
|
|
+ );
|
|
|
+ }
|
|
|
+ vo.setScoreList(scoreList);
|
|
|
+ }
|
|
|
+ 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 ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|