Эх сурвалжийг харах

3.3.0 二次识别换卡格式、重新绑定、重新扫描后删除评卷任务

yin 1 жил өмнө
parent
commit
0b36b1b597

+ 8 - 8
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/ScanStudentPaperService.java

@@ -9,7 +9,7 @@ import com.qmth.teachcloud.mark.entity.ScanStudentPaper;
 
 /**
  * <p>
- *  服务类
+ * 服务类
  * </p>
  *
  * @author xf
@@ -17,16 +17,16 @@ import com.qmth.teachcloud.mark.entity.ScanStudentPaper;
  */
 public interface ScanStudentPaperService extends IService<ScanStudentPaper> {
 
-	List<ScanStudentPaper> findByStudentId(Long studentId);
+    List<ScanStudentPaper> findByStudentId(Long studentId);
 
-	ScanStudentPaper findByPaperId(Long paperId);
+    ScanStudentPaper findByPaperId(Long paperId);
 
-	void removeByStudentId(@NotNull Long studentId);
-	
-	void removeByStudentIdAndPaperId(@NotNull Long studentId,@NotNull Long paperId);
+    int removeByStudentId(@NotNull Long studentId);
 
-	ScanStudentPaper findByStudentIdAndPaperNumber(Long studentId, Integer number);
+    void removeByStudentIdAndPaperId(@NotNull Long studentId, @NotNull Long paperId);
 
-	List<ScanStudentPaper> findByPaperIds(List<Long> paperIds);
+    ScanStudentPaper findByStudentIdAndPaperNumber(Long studentId, Integer number);
+
+    List<ScanStudentPaper> findByPaperIds(List<Long> paperIds);
 
 }

+ 139 - 92
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkStudentServiceImpl.java

@@ -1,5 +1,22 @@
 package com.qmth.teachcloud.mark.service.impl;
 
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.text.DecimalFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.constraints.NotNull;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.FileCopyUtils;
+
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -52,21 +69,6 @@ import com.qmth.teachcloud.mark.service.*;
 import com.qmth.teachcloud.mark.utils.BatchGetDataUtil;
 import com.qmth.teachcloud.mark.utils.Calculator;
 import com.qmth.teachcloud.mark.utils.ScoreCalculateUtil;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.FileCopyUtils;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletResponse;
-import javax.validation.constraints.NotNull;
-import java.io.File;
-import java.nio.charset.StandardCharsets;
-import java.text.DecimalFormat;
-import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -78,39 +80,55 @@ import java.util.stream.Collectors;
  */
 @Service
 public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkStudent> implements MarkStudentService {
+
     @Autowired
     private MarkPaperService markPaperService;
+
     @Resource
     private MarkPaperPackageService markPaperPackageService;
+
     @Autowired
     private ScanPackageService scanPackageService;
+
     @Autowired
     private ScanPaperService scanPaperService;
+
     @Autowired
     private ScanPaperPageService scanPaperPageService;
+
     @Autowired
     private ScanOmrTaskService scanOmrTaskService;
+
     @Autowired
     private ScanAnswerCardService answerCardService;
+
     @Autowired
     private ScanStudentPaperService studentPaperService;
+
     @Resource
     private MarkQuestionService markQuestionService;
+
     @Resource
     private TeachcloudCommonService teachcloudCommonService;
+
     @Autowired
     private ConcurrentService concurrentService;
+
     @Resource
     private MarkService markService;
+
     @Resource
     private LockService lockService;
+
     @Resource
     private TaskService taskService;
+
     @Resource
     private BasicRoleDataPermissionService basicRoleDataPermissionService;
 
     @Autowired
     private MarkSubjectiveScoreService markSubjectiveScoreService;
+
     @Resource
     private MarkSyncService markSyncService;
 
@@ -130,17 +148,16 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
 
     @Override
     public void updateSubjectiveStatusAndScore(Long studentId, SubjectiveStatus status, Double score,
-                                               String scoreList) {
+            String scoreList) {
         UpdateWrapper<MarkStudent> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.lambda().set(MarkStudent::getSubjectiveStatus, status)
-                .set(MarkStudent::getSubjectiveScore, score)
+        updateWrapper.lambda().set(MarkStudent::getSubjectiveStatus, status).set(MarkStudent::getSubjectiveScore, score)
                 .set(MarkStudent::getSubjectiveScoreList, scoreList).eq(MarkStudent::getId, studentId);
         this.update(updateWrapper);
     }
 
     @Override
     public void updateSubjectiveStatusAndScore(Long examId, String paperNumber, SubjectiveStatus status, double score,
-                                               String scoreList) {
+            String scoreList) {
         UpdateWrapper<MarkStudent> updateWrapper = new UpdateWrapper<>();
         updateWrapper.lambda().set(MarkStudent::getSubjectiveStatus, status).set(MarkStudent::getSubjectiveScore, score)
                 .set(MarkStudent::getSubjectiveScoreList, scoreList).eq(MarkStudent::getExamId, examId)
@@ -151,24 +168,31 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public ScanExamInfoVo getScanExamInfo(BasicExam exam, String courseCode, String coursePaperId) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(), sysUser.getId(), ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(),
+                sysUser.getId(), ServletUtil.getRequest().getServletPath());
         ScanExamInfoVo vo = new ScanExamInfoVo();
         vo.setId(exam.getId());
         vo.setName(exam.getName());
-        vo.getAnswerScan().setCourseCount(markPaperService.getCourseCount(exam.getId(), courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        vo.getAnswerScan().setPaperNumberCount(markPaperService.getPaperNumberCount(exam.getId(), courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        vo.getAnswerScan().setTotalCount(getCount(exam.getId(), null, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        vo.getAnswerScan().setScannedCount(getCount(exam.getId(), ScanStatus.SCANNED, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        vo.getPackageScan().setTotalCount(markPaperPackageService.getPackageCountByExamId(exam.getId(), courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        vo.getPackageScan().setScannedCount(scanPackageService.getCount(exam.getId(), courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        vo.getAnswerScan().setCourseCount(
+                markPaperService.getCourseCount(exam.getId(), courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        vo.getAnswerScan().setPaperNumberCount(markPaperService.getPaperNumberCount(exam.getId(), courseCode,
+                coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        vo.getAnswerScan()
+                .setTotalCount(getCount(exam.getId(), null, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        vo.getAnswerScan().setScannedCount(
+                getCount(exam.getId(), ScanStatus.SCANNED, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        vo.getPackageScan().setTotalCount(markPaperPackageService.getPackageCountByExamId(exam.getId(), courseCode,
+                coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        vo.getPackageScan().setScannedCount(
+                scanPackageService.getCount(exam.getId(), courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
         return vo;
     }
 
     @Override
     public IPage<StudentScoreDetailDto> pageStudentScore(Long examId, String paperNumber, String college,
-                                                         String className, String teacher, Integer filter, Boolean absent, Boolean breach, Double startScore,
-                                                         Double endScore, Double subScore, Integer objectiveScoreRateLt, String studentName, String studentCode,
-                                                         String orderType, String orderField, Integer pageNumber, Integer pageSize) {
+            String className, String teacher, Integer filter, Boolean absent, Boolean breach, Double startScore,
+            Double endScore, Double subScore, Integer objectiveScoreRateLt, String studentName, String studentCode,
+            String orderType, String orderField, Integer pageNumber, Integer pageSize) {
         if (startScore != null && endScore == null) {
             throw ExceptionResultEnum.ERROR.exception("请输入结束分数值");
         }
@@ -176,7 +200,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
         Double objectiveScoreLt = objectiveScoreRateLt == null ? null
                 : Double.parseDouble(new DecimalFormat("####.##")
-                .format(markPaper.getObjectiveScore() * objectiveScoreRateLt / 100));
+                        .format(markPaper.getObjectiveScore() * objectiveScoreRateLt / 100));
         IPage<StudentScoreDetailDto> studentScoreDetailDtoIPage = this.baseMapper.pageStudentScore(page, examId,
                 paperNumber, college, className, teacher, filter, absent, breach, startScore, endScore, subScore,
                 objectiveScoreLt, studentName, studentCode, orderType, orderField);
@@ -202,7 +226,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         return sheetUrls;
     }
 
-    private int getCount(Long examId, ScanStatus status, String courseCode, String coursePaperId, MarkPaperStatus markPaperStatus, DataPermissionRule dpr) {
+    private int getCount(Long examId, ScanStatus status, String courseCode, String coursePaperId,
+            MarkPaperStatus markPaperStatus, DataPermissionRule dpr) {
         MarkStudent markStudent = new MarkStudent();
         markStudent.setExamId(examId);
         markStudent.setCourseCode(courseCode);
@@ -212,7 +237,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         return baseMapper.selectCountByQuery(markStudent, dpr);
     }
 
-    private int getOmrAbsentCount(Long examId, Boolean checked, String courseCode, String coursePaperId, MarkPaperStatus status, DataPermissionRule dpr) {
+    private int getOmrAbsentCount(Long examId, Boolean checked, String courseCode, String coursePaperId,
+            MarkPaperStatus status, DataPermissionRule dpr) {
         MarkStudent markStudent = new MarkStudent();
         markStudent.setExamId(examId);
         markStudent.setCourseCode(courseCode);
@@ -223,7 +249,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         return baseMapper.selectCountByQuery(markStudent, dpr);
     }
 
-    private int getIncompleteCount(Long examId, String courseCode, String coursePaperId, MarkPaperStatus status, DataPermissionRule dpr) {
+    private int getIncompleteCount(Long examId, String courseCode, String coursePaperId, MarkPaperStatus status,
+            DataPermissionRule dpr) {
         MarkStudent markStudent = new MarkStudent();
         markStudent.setExamId(examId);
         markStudent.setCourseCode(courseCode);
@@ -236,20 +263,28 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public ScanExamCheckInfoVo checkInfo(BasicExam exam, String courseCode, String coursePaperId) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(), sysUser.getId(), ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(),
+                sysUser.getId(), ServletUtil.getRequest().getServletPath());
         Long examId = exam.getId();
         ScanExamCheckInfoVo vo = new ScanExamCheckInfoVo();
         vo.setId(exam.getId());
         vo.setName(exam.getName());
         CheckTask ct = vo.getCheckTask();
-        ct.setUnexistCount(getCount(examId, ScanStatus.UNEXIST, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        ct.setUnexistCheckedCount(getCount(examId, ScanStatus.MANUAL_ABSENT, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        ct.setUnexistCount(
+                getCount(examId, ScanStatus.UNEXIST, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        ct.setUnexistCheckedCount(
+                getCount(examId, ScanStatus.MANUAL_ABSENT, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
         ct.setAssignedCount(getAssignedCount(examId, false, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        ct.setAssignedCheckedCount(getAssignedCount(examId, true, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        ct.setAbsentCheckCount(getOmrAbsentCount(examId, false, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        ct.setAbsentCheckedCount(getOmrAbsentCount(examId, true, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        ct.setObjectiveCheckCount(scanOmrTaskService.getCount(examId, OmrTaskStatus.WAITING, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
-        ct.setObjectiveCheckedCount(scanOmrTaskService.getCount(examId, OmrTaskStatus.PROCESSED, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        ct.setAssignedCheckedCount(
+                getAssignedCount(examId, true, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        ct.setAbsentCheckCount(
+                getOmrAbsentCount(examId, false, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        ct.setAbsentCheckedCount(
+                getOmrAbsentCount(examId, true, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
+        ct.setObjectiveCheckCount(scanOmrTaskService.getCount(examId, OmrTaskStatus.WAITING, courseCode, coursePaperId,
+                MarkPaperStatus.FORMAL, dpr));
+        ct.setObjectiveCheckedCount(scanOmrTaskService.getCount(examId, OmrTaskStatus.PROCESSED, courseCode,
+                coursePaperId, MarkPaperStatus.FORMAL, dpr));
         ct.setIncompleteCount(getIncompleteCount(examId, courseCode, coursePaperId, MarkPaperStatus.FORMAL, dpr));
         return vo;
     }
@@ -268,7 +303,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         student.setIncomplete(false);
         student.setAssigned(false);
         student.setQuestionFilled(false);
-//        student.setOmrAbsent(false);
+        // student.setOmrAbsent(false);
         int paperCount = 0;
         List<ScanStudentPaper> studentPaperList = studentPaperService.findByStudentId(studentId);
         List<String> objectiveAnswers = new ArrayList<>();
@@ -284,12 +319,13 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
                 // 根据识别结果更新考生属性
                 ScanPaperPage page = scanPaperPageService.findPaperIdAndIndex(paper.getId(), 1);
                 student.setOmrAbsent(page.getAbsent() == null ? false : page.getAbsent().getResult());
-//                student.setDevice(batchService.findByPaperId(paper.getId()).getDevice());
+                // student.setDevice(batchService.findByPaperId(paper.getId()).getDevice());
             }
 
             List<ScanPaperPage> scanPaperPages = scanPaperPageService.listByPaperId(studentPaper.getPaperId());
             for (ScanPaperPage scanPaperPage : scanPaperPages) {
-                if (scanPaperPage.getQuestion() != null && CollectionUtils.isNotEmpty(scanPaperPage.getQuestion().getResult())) {
+                if (scanPaperPage.getQuestion() != null
+                        && CollectionUtils.isNotEmpty(scanPaperPage.getQuestion().getResult())) {
                     for (String s : scanPaperPage.getQuestion().getResult()) {
                         if (s.startsWith("?")) {
                             s = s.replace("?", "");
@@ -312,8 +348,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         } else {
             student.setScanStatus(ScanStatus.UNEXIST);
         }
-//        student.setUpdaterId(userId);
-//        student.setUpdateTime(System.currentTimeMillis());
+        // student.setUpdaterId(userId);
+        // student.setUpdateTime(System.currentTimeMillis());
         this.saveOrUpdate(student);
         // 客观题统分
         this.calculateObjectiveScore(student);
@@ -348,7 +384,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     }
 
     @Override
-    public MarkStudent findByExamIdAndCoursePaperIdAndStudentCode(Long examId, String coursePaperId, String studentCode) {
+    public MarkStudent findByExamIdAndCoursePaperIdAndStudentCode(Long examId, String coursePaperId,
+            String studentCode) {
         QueryWrapper<MarkStudent> wrapper = new QueryWrapper<>();
         LambdaQueryWrapper<MarkStudent> lw = wrapper.lambda();
         lw.eq(MarkStudent::getExamId, examId);
@@ -443,11 +480,9 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     public boolean updateScanInfo(MarkStudent student) {
         UpdateWrapper<MarkStudent> updateWrapper = new UpdateWrapper<>();
         updateWrapper.lambda().set(MarkStudent::getAnswers, student.getAnswers())
-                .set(MarkStudent::getBatchCode, student.getBatchCode())
-                .set(MarkStudent::getAbsent, student.getAbsent())
+                .set(MarkStudent::getBatchCode, student.getBatchCode()).set(MarkStudent::getAbsent, student.getAbsent())
                 .set(MarkStudent::getUploadTime, System.currentTimeMillis())
-                .set(MarkStudent::getCardNumber, student.getCardNumber())
-                .eq(MarkStudent::getId, student.getId());
+                .set(MarkStudent::getCardNumber, student.getCardNumber()).eq(MarkStudent::getId, student.getId());
         return this.update(updateWrapper);
 
     }
@@ -514,14 +549,18 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     @Transactional
     public void updateStudentAndPaper(@NotNull SysUser user, @NotNull Long id,
-                                      @NotNull List<ScanStudentPaper> studentPaperList) {
+            @NotNull List<ScanStudentPaper> studentPaperList) {
         if (CollectionUtils.isNotEmpty(studentPaperList)) {
             for (ScanStudentPaper studentPaper : studentPaperList) {
                 studentPaper.setStudentId(id);
             }
         }
         // 清空原有绑定关系
-        studentPaperService.removeByStudentId(id);
+        if (studentPaperService.removeByStudentId(id) > 0) {
+            // 删除评卷任务
+            MarkStudent student = this.getById(id);
+            markService.deleteMarkTaskByStudent(student);
+        }
         if (CollectionUtils.isNotEmpty(studentPaperList)) {
             // 保存绑定关系
             studentPaperService.saveOrUpdateBatch(studentPaperList);
@@ -552,10 +591,12 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public IPage<AnswerQueryVo> query(AnswerQueryDomain query) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(), sysUser.getId(), ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(),
+                sysUser.getId(), ServletUtil.getRequest().getServletPath());
         // 查询考生分页信息
         query.setMarkPaperStatus(MarkPaperStatus.FORMAL.name());
-        IPage<AnswerQueryVo> iPage = baseMapper.queryPage(new Page<>(query.getPageNumber(), query.getPageSize()), query, dpr);
+        IPage<AnswerQueryVo> iPage = baseMapper.queryPage(new Page<>(query.getPageNumber(), query.getPageSize()), query,
+                dpr);
         if (CollectionUtils.isNotEmpty(iPage.getRecords())) {
             for (AnswerQueryVo vo : iPage.getRecords()) {
                 if (vo.getIsAbsent() != null && vo.getIsAbsent()) {
@@ -651,7 +692,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public List<String> summary(AnswerQueryDomain query) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(), sysUser.getId(), ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(),
+                sysUser.getId(), ServletUtil.getRequest().getServletPath());
 
         // 不分页查询考生准考证号
         query.setMarkPaperStatus(MarkPaperStatus.FORMAL.name());
@@ -661,7 +703,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Transactional
     @Override
     public UpdateTimeVo omrEdit(Long userId, OmrEditDomain domain) {
-        MarkStudent student = findByExamIdAndCoursePaperIdAndStudentCode(domain.getExamId(), domain.getCoursePaperId(), domain.getStudentCode());
+        MarkStudent student = findByExamIdAndCoursePaperIdAndStudentCode(domain.getExamId(), domain.getCoursePaperId(),
+                domain.getStudentCode());
         if (student == null) {
             throw new ParameterException("考生信息未找到");
         }
@@ -702,7 +745,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
 
     @Transactional
     @Override
-    public AbsentManualUpdateVo absentManualUpdate(Long examId, String coursePaperId, String studentCode, ScanStatus status) {
+    public AbsentManualUpdateVo absentManualUpdate(Long examId, String coursePaperId, String studentCode,
+            ScanStatus status) {
         MarkStudent student = findByExamIdAndCoursePaperIdAndStudentCode(examId, coursePaperId, studentCode);
         if (student == null) {
             throw new ParameterException("考生未找到");
@@ -716,7 +760,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         lw.set(MarkStudent::getAbsent, ScanStatus.MANUAL_ABSENT.equals(status));
         lw.eq(MarkStudent::getId, student.getId());
         update(lw);
-        markPaperService.updateAbsentCount(examId, student.getPaperNumber(), this.countAbsentByExamIdAndPaperNumber(examId, student.getPaperNumber()));
+        markPaperService.updateAbsentCount(examId, student.getPaperNumber(),
+                this.countAbsentByExamIdAndPaperNumber(examId, student.getPaperNumber()));
         return AbsentManualUpdateVo.create(status);
     }
 
@@ -731,13 +776,14 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         }
         lw.eq(MarkStudent::getId, student.getId());
         update(lw);
-        markPaperService.updateAbsentCount(examId, student.getPaperNumber(), this.countAbsentByExamIdAndPaperNumber(examId, student.getPaperNumber()));
+        markPaperService.updateAbsentCount(examId, student.getPaperNumber(),
+                this.countAbsentByExamIdAndPaperNumber(examId, student.getPaperNumber()));
         return UpdateTimeVo.create();
     }
 
     @Override
     public List<Long> findIdByExamIdAndPaperNumberAndSubjectiveStatus(Long examId, String paperNumber,
-                                                                      SubjectiveStatus unmark, SubjectiveStatus marked) {
+            SubjectiveStatus unmark, SubjectiveStatus marked) {
         return this.baseMapper.findIdByExamIdAndPaperNumberAndSubjectiveStatus(examId, paperNumber, unmark.name(),
                 marked.name());
     }
@@ -763,7 +809,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         if (markStudent == null) {
             throw ExceptionResultEnum.ERROR.exception("考生不存在");
         }
-        MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(markStudent.getExamId(), markStudent.getPaperNumber());
+        MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(markStudent.getExamId(),
+                markStudent.getPaperNumber());
         // 评卷是否结束
         if (markPaper == null || MarkPaperStatus.FINISH.equals(markPaper.getStatus())) {
             throw ExceptionResultEnum.ERROR.exception("科目已结束评卷,无法打分");
@@ -799,7 +846,6 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         return ret;
     }
 
-
     @Override
     public void scoreExport(ArchiveStudentQuery query, HttpServletResponse response) {
         List<ArchiveStudentVo> ret = baseMapper.studentList(query);
@@ -818,8 +864,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
             double total = ret.getOverview().getStudentCount() - ret.getOverview().getAbsentCount();
             ret.getOverview().setPassRate(
                     Calculator.divide2String(Calculator.multiply(ret.getOverview().getPassCount(), 100), total, 2));
-            ret.getOverview().setExcellentRate(
-                    Calculator.divide2String(Calculator.multiply(ret.getOverview().getExcellentCount(), 100), total, 2));
+            ret.getOverview().setExcellentRate(Calculator
+                    .divide2String(Calculator.multiply(ret.getOverview().getExcellentCount(), 100), total, 2));
             ret.getOverview().setAvgScore(Calculator.round(ret.getOverview().getAvgScore(), 2));
         }
 
@@ -885,8 +931,10 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     public void exportUnexist(Long examId, String courseCode, String coursePaperId, HttpServletResponse response) {
         try {
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-            DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(), sysUser.getId(), ServletUtil.getRequest().getServletPath());
-            List<UnexistStudentDto> unexistStudentDtoList = this.baseMapper.listUnexistStudentByExamIdAndCoursePaperId(examId, courseCode, coursePaperId, MarkPaperStatus.FORMAL.name(), dpr);
+            DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(sysUser.getSchoolId(),
+                    sysUser.getId(), ServletUtil.getRequest().getServletPath());
+            List<UnexistStudentDto> unexistStudentDtoList = this.baseMapper.listUnexistStudentByExamIdAndCoursePaperId(
+                    examId, courseCode, coursePaperId, MarkPaperStatus.FORMAL.name(), dpr);
             ExcelUtil.excelExport("评卷员工作量", UnexistStudentDto.class, unexistStudentDtoList, response);
         } catch (Exception e) {
             throw ExceptionResultEnum.ERROR.exception("导出评卷员工作量失败");
@@ -897,15 +945,12 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     public int countByExamIdAndPaperNumberAndMarkStatus(Long examId, String paperNumber, SubjectiveStatus status) {
         QueryWrapper<MarkStudent> queryWrapper = new QueryWrapper<>();
         LambdaQueryWrapper<MarkStudent> lambdaQueryWrapper = queryWrapper.lambda();
-        lambdaQueryWrapper.eq(MarkStudent::getExamId, examId)
-                .eq(MarkStudent::getPaperNumber, paperNumber);
+        lambdaQueryWrapper.eq(MarkStudent::getExamId, examId).eq(MarkStudent::getPaperNumber, paperNumber);
         if (status != null) {
             lambdaQueryWrapper.eq(MarkStudent::getSubjectiveStatus, status);
         }
-        lambdaQueryWrapper.eq(MarkStudent::getUpload, true)
-                .eq(MarkStudent::getAbsent, false)
-                .eq(MarkStudent::getBreach, false)
-                .eq(MarkStudent::getOmrAbsent, false);
+        lambdaQueryWrapper.eq(MarkStudent::getUpload, true).eq(MarkStudent::getAbsent, false)
+                .eq(MarkStudent::getBreach, false).eq(MarkStudent::getOmrAbsent, false);
         return this.count(queryWrapper);
     }
 
@@ -913,18 +958,15 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     public void updateCheckInfo(Long studentId, Long userId) {
         UpdateWrapper<MarkStudent> updateWrapper = new UpdateWrapper<>();
         updateWrapper.lambda().set(MarkStudent::getCheckUserId, userId)
-                .set(MarkStudent::getCheckTime, System.currentTimeMillis())
-                .eq(MarkStudent::getId, studentId);
+                .set(MarkStudent::getCheckTime, System.currentTimeMillis()).eq(MarkStudent::getId, studentId);
         this.update(updateWrapper);
     }
 
     @Override
     public int countOmrAbsentStudent(Long examId, String paperNumber, String paperType, boolean isOmrAbsentConfirm) {
         QueryWrapper<MarkStudent> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda().eq(MarkStudent::getExamId, examId)
-                .eq(MarkStudent::getPaperNumber, paperNumber)
-                .eq(MarkStudent::getPaperType, paperType)
-                .eq(MarkStudent::getOmrAbsent, true)
+        queryWrapper.lambda().eq(MarkStudent::getExamId, examId).eq(MarkStudent::getPaperNumber, paperNumber)
+                .eq(MarkStudent::getPaperType, paperType).eq(MarkStudent::getOmrAbsent, true)
                 .eq(MarkStudent::getOmrAbsentChecked, isOmrAbsentConfirm);
         return this.count(queryWrapper);
     }
@@ -936,7 +978,9 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
         File pdfFile;
         try {
             // 本地保存目录
-            File tempFile = SystemConstant.getFileTempDirVar(System.currentTimeMillis() + File.separator + SystemConstant.getNanoId(), SystemConstant.TEMP_PREFIX);
+            File tempFile = SystemConstant.getFileTempDirVar(
+                    System.currentTimeMillis() + File.separator + SystemConstant.getNanoId(),
+                    SystemConstant.TEMP_PREFIX);
             rootPath = tempFile.getParent();
 
             // 删除临时目录中创建的临时文件
@@ -944,7 +988,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
                 tempFile.delete();
             }
             // html文件
-            String cardHtmlPath = rootPath + File.separator + System.currentTimeMillis() + File.separator + "temp" + SystemConstant.HTML_PREFIX;
+            String cardHtmlPath = rootPath + File.separator + System.currentTimeMillis() + File.separator + "temp"
+                    + SystemConstant.HTML_PREFIX;
             htmlFile = new File(cardHtmlPath);
             if (!htmlFile.exists()) {
                 htmlFile.getParentFile().mkdirs();
@@ -954,7 +999,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
             FileCopyUtils.copy(jsonObject.getString("htmlContent").getBytes(StandardCharsets.UTF_8), htmlFile);
 
             // pdf文件
-            String cardPdfPath = rootPath + File.separator + System.currentTimeMillis() + File.separator + "temp" + SystemConstant.PDF_PREFIX;
+            String cardPdfPath = rootPath + File.separator + System.currentTimeMillis() + File.separator + "temp"
+                    + SystemConstant.PDF_PREFIX;
             pdfFile = new File(cardPdfPath);
             if (!pdfFile.exists()) {
                 pdfFile.getParentFile().mkdirs();
@@ -974,8 +1020,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public void deleteByExamIdAndPaperNumber(Long examId, String paperNumber) {
         UpdateWrapper<MarkStudent> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.lambda().eq(MarkStudent::getExamId, examId)
-                .eq(MarkStudent::getPaperNumber, paperNumber);
+        updateWrapper.lambda().eq(MarkStudent::getExamId, examId).eq(MarkStudent::getPaperNumber, paperNumber);
         this.remove(updateWrapper);
     }
 
@@ -996,8 +1041,7 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public IPage<MarkStudent> pageByExamAndPaperNumber(Long examId, String paperNumber, int pageNumber, int pageSize) {
         QueryWrapper<MarkStudent> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda().eq(MarkStudent::getExamId, examId)
-                .eq(MarkStudent::getPaperNumber, paperNumber)
+        queryWrapper.lambda().eq(MarkStudent::getExamId, examId).eq(MarkStudent::getPaperNumber, paperNumber)
                 .orderByAsc(MarkStudent::getId);
         return this.page(new Page<>(pageNumber, pageSize), queryWrapper);
     }
@@ -1014,13 +1058,13 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     @Override
     public boolean updateAssignConfirm(Long studentId, boolean assignConfirm) {
         UpdateWrapper<MarkStudent> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.lambda().set(MarkStudent::getAssignConfirmed, assignConfirm)
-                .eq(MarkStudent::getId, studentId);
+        updateWrapper.lambda().set(MarkStudent::getAssignConfirmed, assignConfirm).eq(MarkStudent::getId, studentId);
         return this.update(updateWrapper);
     }
 
     private void fillObjective(ScoreReportVo ret, Long examId, String paperNumber) {
-        List<MarkQuestion> qs = markQuestionService.listQuestionByExamIdAndPaperNumberAndPaperType(examId, paperNumber, null);
+        List<MarkQuestion> qs = markQuestionService.listQuestionByExamIdAndPaperNumberAndPaperType(examId, paperNumber,
+                null);
         List<MarkStudent> students = listByExamIdAndPaperNumberAndAbsent(examId, paperNumber, false);
         Map<String, QuestionVo> map = new HashMap<>();
         List<QuestionVo> list = new ArrayList<>();
@@ -1125,7 +1169,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     }
 
     @Override
-    public int getAssignedCount(Long examId, Boolean checked, String courseCode, String coursePaperId, MarkPaperStatus status, DataPermissionRule dpr) {
+    public int getAssignedCount(Long examId, Boolean checked, String courseCode, String coursePaperId,
+            MarkPaperStatus status, DataPermissionRule dpr) {
         MarkStudent markStudent = new MarkStudent();
         markStudent.setExamId(examId);
         markStudent.setCourseCode(courseCode);
@@ -1145,8 +1190,10 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
     }
 
     @Override
-    public List<MarkStudent> listScanCollegeByExamIdAndCourseCodeAndCoursePaperId(Long examId, String courseCode, String coursePaperId, String status, DataPermissionRule dpr) {
-        return this.baseMapper.listScanCollegeByExamIdAndCourseCodeAndCoursePaperId(examId, courseCode, coursePaperId, status, dpr);
+    public List<MarkStudent> listScanCollegeByExamIdAndCourseCodeAndCoursePaperId(Long examId, String courseCode,
+            String coursePaperId, String status, DataPermissionRule dpr) {
+        return this.baseMapper.listScanCollegeByExamIdAndCourseCodeAndCoursePaperId(examId, courseCode, coursePaperId,
+                status, dpr);
     }
 
     @Override

+ 122 - 119
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/ScanPaperServiceImpl.java

@@ -1,5 +1,16 @@
 package com.qmth.teachcloud.mark.service.impl;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.validation.constraints.NotNull;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -20,15 +31,6 @@ import com.qmth.teachcloud.mark.entity.*;
 import com.qmth.teachcloud.mark.enums.LockType;
 import com.qmth.teachcloud.mark.mapper.ScanPaperMapper;
 import com.qmth.teachcloud.mark.service.*;
-import org.apache.commons.collections4.CollectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.validation.constraints.NotNull;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -40,19 +42,25 @@ import java.util.stream.Collectors;
  */
 @Service
 public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper> implements ScanPaperService {
+
     @Autowired
     private ScanAnswerCardService answerCardService;
+
     @Autowired
     private ScanPaperPageService paperPageService;
+
     @Autowired
     private MarkStudentService markStudentService;
+
     @Autowired
     private ConcurrentService concurrentService;
+
     @Autowired
     private ScanStudentPaperService scanStudentPaperService;
+
     @Autowired
     private MarkService markService;
-    
+
     /**
      * 全量更新paper和所属的page集合,并刷新paper相关属性
      *
@@ -82,12 +90,12 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
         for (ScanPaperPage page : pages) {
             // FIXME
             // 验证原图与裁切图已上传
-//            if (!fileStore.exist(page.getSheetPath())) {
-//            	throw ExceptionResultEnum.ERROR.exception("原图不存在:" + page.getSheetPath());
-//            }
-//            if (page.getId() == null) {
-//                page.setId(SystemConstant.getDbUuid());
-//            }
+            // if (!fileStore.exist(page.getSheetPath())) {
+            // throw ExceptionResultEnum.ERROR.exception("原图不存在:" + page.getSheetPath());
+            // }
+            // if (page.getId() == null) {
+            // page.setId(SystemConstant.getDbUuid());
+            // }
             page.setPaperId(paper.getId());
         }
         // 保存page数据
@@ -118,21 +126,21 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
     }
 
     private boolean isEmptyPage(PaperMigrateDomain domain) {
-    	for(PaperMigratePaper paper:domain.getPapers()) {
-			if (CollectionUtils.isEmpty(paper.getPages())) {
-				return true;
-	        }
-    	}
-    	return false;
+        for (PaperMigratePaper paper : domain.getPapers()) {
+            if (CollectionUtils.isEmpty(paper.getPages())) {
+                return true;
+            }
+        }
+        return false;
     }
-    
+
     @Transactional
     @Override
     public PaperMigrateVo paperMigrate(SysUser user, PaperMigrateDomain domain) {
-    	if (CollectionUtils.isEmpty(domain.getPapers())) {
+        if (CollectionUtils.isEmpty(domain.getPapers())) {
             throw new ParameterException("papers信息不能为空");
         }
-    	List<Long> paperIds=domain.getPapers().stream().map(e -> e.getPaperId()).collect(Collectors.toList());
+        List<Long> paperIds = domain.getPapers().stream().map(e -> e.getPaperId()).collect(Collectors.toList());
         // 查找目标考生
         MarkStudent student = markStudentService.findByExamIdAndCoursePaperIdAndStudentCode(domain.getExamId(),
                 domain.getCoursePaperId(), domain.getStudentCode());
@@ -149,22 +157,22 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
             throw new ParameterException("卡格式信息未找到");
         }
         // cardNumber有变化,需要重新识别
-        if (student.getCardNumber()!=null&&!student.getCardNumber().equals(domain.getCardNumber())
+        if (student.getCardNumber() != null && !student.getCardNumber().equals(domain.getCardNumber())
                 && isEmptyPage(domain)) {
             throw new ParameterException("卡格式有变化需要重新识别, pages信息不能为空");
         }
-        
+
         // 指定paper现有绑定考生
         MarkStudent previousStudent = null;
         List<ScanStudentPaper> previousStudentPapers = scanStudentPaperService.findByPaperIds(paperIds);
         if (CollectionUtils.isEmpty(previousStudentPapers)) {
-        	throw new ParameterException("被绑定的题卡信息未关联考生");
+            throw new ParameterException("被绑定的题卡信息未关联考生");
         }
-        checkStudent(previousStudentPapers,paperIds);
-        Long previousStudentId=previousStudentPapers.get(0).getStudentId();
+        checkStudent(previousStudentPapers, paperIds);
+        Long previousStudentId = previousStudentPapers.get(0).getStudentId();
         // 考生ID变了才需要获取原考生
         if (!previousStudentId.equals(student.getId())) {
-        	previousStudent = markStudentService.getById(previousStudentId);
+            previousStudent = markStudentService.getById(previousStudentId);
         }
         if (previousStudent != null) {
             concurrentService.getReadWriteLock(LockType.STUDENT + "-" + previousStudent.getId()).writeLock().lock();
@@ -173,53 +181,48 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
         try {
             // 解绑paper和原有考生
             if (previousStudent != null) {
-            	//重置考生状态
-            	resetStudent(previousStudent);
-            	//删除阅卷任务信息
-            	markService.deleteMarkTaskByStudent(previousStudent);
+                // 重置考生状态
+                resetStudent(previousStudent);
                 markStudentService.updateStudentAndPaper(user, previousStudent.getId(), null);
             }
-        	for(PaperMigratePaper vp:domain.getPapers()) {
-        		ScanPaper paper=getById(vp.getPaperId());
-        		if(paper==null) {
-        			throw new ParameterException("题卡信息未找到.paperId="+vp.getPaperId());
-        		}
-	            // 更新paper属性
-	            paper.setCardNumber(domain.getCardNumber());
-	            paper.setNumber(vp.getPaperNumber());
-	            // 修改的paper强制置为人工绑定
-	            paper.setAssigned(true);
-	            // 原有mismatch标记需要清除
-	            paper.setMismatch(false);
-	            paper.setUpdaterId(user.getId());
-	            paper.setUpdateTime(System.currentTimeMillis());
-	            if (CollectionUtils.isNotEmpty(vp.getPages())) {
-	                // 重新识别时更新所有page
-	                List<ScanPaperPage> pages = new ArrayList<>();
-	                for (PaperMigratePage page : vp.getPages()) {
-	                    pages.add(page.update(paperPageService.findPaperIdAndIndex(paper.getId(), page.getIndex())));
-	                }
-	                savePaperAndPages(paper, pages);
-	            } else {
-	                saveOrUpdate(paper);
-	            }
-        	}
-        	// 查找目标考生现有绑定paper
-        	List<ScanStudentPaper> currentStudentPaperList = scanStudentPaperService.findByStudentId(student.getId());
-        	if (CollectionUtils.isNotEmpty(currentStudentPaperList)) {
-        		for (ScanStudentPaper current : currentStudentPaperList) {
-	    			updateMismatch(current.getPaperId(), true);
-	        	}
-        	}
-        	//解绑目标考生现有paper
-        	scanStudentPaperService.removeByStudentId(student.getId());
-        	// 更新目标考生状态
-        	currentStudentPaperList.clear();
-        	for(PaperMigratePaper vp:domain.getPapers()) {
-        		currentStudentPaperList.add(new ScanStudentPaper(student.getId(), vp.getPaperNumber(), vp.getPaperId()));
-        	}
-        	//删除阅卷任务信息
-        	markService.deleteMarkTaskByStudent(student);
+            for (PaperMigratePaper vp : domain.getPapers()) {
+                ScanPaper paper = getById(vp.getPaperId());
+                if (paper == null) {
+                    throw new ParameterException("题卡信息未找到.paperId=" + vp.getPaperId());
+                }
+                // 更新paper属性
+                paper.setCardNumber(domain.getCardNumber());
+                paper.setNumber(vp.getPaperNumber());
+                // 修改的paper强制置为人工绑定
+                paper.setAssigned(true);
+                // 原有mismatch标记需要清除
+                paper.setMismatch(false);
+                paper.setUpdaterId(user.getId());
+                paper.setUpdateTime(System.currentTimeMillis());
+                if (CollectionUtils.isNotEmpty(vp.getPages())) {
+                    // 重新识别时更新所有page
+                    List<ScanPaperPage> pages = new ArrayList<>();
+                    for (PaperMigratePage page : vp.getPages()) {
+                        pages.add(page.update(paperPageService.findPaperIdAndIndex(paper.getId(), page.getIndex())));
+                    }
+                    savePaperAndPages(paper, pages);
+                } else {
+                    saveOrUpdate(paper);
+                }
+            }
+            // 查找目标考生现有绑定paper
+            List<ScanStudentPaper> currentStudentPaperList = scanStudentPaperService.findByStudentId(student.getId());
+            if (CollectionUtils.isNotEmpty(currentStudentPaperList)) {
+                for (ScanStudentPaper current : currentStudentPaperList) {
+                    updateMismatch(current.getPaperId(), true);
+                }
+            }
+            // 更新目标考生状态
+            currentStudentPaperList.clear();
+            for (PaperMigratePaper vp : domain.getPapers()) {
+                currentStudentPaperList
+                        .add(new ScanStudentPaper(student.getId(), vp.getPaperNumber(), vp.getPaperId()));
+            }
             markStudentService.updateStudentAndPaper(user, student.getId(), currentStudentPaperList);
             // 返回数据结果
             return PaperMigrateVo.create(student.getId());
@@ -231,53 +234,53 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
             }
         }
     }
-    
+
     private void resetStudent(MarkStudent ms) {
-    	ms.setSheetCount(0);
-    	ms.setSheetPath(null);
-    	ms.setAnswers(null);
-    	ms.setUpload(false);
-    	ms.setAbsent(false);
-    	ms.setBreach(false);
-    	ms.setUploadTime(null);
-    	ms.setObjectiveScore(null);
-    	ms.setObjectiveScoreList(null);
-    	ms.setSubjectiveStatus(SubjectiveStatus.UNMARK);
-    	ms.setSubjectiveScore(null);
-    	ms.setSubjectiveScoreList(null);
-    	ms.setScanStatus(ScanStatus.UNEXIST);
-    	ms.setQuestionFilled(false);
-    	ms.setAssigned(false);
-    	ms.setAssignConfirmed(false);
-    	ms.setAbsentSuspect(false);
-    	ms.setIncomplete(false);
-    	ms.setBreachCode(null);
-    	ms.setOmrAbsent(false);
-    	ms.setOmrAbsentChecked(false);
-    	ms.setCardNumber(null);
-    	markStudentService.saveOrUpdate(ms);
+        ms.setSheetCount(0);
+        ms.setSheetPath(null);
+        ms.setAnswers(null);
+        ms.setUpload(false);
+        ms.setAbsent(false);
+        ms.setBreach(false);
+        ms.setUploadTime(null);
+        ms.setObjectiveScore(null);
+        ms.setObjectiveScoreList(null);
+        ms.setSubjectiveStatus(SubjectiveStatus.UNMARK);
+        ms.setSubjectiveScore(null);
+        ms.setSubjectiveScoreList(null);
+        ms.setScanStatus(ScanStatus.UNEXIST);
+        ms.setQuestionFilled(false);
+        ms.setAssigned(false);
+        ms.setAssignConfirmed(false);
+        ms.setAbsentSuspect(false);
+        ms.setIncomplete(false);
+        ms.setBreachCode(null);
+        ms.setOmrAbsent(false);
+        ms.setOmrAbsentChecked(false);
+        ms.setCardNumber(null);
+        markStudentService.saveOrUpdate(ms);
     }
 
-    private void checkStudent(List<ScanStudentPaper> previousStudentPapers,List<Long> paperIds) {
-    	if(previousStudentPapers.size()!=paperIds.size()) {
-    		throw new ParameterException("被绑定的题卡不属于同一个考生");
-    	}
-    	Long studentId=null;
-		for(ScanStudentPaper sp:previousStudentPapers) {
-			if(!paperIds.contains(sp.getPaperId())) {
-				throw new ParameterException("被绑定的题卡不属于同一个考生");
-			}
-			if(studentId==null) {
-				studentId=sp.getStudentId();
-			}else {
-				if(!sp.getStudentId().equals(studentId)) {
-					throw new ParameterException("被绑定的题卡不属于同一个考生");
-				}
-			}
-		}
-	}
+    private void checkStudent(List<ScanStudentPaper> previousStudentPapers, List<Long> paperIds) {
+        if (previousStudentPapers.size() != paperIds.size()) {
+            throw new ParameterException("被绑定的题卡不属于同一个考生");
+        }
+        Long studentId = null;
+        for (ScanStudentPaper sp : previousStudentPapers) {
+            if (!paperIds.contains(sp.getPaperId())) {
+                throw new ParameterException("被绑定的题卡不属于同一个考生");
+            }
+            if (studentId == null) {
+                studentId = sp.getStudentId();
+            } else {
+                if (!sp.getStudentId().equals(studentId)) {
+                    throw new ParameterException("被绑定的题卡不属于同一个考生");
+                }
+            }
+        }
+    }
 
-	@Override
+    @Override
     @Transactional
     public boolean updateMismatch(Long id, boolean mismatch) {
         LambdaUpdateWrapper<ScanPaper> lw = new LambdaUpdateWrapper<>();

+ 83 - 78
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/ScanRefixBatchServiceImpl.java

@@ -14,21 +14,10 @@ import com.qmth.teachcloud.mark.dto.refix.AnswerRefixDomain;
 import com.qmth.teachcloud.mark.dto.refix.AnswerRefixVo;
 import com.qmth.teachcloud.mark.dto.refix.PageRefixDomain;
 import com.qmth.teachcloud.mark.dto.refix.PaperRefixDomain;
-import com.qmth.teachcloud.mark.entity.MarkStudent;
-import com.qmth.teachcloud.mark.entity.ScanAnswerCard;
-import com.qmth.teachcloud.mark.entity.ScanPaper;
-import com.qmth.teachcloud.mark.entity.ScanPaperPage;
-import com.qmth.teachcloud.mark.entity.ScanRefixBatch;
-import com.qmth.teachcloud.mark.entity.ScanStudentPaper;
+import com.qmth.teachcloud.mark.entity.*;
 import com.qmth.teachcloud.mark.enums.LockType;
 import com.qmth.teachcloud.mark.mapper.ScanRefixBatchMapper;
-import com.qmth.teachcloud.mark.service.MarkStudentService;
-import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
-import com.qmth.teachcloud.mark.service.ScanAnswerCardSubjectService;
-import com.qmth.teachcloud.mark.service.ScanPaperPageService;
-import com.qmth.teachcloud.mark.service.ScanPaperService;
-import com.qmth.teachcloud.mark.service.ScanRefixBatchService;
-import com.qmth.teachcloud.mark.service.ScanStudentPaperService;
+import com.qmth.teachcloud.mark.service.*;
 
 /**
  * <p>
@@ -40,72 +29,88 @@ import com.qmth.teachcloud.mark.service.ScanStudentPaperService;
  */
 @Service
 public class ScanRefixBatchServiceImpl extends ServiceImpl<ScanRefixBatchMapper, ScanRefixBatch>
-		implements ScanRefixBatchService {
-	@Autowired
-	private ScanStudentPaperService studentPaperService;
-	@Autowired
-	private MarkStudentService studentService;
-	@Autowired
-	private ScanPaperService paperService;
-	@Autowired
-	private ScanPaperPageService paperPageService;
-	@Autowired
-	private ConcurrentService concurrentService;
-	@Autowired
-	private ScanAnswerCardService answerCardService;
-	@Autowired
-	private ScanAnswerCardSubjectService answerCardSubjectService;
+        implements ScanRefixBatchService {
 
-	@Transactional
-	@Override
-	public AnswerRefixVo answerRefix(Long userId, AnswerRefixDomain domain) {
-		MarkStudent student = studentService.getById(domain.getStudentId());
-		if (student == null) {
-			throw new ParameterException("考生信息未找到");
-		}
-		ScanAnswerCard answerCard = answerCardService.findByExamAndNumber(student.getExamId(), domain.getCardNumber());
-		if (answerCard == null) {
-			throw new ParameterException("卡格式信息未找到");
-		}
-//		boolean allowSubject = answerCardSubjectService.checkSubject(answerCard.getExamId(), answerCard.getNumber(),
-//				student.getCoursePaperId());
-//		if (!allowSubject) {
-//			throw new ParameterException("卡格式与考生科目不匹配");
-//		}
-		if (domain.getPapers().size() != answerCard.getPaperCount()) {
-			throw new ParameterException("卡格式张数不一致");
-		}
+    @Autowired
+    private ScanStudentPaperService studentPaperService;
 
-		concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().lock();
-		try {
-			List<ScanStudentPaper> studentPaperList = studentPaperService.findByStudentId(student.getId());
-			for (ScanStudentPaper studentPaper : studentPaperList) {
-				PaperRefixDomain paperDomain = domain.findPaperDomain(studentPaper.getPaperIndex(),
-						studentPaper.getPaperId());
-				if (paperDomain == null) {
-					throw new ParameterException("与考生当前paper不一致,paperNumber=" + studentPaper.getPaperIndex());
-				}
-				ScanPaper paper = paperService.getById(paperDomain.getId());
-				if (paper == null) {
-					throw new ParameterException("考生当前paper不存在,paperId=" + paperDomain.getId());
-				}
-				paper.setCardNumber(answerCard.getNumber());
-				paper.setMismatch(paperDomain.getMismatch());
-				List<ScanPaperPage> pages = new ArrayList<>();
-				for (PageRefixDomain pageDomain : paperDomain.getPages()) {
-					ScanPaperPage page = paperPageService.findPaperIdAndIndex(paper.getId(), pageDomain.getIndex());
-					if (page == null) {
-						throw new ParameterException("与考生当前page不一致,pageIndex=" + pageDomain.getIndex());
-					}
-					pages.add(pageDomain.update(page));
-				}
-				paperService.savePaperAndPages(paper, pages);
-			}
-			studentService.updateStudentByPaper(userId, student.getId(), true);
-			return AnswerRefixVo.create();
-		} finally {
-			concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().unlock();
-		}
-	}
+    @Autowired
+    private MarkStudentService studentService;
+
+    @Autowired
+    private ScanPaperService paperService;
+
+    @Autowired
+    private ScanPaperPageService paperPageService;
+
+    @Autowired
+    private ConcurrentService concurrentService;
+
+    @Autowired
+    private ScanAnswerCardService answerCardService;
+
+    @Autowired
+    private ScanAnswerCardSubjectService answerCardSubjectService;
+
+    @Autowired
+    private MarkService markService;
+
+    @Transactional
+    @Override
+    public AnswerRefixVo answerRefix(Long userId, AnswerRefixDomain domain) {
+        MarkStudent student = studentService.getById(domain.getStudentId());
+        if (student == null) {
+            throw new ParameterException("考生信息未找到");
+        }
+        ScanAnswerCard answerCard = answerCardService.findByExamAndNumber(student.getExamId(), domain.getCardNumber());
+        if (answerCard == null) {
+            throw new ParameterException("卡格式信息未找到");
+        }
+        // boolean allowSubject =
+        // answerCardSubjectService.checkSubject(answerCard.getExamId(),
+        // answerCard.getNumber(),
+        // student.getCoursePaperId());
+        // if (!allowSubject) {
+        // throw new ParameterException("卡格式与考生科目不匹配");
+        // }
+        if (domain.getPapers().size() != answerCard.getPaperCount()) {
+            throw new ParameterException("卡格式张数不一致");
+        }
+
+        concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().lock();
+        try {
+            List<ScanStudentPaper> studentPaperList = studentPaperService.findByStudentId(student.getId());
+            for (ScanStudentPaper studentPaper : studentPaperList) {
+                PaperRefixDomain paperDomain = domain.findPaperDomain(studentPaper.getPaperIndex(),
+                        studentPaper.getPaperId());
+                if (paperDomain == null) {
+                    throw new ParameterException("与考生当前paper不一致,paperNumber=" + studentPaper.getPaperIndex());
+                }
+                ScanPaper paper = paperService.getById(paperDomain.getId());
+                if (paper == null) {
+                    throw new ParameterException("考生当前paper不存在,paperId=" + paperDomain.getId());
+                }
+                paper.setCardNumber(answerCard.getNumber());
+                paper.setMismatch(paperDomain.getMismatch());
+                List<ScanPaperPage> pages = new ArrayList<>();
+                for (PageRefixDomain pageDomain : paperDomain.getPages()) {
+                    ScanPaperPage page = paperPageService.findPaperIdAndIndex(paper.getId(), pageDomain.getIndex());
+                    if (page == null) {
+                        throw new ParameterException("与考生当前page不一致,pageIndex=" + pageDomain.getIndex());
+                    }
+                    pages.add(pageDomain.update(page));
+                }
+                paperService.savePaperAndPages(paper, pages);
+            }
+            // 更换卡格式后需要删除阅卷任务
+            if (!student.getCardNumber().equals(answerCard.getNumber())) {
+                markService.deleteMarkTaskByStudent(student);
+            }
+            studentService.updateStudentByPaper(userId, student.getId(), true);
+            return AnswerRefixVo.create();
+        } finally {
+            concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().unlock();
+        }
+    }
 
 }

+ 31 - 31
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/ScanStudentPaperServiceImpl.java

@@ -24,42 +24,42 @@ import com.qmth.teachcloud.mark.service.ScanStudentPaperService;
  */
 @Service
 public class ScanStudentPaperServiceImpl extends ServiceImpl<ScanStudentPaperMapper, ScanStudentPaper>
-		implements ScanStudentPaperService {
+        implements ScanStudentPaperService {
 
-	@Override
-	public List<ScanStudentPaper> findByStudentId(Long studentId) {
-		QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
-		LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
-		lw.eq(ScanStudentPaper::getStudentId, studentId);
+    @Override
+    public List<ScanStudentPaper> findByStudentId(Long studentId) {
+        QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
+        lw.eq(ScanStudentPaper::getStudentId, studentId);
         lw.orderByAsc(ScanStudentPaper::getPaperIndex);
-		return this.list(wrapper);
-	}
+        return this.list(wrapper);
+    }
+
+    @Override
+    public ScanStudentPaper findByPaperId(Long paperId) {
+        QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
+        lw.eq(ScanStudentPaper::getPaperId, paperId);
+        return baseMapper.selectOne(wrapper);
+    }
+
+    @Override
+    public List<ScanStudentPaper> findByPaperIds(List<Long> paperIds) {
+        QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
+        lw.in(ScanStudentPaper::getPaperId, paperIds);
+        return this.list(wrapper);
+    }
 
-	@Override
-	public ScanStudentPaper findByPaperId(Long paperId) {
-		QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
-		LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
-		lw.eq(ScanStudentPaper::getPaperId, paperId);
-		return baseMapper.selectOne(wrapper);
-	}
-	
-	@Override
-	public List<ScanStudentPaper> findByPaperIds(List<Long> paperIds) {
-		QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
-		LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
-		lw.in(ScanStudentPaper::getPaperId, paperIds);
-		return this.list(wrapper);
-	}
-	
     @Transactional
     @Override
-    public void removeByStudentId(Long studentId) {
+    public int removeByStudentId(Long studentId) {
         QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
         LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
         lw.eq(ScanStudentPaper::getStudentId, studentId);
-        this.baseMapper.delete(wrapper);
+        return this.baseMapper.delete(wrapper);
     }
-    
+
     @Override
     public ScanStudentPaper findByStudentIdAndPaperNumber(Long studentId, Integer paperNumber) {
         QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
@@ -70,12 +70,12 @@ public class ScanStudentPaperServiceImpl extends ServiceImpl<ScanStudentPaperMap
     }
 
     @Transactional
-	@Override
-	public void removeByStudentIdAndPaperId(@NotNull Long studentId, @NotNull Long paperId) {
-		QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
+    @Override
+    public void removeByStudentIdAndPaperId(@NotNull Long studentId, @NotNull Long paperId) {
+        QueryWrapper<ScanStudentPaper> wrapper = new QueryWrapper<>();
         LambdaQueryWrapper<ScanStudentPaper> lw = wrapper.lambda();
         lw.eq(ScanStudentPaper::getStudentId, studentId);
         lw.eq(ScanStudentPaper::getPaperId, paperId);
         this.baseMapper.delete(wrapper);
-	}
+    }
 }