Browse Source

食堂评价内容导出

dzx 11 months ago
parent
commit
7e130d2cc2

+ 55 - 0
src/main/java/com/xjrsoft/common/enums/AssessQuestionTypeEnum.java

@@ -0,0 +1,55 @@
+package com.xjrsoft.common.enums;
+
+/**
+ * @description: 食堂评价题目类型
+ * @author: dzx
+ * @create: 2024年12月18日
+ * @Version 1.0
+ */
+public enum AssessQuestionTypeEnum {
+
+    RADIO("radio_question", "单选题"),
+
+    MULTI("multi_question", "多选题"),
+
+    JUDGE("judge_question", "判断题"),
+
+    TEXT("text_question", "文本题"),
+
+    SCALE("scale_question", "量表题");
+
+    final String code;
+    final String value;
+
+    public String getCode() {
+        return this.code;
+    }
+
+    public String getValue() {
+        return this.value;
+    }
+
+    AssessQuestionTypeEnum(final String code, final String message) {
+        this.code = code;
+        this.value = message;
+    }
+
+    public static String getValue(String code) {
+        for (AssessQuestionTypeEnum item : values()) {
+            if (item.getCode().equals(code)) {
+                return  item.getValue();
+            }
+        }
+        return null;
+    }
+
+    public static String[] getCodes() {
+        String[] codes = {"radio_question", "multi_question", "judge_question", "text_question", "scale_question"};
+        return codes;
+    }
+
+    public static String[] getValues() {
+        String[] values = {"单选题", "多选题", "判断题", "文本题", "量表题"};
+        return values;
+    }
+}

+ 7 - 2
src/main/java/com/xjrsoft/module/assessment/controller/AssessmentPlanAnswerController.java

@@ -2,6 +2,7 @@ package com.xjrsoft.module.assessment.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.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
@@ -23,6 +24,7 @@ import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanResultVo;
 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.RequestBody;
@@ -31,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -173,7 +176,9 @@ public class AssessmentPlanAnswerController {
     @PostMapping(value = "/answer-export-query")
     @ApiOperation(value="考核计划答题列表-学生答题情况导出")
     @SaCheckPermission("assessmenttemplateplan:detail")
-    public RT<List<AssessmentPlanAnswerStudentVo>> answerExportQuery(@Valid @RequestBody AssessmentPlanAnswerStudentDto dto){
-        return RT.ok();
+    public ResponseEntity<byte[]> answerExportQuery(@Valid @RequestBody AssessmentPlanAnswerStudentDto dto) throws IOException {
+        String fileName = "answerExportQuery" + ExcelTypeEnum.XLSX.getValue();
+        byte[] bytes = planService.answerExportQuery(dto);
+        return RT.fileStream(bytes, fileName);
     }
 }

+ 2 - 0
src/main/java/com/xjrsoft/module/assessment/mapper/AssessmentPlanAnswerResultMapper.java

@@ -29,4 +29,6 @@ public interface AssessmentPlanAnswerResultMapper extends MPJBaseMapper<Assessme
     List<AssessmentPlanAnswerDetailVo> getScaleQuestionResult(Long id);
 
     List<AssessmentPlanAnswerDetailVo> getStudentQuestionResultList(@Param("templatePlanId") Long templatePlanId, @Param("studentUserId") Long studentUserId);
+
+    List<AssessmentPlanAnswerDetailVo> getPlanQuestionResultList(@Param("templatePlanId") Long templatePlanId);
 }

+ 2 - 0
src/main/java/com/xjrsoft/module/assessment/mapper/AssessmentTemplatePlanMapper.java

@@ -41,4 +41,6 @@ public interface AssessmentTemplatePlanMapper extends MPJBaseMapper<AssessmentTe
     Page<AssessmentPlanAnswerStudentVo> getAnswerStudent(Page<AssessmentPlanAnswerStudentDto> page, @Param("dto") AssessmentPlanAnswerStudentDto dto);
 
     List<Long> getSemesterClass(Long id);
+
+    List<AssessmentPlanAnswerStudentVo> getAnswerStudentList(@Param("dto") AssessmentPlanAnswerStudentDto dto);
 }

+ 3 - 0
src/main/java/com/xjrsoft/module/assessment/service/IAssessmentTemplatePlanService.java

@@ -21,6 +21,7 @@ import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanQuestionVo;
 import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanResultVo;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -93,4 +94,6 @@ public interface IAssessmentTemplatePlanService extends MPJBaseService<Assessmen
     Boolean sendMsg(AssessmentTemplatePlanSureDto dto);
 
     AssessmentTemplatePlanAnswerResultVo getAnswerStudentResult(Long studentUserId, Long assessmentTemplatePlanId);
+
+    byte[] answerExportQuery(AssessmentPlanAnswerStudentDto dto) throws IOException;
 }

+ 195 - 0
src/main/java/com/xjrsoft/module/assessment/service/impl/AssessmentTemplatePlanServiceImpl.java

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

+ 3 - 0
src/main/java/com/xjrsoft/module/assessment/vo/AssessmentPlanAnswerDetailVo.java

@@ -21,4 +21,7 @@ public class AssessmentPlanAnswerDetailVo {
     @ApiModelProperty("数量")
     private Integer chooseCount;
 
+    @ApiModelProperty("学生id")
+    private Long studentUserId;
+
 }

+ 5 - 0
src/main/resources/mapper/assessment/AssessmentPlanAnswerResultMapper.xml

@@ -43,4 +43,9 @@
         and t1.student_user_id = #{studentUserId}
         order BY t1.id
     </select>
+    <select id="getPlanQuestionResultList" resultType="com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerDetailVo">
+        SELECT t1.student_user_id,t1.question_id,IFNULL(t2.name, t1.answer_id) FROM assessment_plan_answer_result t1
+        LEFT JOIN assessment_plan_question t2 ON t1.answer_id =  CAST(t2.id AS CHAR)
+        WHERE t1.delete_mark = 0 AND t1.assessment_template_plan_id = #{templatePlanId}
+    </select>
 </mapper>

+ 21 - 0
src/main/resources/mapper/assessment/AssessmentTemplatePlanMapper.xml

@@ -130,4 +130,25 @@
         INNER JOIN assessment_template_plan t2 ON t1.assessment_template_plan_id = t2.id
         WHERE t1.delete_mark = 0 AND t2.delete_mark = 0 AND t2.status in (0, 1) AND t2.base_semester_id = #{id}
     </select>
+    <select id="getAnswerStudentList" parameterType="com.xjrsoft.module.assessment.dto.AssessmentPlanAnswerStudentDto" resultType="com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerStudentVo">
+        SELECT t1.student_user_id,t4.name AS class_name,t1.modify_date AS submit_date,t2.name,t1.submit_status,t1.assessment_template_plan_id FROM assessment_plan_answer_student t1
+        LEFT JOIN xjr_user t2 ON t1.student_user_id = t2.id
+        LEFT JOIN base_student_school_roll t3 ON t1.student_user_id = t3.user_id
+        LEFT JOIN base_class t4 ON t3.class_id = t4.id
+        WHERE t1.delete_mark = 0 AND t1.assessment_template_plan_id = #{dto.assessmentTemplatePlanId}
+        and t1.submit_status = 1
+        <if test="dto.keyword != null and dto.keyword != ''">
+            and (t2.name like concat('%', #{dto.keyword}, '%') or t4.name like concat('%', #{dto.keyword}, '%'))
+        </if>
+        <if test="dto.name != null and dto.name != ''">
+            and (t2.name like concat('%', #{dto.name}, '%') or t4.name like concat('%', #{dto.name}, '%'))
+        </if>
+
+        <if test="dto.teacherId != null">
+            AND t4.teacher_id = #{dto.teacherId}
+        </if>
+        <if test="dto.classId != null">
+            AND t4.id = #{dto.classId}
+        </if>
+    </select>
 </mapper>

+ 24 - 0
src/main/resources/sqlScript/20241216_sql.sql

@@ -4,3 +4,27 @@ ALTER TABLE `assessment_template_plan`
 
 ALTER TABLE `assessment_template_plan`   
   ADD COLUMN is_need_confirm INT DEFAULT 0 COMMENT '是否需要班主任确认(0:否 1:是)';
+
+ALTER TABLE `assessment_plan_answer_result`   
+  CHANGE `answer_id` `answer_id` VARCHAR(120) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL   COMMENT '选项id(assessment_plan_question[category=3的id])';
+
+CREATE TABLE `temporary_change_class`  (
+  `id` BIGINT NOT NULL COMMENT '主键',
+  `create_user_id` BIGINT NULL DEFAULT NULL COMMENT '创建人',
+  `create_date` DATETIME(3) NULL DEFAULT NULL COMMENT '创建时间',
+  `modify_user_id` BIGINT NULL DEFAULT NULL COMMENT '修改人id',
+  `modify_date` DATETIME(3) NULL DEFAULT NULL COMMENT '修改日期',
+  `delete_mark` INT NULL DEFAULT NULL COMMENT '删除标记',
+  `enabled_mark` INT NULL DEFAULT NULL COMMENT '有效标记',
+  `before_class_id` BIGINT NULL DEFAULT NULL COMMENT '转出班级id',
+  `student_user_id` BIGINT NULL DEFAULT NULL COMMENT '学生用户id',
+  `student_name` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '学生姓名',
+  `gender` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '性别',
+  `I_D_number` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '身份证号',
+  `after_grade_id` BIGINT NULL DEFAULT NULL COMMENT '年级id',
+  `after_class_id` BIGINT NULL DEFAULT NULL COMMENT '转入班级id',
+  `teacher_id` BIGINT NULL DEFAULT NULL COMMENT '班主任id',
+  `status` INT NULL DEFAULT 0 COMMENT '状态(0:未结束 1:结束)',
+  `type` INT NULL DEFAULT 0 COMMENT '类型(0:临时转班 1:德育转班)',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = INNODB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '临时转班' ROW_FORMAT = DYNAMIC;