|
|
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.enums.AssessQuestionTypeEnum;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.common.utils.WeChatUtil;
|
|
|
@@ -63,9 +64,21 @@ import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import com.xjrsoft.module.teacher.mapper.XjrUserMapper;
|
|
|
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 org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -73,6 +86,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @title: 考核计划
|
|
|
@@ -592,4 +606,185 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
|
|
|
return vo;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public byte[] answerExportQuery(AssessmentPlanAnswerStudentDto dto) throws IOException {
|
|
|
+ //查询大题
|
|
|
+ List<AssessmentPlanQuestion> oneQuesList = planQuestionMapper.selectList(
|
|
|
+ new QueryWrapper<AssessmentPlanQuestion>().lambda()
|
|
|
+ .eq(AssessmentPlanQuestion::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(AssessmentPlanQuestion::getAssessmentTemplatePlanId, dto.getAssessmentTemplatePlanId())
|
|
|
+ .eq(AssessmentPlanQuestion::getCategory, 1)
|
|
|
+ .orderByAsc(AssessmentPlanQuestion::getId)
|
|
|
+ );
|
|
|
+
|
|
|
+ //查询二级题目
|
|
|
+ List<AssessmentPlanQuestion> towQuesList = planQuestionMapper.selectList(
|
|
|
+ new QueryWrapper<AssessmentPlanQuestion>().lambda()
|
|
|
+ .eq(AssessmentPlanQuestion::getCategory, 2)
|
|
|
+ .eq(AssessmentPlanQuestion::getAssessmentTemplatePlanId, dto.getAssessmentTemplatePlanId())
|
|
|
+ .eq(AssessmentPlanQuestion::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .orderByAsc(AssessmentPlanQuestion::getId)
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<Long, List<AssessmentPlanQuestion>> towQuesMaps = towQuesList.stream().collect(Collectors.groupingBy(AssessmentPlanQuestion::getParentId));
|
|
|
+
|
|
|
+ List<AssessmentPlanAnswerDetailVo> results = resultMapper.getPlanQuestionResultList(dto.getAssessmentTemplatePlanId());
|
|
|
+ Map<Long, List<AssessmentPlanAnswerDetailVo>> studentAnswerMaps = results.stream().collect(Collectors.groupingBy(AssessmentPlanAnswerDetailVo::getStudentUserId));
|
|
|
+ //查询已答题学生
|
|
|
+ List<AssessmentPlanAnswerStudentVo> studentList = this.baseMapper.getAnswerStudentList(dto);
|
|
|
+ List<List<String>> dataList = new ArrayList<>();
|
|
|
+ int sortCode = 1;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (AssessmentPlanAnswerStudentVo studentVo : studentList) {
|
|
|
+ List<String> rowData = new ArrayList<>();
|
|
|
+ rowData.add(sortCode + "");
|
|
|
+ rowData.add(studentVo.getClassName());
|
|
|
+ rowData.add(studentVo.getName());
|
|
|
+ rowData.add(sdf.format(studentVo.getSubmitDate()));
|
|
|
+ Map<Long, List<AssessmentPlanAnswerDetailVo>> answerMaps = studentAnswerMaps.get(Long.parseLong(studentVo.getStudentUserId()))
|
|
|
+ .stream().collect(Collectors.groupingBy(AssessmentPlanAnswerDetailVo::getQuestionId));
|
|
|
+ for (AssessmentPlanQuestion question : towQuesList) {
|
|
|
+ List<AssessmentPlanAnswerDetailVo> resultList = answerMaps.get(question.getId());
|
|
|
+ if(resultList.isEmpty()){
|
|
|
+ rowData.add("");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(AssessQuestionTypeEnum.MULTI.getCode().equals(question.getType())){
|
|
|
+ String answerStr = "";
|
|
|
+ for(int i = 0; i < resultList.size(); i ++){
|
|
|
+ if(i > 0){
|
|
|
+ answerStr += "\r\n";
|
|
|
+ }
|
|
|
+ answerStr += resultList.get(i).getAnswerId() + "";
|
|
|
+ }
|
|
|
+ rowData.add(answerStr);
|
|
|
+ }else if(AssessQuestionTypeEnum.SCALE.getCode().equals(question.getType())){
|
|
|
+ rowData.add(resultList.get(0).getAnswerId() + "星");
|
|
|
+ }else{
|
|
|
+ List<String> answerList = resultList.stream().map(AssessmentPlanAnswerDetailVo::getAnswerId).collect(Collectors.toList());
|
|
|
+ rowData.add(answerList.toString().replace("[", "").replace("]", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dataList.add(rowData);
|
|
|
+ sortCode ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ // 创建一个工作表(sheet)
|
|
|
+ String sheetName = "数据";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+
|
|
|
+ createFirstTitle(workbook, sheet, oneQuesList, towQuesMaps);
|
|
|
+ createSecondTitle(workbook, sheet, towQuesList);
|
|
|
+
|
|
|
+ int dataRowNumber = 2;
|
|
|
+
|
|
|
+ for (List<String> rowData : dataList) {
|
|
|
+ Row dataRow = sheet.createRow(dataRowNumber);
|
|
|
+ for (int i = 0; i < rowData.size(); i ++){
|
|
|
+// if(i < 7){
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
+// }
|
|
|
+ String content = rowData.get(i);
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(false);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
|
|
+
|
|
|
+ Cell row1cell2 = dataRow.createCell(i);
|
|
|
+ row1cell2.setCellValue(content);
|
|
|
+ row1cell2.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataRowNumber ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入文件
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+ workbook.write(bot);
|
|
|
+ return bot.toByteArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建第一行表头
|
|
|
+ */
|
|
|
+ void createFirstTitle(Workbook workbook, Sheet sheet, List<AssessmentPlanQuestion> oneQuesList, Map<Long, List<AssessmentPlanQuestion>> towQuesMaps) {
|
|
|
+ int rowNumber = 0;
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(true);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, 1, cellNumber, cellNumber));
|
|
|
+
|
|
|
+ cellNumber ++;
|
|
|
+ cell = row.createCell(cellNumber);
|
|
|
+ cell.setCellValue("班级");
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, 1, cellNumber, cellNumber));
|
|
|
+
|
|
|
+ cellNumber ++;
|
|
|
+ cell = row.createCell(cellNumber);
|
|
|
+ cell.setCellValue("学生姓名");
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, 1, cellNumber, cellNumber));
|
|
|
+
|
|
|
+ cellNumber ++;
|
|
|
+ cell = row.createCell(cellNumber);
|
|
|
+ cell.setCellValue("提交时间");
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, 1, cellNumber, cellNumber));
|
|
|
+
|
|
|
+ cellNumber ++;
|
|
|
+ for (AssessmentPlanQuestion question : oneQuesList) {
|
|
|
+ int size = towQuesMaps.get(question.getId()).size();
|
|
|
+
|
|
|
+ cell = row.createCell(cellNumber);
|
|
|
+ cell.setCellValue(question.getName());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, cellNumber, cellNumber + size));
|
|
|
+ cellNumber = cellNumber + size;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void createSecondTitle(Workbook workbook, Sheet sheet, List<AssessmentPlanQuestion> towQuesList) {
|
|
|
+ int rowNumber = 1;
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(true);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ Row row = sheet.createRow(rowNumber);
|
|
|
+ int cellNumber = 4;
|
|
|
+ for (AssessmentPlanQuestion question : towQuesList) {
|
|
|
+ Cell cell = row.createCell(cellNumber);
|
|
|
+ cell.setCellValue(question.getName());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ cellNumber ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|