|
@@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
@@ -21,6 +22,7 @@ import com.qmth.teachcloud.mark.bean.answerbatch.BatchCreateVo;
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.BatchFinishVo;
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.BatchFinishVo;
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.Paper;
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.Paper;
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.Rescan;
|
|
import com.qmth.teachcloud.mark.bean.answerbatch.Rescan;
|
|
|
|
+import com.qmth.teachcloud.mark.bean.scananswer.SheetUploadVo;
|
|
import com.qmth.teachcloud.mark.bean.scanpaper.PaperVo;
|
|
import com.qmth.teachcloud.mark.bean.scanpaper.PaperVo;
|
|
import com.qmth.teachcloud.mark.entity.MarkStudent;
|
|
import com.qmth.teachcloud.mark.entity.MarkStudent;
|
|
import com.qmth.teachcloud.mark.entity.ScanAnswerCard;
|
|
import com.qmth.teachcloud.mark.entity.ScanAnswerCard;
|
|
@@ -32,6 +34,7 @@ import com.qmth.teachcloud.mark.entity.ScanStudentPaper;
|
|
import com.qmth.teachcloud.mark.enums.BatchStatus;
|
|
import com.qmth.teachcloud.mark.enums.BatchStatus;
|
|
import com.qmth.teachcloud.mark.enums.LockType;
|
|
import com.qmth.teachcloud.mark.enums.LockType;
|
|
import com.qmth.teachcloud.mark.mapper.ScanBatchMapper;
|
|
import com.qmth.teachcloud.mark.mapper.ScanBatchMapper;
|
|
|
|
+import com.qmth.teachcloud.mark.service.FileService;
|
|
import com.qmth.teachcloud.mark.service.MarkStudentService;
|
|
import com.qmth.teachcloud.mark.service.MarkStudentService;
|
|
import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
|
|
import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
|
|
import com.qmth.teachcloud.mark.service.ScanBatchPaperService;
|
|
import com.qmth.teachcloud.mark.service.ScanBatchPaperService;
|
|
@@ -49,27 +52,28 @@ import com.qmth.teachcloud.mark.service.ScanPaperService;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class ScanBatchServiceImpl extends ServiceImpl<ScanBatchMapper, ScanBatch> implements ScanBatchService {
|
|
public class ScanBatchServiceImpl extends ServiceImpl<ScanBatchMapper, ScanBatch> implements ScanBatchService {
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ConcurrentService concurrentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FileService fileService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ConcurrentService concurrentService;
|
|
@Autowired
|
|
@Autowired
|
|
private MarkStudentService markStudentService;
|
|
private MarkStudentService markStudentService;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ScanPaperService scanPaperService;
|
|
private ScanPaperService scanPaperService;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ScanPaperPageService scanPaperPageService;
|
|
private ScanPaperPageService scanPaperPageService;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ScanBatchPaperService scanBatchPaperService;
|
|
private ScanBatchPaperService scanBatchPaperService;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ScanAnswerCardService scanAnswerCardService;
|
|
private ScanAnswerCardService scanAnswerCardService;
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public BatchCreateVo batchCreate(BatchCreateDomain domain,SysUser sysUser) {
|
|
|
|
|
|
+ public BatchCreateVo batchCreate(BatchCreateDomain domain, SysUser sysUser) {
|
|
List<Rescan> rescan = new ArrayList<>();
|
|
List<Rescan> rescan = new ArrayList<>();
|
|
String packageCode = null;
|
|
String packageCode = null;
|
|
for (String studentCode : domain.getStudentCodes()) {
|
|
for (String studentCode : domain.getStudentCodes()) {
|
|
@@ -100,142 +104,162 @@ public class ScanBatchServiceImpl extends ServiceImpl<ScanBatchMapper, ScanBatch
|
|
vo.setCreateTime(b.getCreateTime());
|
|
vo.setCreateTime(b.getCreateTime());
|
|
return vo;
|
|
return vo;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private Rescan getRescan(MarkStudent student) {
|
|
private Rescan getRescan(MarkStudent student) {
|
|
- Rescan res = new Rescan();
|
|
|
|
- res.setStudentCode(student.getStudentCode());
|
|
|
|
- List<PaperVo> papers = scanPaperService.findStudentPaper(student.getId());
|
|
|
|
- List<Paper> resPapers = new ArrayList<>();
|
|
|
|
- res.setPapers(resPapers);
|
|
|
|
- if (CollectionUtils.isEmpty(papers)) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- PaperVo first = papers.get(0);
|
|
|
|
- res.setBatchId(first.getBatchId());
|
|
|
|
- res.setUser(first.getUserName());
|
|
|
|
- res.setCreateTime(first.getCreateTime());
|
|
|
|
- for (PaperVo paper : papers) {
|
|
|
|
- Paper p = new Paper();
|
|
|
|
- p.setId(paper.getId());
|
|
|
|
- p.setNumber(paper.getNumber());
|
|
|
|
- p.setMismatch(paper.getMismatch());
|
|
|
|
- List<String> pages = new ArrayList<>();
|
|
|
|
- p.setPages(pages);
|
|
|
|
- List<ScanPaperPage> paperPages = scanPaperPageService.listByPaperId(paper.getId());
|
|
|
|
- if (CollectionUtils.isNotEmpty(paperPages)) {
|
|
|
|
- for (ScanPaperPage pp : paperPages) {
|
|
|
|
- pages.add(pp.getSheetPath());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- resPapers.add(p);
|
|
|
|
- }
|
|
|
|
- return res;
|
|
|
|
- }
|
|
|
|
|
|
+ Rescan res = new Rescan();
|
|
|
|
+ res.setStudentCode(student.getStudentCode());
|
|
|
|
+ List<PaperVo> papers = scanPaperService.findStudentPaper(student.getId());
|
|
|
|
+ List<Paper> resPapers = new ArrayList<>();
|
|
|
|
+ res.setPapers(resPapers);
|
|
|
|
+ if (CollectionUtils.isEmpty(papers)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ PaperVo first = papers.get(0);
|
|
|
|
+ res.setBatchId(first.getBatchId());
|
|
|
|
+ res.setUser(first.getUserName());
|
|
|
|
+ res.setCreateTime(first.getCreateTime());
|
|
|
|
+ for (PaperVo paper : papers) {
|
|
|
|
+ Paper p = new Paper();
|
|
|
|
+ p.setId(paper.getId());
|
|
|
|
+ p.setNumber(paper.getNumber());
|
|
|
|
+ p.setMismatch(paper.getMismatch());
|
|
|
|
+ List<String> pages = new ArrayList<>();
|
|
|
|
+ p.setPages(pages);
|
|
|
|
+ List<ScanPaperPage> paperPages = scanPaperPageService.listByPaperId(paper.getId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(paperPages)) {
|
|
|
|
+ for (ScanPaperPage pp : paperPages) {
|
|
|
|
+ pages.add(pp.getSheetPath());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ resPapers.add(p);
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
public BatchFinishVo batchFinish(Long id) {
|
|
public BatchFinishVo batchFinish(Long id) {
|
|
ScanBatch batch = checkBatchStatus(getById(id));
|
|
ScanBatch batch = checkBatchStatus(getById(id));
|
|
batch.setStatus(BatchStatus.FINISH);
|
|
batch.setStatus(BatchStatus.FINISH);
|
|
- this.saveOrUpdate(batch);
|
|
|
|
- BatchFinishVo vo = new BatchFinishVo();
|
|
|
|
- vo.setStatus(batch.getStatus());
|
|
|
|
- vo.setUpdateTime(System.currentTimeMillis());
|
|
|
|
- return vo;
|
|
|
|
|
|
+ this.saveOrUpdate(batch);
|
|
|
|
+ BatchFinishVo vo = new BatchFinishVo();
|
|
|
|
+ vo.setStatus(batch.getStatus());
|
|
|
|
+ vo.setUpdateTime(System.currentTimeMillis());
|
|
|
|
+ return vo;
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
public AnswerSaveVo batchSave(AnswerDomain domain, SysUser user) {
|
|
public AnswerSaveVo batchSave(AnswerDomain domain, SysUser user) {
|
|
ScanBatch batch = checkBatchStatus(getById(domain.getBatchId()));
|
|
ScanBatch batch = checkBatchStatus(getById(domain.getBatchId()));
|
|
- String studentCode = domain.getStudentCode();
|
|
|
|
- MarkStudent student = markStudentService.findByExamIdAndCoursePaperIdAndStudentCode(batch.getExamId(),
|
|
|
|
- batch.getCoursePaperId(), studentCode);
|
|
|
|
|
|
+ String studentCode = domain.getStudentCode();
|
|
|
|
+ MarkStudent student = markStudentService.findByExamIdAndCoursePaperIdAndStudentCode(batch.getExamId(),
|
|
|
|
+ batch.getCoursePaperId(), studentCode);
|
|
if (student == null) {
|
|
if (student == null) {
|
|
throw new ParameterException("未找到考生信息:" + studentCode);
|
|
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()));
|
|
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public SheetUploadVo sheetUpload(Long batchId, String coursePaperId, String studentCode, Integer paperNumber,
|
|
|
|
+ Integer pageIndex, MultipartFile file, String md5) {
|
|
|
|
+ ScanBatch batch = checkBatchStatus(getById(batchId));
|
|
|
|
+ try {
|
|
|
|
+ String path = fileService.uploadSheet(file.getInputStream(), md5, batch.getExamId(), batchId, coursePaperId,
|
|
|
|
+ studentCode, paperNumber, pageIndex);
|
|
|
|
+ return SheetUploadVo.create(path);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("原图上传失败,batchId=" + batch + ", coursePaperId=" + coursePaperId + ",studentCode=" + studentCode
|
|
|
|
+ + ", paperNumber=" + paperNumber + ", pageIndex=" + pageIndex, e);
|
|
|
|
+ throw new ParameterException("原图上传失败", e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- @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;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|