|
@@ -4,13 +4,18 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
+import com.qmth.teachcloud.mark.bean.answerbatch.AnswerDomain;
|
|
|
+import com.qmth.teachcloud.mark.bean.answerbatch.AnswerPaper;
|
|
|
+import com.qmth.teachcloud.mark.bean.answerbatch.AnswerSaveVo;
|
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.BatchCreateDomain;
|
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.BatchCreateVo;
|
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.BatchFinishVo;
|
|
@@ -18,11 +23,18 @@ import com.qmth.teachcloud.mark.bean.answerbatch.Paper;
|
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.Rescan;
|
|
|
import com.qmth.teachcloud.mark.bean.scanpaper.PaperVo;
|
|
|
import com.qmth.teachcloud.mark.entity.MarkStudent;
|
|
|
+import com.qmth.teachcloud.mark.entity.ScanAnswerCard;
|
|
|
import com.qmth.teachcloud.mark.entity.ScanBatch;
|
|
|
+import com.qmth.teachcloud.mark.entity.ScanBatchPaper;
|
|
|
+import com.qmth.teachcloud.mark.entity.ScanPaper;
|
|
|
import com.qmth.teachcloud.mark.entity.ScanPaperPage;
|
|
|
+import com.qmth.teachcloud.mark.entity.ScanStudentPaper;
|
|
|
import com.qmth.teachcloud.mark.enums.BatchStatus;
|
|
|
+import com.qmth.teachcloud.mark.enums.LockType;
|
|
|
import com.qmth.teachcloud.mark.mapper.ScanBatchMapper;
|
|
|
import com.qmth.teachcloud.mark.service.MarkStudentService;
|
|
|
+import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
|
|
|
+import com.qmth.teachcloud.mark.service.ScanBatchPaperService;
|
|
|
import com.qmth.teachcloud.mark.service.ScanBatchService;
|
|
|
import com.qmth.teachcloud.mark.service.ScanPaperPageService;
|
|
|
import com.qmth.teachcloud.mark.service.ScanPaperService;
|
|
@@ -38,6 +50,8 @@ import com.qmth.teachcloud.mark.service.ScanPaperService;
|
|
|
@Service
|
|
|
public class ScanBatchServiceImpl extends ServiceImpl<ScanBatchMapper, ScanBatch> implements ScanBatchService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ConcurrentService concurrentService;
|
|
|
@Autowired
|
|
|
private MarkStudentService markStudentService;
|
|
|
|
|
@@ -46,6 +60,12 @@ public class ScanBatchServiceImpl extends ServiceImpl<ScanBatchMapper, ScanBatch
|
|
|
|
|
|
@Autowired
|
|
|
private ScanPaperPageService scanPaperPageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ScanBatchPaperService scanBatchPaperService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ScanAnswerCardService scanAnswerCardService;
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
@@ -115,19 +135,107 @@ public class ScanBatchServiceImpl extends ServiceImpl<ScanBatchMapper, ScanBatch
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public BatchFinishVo batchFinish(Long id) {
|
|
|
- ScanBatch entity = this.getById(id);
|
|
|
- if (entity == null) {
|
|
|
- throw new ParameterException("批次不存在");
|
|
|
- }
|
|
|
- if (BatchStatus.FINISH.equals(entity.getStatus())) {
|
|
|
- throw new ParameterException("批次已经完成");
|
|
|
- }
|
|
|
- entity.setStatus(BatchStatus.FINISH);
|
|
|
- this.saveOrUpdate(entity);
|
|
|
+ ScanBatch batch = checkBatchStatus(getById(id));
|
|
|
+ batch.setStatus(BatchStatus.FINISH);
|
|
|
+ this.saveOrUpdate(batch);
|
|
|
BatchFinishVo vo = new BatchFinishVo();
|
|
|
- vo.setStatus(entity.getStatus());
|
|
|
+ vo.setStatus(batch.getStatus());
|
|
|
vo.setUpdateTime(System.currentTimeMillis());
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public AnswerSaveVo batchSave(AnswerDomain domain, SysUser user) {
|
|
|
+ ScanBatch batch = checkBatchStatus(getById(domain.getBatchId()));
|
|
|
+ String studentCode = domain.getStudentCode();
|
|
|
+ MarkStudent student = markStudentService.findByExamIdAndCoursePaperIdAndStudentCode(batch.getExamId(),
|
|
|
+ batch.getCoursePaperId(), studentCode);
|
|
|
+ if (student == null) {
|
|
|
+ throw new ParameterException("未找到考生信息:" + studentCode);
|
|
|
+ }
|
|
|
+ ScanAnswerCard answerCard = scanAnswerCardService.findByExamAndNumber(batch.getExamId(), domain.getCardNumber());
|
|
|
+ if (answerCard == null) {
|
|
|
+ throw new ParameterException("卡格式信息未找到");
|
|
|
+ }
|
|
|
+ if (!StringUtils.equals(batch.getPackageCode(), student.getPackageCode())) {
|
|
|
+ throw new ParameterException("与批次卷袋号不一致");
|
|
|
+ }
|
|
|
+ boolean studentAssigned = false;
|
|
|
+ List<ScanStudentPaper> studentPaperList = new ArrayList<>();
|
|
|
+ for (AnswerPaper answerPaper : domain.getPapers()) {
|
|
|
+ // 验证page数量
|
|
|
+ answerPaper.answerCardValidate(answerCard);
|
|
|
+ Integer paperNumber = answerPaper.getNumber();
|
|
|
+ ScanPaper paper = findOrCreatePaper(batch, student, paperNumber, user);
|
|
|
+ // 设置paper属性
|
|
|
+ paper.setExamId(batch.getExamId());
|
|
|
+ paper.setCardNumber(answerCard.getNumber());
|
|
|
+ paper.setNumber(paperNumber);
|
|
|
+ paper.setMismatch(false);
|
|
|
+ paper.setQuestionFilled(false);
|
|
|
+ paper.setAssigned(answerPaper.getAssigned());
|
|
|
+ // 保存paper与page到数据库
|
|
|
+ scanPaperService.savePaperAndPages(paper, answerPaper.buildPageList());
|
|
|
+ // 记录paper与batch关联关系
|
|
|
+ scanBatchPaperService.update(batch, paper, student.getId(), paperNumber);
|
|
|
+ // 创建student与paper的关联关系
|
|
|
+ studentPaperList.add(new ScanStudentPaper(student.getId(), paperNumber, paper.getId()));
|
|
|
+ studentAssigned = studentAssigned || paper.getAssigned();
|
|
|
+ }
|
|
|
+ // 更新批次统计数量
|
|
|
+ updateAssignedCount(batch.getId());
|
|
|
+ updateScanCount(batch.getId());
|
|
|
+ // 没有人工绑定的情况下,直接更新考生扫描状态
|
|
|
+ if (!studentAssigned) {
|
|
|
+ concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().lock();
|
|
|
+ try {
|
|
|
+ markStudentService.updateStudentAndPaper(user, student.getId(), studentPaperList);
|
|
|
+ } finally {
|
|
|
+ concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AnswerSaveVo.create(findStudentCountByBatch(batch.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer findStudentCountByBatch(Long batchId) {
|
|
|
+ return baseMapper.findStudentCountByBatch(batchId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void updateAssignedCount(Long id) {
|
|
|
+ baseMapper.updateAssignedCount(id);
|
|
|
+ }
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void updateScanCount(Long id) {
|
|
|
+ baseMapper.updateScanCount(id);
|
|
|
+ }
|
|
|
+ private ScanPaper findOrCreatePaper(ScanBatch batch, MarkStudent student, Integer paperNumber, SysUser user) {
|
|
|
+ ScanPaper paper = null;
|
|
|
+ // 尝试重用已有paper对象
|
|
|
+ ScanBatchPaper batchPaper = scanBatchPaperService
|
|
|
+ .findByBatchIdAndStudentIdAndPaperNumber(batch.getId(), student.getId(), paperNumber);
|
|
|
+ if (batchPaper != null) {
|
|
|
+ paper = scanPaperService.getById(batchPaper.getPaperId());
|
|
|
+ }
|
|
|
+ // 构造全新paper对象
|
|
|
+ if (paper == null) {
|
|
|
+ paper = new ScanPaper();
|
|
|
+ paper.setCreateTime(System.currentTimeMillis());
|
|
|
+ paper.setCreatorId(user.getId());
|
|
|
+ }
|
|
|
+ return paper;
|
|
|
+ }
|
|
|
+ private ScanBatch checkBatchStatus(ScanBatch b) {
|
|
|
+ if (b == null) {
|
|
|
+ throw new ParameterException("批次未找到");
|
|
|
+ }
|
|
|
+ if (BatchStatus.FINISH.equals(b.getStatus())) {
|
|
|
+ throw new ParameterException("批次已经完成");
|
|
|
+ }
|
|
|
+ return b;
|
|
|
+ }
|
|
|
}
|