wangliang 4 vuotta sitten
vanhempi
commit
c286400964

+ 17 - 0
themis-business/src/main/java/com/qmth/themis/business/annotation/ExcelDynamicExport.java

@@ -0,0 +1,17 @@
+package com.qmth.themis.business.annotation;
+
+import java.lang.annotation.*;
+
+/**
+* @Description: excel字段动态导出注释
+* @Param:
+* @return:
+* @Author: wangliang
+* @Date: 2020/7/20
+*/
+@Documented
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelDynamicExport {
+
+}

+ 4 - 0
themis-business/src/main/java/com/qmth/themis/business/dto/ExcelDto.java

@@ -23,6 +23,10 @@ public class ExcelDto implements Serializable {
 
     }
 
+    public ExcelDto(String title) {
+        this.title = title;
+    }
+
     public ExcelDto(String title, String content) {
         this.title = title;
         this.content = content;

+ 5 - 4
themis-business/src/main/java/com/qmth/themis/business/dto/MarkResultStandardExportDto.java

@@ -1,5 +1,6 @@
 package com.qmth.themis.business.dto;
 
+import com.qmth.themis.business.annotation.ExcelDynamicExport;
 import com.qmth.themis.business.annotation.ExcelNotExport;
 import com.qmth.themis.business.annotation.ExcelNote;
 import io.swagger.annotations.ApiModelProperty;
@@ -75,6 +76,10 @@ public class MarkResultStandardExportDto implements Serializable{
     @ExcelNote(value = "总分")
     private String sumScore;
 
+    @ApiModelProperty(value = "答题记录")
+    @ExcelDynamicExport
+    private Map<Long, List<ExcelDto>> answerExcetDto;
+
     @ApiModelProperty(value = "考试记录ID")
     @ExcelNotExport
     private Long recordId;
@@ -87,10 +92,6 @@ public class MarkResultStandardExportDto implements Serializable{
     @ExcelNotExport
     private Long examStudentId;
 
-    @ApiModelProperty(value = "答题记录")
-    @ExcelNotExport
-    private Map<Long, List<ExcelDto>> answerExcetDto;
-
     public Map<Long, List<ExcelDto>> getAnswerExcetDto() {
         return answerExcetDto;
     }

+ 40 - 5
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskMarkResultStandardExportTemplete.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.common.reflect.TypeToken;
 import com.google.gson.Gson;
+import com.qmth.themis.business.annotation.ExcelDynamicExport;
 import com.qmth.themis.business.annotation.ExcelNotExport;
 import com.qmth.themis.business.annotation.ExcelNote;
 import com.qmth.themis.business.cache.bean.ObjectiveAnswerCacheBean;
@@ -92,6 +93,7 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
             }.getType());
             Map<Long, List<ExcelDto>> excelDtoMap = null;
             Map<Long, Map<String, ObjectiveAnswerCacheBean>> paperObjectiveAnswerMap = new HashMap<>();
+            List<ExcelDto> dynamicExcelHead = new ArrayList<>();
             if (Objects.nonNull(markResultStandardExportDtoList) && markResultStandardExportDtoList.size() > 0) {
                 for (MarkResultStandardExportDto m : markResultStandardExportDtoList) {
                     excelDtoMap = new HashMap<>();
@@ -103,6 +105,16 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
                         } else {
                             objectiveAnswerCacheBeanMap = paperObjectiveAnswerMap.get(m.getPaperId());
                         }
+                        if (dynamicExcelHead.size() == 0) {
+                            objectiveAnswerCacheBeanMap.forEach((k, v) -> {
+                                ObjectiveAnswerCacheBean objectiveAnswerCacheBean = v;
+                                String title = QuestionTypeEnum.convertToTitle(objectiveAnswerCacheBean.getStructType()) + k;
+                                ExcelDto excelAnswerDto = new ExcelDto(title + "作答");
+                                ExcelDto excelScoreDto = new ExcelDto(title + "得分");
+                                dynamicExcelHead.add(excelAnswerDto);
+                                dynamicExcelHead.add(excelScoreDto);
+                            });
+                        }
                     } else {
                         continue;
                     }
@@ -165,18 +177,30 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
             style.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
             Row row = sheet.createRow(0);
             Field[] fields = MarkResultStandardExportDto.class.getDeclaredFields();
+            int num = 0;
             //绘制表头
             for (int i = 0; i < fields.length; i++) {
                 Field field = fields[i];
                 field.setAccessible(true);
-                Annotation annotation = field.getAnnotation(ExcelNotExport.class);
-                if (Objects.isNull(annotation)) {
+                Annotation annotation = field.getAnnotation(ExcelNote.class);
+                if (Objects.nonNull(annotation)) {
                     Cell cell = row.createCell(i);
                     cell.setCellValue(field.getAnnotation(ExcelNote.class).value());
                     cell.setCellStyle(style);
-//                    sheet.setColumnWidth(i, 15 * 256);
+                    num = i;
                 }
             }
+            num++;
+            Map<String, Integer> position = new HashMap<>();
+            //动态表头
+            for (ExcelDto excelDto : dynamicExcelHead) {
+                Cell cell = row.createCell(num);
+                cell.setCellValue(excelDto.getTitle());
+                cell.setCellStyle(style);
+                sheet.setColumnWidth(num, 15 * 256);
+                position.put(excelDto.getTitle(), num);
+                num++;
+            }
             int cellIndex = 0, max = SystemConstant.MAX_EXPORT_SIZE, size = markResultStandardExportDtoList.size();
             if (max >= size) {
                 max = size;
@@ -193,8 +217,19 @@ public class TaskMarkResultStandardExportTemplete implements TaskExportTemplete
                         field.setAccessible(true);
                         Annotation annotation = field.getAnnotation(ExcelNotExport.class);
                         if (Objects.isNull(annotation)) {
-                            taskExportCommon.createExcelCell(sxssfRow, cellIndex, field.get(markResultStandardExportDto), style);
-                            cellIndex++;
+                            Annotation dynamicExport = field.getAnnotation(ExcelDynamicExport.class);
+                            if (Objects.nonNull(dynamicExport)) {
+                                Map<Long, List<ExcelDto>> answerExcetDto = markResultStandardExportDto.getAnswerExcetDto();
+                                if (Objects.nonNull(answerExcetDto)) {
+                                    List<ExcelDto> excelDtoList = answerExcetDto.get(markResultStandardExportDto.getExamStudentId());
+                                    excelDtoList.forEach(s -> {
+                                        taskExportCommon.createExcelCell(sxssfRow, position.get(s.getTitle()), s.getContent(), style);
+                                    });
+                                }
+                            } else {
+                                taskExportCommon.createExcelCell(sxssfRow, cellIndex, field.get(markResultStandardExportDto), style);
+                                cellIndex++;
+                            }
                         }
                     }
                 }

+ 2 - 2
themis-business/src/main/resources/mapper/TEExamStudentMapper.xml

@@ -322,14 +322,14 @@
 		left join t_e_exam_student tees on
 		tees.student_id = tes.id
 		left join (select
-			max(toer.objective_score) as objective_score,toer.id,toer.exam_student_id,toer.paper_id
+			max(toer.objective_score) as objective_score,max(toer.id) as id,toer.exam_student_id,toer.paper_id
 			from
 			t_oe_exam_record toer
 			where
 			(toer.breach_status = 1
 			or breach_status is null)
 			and (toer.status = 'FINISHED'
-			or toer.status = 'PERSISTED') group by toer.id,toer.paper_id,toer.exam_student_id order by toer.id desc limit 1) temp on temp.exam_student_id = tees.id
+			or toer.status = 'PERSISTED') group by toer.paper_id,toer.exam_student_id) temp on temp.exam_student_id = tees.id
 		left join t_e_exam tee on
 		tee.id = tees.exam_id
 		left join t_e_exam_activity teea on