Browse Source

3.4.4 update-20250418,归档优化

xiaofei 2 months ago
parent
commit
88111a1335

+ 0 - 3
distributed-print/install/mysql/upgrade/3.4.2.sql

@@ -140,9 +140,6 @@ ALTER TABLE `t_sync_exam_student_score` CHANGE COLUMN `paper_number` `paper_numb
 
 ALTER TABLE `exam_card` ADD COLUMN `open_ab` TINYINT(1) NULL DEFAULT 0 COMMENT '是否AB卷(AB卷题卡)' AFTER `page_size`;
 
-update mark_paper set paper_file_path = concat('[',paper_file_path, ']') where paper_file_path is not null;
-update mark_document set file_path = concat('[',file_path, ']') where type = 'PAPER' and file_path is not null;
-
 -- 2024-11-11
 ALTER TABLE obe_course_outline MODIFY COLUMN course_type varchar(50) NOT NULL COMMENT '课程类别';
 

+ 50 - 1
distributed-print/src/main/java/com/qmth/distributed/print/upgrade/DataUpgrade_3_4_2.java

@@ -6,9 +6,12 @@ import com.qmth.boot.data.upgrade.service.DataUpgradeService;
 import com.qmth.boot.data.upgrade.utils.ResourceFileHelper;
 import com.qmth.distributed.print.business.entity.ExamTask;
 import com.qmth.distributed.print.business.entity.ExamTaskDetail;
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
 import com.qmth.teachcloud.common.bean.vo.PaperInfoVo;
 import com.qmth.teachcloud.common.entity.MarkQuestion;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.mark.dto.mark.MarkPaperFileDto;
+import com.qmth.teachcloud.mark.entity.MarkPaper;
 import com.qmth.teachcloud.mark.entity.MarkQuestionAnswer;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -158,8 +161,25 @@ public class DataUpgrade_3_4_2 implements DataUpgradeService {
             this.saveBatchMarkQuestionAnswer(jdbcTemplate, markQuestionAnswerList);
         }
         log.info("2.1结束拆分mark_question表中客观题标答到mark_question_answer表");
-        log.info("历史数据处理完成;时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
 
+        log.info("3.1开始修改mark_paper表中的paper_file_path格式");
+        // 拆分客观题标答
+        for (MarkPaper markPaper : this.markPaperList(jdbcTemplate)) {
+            List<FilePathVo> paperFilePathList = new ArrayList<>();
+            paperFilePathList.add(JSON.parseObject(markPaper.getPaperFilePath(), FilePathVo.class));
+            markPaper.setPaperFilePath(JSON.toJSONString(paperFilePathList));
+            this.updateMarkPaperFilePath(jdbcTemplate, markPaper);
+        }
+        log.info("3.1结束修改mark_paper表中的paper_file_path格式");
+
+        log.info("3.2开始更新mark_document表中type='PAPER'的file_path值");
+        this.updateMarkDocumentPaper(jdbcTemplate);
+        log.info("3.2结束更新mark_document表中type='PAPER'的file_path值");
+
+        log.info("3.3开始更新mark_document表中type='ANSWER'的file_path值");
+        this.updateMarkDocumentAnswer(jdbcTemplate);
+        log.info("3.3结束更新mark_document表中type='ANSWER'的file_path值");
+        log.info("历史数据处理完成;时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
     }
 
     private void execUpgradeSql(JdbcTemplate jdbcTemplate, String upgradeSql) {
@@ -212,6 +232,14 @@ public class DataUpgrade_3_4_2 implements DataUpgradeService {
         }
     }
 
+    private int update(JdbcTemplate jdbcTemplate, String sql, Object[] params) {
+        try {
+            return jdbcTemplate.update(sql, params);
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception("更新失败:" + e.getMessage());
+        }
+    }
+
     private <T> List<T> pageData(JdbcTemplate jdbcTemplate, String sql, Class<T> tClass) {
         if (!sql.contains("limit")) {
             sql += " limit ?,?";
@@ -301,11 +329,26 @@ public class DataUpgrade_3_4_2 implements DataUpgradeService {
         jdbcTemplate.update(sql);
     }
 
+    private void updateMarkDocumentPaper(JdbcTemplate jdbcTemplate) {
+        String sql = "update mark_document md left join mark_paper mp on md.exam_id = mp.exam_id and md.paper_number = mp.paper_number set md.file_path = mp.paper_file_path where md.type = 'PAPER'";
+        jdbcTemplate.update(sql);
+    }
+
+    private void updateMarkDocumentAnswer(JdbcTemplate jdbcTemplate) {
+        String sql = "update mark_document md left join mark_paper mp on md.exam_id = mp.exam_id and md.paper_number = mp.paper_number set md.file_path = mp.answer_file_path where md.type = 'ANSWER'";
+        jdbcTemplate.update(sql);
+    }
+
     private List<MarkQuestion> markQuestionList(JdbcTemplate jdbcTemplate) {
         String sql = "select * from mark_question where objective = true order by exam_id, paper_number";
         return this.listData(jdbcTemplate, sql, MarkQuestion.class);
     }
 
+    private List<MarkPaper> markPaperList(JdbcTemplate jdbcTemplate) {
+        String sql = "select * from mark_paper where paper_file_path is not null";
+        return this.listData(jdbcTemplate, sql, MarkPaper.class);
+    }
+
     private long saveBatchExamTaskDetail(JdbcTemplate jdbcTemplate, List<ExamTaskDetail> list) {
         String sql = "insert into exam_task_detail(exam_task_id, serial_number, paper_type, paper_attachment_ids, exposed, exposed_exam_id, create_id, create_time, update_id, update_time) values (?,?,?,?,?,?,?,?,?,?)";
         int[] ints = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@@ -454,6 +497,12 @@ public class DataUpgrade_3_4_2 implements DataUpgradeService {
         return Arrays.stream(ints).mapToLong(m -> m).sum();
     }
 
+    private int updateMarkPaperFilePath(JdbcTemplate jdbcTemplate, MarkPaper markPaper) {
+        String sql = "update mark_paper set paper_file_path = ? where id = ?";
+        Object[] params = new Object[]{markPaper.getPaperFilePath(), markPaper.getAnswerFilePath(), markPaper.getId()};
+        return this.update(jdbcTemplate, sql, params);
+    }
+
     private String getPaperTypeIds(List<PaperInfoVo> paperInfoVoList, String oldPaperType) {
         PaperInfoVo paperInfoVo = paperInfoVoList.stream().filter(m -> m.getName().equals(oldPaperType)).findFirst().get();
         paperInfoVo.setName(oldPaperType);

+ 42 - 2
distributed-print/src/main/java/com/qmth/distributed/print/upgrade/DataUpgrade_3_4_4.java

@@ -7,11 +7,13 @@ import com.qmth.boot.data.upgrade.utils.ResourceFileHelper;
 import com.qmth.distributed.print.business.entity.ExamCard;
 import com.qmth.distributed.print.business.entity.ExamCardModelFour;
 import com.qmth.teachcloud.common.bean.dto.mark.PictureConfig;
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
 import com.qmth.teachcloud.common.entity.BasicExam;
 import com.qmth.teachcloud.common.entity.MarkQuestion;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExamModelEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.mark.dto.mark.MarkPaperFileDto;
 import com.qmth.teachcloud.mark.dto.mark.MarkQuestionAnswerVo;
 import com.qmth.teachcloud.mark.dto.mark.manage.MarkerScoreDTO;
 import com.qmth.teachcloud.mark.dto.mark.manage.TaskQuestion;
@@ -62,7 +64,7 @@ public class DataUpgrade_3_4_4 implements DataUpgradeService {
         log.info("结束处理3.4.3历史数据,更新脚本1;时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
 
         log.info("开始处理3.4.3历史数据,数据归档;时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
-//         执行历史数据归档
+        // 执行历史数据归档
         this.execDataArchive(jdbcTemplate);
         log.info("结束处理3.4.3历史数据,数据归档;时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
 
@@ -126,9 +128,40 @@ public class DataUpgrade_3_4_4 implements DataUpgradeService {
                 this.updateMarkPaperArchive(jdbcTemplate, markPaper.getId());
             }
             log.info("1.1.2结束更新课程归档状态:[" + basicExam.getName() + "],试卷编号:[" + paperNumber + "];时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
+
+            log.info("1.1.3开始更新试卷、答案文件存储json结构状态:[" + basicExam.getName() + "],试卷编号:[" + paperNumber + "];时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
+            this.parseMarkPaperAndAnswerFilePath(jdbcTemplate, markPaper);
+            log.info("1.1.3结束更试卷、答案文件存储json结构状态:[" + basicExam.getName() + "],试卷编号:[" + paperNumber + "];时间:" + DateFormatUtils.format(new Date(), DATE_PATTERN));
         }
     }
 
+    private void parseMarkPaperAndAnswerFilePath(JdbcTemplate jdbcTemplate, MarkPaper markPaper) {
+        String[] paperTypes = markPaper.getPaperTypeList().toArray(new String[0]);
+        if (StringUtils.isNotBlank(markPaper.getPaperFilePath())) {
+            List<MarkPaperFileDto> subjectivePaperFileDtoList = new ArrayList<>();
+            List<FilePathVo> paperFilePathList = JSON.parseArray(markPaper.getPaperFilePath(), FilePathVo.class);
+            for (int i = 0; i < paperFilePathList.size(); i++) {
+                MarkPaperFileDto subjectiveAnswerFileDto = new MarkPaperFileDto();
+                subjectiveAnswerFileDto.setPaperType(paperTypes[i]);
+                subjectiveAnswerFileDto.setFilePathVo(paperFilePathList.get(i));
+                subjectivePaperFileDtoList.add(subjectiveAnswerFileDto);
+            }
+            markPaper.setPaperFilePath(JSON.toJSONString(subjectivePaperFileDtoList));
+        }
+
+        if (StringUtils.isNotBlank(markPaper.getAnswerFilePath())) {
+            List<MarkPaperFileDto> subjectiveAnswerFileDtoList = new ArrayList<>();
+            FilePathVo answerFilePath = JSON.parseObject(markPaper.getAnswerFilePath(), FilePathVo.class);
+            MarkPaperFileDto subjectiveAnswerFileDto = new MarkPaperFileDto();
+            subjectiveAnswerFileDto.setPaperType(paperTypes[0]);
+            subjectiveAnswerFileDto.setFilePathVo(answerFilePath);
+            subjectiveAnswerFileDtoList.add(subjectiveAnswerFileDto);
+            markPaper.setAnswerFilePath(JSON.toJSONString(subjectiveAnswerFileDtoList));
+        }
+
+        this.updateMarkPaperAndAnswerFilePath(jdbcTemplate, markPaper);
+    }
+
     /**
      * 电子卡格式信息
      */
@@ -138,7 +171,7 @@ public class DataUpgrade_3_4_4 implements DataUpgradeService {
             return null;
         }
         String md5 = this.md5String(cardContent);
-        if(md5Set.contains(md5)){
+        if (md5Set.contains(md5)) {
             return md5;
         }
         int count = this.getMarkArchiveStudentCard(jdbcTemplate, md5);
@@ -215,6 +248,7 @@ public class DataUpgrade_3_4_4 implements DataUpgradeService {
             String answer = answerCount > i ? answers.get(i) : "#";
             String answerScore = answerScoreCount > i ? answerScores.get(i) : "0";
             StudentObjectiveAnswerDto studentObjectiveAnswerDto = new StudentObjectiveAnswerDto();
+            studentObjectiveAnswerDto.setTitle(q != null ? q.getMainTitle() : null);
             studentObjectiveAnswerDto.setMainNumber(q != null ? q.getMainNumber() : 0);
             studentObjectiveAnswerDto.setSubNumber(q != null ? q.getSubNumber() : 0);
             studentObjectiveAnswerDto.setStandardAnswer(q != null ? q.getAnswer() : null);
@@ -675,4 +709,10 @@ public class DataUpgrade_3_4_4 implements DataUpgradeService {
         });
         return Arrays.stream(ints).mapToLong(m -> m).sum();
     }
+
+    private int updateMarkPaperAndAnswerFilePath(JdbcTemplate jdbcTemplate, MarkPaper markPaper) {
+        String sql = "update mark_paper set paper_file_path = ?, answer_file_path = ? where id = ?";
+        Object[] params = new Object[]{markPaper.getPaperFilePath(), markPaper.getAnswerFilePath(), markPaper.getId()};
+        return this.update(jdbcTemplate, sql, params);
+    }
 }

+ 2 - 1
distributed-print/src/main/resources/upgrade/3.4.4-upgrade-1.sql

@@ -14,7 +14,8 @@ CREATE TABLE `mark_archive_student`
     `objective_questions`  MEDIUMTEXT NULL,
     `archive_card_id`      VARCHAR(50) NULL,
     `create_time`          BIGINT(20) NULL,
-    PRIMARY KEY (`student_id`)
+    PRIMARY KEY (`student_id`),
+    INDEX `idx_student_id` (`student_id` ASC)
 ) COMMENT = '考生归档数据表';
 
 

+ 9 - 0
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/dto/mark/score/StudentObjectiveAnswerDto.java

@@ -2,6 +2,7 @@ package com.qmth.teachcloud.mark.dto.mark.score;
 
 public class StudentObjectiveAnswerDto {
 
+    private String title;
     private Integer mainNumber;
     private Integer subNumber;
     // 标答
@@ -12,6 +13,14 @@ public class StudentObjectiveAnswerDto {
     private Boolean exist;
     private Integer questionType;
 
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
     public Integer getMainNumber() {
         return mainNumber;
     }

+ 6 - 0
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/MarkArchiveStudentService.java

@@ -1,8 +1,11 @@
 package com.qmth.teachcloud.mark.service;
 
+import com.qmth.teachcloud.mark.dto.mark.manage.TaskQuestion;
 import com.qmth.teachcloud.mark.entity.MarkArchiveStudent;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  * 考生归档数据表 服务类
@@ -13,4 +16,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface MarkArchiveStudentService extends IService<MarkArchiveStudent> {
 
+    List<MarkArchiveStudent> listByStudentIds(List<Long> studentIds);
+
+    List<TaskQuestion> listTaskQuestionByStudentIds(List<Long> studentIds);
 }

+ 2 - 1
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/MarkSubjectiveScoreService.java

@@ -3,6 +3,7 @@ package com.qmth.teachcloud.mark.service;
 import com.github.jeffreyning.mybatisplus.service.IMppService;
 import com.qmth.teachcloud.mark.bean.archivescore.QuestionVo;
 import com.qmth.teachcloud.mark.bean.dto.MarkAreaDto;
+import com.qmth.teachcloud.mark.entity.MarkPaper;
 import com.qmth.teachcloud.mark.entity.MarkSubjectiveScore;
 
 import java.util.List;
@@ -26,7 +27,7 @@ public interface MarkSubjectiveScoreService extends IMppService<MarkSubjectiveSc
 
     void deleteByStudentId(Long studentId);
 
-    List<QuestionVo> getSubjectiveVo(List<Long> studentIds);
+    List<QuestionVo> getSubjectiveVo(MarkPaper markPaper, List<Long> studentIds);
 
     List<MarkSubjectiveScore> listByStudentId(Long studentId);
 

+ 25 - 0
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkArchiveStudentServiceImpl.java

@@ -1,11 +1,20 @@
 package com.qmth.teachcloud.mark.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.mark.dto.mark.manage.TaskQuestion;
 import com.qmth.teachcloud.mark.entity.MarkArchiveStudent;
 import com.qmth.teachcloud.mark.mapper.MarkArchiveStudentMapper;
 import com.qmth.teachcloud.mark.service.MarkArchiveStudentService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  * 考生归档数据表 服务实现类
@@ -17,4 +26,20 @@ import org.springframework.stereotype.Service;
 @Service
 public class MarkArchiveStudentServiceImpl extends ServiceImpl<MarkArchiveStudentMapper, MarkArchiveStudent> implements MarkArchiveStudentService {
 
+    @Override
+    public List<MarkArchiveStudent> listByStudentIds(List<Long> studentIds) {
+        QueryWrapper<MarkArchiveStudent> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().in(MarkArchiveStudent::getStudentId, studentIds);
+        return this.list(queryWrapper);
+    }
+
+    @Override
+    public List<TaskQuestion> listTaskQuestionByStudentIds(List<Long> studentIds) {
+        List<MarkArchiveStudent> markArchiveStudents = this.listByStudentIds(studentIds);
+        List<TaskQuestion> taskQuestions = markArchiveStudents.stream()
+                .filter(m -> StringUtils.isNotBlank(m.getSubjectiveQuestions()))
+                .map(m -> JSON.parseArray(m.getSubjectiveQuestions(), TaskQuestion.class))
+                .flatMap(List::stream).collect(Collectors.toList());
+        return taskQuestions;
+    }
 }

+ 64 - 17
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkStudentServiceImpl.java

@@ -18,6 +18,7 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.NotNull;
 
+import com.qmth.teachcloud.mark.dto.mark.manage.TaskQuestion;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -157,7 +158,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     private BasicCourseService basicCourseService;
 
     @Resource
-    CommonCacheService commonCacheService;
+    MarkArchiveStudentService markArchiveStudentService;
 
     @Autowired
     private MarkHeaderHistoryService markHeaderHistoryService;
@@ -1468,6 +1469,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         String postUrl = "/api/admin/mark/archive/score/list";
         DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(), sysUser.getId(), postUrl);
+        MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(query.getExamId(), query.getPaperNumber());
         ScoreReportVo ret = new ScoreReportVo();
         // 考试概况
         ret.setOverview(baseMapper.overview(sysUser.getSchoolId(), query, dpr));
@@ -1543,7 +1545,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
 
         // 主观题成绩分析
         List<Long> studentIds = studentList.stream().map(ArchiveStudentVo::getStudentId).collect(Collectors.toList());
-        ret.setSubjective(markSubjectiveScoreService.getSubjectiveVo(studentIds));
+        ret.setSubjective(markSubjectiveScoreService.getSubjectiveVo(markPaper, studentIds));
         if (CollectionUtils.isNotEmpty(ret.getSubjective())) {
             for (QuestionVo vo : ret.getSubjective()) {
                 double total = vo.getStudentCount();
@@ -1554,7 +1556,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         }
 
         // 大题分析
-        fillMainQuestionAnalysis(ret, studentList, query.getExamId(), query.getPaperNumber());
+        fillMainQuestionAnalysis(ret, markPaper, studentList, query.getExamId(), query.getPaperNumber());
         return ret;
     }
 
@@ -1786,16 +1788,71 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
      * 填充大题分析
      *
      * @param ret         ret
+     * @param markPaper
      * @param studentList 涉及的考生集合
      * @param examId      考试id
      * @param paperNumber 试卷编号
      */
-    private void fillMainQuestionAnalysis(ScoreReportVo ret, List<ArchiveStudentVo> studentList, Long
-            examId, String paperNumber) {
+    private void fillMainQuestionAnalysis(ScoreReportVo ret, MarkPaper markPaper, List<ArchiveStudentVo> studentList, Long examId, String paperNumber) {
+        studentList = studentList.stream().filter(e -> !BasicExamStudentStatusEnum.M.equals(e.getStatus())).collect(Collectors.toList());
+        List<Long> studentIdList = studentList.stream().map(ArchiveStudentVo::getStudentId).distinct().collect(Collectors.toList());
+        Map<String, Double> studentMainNumberScoreMap = new HashMap<>();
+        List<MarkQuestion> questionDatasource = new ArrayList<>();
+        if (markPaper.getArchive()) {
+            List<MarkArchiveStudent> markArchiveStudents = new ArrayList<>();
+            if (CollectionUtils.isNotEmpty(studentIdList)) {
+                markArchiveStudents = markArchiveStudentService.listByStudentIds(studentIdList);
+            }
+            if(CollectionUtils.isNotEmpty(markArchiveStudents)) {
+                for (MarkArchiveStudent markArchiveStudent : markArchiveStudents) {
+                    List<TaskQuestion> taskQuestionList = JSON.parseArray(markArchiveStudent.getSubjectiveQuestions(), TaskQuestion.class);
+                    Map<Integer, Double> listMap = taskQuestionList.stream().collect(Collectors.groupingBy(m -> m.getMainNumber(), Collectors.summingDouble(n -> n.getMarkerScore())));
+                    for (Map.Entry<Integer, Double> entry : listMap.entrySet()) {
+                        studentMainNumberScoreMap.put(markArchiveStudent.getStudentId() + "-" + entry.getKey(), entry.getValue());
+                    }
+                }
+                MarkArchiveStudent markArchiveStudent = markArchiveStudents.get(0);
+                if(markArchiveStudent!= null) {
+                    if(StringUtils.isNotBlank(markArchiveStudent.getObjectiveQuestions())) {
+                        List<StudentObjectiveAnswerDto> taskQuestions = JSON.parseArray(markArchiveStudent.getObjectiveQuestions(), StudentObjectiveAnswerDto.class);
+                        for (StudentObjectiveAnswerDto taskQuestion : taskQuestions) {
+                            MarkQuestion markQuestion = new MarkQuestion();
+                            markQuestion.setMainTitle(taskQuestion.getTitle());
+                            markQuestion.setMainNumber(taskQuestion.getMainNumber());
+                            markQuestion.setSubNumber(taskQuestion.getSubNumber());
+                            markQuestion.setTotalScore(taskQuestion.getTotalScore());
+                            markQuestion.setObjective(true);
+                            questionDatasource.add(markQuestion);
+                        }
+                    }
+                    if(StringUtils.isNotBlank(markArchiveStudent.getSubjectiveQuestions())) {
+                        List<TaskQuestion> taskQuestions = JSON.parseArray(markArchiveStudent.getSubjectiveQuestions(), TaskQuestion.class);
+                        for (TaskQuestion taskQuestion : taskQuestions) {
+                            MarkQuestion markQuestion = new MarkQuestion();
+                            markQuestion.setMainTitle(taskQuestion.getTitle());
+                            markQuestion.setMainNumber(taskQuestion.getMainNumber());
+                            markQuestion.setSubNumber(taskQuestion.getSubNumber());
+                            markQuestion.setTotalScore(taskQuestion.getMaxScore());
+                            markQuestion.setObjective(false);
+                            questionDatasource.add(markQuestion);
+                        }
+                    }
+                }
+            }
+        } else {
+            List<MarkSubjectiveScore> subjectiveScoreDatasource = new ArrayList<>();
+            if (CollectionUtils.isNotEmpty(studentIdList)) {
+                subjectiveScoreDatasource = markSubjectiveScoreService.list(
+                        new QueryWrapper<MarkSubjectiveScore>().lambda().eq(MarkSubjectiveScore::getExamId, examId)
+                                .eq(MarkSubjectiveScore::getPaperNumber, paperNumber).in(MarkSubjectiveScore::getStudentId, studentIdList));
+            }
+
+            studentMainNumberScoreMap = subjectiveScoreDatasource.stream().collect(Collectors.groupingBy(m -> m.getStudentId() + "-" + m.getMainNumber(), Collectors.summingDouble(n -> n.getScore())));
+            questionDatasource = markQuestionService.listByExamIdAndPaperNumber(examId, paperNumber);
+        }
+
         // 试卷结构数据
         Map<String, QuestionVo> mainQuestionMap = new HashMap<>();
-
-        List<MarkQuestion> questionDatasource = markQuestionService.listByExamIdAndPaperNumber(examId, paperNumber);
         for (MarkQuestion question : questionDatasource) {
             Integer mainNumber = question.getMainNumber();
             String key = getMainQuestionMapKey(mainNumber, question.getObjective());
@@ -1817,16 +1874,6 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
                 mainQuestionMap.put(key, questionVo);
             }
         }
-        studentList = studentList.stream().filter(e -> !BasicExamStudentStatusEnum.M.equals(e.getStatus())).collect(Collectors.toList());
-        List<Long> studentIdList = studentList.stream().map(ArchiveStudentVo::getStudentId).distinct().collect(Collectors.toList());
-        List<MarkSubjectiveScore> subjectiveScoreDatasource = new ArrayList<>();
-        if (CollectionUtils.isNotEmpty(studentIdList)) {
-            subjectiveScoreDatasource = markSubjectiveScoreService.list(
-                    new QueryWrapper<MarkSubjectiveScore>().lambda().eq(MarkSubjectiveScore::getExamId, examId)
-                            .eq(MarkSubjectiveScore::getPaperNumber, paperNumber).in(MarkSubjectiveScore::getStudentId, studentIdList));
-        }
-
-        Map<String, Double> studentMainNumberScoreMap = subjectiveScoreDatasource.stream().collect(Collectors.groupingBy(m -> m.getStudentId() + "-" + m.getMainNumber(), Collectors.summingDouble(n -> n.getScore())));
 
         List<MarkQuestion> objectiveQuestions = questionDatasource.stream().filter(MarkQuestion::getObjective).collect(Collectors.toList());
         for (ArchiveStudentVo studentVo : studentList) {

+ 45 - 6
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkSubjectiveScoreServiceImpl.java

@@ -1,20 +1,30 @@
 package com.qmth.teachcloud.mark.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.Update;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.mark.bean.archivescore.QuestionVo;
 import com.qmth.teachcloud.mark.bean.dto.MarkAreaDto;
+import com.qmth.teachcloud.mark.dto.mark.manage.Task;
+import com.qmth.teachcloud.mark.dto.mark.manage.TaskQuestion;
+import com.qmth.teachcloud.mark.entity.MarkArchiveStudent;
+import com.qmth.teachcloud.mark.entity.MarkPaper;
 import com.qmth.teachcloud.mark.entity.MarkSubjectiveScore;
 import com.qmth.teachcloud.mark.mapper.MarkSubjectiveScoreMapper;
+import com.qmth.teachcloud.mark.service.MarkArchiveStudentService;
 import com.qmth.teachcloud.mark.service.MarkSubjectiveScoreService;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.tomcat.util.security.Escape;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestMapping;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -27,6 +37,9 @@ import java.util.Set;
 @Service
 public class MarkSubjectiveScoreServiceImpl extends MppServiceImpl<MarkSubjectiveScoreMapper, MarkSubjectiveScore> implements MarkSubjectiveScoreService {
 
+    @Resource
+    private MarkArchiveStudentService markArchiveStudentService;
+
     @Override
     public MarkSubjectiveScore getByStudentIdAndQuestionId(Long studentId, Long questionId) {
         QueryWrapper<MarkSubjectiveScore> queryWrapper = new QueryWrapper<>();
@@ -62,11 +75,37 @@ public class MarkSubjectiveScoreServiceImpl extends MppServiceImpl<MarkSubjectiv
     }
 
     @Override
-    public List<QuestionVo> getSubjectiveVo(List<Long> studentIds) {
+    public List<QuestionVo> getSubjectiveVo(MarkPaper markPaper, List<Long> studentIds) {
         if (CollectionUtils.isEmpty(studentIds)) {
             return null;
         }
-        return this.baseMapper.getSubjectiveVo(studentIds);
+        if (markPaper.getArchive()) {
+            List<TaskQuestion> taskQuestionList = markArchiveStudentService.listTaskQuestionByStudentIds(studentIds);
+            Map<String, List<TaskQuestion>> taskQuestions = taskQuestionList.stream().collect(Collectors.groupingBy(m -> m.getMainNumber() + SystemConstant.DEFAULT_SIGN + m.getSubNumber()));
+            List<QuestionVo> questionVos = new ArrayList<>();
+            for (Map.Entry<String, List<TaskQuestion>> entry : taskQuestions.entrySet()) {
+                String[] keys = entry.getKey().split(SystemConstant.DEFAULT_SIGN);
+                List<TaskQuestion> valueList = entry.getValue();
+                TaskQuestion taskQuestion = valueList.get(0);
+                QuestionVo questionVo = new QuestionVo();
+                questionVo.setTitle(taskQuestion.getTitle());
+                questionVo.setMainNumber(Integer.valueOf(keys[0]));
+                questionVo.setSubNumber(Integer.valueOf(keys[1]));
+                questionVo.setScore(taskQuestion.getMaxScore());
+                questionVo.setStudentCount(valueList.size());
+                Double collect = valueList.stream().collect(Collectors.averagingDouble(TaskQuestion::getMarkerScore));
+                questionVo.setAvgScore(collect);
+                long count = valueList.stream().filter(m -> m.getMarkerScore() > 0).count();
+                questionVo.setScoreCount(Math.toIntExact(count));
+                long fullCount = valueList.stream().filter(m -> m.getMarkerScore() - m.getMaxScore() == 0).count();
+                questionVo.setFullScoreCount(Math.toIntExact(fullCount));
+                questionVos.add(questionVo);
+            }
+            return questionVos;
+
+        } else {
+            return this.baseMapper.getSubjectiveVo(studentIds);
+        }
     }
 
     @Override