|
@@ -1,8 +1,24 @@
|
|
|
package cn.com.qmth.scancentral.service.impl;
|
|
|
|
|
|
-import java.io.*;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.LineNumberReader;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
@@ -35,7 +51,14 @@ import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
import com.qmth.boot.tools.uuid.FastUUID;
|
|
|
|
|
|
-import cn.com.qmth.scancentral.bean.*;
|
|
|
+import cn.com.qmth.scancentral.bean.AbsentQueryDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.AnswerDeleteDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.AnswerQueryDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.AssignedQueryDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.ImportCetAbsentDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.ImportStudentDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.PageDeleteDomain;
|
|
|
+import cn.com.qmth.scancentral.bean.User;
|
|
|
import cn.com.qmth.scancentral.bean.answersave.ArrayResult;
|
|
|
import cn.com.qmth.scancentral.bean.answersave.BoolResult;
|
|
|
import cn.com.qmth.scancentral.bean.answersave.StringResult;
|
|
@@ -46,32 +69,98 @@ import cn.com.qmth.scancentral.bean.refix.AnswerRefixDomain;
|
|
|
import cn.com.qmth.scancentral.bean.refix.PageRefixDomain;
|
|
|
import cn.com.qmth.scancentral.bean.refix.PaperRefixDomain;
|
|
|
import cn.com.qmth.scancentral.config.SysProperty;
|
|
|
+import cn.com.qmth.scancentral.consumer.BreachImportConsumer;
|
|
|
+import cn.com.qmth.scancentral.consumer.CustStatusImportConsumer;
|
|
|
import cn.com.qmth.scancentral.dao.StudentDao;
|
|
|
-import cn.com.qmth.scancentral.entity.*;
|
|
|
-import cn.com.qmth.scancentral.enums.*;
|
|
|
+import cn.com.qmth.scancentral.entity.AnswerCardEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.ExamEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.OmrGroupEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.PaperEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.PaperPageEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.QuestionEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.StudentEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.StudentPaperEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.SubjectEntity;
|
|
|
+import cn.com.qmth.scancentral.entity.UserEntity;
|
|
|
+import cn.com.qmth.scancentral.enums.ExamMode;
|
|
|
+import cn.com.qmth.scancentral.enums.ExamStatus;
|
|
|
+import cn.com.qmth.scancentral.enums.ExamStatusCheckMode;
|
|
|
+import cn.com.qmth.scancentral.enums.GroupType;
|
|
|
+import cn.com.qmth.scancentral.enums.ImageCheckStatus;
|
|
|
+import cn.com.qmth.scancentral.enums.LockType;
|
|
|
+import cn.com.qmth.scancentral.enums.OP;
|
|
|
+import cn.com.qmth.scancentral.enums.OmrField;
|
|
|
+import cn.com.qmth.scancentral.enums.Role;
|
|
|
+import cn.com.qmth.scancentral.enums.ScanStatus;
|
|
|
+import cn.com.qmth.scancentral.enums.UploadStatus;
|
|
|
import cn.com.qmth.scancentral.exception.NotFoundExceptions;
|
|
|
import cn.com.qmth.scancentral.exception.ParameterExceptions;
|
|
|
import cn.com.qmth.scancentral.model.ManualAbsentImportDTO;
|
|
|
-import cn.com.qmth.scancentral.service.*;
|
|
|
+import cn.com.qmth.scancentral.service.AnswerCardService;
|
|
|
+import cn.com.qmth.scancentral.service.AnswerCardSubjectService;
|
|
|
+import cn.com.qmth.scancentral.service.AssignedCheckHistoryService;
|
|
|
+import cn.com.qmth.scancentral.service.AsyncTaskService;
|
|
|
+import cn.com.qmth.scancentral.service.BatchService;
|
|
|
+import cn.com.qmth.scancentral.service.ExamService;
|
|
|
+import cn.com.qmth.scancentral.service.FileService;
|
|
|
+import cn.com.qmth.scancentral.service.OmrGroupService;
|
|
|
+import cn.com.qmth.scancentral.service.OmrTaskService;
|
|
|
+import cn.com.qmth.scancentral.service.PaperPageService;
|
|
|
+import cn.com.qmth.scancentral.service.PaperService;
|
|
|
+import cn.com.qmth.scancentral.service.QuestionService;
|
|
|
+import cn.com.qmth.scancentral.service.StudentPaperService;
|
|
|
+import cn.com.qmth.scancentral.service.StudentService;
|
|
|
+import cn.com.qmth.scancentral.service.SubjectService;
|
|
|
+import cn.com.qmth.scancentral.service.ToolExportService;
|
|
|
+import cn.com.qmth.scancentral.service.UserService;
|
|
|
+import cn.com.qmth.scancentral.support.SpringContextHolder;
|
|
|
import cn.com.qmth.scancentral.support.TaskLock;
|
|
|
import cn.com.qmth.scancentral.support.TaskLockUtil;
|
|
|
import cn.com.qmth.scancentral.util.BatchGetDataUtil;
|
|
|
import cn.com.qmth.scancentral.util.BatchSetDataUtil;
|
|
|
import cn.com.qmth.scancentral.util.MD5Util;
|
|
|
import cn.com.qmth.scancentral.util.PageUtil;
|
|
|
-import cn.com.qmth.scancentral.vo.*;
|
|
|
-import cn.com.qmth.scancentral.vo.answerquery.*;
|
|
|
+import cn.com.qmth.scancentral.vo.AbsentInfoVo;
|
|
|
+import cn.com.qmth.scancentral.vo.AbsentManualImportVo;
|
|
|
+import cn.com.qmth.scancentral.vo.AbsentQueryVo;
|
|
|
+import cn.com.qmth.scancentral.vo.AnswerDeleteVo;
|
|
|
+import cn.com.qmth.scancentral.vo.AnswerExportK12Vo;
|
|
|
+import cn.com.qmth.scancentral.vo.AnswerExportVo;
|
|
|
+import cn.com.qmth.scancentral.vo.AnswerRefixVo;
|
|
|
+import cn.com.qmth.scancentral.vo.CampusVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ExamSiteVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ExportCetMarkingQueryVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ExportCetVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ImportResult;
|
|
|
+import cn.com.qmth.scancentral.vo.ImportStudentQueryVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ImportStudentVo;
|
|
|
+import cn.com.qmth.scancentral.vo.PaperDeleteVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ScanAnswerInfoVo;
|
|
|
+import cn.com.qmth.scancentral.vo.StudentUploadVo;
|
|
|
+import cn.com.qmth.scancentral.vo.UpdateTimeVo;
|
|
|
+import cn.com.qmth.scancentral.vo.answerquery.AnswerPageVo;
|
|
|
+import cn.com.qmth.scancentral.vo.answerquery.AnswerPaperVo;
|
|
|
+import cn.com.qmth.scancentral.vo.answerquery.AnswerQueryParam;
|
|
|
+import cn.com.qmth.scancentral.vo.answerquery.AnswerQueryVo;
|
|
|
+import cn.com.qmth.scancentral.vo.answerquery.StudentPaperVo;
|
|
|
import cn.com.qmth.scancentral.vo.assginedcheck.AssginedTaskResult;
|
|
|
import cn.com.qmth.scancentral.vo.assginedcheck.AssignedCheckExamRoomExport;
|
|
|
import cn.com.qmth.scancentral.vo.assginedcheck.AssignedCheckExport;
|
|
|
import cn.com.qmth.scancentral.vo.assginedcheck.AssignedTaskSaveVo;
|
|
|
+import cn.com.qmth.scancentral.vo.asynctask.BreachAndStatusImportTaskVo;
|
|
|
import cn.com.qmth.scancentral.vo.examroom.ExamRoomScannedQuery;
|
|
|
import cn.com.qmth.scancentral.vo.examroom.ExamRoomScannedVo;
|
|
|
import cn.com.qmth.scancentral.vo.paper.PaperCetVo;
|
|
|
import cn.com.qmth.scancentral.vo.paper.PaperPageCetVo;
|
|
|
-import cn.com.qmth.scancentral.vo.student.*;
|
|
|
+import cn.com.qmth.scancentral.vo.student.StudentAnswerVo;
|
|
|
+import cn.com.qmth.scancentral.vo.student.StudentExamRoomVo;
|
|
|
+import cn.com.qmth.scancentral.vo.student.StudentPageQuery;
|
|
|
+import cn.com.qmth.scancentral.vo.student.StudentPageVo;
|
|
|
+import cn.com.qmth.scancentral.vo.student.StudentQuery;
|
|
|
+import cn.com.qmth.scancentral.vo.student.StudentVo;
|
|
|
import cn.com.qmth.scancentral.vo.studentimport.StudentCountVo;
|
|
|
import cn.com.qmth.scancentral.vo.subject.SubjectScanProgressVo;
|
|
|
+import cn.com.qmth.scancentral.vo.subject.TaskIdVo;
|
|
|
import cn.com.qmth.scancentral.vo.task.TaskStatusVo;
|
|
|
|
|
|
@Service
|
|
@@ -79,6 +168,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(StudentService.class);
|
|
|
|
|
|
+ private static ExecutorService exec;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AsyncTaskService asyncTaskService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private PaperService paperService;
|
|
|
|
|
@@ -130,6 +224,23 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
@Autowired
|
|
|
private FileService fileService;
|
|
|
|
|
|
+ static {
|
|
|
+ int threadCount = 5;
|
|
|
+ exec = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.SECONDS,
|
|
|
+ new LinkedBlockingQueue<>(threadCount * 2), r -> {
|
|
|
+ Thread t = new Thread(r);
|
|
|
+ return t;
|
|
|
+ }, (r, executor) -> {
|
|
|
+ if (!executor.isShutdown()) {
|
|
|
+ try {
|
|
|
+ executor.getQueue().put(r);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 整体更新考生绑定的paper并刷新考生状态,若集合为空则表示考生无扫描结果,需要在外部调用处对考生上锁
|
|
|
*
|
|
@@ -185,7 +296,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
// 获取paper详情更新考生状态
|
|
|
PaperEntity paper = paperService.getById(studentPaper.getPaperId());
|
|
|
student.setAssigned(student.getAssigned() || paper.getAssigned());
|
|
|
-// student.setAssignedSuspect(student.getAssignedSuspect() || paper.getAssignedSuspect());
|
|
|
+ // student.setAssignedSuspect(student.getAssignedSuspect() ||
|
|
|
+ // paper.getAssignedSuspect());
|
|
|
student.setQuestionFilled(student.getQuestionFilled() || paper.getQuestionFilled());
|
|
|
student.setSubjectiveFilled(student.getSubjectiveFilled() || paper.getSubjectiveFilled());
|
|
|
student.setCardNumber(paper.getCardNumber());
|
|
@@ -1673,10 +1785,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int getCountByExamAndAssignedCheckCount(Long examId,String subjectCode, int assignedCheckCount, OP op) {
|
|
|
+ public int getCountByExamAndAssignedCheckCount(Long examId, String subjectCode, int assignedCheckCount, OP op) {
|
|
|
LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StudentEntity::getExamId, examId);
|
|
|
- if(subjectCode!=null){
|
|
|
+ if (subjectCode != null) {
|
|
|
wrapper.eq(StudentEntity::getSubjectCode, subjectCode);
|
|
|
}
|
|
|
wrapper.eq(StudentEntity::getAssigned, true);
|
|
@@ -1766,7 +1878,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
pvo.setId(p.getPaperId());
|
|
|
pvo.setNumber(p.getNumber());
|
|
|
pvo.setAssigned(p.getAssigned());
|
|
|
-// pvo.setAssignedSuspect(p.getAssignedSuspect());
|
|
|
+ // pvo.setAssignedSuspect(p.getAssignedSuspect());
|
|
|
papers.add(pvo);
|
|
|
paperMap.put(p.getPaperId(), pvo);
|
|
|
}
|
|
@@ -1812,7 +1924,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
|
|
|
@Override
|
|
|
public boolean apply(StudentEntity t, String account) {
|
|
|
- TaskLock taskLock = TaskLockUtil.getAssignedCheckTask(t.getExamId()+"_"+t.getSubjectCode());
|
|
|
+ TaskLock taskLock = TaskLockUtil.getAssignedCheckTask(t.getExamId() + "_" + t.getSubjectCode());
|
|
|
boolean lock = taskLock.add(t.getId(), account);
|
|
|
// 上锁失败直接返回
|
|
|
if (!lock) {
|
|
@@ -1829,26 +1941,26 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
|
|
|
@Override
|
|
|
public boolean hasAppliedAssignedCheckTask(StudentEntity t, String account) {
|
|
|
- TaskLock taskLock = TaskLockUtil.getAssignedCheckTask(t.getExamId()+"_"+t.getSubjectCode());
|
|
|
+ TaskLock taskLock = TaskLockUtil.getAssignedCheckTask(t.getExamId() + "_" + t.getSubjectCode());
|
|
|
return taskLock.exist(t.getId(), account);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public TaskStatusVo getAssignedCheckTaskStatus(Long examId,String subjectCode, User user) {
|
|
|
+ public TaskStatusVo getAssignedCheckTaskStatus(Long examId, String subjectCode, User user) {
|
|
|
TaskStatusVo status = new TaskStatusVo();
|
|
|
if (Role.AUDITOR.equals(user.getRole())) {
|
|
|
- status.setFinishCount(assignedCheckHistoryService.getCountByUserId(user.getId(), examId,subjectCode));
|
|
|
- status.setTodoCount(this.getCountByExamAndAssignedCheckCount(examId,subjectCode, 0, OP.EQ));
|
|
|
+ status.setFinishCount(assignedCheckHistoryService.getCountByUserId(user.getId(), examId, subjectCode));
|
|
|
+ status.setTodoCount(this.getCountByExamAndAssignedCheckCount(examId, subjectCode, 0, OP.EQ));
|
|
|
} else {
|
|
|
- status.setFinishCount(this.getCountByExamAndAssignedCheckCount(examId,subjectCode, 2, OP.GE));
|
|
|
- status.setTodoCount(this.getCountByExamAndAssignedCheckCount(examId, subjectCode,1, OP.EQ));
|
|
|
+ status.setFinishCount(this.getCountByExamAndAssignedCheckCount(examId, subjectCode, 2, OP.GE));
|
|
|
+ status.setTodoCount(this.getCountByExamAndAssignedCheckCount(examId, subjectCode, 1, OP.EQ));
|
|
|
}
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void releaseAssignedCheckTaskByUser(Long examId,String subjectCode , String account) {
|
|
|
- TaskLock taskLock = TaskLockUtil.getAssignedCheckTask(examId+"_"+subjectCode);
|
|
|
+ public void releaseAssignedCheckTaskByUser(Long examId, String subjectCode, String account) {
|
|
|
+ TaskLock taskLock = TaskLockUtil.getAssignedCheckTask(examId + "_" + subjectCode);
|
|
|
taskLock.clear(account);
|
|
|
}
|
|
|
|
|
@@ -1864,10 +1976,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
concurrentService.getReadWriteLock(LockType.STUDENT + "-" + student.getId()).writeLock().lock();
|
|
|
try {
|
|
|
assignedCheckHistoryService.save(user.getId(), student.getId(), student.getExamId());
|
|
|
-// for (AssignedTaskResultPaper paper : result.getPapers()) {
|
|
|
-// paperService.updatePaperAssignedSuspect(student.getId(), paper.getNumber(), result.getAssignedSuspect());
|
|
|
-// }
|
|
|
-// updateStudentByPaper(user, student.getId(), false);
|
|
|
+ // for (AssignedTaskResultPaper paper : result.getPapers()) {
|
|
|
+ // paperService.updatePaperAssignedSuspect(student.getId(),
|
|
|
+ // paper.getNumber(), result.getAssignedSuspect());
|
|
|
+ // }
|
|
|
+ // updateStudentByPaper(user, student.getId(), false);
|
|
|
student.setAbsentSuspect(result.getAssignedSuspect());
|
|
|
saveOrUpdate(student);
|
|
|
updateAssignedCheckCount(student.getId(), false);
|
|
@@ -1876,31 +1989,33 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
}
|
|
|
AssignedTaskSaveVo vo = new AssignedTaskSaveVo();
|
|
|
vo.setId(student.getId());
|
|
|
- vo.setStatus(this.getAssignedCheckTaskStatus(student.getExamId(),student.getSubjectCode(), user));
|
|
|
+ vo.setStatus(this.getAssignedCheckTaskStatus(student.getExamId(), student.getSubjectCode(), user));
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageResult<AnswerQueryVo> getAssignedCheckTaskHistory(Long examId,String subjectCode,Long pageNumber, Long pageSize, User user) {
|
|
|
- IPage<AnswerQueryVo> result = this.baseMapper.getAssignedCheckTaskHistory(new Page<>(pageNumber, pageSize),examId,subjectCode,user.getId());
|
|
|
+ public PageResult<AnswerQueryVo> getAssignedCheckTaskHistory(Long examId, String subjectCode, Long pageNumber,
|
|
|
+ Long pageSize, User user) {
|
|
|
+ IPage<AnswerQueryVo> result = this.baseMapper.getAssignedCheckTaskHistory(new Page<>(pageNumber, pageSize),
|
|
|
+ examId, subjectCode, user.getId());
|
|
|
for (AnswerQueryVo t : result.getRecords()) {
|
|
|
t = toTaskVo(t);
|
|
|
}
|
|
|
- return PageUtil.of(result);
|
|
|
+ return PageUtil.of(result);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AnswerQueryVo getAssignedCheckTask(Long examId,String subjectCode, User user) {
|
|
|
+ public AnswerQueryVo getAssignedCheckTask(Long examId, String subjectCode, User user) {
|
|
|
int retry = 0;
|
|
|
AnswerQueryVo task = null;
|
|
|
int checkCount = 0;
|
|
|
if (Role.AUDITOR.equals(user.getRole())) {
|
|
|
checkCount = 0;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
checkCount = 1;
|
|
|
}
|
|
|
while (task == null) {
|
|
|
- List<AnswerQueryVo> list = this.findUnCheck(examId,subjectCode,checkCount, retry * 20, 20);
|
|
|
+ List<AnswerQueryVo> list = this.findUnCheck(examId, subjectCode, checkCount, retry * 20, 20);
|
|
|
if (list.isEmpty()) {
|
|
|
break;
|
|
|
}
|
|
@@ -1921,8 +2036,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
return task;
|
|
|
}
|
|
|
|
|
|
- private List<AnswerQueryVo> findUnCheck(Long examId,String subjectCode,int checkCount, int pageNumber, int pageSize) {
|
|
|
- return this.baseMapper.findUnCheck(examId,subjectCode, checkCount,pageNumber, pageSize );
|
|
|
+ private List<AnswerQueryVo> findUnCheck(Long examId, String subjectCode, int checkCount, int pageNumber,
|
|
|
+ int pageSize) {
|
|
|
+ return this.baseMapper.findUnCheck(examId, subjectCode, checkCount, pageNumber, pageSize);
|
|
|
}
|
|
|
|
|
|
private AnswerQueryVo toTaskVo(AnswerQueryVo t) {
|
|
@@ -1962,7 +2078,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
pvo.setId(p.getPaperId());
|
|
|
pvo.setNumber(p.getNumber());
|
|
|
pvo.setAssigned(p.getAssigned());
|
|
|
-// pvo.setAssignedSuspect(p.getAssignedSuspect());
|
|
|
+ // pvo.setAssignedSuspect(p.getAssignedSuspect());
|
|
|
papers.add(pvo);
|
|
|
paperMap.put(p.getPaperId(), pvo);
|
|
|
}
|
|
@@ -2112,88 +2228,109 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ImportBreachResult breachImport(Long examId, String subjectCode, MultipartFile file) {
|
|
|
+ public TaskIdVo breachImport(Long examId, String subjectCode, MultipartFile file) {
|
|
|
+ if (!file.getName().toLowerCase().endsWith(".txt")) {
|
|
|
+ throw new ParameterException("只能是txt文件");
|
|
|
+ }
|
|
|
+ String taskId = FastUUID.get();
|
|
|
// 暂存临时文件
|
|
|
- File temDir = new File("temp/" + FastUUID.get() + "/");
|
|
|
+ File temDir = new File("temp/" + taskId + "/");
|
|
|
+ temDir.mkdirs();
|
|
|
+ File txt = new File(temDir.getAbsolutePath() + "/breach.txt");
|
|
|
try {
|
|
|
- temDir.mkdirs();
|
|
|
- File excel = new File(temDir.getAbsolutePath() + "/breach.txt");
|
|
|
- try {
|
|
|
- file.transferTo(excel);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
+ file.transferTo(txt);
|
|
|
+ List<String> list = FileUtils.readLines(txt, "utf-8");
|
|
|
+ if (CollectionUtils.isEmpty(list) || list.size() <= 1) {
|
|
|
+ throw new ParameterException("文件内容为空");
|
|
|
+ }
|
|
|
+ BreachAndStatusImportTaskVo vo = new BreachAndStatusImportTaskVo();
|
|
|
+ vo.setTaskId(taskId);
|
|
|
+ vo.setTotalCount(list.size() - 1);
|
|
|
+ vo.setExamId(examId);
|
|
|
+ vo.setSubjectCode(subjectCode);
|
|
|
+ vo.setSuccess(true);
|
|
|
+ vo.setProgress(0.0);
|
|
|
+ vo.setTempDir(temDir);
|
|
|
+ vo.setFile(txt);
|
|
|
+ vo.setSuccess(true);
|
|
|
+ BreachImportConsumer com = SpringContextHolder.getBean(BreachImportConsumer.class);
|
|
|
+ com.setVo(vo);
|
|
|
+ exec.execute(com);
|
|
|
+ asyncTaskService.addTask(vo);
|
|
|
+ return TaskIdVo.create(vo.getTaskId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void breachImportDispose(BreachAndStatusImportTaskVo vo) {
|
|
|
+ InputStream in = null;
|
|
|
+ try {
|
|
|
+ in = new FileInputStream(vo.getFile());
|
|
|
+ breachImportCheck(vo, in);
|
|
|
+ } catch (ParameterException e) {
|
|
|
+ vo.setErrMsg(e.getMessage());
|
|
|
+ vo.setSuccess(false);
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ vo.setErrMsg("系统错误");
|
|
|
+ vo.setSuccess(false);
|
|
|
+ throw new ParameterException("系统错误", e);
|
|
|
+ } finally {
|
|
|
+ if (in != null) {
|
|
|
+ try {
|
|
|
+ in.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
}
|
|
|
- // 校验Excel
|
|
|
- ImportBreachResult ret = null;
|
|
|
- InputStream in = null;
|
|
|
+ }
|
|
|
+ // 根据校验结果上传文件
|
|
|
+ if (vo.getSuccess()) {
|
|
|
+ InputStream excelIn = null;
|
|
|
try {
|
|
|
- in = new FileInputStream(excel);
|
|
|
- ret = breachImportCheck(examId, subjectCode, in);
|
|
|
+ String md5 = MD5Util.md5Hex(vo.getFile());
|
|
|
+ excelIn = new FileInputStream(vo.getFile());
|
|
|
+ fileService.uploadBreach(excelIn, md5, vo.getExamId(), vo.getSubjectCode());
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
+ throw new ParameterException("系统错误", e);
|
|
|
} finally {
|
|
|
- if (in != null) {
|
|
|
+ if (excelIn != null) {
|
|
|
try {
|
|
|
- in.close();
|
|
|
+ excelIn.close();
|
|
|
} catch (IOException e) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 根据校验结果上传文件
|
|
|
- if (ret != null && ret.getSuccess()) {
|
|
|
- InputStream excelIn = null;
|
|
|
- try {
|
|
|
- String md5 = MD5Util.md5Hex(excel);
|
|
|
- excelIn = new FileInputStream(excel);
|
|
|
- fileService.uploadBreach(excelIn, md5, examId, subjectCode);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- } finally {
|
|
|
- if (excelIn != null) {
|
|
|
- try {
|
|
|
- excelIn.close();
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- File info = new File(temDir.getAbsolutePath() + "/breach-info.txt");
|
|
|
- InputStream infoIn = null;
|
|
|
- try {
|
|
|
- FileUtils.write(info, ret.getBreachCount().toString(), "utf-8");
|
|
|
- String md5 = MD5Util.md5Hex(info);
|
|
|
- infoIn = new FileInputStream(info);
|
|
|
- fileService.uploadBreachInfo(infoIn, md5, examId, subjectCode);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- } finally {
|
|
|
- if (infoIn != null) {
|
|
|
- try {
|
|
|
- infoIn.close();
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return ret;
|
|
|
- } finally {
|
|
|
+ File info = new File(vo.getTempDir().getAbsolutePath() + "/breach-info.txt");
|
|
|
+ InputStream infoIn = null;
|
|
|
try {
|
|
|
- FileUtils.deleteDirectory(temDir);
|
|
|
+ FileUtils.write(info, vo.getProgressCount() + "", "utf-8");
|
|
|
+ String md5 = MD5Util.md5Hex(info);
|
|
|
+ infoIn = new FileInputStream(info);
|
|
|
+ fileService.uploadBreachInfo(infoIn, md5, vo.getExamId(), vo.getSubjectCode());
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
+ throw new ParameterException("系统错误", e);
|
|
|
+ } finally {
|
|
|
+ if (infoIn != null) {
|
|
|
+ try {
|
|
|
+ infoIn.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ vo.setTotalCount(vo.getProgressCount());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ImportBreachResult breachImportCheck(Long examId, String subjectCode, InputStream in) {
|
|
|
+ private void breachImportCheck(BreachAndStatusImportTaskVo vo, InputStream in) {
|
|
|
List<String> lineList = null;
|
|
|
try {
|
|
|
lineList = IOUtils.readLines(in, "UTF-8");
|
|
|
} catch (IOException e) {
|
|
|
- throw new StatusException("读取文件出错", e);
|
|
|
+ throw new ParameterException("读取文件出错", e);
|
|
|
}
|
|
|
- ImportBreachResult ret = new ImportBreachResult();
|
|
|
- List<String> failRecords = new ArrayList<>();
|
|
|
- ret.setErrMsg(failRecords);
|
|
|
Set<String> examNumberSet = new HashSet<>();
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
|
String lineString = lineList.get(i);
|
|
@@ -2209,7 +2346,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
if (StringUtils.isBlank(examNumber)) {
|
|
|
msg.append(" 准考证号不能为空");
|
|
|
} else {
|
|
|
- StudentEntity s = findByExamAndSubjectCodeAndExamNumber(examId, subjectCode, examNumber);
|
|
|
+ StudentEntity s = findByExamAndSubjectCodeAndExamNumber(vo.getExamId(), vo.getSubjectCode(),
|
|
|
+ examNumber);
|
|
|
if (s == null) {
|
|
|
msg.append(" 准考证号未找到");
|
|
|
} else {
|
|
@@ -2222,21 +2360,17 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
}
|
|
|
|
|
|
String breach = trimAndNullIfBlank(line[1]);
|
|
|
- if (StringUtils.isNotBlank(breach)) {
|
|
|
- ret.setBreachCount(ret.getBreachCount() + 1);
|
|
|
+ if (StringUtils.isBlank(breach)) {
|
|
|
+ msg.append(" 违纪不能为空");
|
|
|
+ } else {
|
|
|
+ vo.setProgressCount(vo.getProgressCount() + 1);
|
|
|
}
|
|
|
}
|
|
|
if (msg.length() > 0) {
|
|
|
- failRecords.add(errorMsg(i + 2, msg.toString()));
|
|
|
+ throw new ParameterException(errorMsg(i + 2, msg.toString()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- ret.setSuccess(false);
|
|
|
- return ret;
|
|
|
- }
|
|
|
- ret.setSuccess(true);
|
|
|
- return ret;
|
|
|
}
|
|
|
|
|
|
private String errorMsg(int lineNum, String msg) {
|
|
@@ -2244,88 +2378,108 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ImportBreachResult custStatusImport(Long examId, String subjectCode, MultipartFile file) {
|
|
|
+ public TaskIdVo custStatusImport(Long examId, String subjectCode, MultipartFile file) {
|
|
|
+ if (!file.getName().toLowerCase().endsWith(".txt")) {
|
|
|
+ throw new ParameterException("只能是txt文件");
|
|
|
+ }
|
|
|
+ String taskId = FastUUID.get();
|
|
|
// 暂存临时文件
|
|
|
- File temDir = new File("temp/" + FastUUID.get() + "/");
|
|
|
+ File temDir = new File("temp/" + taskId + "/");
|
|
|
+ temDir.mkdirs();
|
|
|
+ File txt = new File(temDir.getAbsolutePath() + "/cust-status.txt");
|
|
|
try {
|
|
|
- temDir.mkdirs();
|
|
|
- File excel = new File(temDir.getAbsolutePath() + "/cust-status.txt");
|
|
|
- try {
|
|
|
- file.transferTo(excel);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
+ file.transferTo(txt);
|
|
|
+ List<String> list = FileUtils.readLines(txt, "utf-8");
|
|
|
+ if (CollectionUtils.isEmpty(list) || list.size() <= 1) {
|
|
|
+ throw new ParameterException("文件内容为空");
|
|
|
+ }
|
|
|
+ BreachAndStatusImportTaskVo vo = new BreachAndStatusImportTaskVo();
|
|
|
+ vo.setTaskId(taskId);
|
|
|
+ vo.setTotalCount(list.size() - 1);
|
|
|
+ vo.setExamId(examId);
|
|
|
+ vo.setSubjectCode(subjectCode);
|
|
|
+ vo.setSuccess(true);
|
|
|
+ vo.setProgress(0.0);
|
|
|
+ vo.setTempDir(temDir);
|
|
|
+ vo.setFile(txt);
|
|
|
+ vo.setSuccess(true);
|
|
|
+ CustStatusImportConsumer com = SpringContextHolder.getBean(CustStatusImportConsumer.class);
|
|
|
+ com.setVo(vo);
|
|
|
+ exec.execute(com);
|
|
|
+ asyncTaskService.addTask(vo);
|
|
|
+ return TaskIdVo.create(vo.getTaskId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void custStatusImportDispose(BreachAndStatusImportTaskVo vo) {
|
|
|
+ InputStream in = null;
|
|
|
+ try {
|
|
|
+ in = new FileInputStream(vo.getFile());
|
|
|
+ custStatusImportCheck(vo, in);
|
|
|
+ } catch (ParameterException e) {
|
|
|
+ vo.setErrMsg(e.getMessage());
|
|
|
+ vo.setSuccess(false);
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ vo.setErrMsg("系统错误");
|
|
|
+ vo.setSuccess(false);
|
|
|
+ throw new ParameterException("系统错误", e);
|
|
|
+ } finally {
|
|
|
+ if (in != null) {
|
|
|
+ try {
|
|
|
+ in.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
}
|
|
|
- // 校验Excel
|
|
|
- ImportBreachResult ret = null;
|
|
|
- InputStream in = null;
|
|
|
+ }
|
|
|
+ // 根据校验结果上传文件
|
|
|
+ if (vo.getSuccess()) {
|
|
|
+ InputStream excelIn = null;
|
|
|
try {
|
|
|
- in = new FileInputStream(excel);
|
|
|
- ret = custStatusImportCheck(examId, subjectCode, in);
|
|
|
+ String md5 = MD5Util.md5Hex(vo.getFile());
|
|
|
+ excelIn = new FileInputStream(vo.getFile());
|
|
|
+ fileService.uploadCustStatus(excelIn, md5, vo.getExamId(), vo.getSubjectCode());
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
+ throw new ParameterException("系统错误", e);
|
|
|
} finally {
|
|
|
- if (in != null) {
|
|
|
+ if (excelIn != null) {
|
|
|
try {
|
|
|
- in.close();
|
|
|
+ excelIn.close();
|
|
|
} catch (IOException e) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 根据校验结果上传文件
|
|
|
- if (ret != null && ret.getSuccess()) {
|
|
|
- InputStream excelIn = null;
|
|
|
- try {
|
|
|
- String md5 = MD5Util.md5Hex(excel);
|
|
|
- excelIn = new FileInputStream(excel);
|
|
|
- fileService.uploadCustStatus(in, md5, examId, subjectCode);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- } finally {
|
|
|
- if (excelIn != null) {
|
|
|
- try {
|
|
|
- excelIn.close();
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- File info = new File(temDir.getAbsolutePath() + "/cust-status-info.txt");
|
|
|
- InputStream infoIn = null;
|
|
|
- try {
|
|
|
- FileUtils.write(info, ret.getBreachCount().toString(), "utf-8");
|
|
|
- String md5 = MD5Util.md5Hex(info);
|
|
|
- infoIn = new FileInputStream(info);
|
|
|
- fileService.uploadCustStatusInfo(infoIn, md5, examId, subjectCode);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- } finally {
|
|
|
- if (infoIn != null) {
|
|
|
- try {
|
|
|
- infoIn.close();
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return ret;
|
|
|
- } finally {
|
|
|
+ File info = new File(vo.getTempDir().getAbsolutePath() + "/cust-status-info.txt");
|
|
|
+ InputStream infoIn = null;
|
|
|
try {
|
|
|
- FileUtils.deleteDirectory(temDir);
|
|
|
+ FileUtils.write(info, vo.getProgressCount() + "", "utf-8");
|
|
|
+ String md5 = MD5Util.md5Hex(info);
|
|
|
+ infoIn = new FileInputStream(info);
|
|
|
+ fileService.uploadCustStatusInfo(infoIn, md5, vo.getExamId(), vo.getSubjectCode());
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
+ throw new ParameterException("系统错误", e);
|
|
|
+ } finally {
|
|
|
+ if (infoIn != null) {
|
|
|
+ try {
|
|
|
+ infoIn.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ vo.setTotalCount(vo.getProgressCount());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ImportBreachResult custStatusImportCheck(Long examId, String subjectCode, InputStream in) {
|
|
|
+ private void custStatusImportCheck(BreachAndStatusImportTaskVo vo, InputStream in) {
|
|
|
List<String> lineList = null;
|
|
|
try {
|
|
|
lineList = IOUtils.readLines(in, "UTF-8");
|
|
|
} catch (IOException e) {
|
|
|
- throw new StatusException("读取文件出错", e);
|
|
|
+ throw new ParameterException("读取文件出错", e);
|
|
|
}
|
|
|
- ImportBreachResult ret = new ImportBreachResult();
|
|
|
- List<String> failRecords = new ArrayList<>();
|
|
|
- ret.setErrMsg(failRecords);
|
|
|
Set<String> examNumberSet = new HashSet<>();
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
|
String lineString = lineList.get(i);
|
|
@@ -2342,7 +2496,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
if (StringUtils.isBlank(examNumber)) {
|
|
|
msg.append(" 准考证号不能为空");
|
|
|
} else {
|
|
|
- StudentEntity s = findByExamAndSubjectCodeAndExamNumber(examId, subjectCode, examNumber);
|
|
|
+ StudentEntity s = findByExamAndSubjectCodeAndExamNumber(vo.getExamId(), vo.getSubjectCode(),
|
|
|
+ examNumber);
|
|
|
if (s == null) {
|
|
|
msg.append(" 准考证号未找到");
|
|
|
} else {
|
|
@@ -2355,21 +2510,17 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
}
|
|
|
|
|
|
String breach = trimAndNullIfBlank(line[1]);
|
|
|
- if (StringUtils.isNotBlank(breach)) {
|
|
|
- ret.setBreachCount(ret.getBreachCount() + 1);
|
|
|
+ if (StringUtils.isBlank(breach)) {
|
|
|
+ msg.append(" 考生状态不能为空");
|
|
|
+ } else {
|
|
|
+ vo.setProgressCount(vo.getProgressCount() + 1);
|
|
|
}
|
|
|
}
|
|
|
if (msg.length() > 0) {
|
|
|
- failRecords.add(errorMsg(i + 2, msg.toString()));
|
|
|
+ throw new ParameterException(errorMsg(i + 2, msg.toString()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- ret.setSuccess(false);
|
|
|
- return ret;
|
|
|
- }
|
|
|
- ret.setSuccess(true);
|
|
|
- return ret;
|
|
|
}
|
|
|
|
|
|
@Override
|