|
@@ -10,6 +10,7 @@ import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.mark.bean.papermigrate.PaperMigrateDomain;
|
|
|
import com.qmth.teachcloud.mark.bean.papermigrate.PaperMigratePage;
|
|
|
+import com.qmth.teachcloud.mark.bean.papermigrate.PaperMigratePaper;
|
|
|
import com.qmth.teachcloud.mark.bean.papermigrate.PaperMigrateVo;
|
|
|
import com.qmth.teachcloud.mark.bean.scananswer.StudentPaperVo;
|
|
|
import com.qmth.teachcloud.mark.bean.scanpaper.PaperVo;
|
|
@@ -48,8 +49,6 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
|
|
|
private ConcurrentService concurrentService;
|
|
|
@Autowired
|
|
|
private ScanStudentPaperService scanStudentPaperService;
|
|
|
- @Autowired
|
|
|
- private ScanAnswerCardSubjectService scanAnswerCardSubjectService;
|
|
|
|
|
|
/**
|
|
|
* 全量更新paper和所属的page集合,并刷新paper相关属性
|
|
@@ -126,14 +125,22 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
|
|
|
return baseMapper.listByStudentIds(paramList);
|
|
|
}
|
|
|
|
|
|
+ private boolean isEmptyPage(PaperMigrateDomain domain) {
|
|
|
+ for(PaperMigratePaper paper:domain.getPapers()) {
|
|
|
+ if (CollectionUtils.isEmpty(paper.getPages())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public PaperMigrateVo paperMigrate(SysUser user, PaperMigrateDomain domain) {
|
|
|
- // 查找修改paper
|
|
|
- ScanPaper paper = getById(domain.getPaperId());
|
|
|
- if (paper == null) {
|
|
|
- throw new ParameterException("题卡信息未找到, paperId=" + domain.getPaperId());
|
|
|
+ if (CollectionUtils.isEmpty(domain.getPapers())) {
|
|
|
+ throw new ParameterException("papers信息不能为空");
|
|
|
}
|
|
|
+ List<Long> paperIds=domain.getPapers().stream().map(e -> e.getPaperId()).collect(Collectors.toList());
|
|
|
// 查找目标考生
|
|
|
MarkStudent student = markStudentService.findByExamIdAndCoursePaperIdAndStudentCode(domain.getExamId(),
|
|
|
domain.getCoursePaperId(), domain.getStudentCode());
|
|
@@ -155,24 +162,21 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
|
|
|
// if (!allowSubject) {
|
|
|
// throw new ParameterException("卡格式与考生科目不一致");
|
|
|
// }
|
|
|
- // cardNumber或paperNumber有变化,都需要重新识别
|
|
|
- if ((!paper.getNumber().equals(domain.getPaperNumber())
|
|
|
- || !paper.getCardNumber().equals(domain.getCardNumber()))
|
|
|
- && CollectionUtils.isEmpty(domain.getPages())) {
|
|
|
+ // cardNumber有变化,需要重新识别
|
|
|
+ if (!student.getCardNumber().equals(domain.getCardNumber())
|
|
|
+ && isEmptyPage(domain)) {
|
|
|
throw new ParameterException("卡格式有变化需要重新识别, pages信息不能为空");
|
|
|
}
|
|
|
+
|
|
|
// 指定paper现有绑定考生
|
|
|
MarkStudent previousStudent = null;
|
|
|
- ScanStudentPaper previousStudentPaper = scanStudentPaperService.findByPaperId(domain.getPaperId());
|
|
|
- if (previousStudentPaper != null) {
|
|
|
- // 考生没变,张数也没变
|
|
|
- if (previousStudentPaper.getStudentId().equals(student.getId())
|
|
|
- && previousStudentPaper.getPaperIndex().equals(domain.getPaperNumber())) {
|
|
|
- throw new ParameterException("该题卡已绑定该考生");
|
|
|
- }
|
|
|
+ List<ScanStudentPaper> previousStudentPapers = scanStudentPaperService.findByPaperIds(paperIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(previousStudentPapers)) {
|
|
|
+ checkStudent(previousStudentPapers);
|
|
|
+ Long previousStudentId=previousStudentPapers.get(0).getStudentId();
|
|
|
// 考生ID变了才需要获取原考生
|
|
|
- if (!previousStudentPaper.getStudentId().equals(student.getId())) {
|
|
|
- previousStudent = markStudentService.getById(previousStudentPaper.getStudentId());
|
|
|
+ if (!previousStudentId.equals(student.getId())) {
|
|
|
+ previousStudent = markStudentService.getById(previousStudentId);
|
|
|
}
|
|
|
}
|
|
|
if (previousStudent != null) {
|
|
@@ -180,57 +184,52 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
|
|
|
}
|
|
|
concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().lock();
|
|
|
try {
|
|
|
- if (previousStudentPaper != null) {
|
|
|
- // 解绑paper和原有考生
|
|
|
- if (previousStudent != null) {
|
|
|
- List<ScanStudentPaper> studentPaperList = scanStudentPaperService
|
|
|
- .findByStudentId(previousStudent.getId()).stream()
|
|
|
- .filter(entity -> !entity.getPaperId().equals(previousStudentPaper.getPaperId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- markStudentService.updateStudentAndPaper(user, previousStudent.getId(), studentPaperList);
|
|
|
- }
|
|
|
- // 考生没变,直接解绑paper
|
|
|
- else {
|
|
|
- scanStudentPaperService.removeByStudentIdAndPaperId(previousStudentPaper.getStudentId(),
|
|
|
- previousStudentPaper.getPaperId());
|
|
|
- }
|
|
|
- }
|
|
|
- // 更新paper属性
|
|
|
- paper.setCardNumber(domain.getCardNumber());
|
|
|
- paper.setNumber(domain.getPaperNumber());
|
|
|
- // 修改的paper强制置为人工绑定
|
|
|
- paper.setAssigned(true);
|
|
|
- // 原有mismatch标记需要清除
|
|
|
- paper.setMismatch(false);
|
|
|
- paper.setUpdaterId(user.getId());
|
|
|
- paper.setUpdateTime(System.currentTimeMillis());
|
|
|
- if (CollectionUtils.isNotEmpty(domain.getPages())) {
|
|
|
- // 重新识别时更新所有page
|
|
|
- List<ScanPaperPage> pages = new ArrayList<>();
|
|
|
- for (PaperMigratePage page : domain.getPages()) {
|
|
|
- pages.add(page.update(paperPageService.findPaperIdAndIndex(paper.getId(), page.getIndex())));
|
|
|
- }
|
|
|
- savePaperAndPages(paper, pages);
|
|
|
- } else {
|
|
|
- saveOrUpdate(paper);
|
|
|
- }
|
|
|
- // 查找目标考生现有绑定paper
|
|
|
- boolean exist = false;
|
|
|
- List<ScanStudentPaper> currentStudentPaperList = scanStudentPaperService.findByStudentId(student.getId());
|
|
|
- for (ScanStudentPaper current : currentStudentPaperList) {
|
|
|
- if (current.getPaperIndex().equals(paper.getNumber())) {
|
|
|
- exist = true;
|
|
|
- updateMismatch(current.getPaperId(), true);
|
|
|
- current.setPaperId(paper.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- if (!exist) {
|
|
|
- currentStudentPaperList.add(new ScanStudentPaper(student.getId(), paper.getNumber(), paper.getId()));
|
|
|
+ // 解绑paper和原有考生
|
|
|
+ if (previousStudent != null) {
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
markStudentService.updateStudentAndPaper(user, student.getId(), currentStudentPaperList);
|
|
|
// 返回数据结果
|
|
|
- return PaperMigrateVo.create(domain.getPaperId());
|
|
|
+ return PaperMigrateVo.create(student.getId());
|
|
|
} finally {
|
|
|
concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().unlock();
|
|
|
if (previousStudent != null) {
|
|
@@ -240,7 +239,20 @@ public class ScanPaperServiceImpl extends ServiceImpl<ScanPaperMapper, ScanPaper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ private void checkStudent(List<ScanStudentPaper> previousStudentPapers) {
|
|
|
+ Long studentId=null;
|
|
|
+ for(ScanStudentPaper sp:previousStudentPapers) {
|
|
|
+ if(studentId==null) {
|
|
|
+ studentId=sp.getStudentId();
|
|
|
+ }else {
|
|
|
+ if(!sp.getStudentId().equals(studentId)) {
|
|
|
+ throw new ParameterException("被绑定的题卡不属于同一个考生");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
@Transactional
|
|
|
public boolean updateMismatch(Long id, boolean mismatch) {
|
|
|
LambdaUpdateWrapper<ScanPaper> lw = new LambdaUpdateWrapper<>();
|