xiatian před 8 měsíci
rodič
revize
e5431c836d

+ 1 - 1
src/main/java/cn/com/qmth/scancentral/controller/admin/AsyncTaskController.java

@@ -41,7 +41,7 @@ public class AsyncTaskController extends BaseController {
         AsyncProgressVo ret = new AsyncProgressVo();
         ret.setErrMsg(vo.getErrMsg());
         ret.setProgress(vo.getProgress());
-        ret.setSuccess(vo.getSuccess());
+        ret.setStatus(vo.getStatus());
         return ret;
     }
 

+ 5 - 4
src/main/java/cn/com/qmth/scancentral/controller/admin/CheckController.java

@@ -43,6 +43,7 @@ import cn.com.qmth.scancentral.bean.AnswerQueryDomain;
 import cn.com.qmth.scancentral.controller.BaseController;
 import cn.com.qmth.scancentral.entity.ExamEntity;
 import cn.com.qmth.scancentral.entity.SubjectEntity;
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
 import cn.com.qmth.scancentral.enums.ExamStatus;
 import cn.com.qmth.scancentral.enums.ExamStatusCheckMode;
 import cn.com.qmth.scancentral.enums.GroupType;
@@ -299,10 +300,10 @@ public class CheckController extends BaseController {
                 }
                 ExamStatusImportTaskVo vo = new ExamStatusImportTaskVo();
                 vo.setTaskId(taskId);
-                vo.setTotalCount(list.size());
+                vo.setTotalCount(list.size() - 1);
                 vo.setExamId(examId);
                 vo.setMode(mode);
-                vo.setSuccess(true);
+                vo.setStatus(AsyncTaskStatus.RUNNING);
                 vo.setProgress(0.0);
                 vo.setTempDir(temDir);
                 vo.setFile(txt);
@@ -350,10 +351,10 @@ public class CheckController extends BaseController {
                 }
                 ExamStatusResetTaskVo vo = new ExamStatusResetTaskVo();
                 vo.setTaskId(taskId);
-                vo.setTotalCount(total + 1);
+                vo.setTotalCount(total);
                 vo.setExamId(examId);
                 vo.setExamNumberFillCount(examNumberFillCount);
-                vo.setSuccess(true);
+                vo.setStatus(AsyncTaskStatus.RUNNING);
                 vo.setProgress(0.0);
                 taskExecutor.submit(new ExamStatusResetThread(vo, studentService, concurrentService));
                 asyncTaskService.addTask(vo);

+ 3 - 2
src/main/java/cn/com/qmth/scancentral/controller/admin/SubjectController.java

@@ -16,6 +16,7 @@ import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.core.exception.ParameterException;
 
 import cn.com.qmth.scancentral.controller.BaseController;
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
 import cn.com.qmth.scancentral.service.AsyncTaskService;
 import cn.com.qmth.scancentral.service.SubjectService;
 import cn.com.qmth.scancentral.vo.subject.DataExportTaskVo;
@@ -75,10 +76,10 @@ public class SubjectController extends BaseController {
         if (vo == null) {
             throw new ParameterException("未找到导出任务");
         }
-        if (vo.getSuccess() == null || !vo.getSuccess()) {
+        if (AsyncTaskStatus.FAILED.equals(vo.getStatus())) {
             throw new ParameterException("导出任务失败");
         }
-        if (vo.getTotalCount() != (vo.getProgressCount())) {
+        if (AsyncTaskStatus.RUNNING.equals(vo.getStatus())) {
             throw new ParameterException("导出任务未结束");
         }
         exportFile(vo.getFileName(), new FileInputStream(vo.getFile()));

+ 75 - 68
src/main/java/cn/com/qmth/scancentral/service/impl/StudentServiceImpl.java

@@ -80,6 +80,7 @@ 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.AsyncTaskStatus;
 import cn.com.qmth.scancentral.enums.ExamMode;
 import cn.com.qmth.scancentral.enums.ExamStatus;
 import cn.com.qmth.scancentral.enums.ExamStatusCheckMode;
@@ -2240,10 +2241,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
             }
             BreachAndStatusImportTaskVo vo = new BreachAndStatusImportTaskVo();
             vo.setTaskId(taskId);
-            vo.setTotalCount(list.size());
+            vo.setTotalCount(list.size() - 1);
             vo.setExamId(examId);
             vo.setSubjectCode(subjectCode);
-            vo.setSuccess(true);
+            vo.setStatus(AsyncTaskStatus.RUNNING);
             vo.setProgress(0.0);
             vo.setTempDir(temDir);
             vo.setFile(txt);
@@ -2268,11 +2269,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
             breachImportCheck(vo, in);
         } catch (ParameterException e) {
             vo.setErrMsg(e.getMessage());
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
             throw e;
         } catch (Exception e) {
             vo.setErrMsg("系统错误");
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
             throw new ParameterException("系统错误", e);
         } finally {
             if (in != null) {
@@ -2283,41 +2284,44 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
             }
         }
         // 根据校验结果上传文件
-        if (vo.getSuccess()) {
-            InputStream excelIn = null;
-            try {
-                String md5 = MD5Util.md5Hex(vo.getFile());
-                excelIn = new FileInputStream(vo.getFile());
-                fileService.uploadBreach(excelIn, md5, vo.getExamId(), vo.getSubjectCode());
-            } catch (IOException e) {
-                throw new ParameterException("系统错误", e);
-            } finally {
-                if (excelIn != null) {
-                    try {
-                        excelIn.close();
-                    } catch (IOException e) {
-                    }
+        InputStream excelIn = null;
+        try {
+            String md5 = MD5Util.md5Hex(vo.getFile());
+            excelIn = new FileInputStream(vo.getFile());
+            fileService.uploadBreach(excelIn, md5, vo.getExamId(), vo.getSubjectCode());
+        } catch (IOException e) {
+            vo.setErrMsg("系统错误");
+            vo.setStatus(AsyncTaskStatus.FAILED);
+            throw new ParameterException("系统错误", e);
+        } finally {
+            if (excelIn != null) {
+                try {
+                    excelIn.close();
+                } catch (IOException e) {
                 }
             }
-            File info = new File(vo.getTempDir().getAbsolutePath() + "/breach-info.txt");
-            InputStream infoIn = null;
-            try {
-                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 ParameterException("系统错误", e);
-            } finally {
-                if (infoIn != null) {
-                    try {
-                        infoIn.close();
-                    } catch (IOException e) {
-                    }
+        }
+        File info = new File(vo.getTempDir().getAbsolutePath() + "/breach-info.txt");
+        InputStream infoIn = null;
+        try {
+            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) {
+            vo.setErrMsg("系统错误");
+            vo.setStatus(AsyncTaskStatus.FAILED);
+            throw new ParameterException("系统错误", e);
+        } finally {
+            if (infoIn != null) {
+                try {
+                    infoIn.close();
+                } catch (IOException e) {
                 }
             }
-            vo.setTotalCount(vo.getProgressCount());
         }
+        vo.setTotalCount(vo.getProgressCount());
+        vo.setStatus(AsyncTaskStatus.SUCCESS);
     }
 
     private void breachImportCheck(BreachAndStatusImportTaskVo vo, InputStream in) {
@@ -2395,10 +2399,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
             }
             BreachAndStatusImportTaskVo vo = new BreachAndStatusImportTaskVo();
             vo.setTaskId(taskId);
-            vo.setTotalCount(list.size());
+            vo.setTotalCount(list.size() - 1);
             vo.setExamId(examId);
             vo.setSubjectCode(subjectCode);
-            vo.setSuccess(true);
+            vo.setStatus(AsyncTaskStatus.RUNNING);
             vo.setProgress(0.0);
             vo.setTempDir(temDir);
             vo.setFile(txt);
@@ -2422,11 +2426,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
             custStatusImportCheck(vo, in);
         } catch (ParameterException e) {
             vo.setErrMsg(e.getMessage());
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
             throw e;
         } catch (Exception e) {
             vo.setErrMsg("系统错误");
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
             throw new ParameterException("系统错误", e);
         } finally {
             if (in != null) {
@@ -2437,41 +2441,44 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
             }
         }
         // 根据校验结果上传文件
-        if (vo.getSuccess()) {
-            InputStream excelIn = null;
-            try {
-                String md5 = MD5Util.md5Hex(vo.getFile());
-                excelIn = new FileInputStream(vo.getFile());
-                fileService.uploadCustStatus(excelIn, md5, vo.getExamId(), vo.getSubjectCode());
-            } catch (IOException e) {
-                throw new ParameterException("系统错误", e);
-            } finally {
-                if (excelIn != null) {
-                    try {
-                        excelIn.close();
-                    } catch (IOException e) {
-                    }
+        InputStream excelIn = null;
+        try {
+            String md5 = MD5Util.md5Hex(vo.getFile());
+            excelIn = new FileInputStream(vo.getFile());
+            fileService.uploadCustStatus(excelIn, md5, vo.getExamId(), vo.getSubjectCode());
+        } catch (IOException e) {
+            vo.setErrMsg("系统错误");
+            vo.setStatus(AsyncTaskStatus.FAILED);
+            throw new ParameterException("系统错误", e);
+        } finally {
+            if (excelIn != null) {
+                try {
+                    excelIn.close();
+                } catch (IOException e) {
                 }
             }
-            File info = new File(vo.getTempDir().getAbsolutePath() + "/cust-status-info.txt");
-            InputStream infoIn = null;
-            try {
-                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 ParameterException("系统错误", e);
-            } finally {
-                if (infoIn != null) {
-                    try {
-                        infoIn.close();
-                    } catch (IOException e) {
-                    }
+        }
+        File info = new File(vo.getTempDir().getAbsolutePath() + "/cust-status-info.txt");
+        InputStream infoIn = null;
+        try {
+            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) {
+            vo.setErrMsg("系统错误");
+            vo.setStatus(AsyncTaskStatus.FAILED);
+            throw new ParameterException("系统错误", e);
+        } finally {
+            if (infoIn != null) {
+                try {
+                    infoIn.close();
+                } catch (IOException e) {
                 }
             }
-            vo.setTotalCount(vo.getProgressCount());
         }
+        vo.setTotalCount(vo.getProgressCount());
+        vo.setStatus(AsyncTaskStatus.SUCCESS);
     }
 
     private void custStatusImportCheck(BreachAndStatusImportTaskVo vo, InputStream in) {

+ 9 - 6
src/main/java/cn/com/qmth/scancentral/service/impl/SubjectServiceImpl.java

@@ -47,6 +47,7 @@ import cn.com.qmth.scancentral.dao.SubjectDao;
 import cn.com.qmth.scancentral.entity.ExamEntity;
 import cn.com.qmth.scancentral.entity.MarkSiteEntity;
 import cn.com.qmth.scancentral.entity.SubjectEntity;
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
 import cn.com.qmth.scancentral.enums.ExamStatus;
 import cn.com.qmth.scancentral.service.AsyncTaskService;
 import cn.com.qmth.scancentral.service.BatchPaperService;
@@ -316,7 +317,7 @@ public class SubjectServiceImpl extends MppServiceImpl<SubjectDao, SubjectEntity
         vo.setTotalCount(scount);
         vo.setExamId(examId);
         vo.setSubjectCode(subjectCode);
-        vo.setSuccess(true);
+        vo.setStatus(AsyncTaskStatus.RUNNING);
         vo.setProgress(0.0);
         AnswerDataExportConsumer com = SpringContextHolder.getBean(AnswerDataExportConsumer.class);
         com.setVo(vo);
@@ -339,7 +340,7 @@ public class SubjectServiceImpl extends MppServiceImpl<SubjectDao, SubjectEntity
         vo.setTotalCount(scount);
         vo.setExamId(examId);
         vo.setSubjectCode(subjectCode);
-        vo.setSuccess(true);
+        vo.setStatus(AsyncTaskStatus.RUNNING);
         vo.setProgress(0.0);
         SliceDataExportConsumer com = SpringContextHolder.getBean(SliceDataExportConsumer.class);
         com.setVo(vo);
@@ -378,12 +379,13 @@ public class SubjectServiceImpl extends MppServiceImpl<SubjectDao, SubjectEntity
             vo.setFileName(subejct.getName() + "_" + exam.getScanSite() + "_OMR.dbf");
             vo.setFile(dbf);
             vo.setTempDir(temDir);
+            vo.setStatus(AsyncTaskStatus.SUCCESS);
         } catch (StatusException e) {
-            vo.setSuccess(false);
             vo.setErrMsg(e.getMessage());
+            vo.setStatus(AsyncTaskStatus.FAILED);
         } catch (Exception e) {
-            vo.setSuccess(false);
             vo.setErrMsg("系统异常");
+            vo.setStatus(AsyncTaskStatus.FAILED);
             log.error("导出扫描答案DBF异常", e);
         }
     }
@@ -591,12 +593,13 @@ public class SubjectServiceImpl extends MppServiceImpl<SubjectDao, SubjectEntity
                     + DateUtil.format(new Date(), DateUtil.DatePatterns.YYYYMMDDHH) + ".dbf");
             vo.setFile(dbf);
             vo.setTempDir(temDir);
+            vo.setStatus(AsyncTaskStatus.SUCCESS);
         } catch (StatusException e) {
-            vo.setSuccess(false);
             vo.setErrMsg(e.getMessage());
+            vo.setStatus(AsyncTaskStatus.FAILED);
         } catch (Exception e) {
-            vo.setSuccess(false);
             vo.setErrMsg("系统异常");
+            vo.setStatus(AsyncTaskStatus.FAILED);
             log.error("导出打包DBF异常", e);
         }
     }

+ 4 - 2
src/main/java/cn/com/qmth/scancentral/task/thread/ExamStatusImportThread.java

@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
 import com.qmth.boot.core.concurrent.service.ConcurrentService;
 import com.qmth.boot.core.exception.ParameterException;
 
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
 import cn.com.qmth.scancentral.enums.LockType;
 import cn.com.qmth.scancentral.service.StudentService;
 import cn.com.qmth.scancentral.vo.asynctask.ExamStatusImportTaskVo;
@@ -33,14 +34,15 @@ public class ExamStatusImportThread implements Runnable {
             if (concurrentService.getLock(LockType.EXAM_STATUS_RESET + "-" + vo.getExamId()).tryLock()) {
                 studentService.importExamStatus(vo);
                 vo.setTotalCount(vo.getProgressCount());
+                vo.setStatus(AsyncTaskStatus.SUCCESS);
             }
         } catch (ParameterException e) {
             vo.setErrMsg(e.getMessage());
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
         } catch (Exception e) {
             log.error("exam status import error", e);
             vo.setErrMsg("缺考校验导入失败");
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
         } finally {
             concurrentService.getLock(LockType.EXAM_STATUS_RESET + "-" + vo.getExamId()).unlock();
         }

+ 4 - 2
src/main/java/cn/com/qmth/scancentral/task/thread/ExamStatusResetThread.java

@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
 import com.qmth.boot.core.concurrent.service.ConcurrentService;
 import com.qmth.boot.core.exception.ParameterException;
 
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
 import cn.com.qmth.scancentral.enums.LockType;
 import cn.com.qmth.scancentral.service.StudentService;
 import cn.com.qmth.scancentral.vo.asynctask.ExamStatusResetTaskVo;
@@ -33,14 +34,15 @@ public class ExamStatusResetThread implements Runnable {
             if (concurrentService.getLock(LockType.EXAM_STATUS_RESET + "-" + vo.getExamId()).tryLock()) {
                 studentService.resetExamStatus(vo);
                 vo.setTotalCount(vo.getProgressCount());
+                vo.setStatus(AsyncTaskStatus.SUCCESS);
             }
         } catch (ParameterException e) {
             vo.setErrMsg(e.getMessage());
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
         } catch (Exception e) {
             log.error("exam status reset error", e);
             vo.setErrMsg("缺考校验重新生成失败");
-            vo.setSuccess(false);
+            vo.setStatus(AsyncTaskStatus.FAILED);
         } finally {
             concurrentService.getLock(LockType.EXAM_STATUS_RESET + "-" + vo.getExamId()).unlock();
         }

+ 7 - 5
src/main/java/cn/com/qmth/scancentral/vo/asynctask/AsyncProgressVo.java

@@ -1,10 +1,12 @@
 package cn.com.qmth.scancentral.vo.asynctask;
 
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
+
 public class AsyncProgressVo {
 
     private Double progress;
 
-    private Boolean success;
+    private AsyncTaskStatus status;
 
     private String errMsg;
 
@@ -16,12 +18,12 @@ public class AsyncProgressVo {
         this.progress = progress;
     }
 
-    public Boolean getSuccess() {
-        return success;
+    public AsyncTaskStatus getStatus() {
+        return status;
     }
 
-    public void setSuccess(Boolean success) {
-        this.success = success;
+    public void setStatus(AsyncTaskStatus status) {
+        this.status = status;
     }
 
     public String getErrMsg() {

+ 7 - 5
src/main/java/cn/com/qmth/scancentral/vo/asynctask/AsyncTaskVo.java

@@ -2,6 +2,8 @@ package cn.com.qmth.scancentral.vo.asynctask;
 
 import java.io.File;
 
+import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
+
 public class AsyncTaskVo {
 
     private String taskId;
@@ -14,7 +16,7 @@ public class AsyncTaskVo {
 
     private Double progress;
 
-    private Boolean success;
+    private AsyncTaskStatus status;
 
     private String errMsg;
 
@@ -38,12 +40,12 @@ public class AsyncTaskVo {
         this.progress = progress;
     }
 
-    public Boolean getSuccess() {
-        return success;
+    public AsyncTaskStatus getStatus() {
+        return status;
     }
 
-    public void setSuccess(Boolean success) {
-        this.success = success;
+    public void setStatus(AsyncTaskStatus status) {
+        this.status = status;
     }
 
     public String getErrMsg() {