wangliang 4 years ago
parent
commit
3dcda8837c

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/TaskListResult.java

@@ -61,6 +61,17 @@ public class TaskListResult implements Serializable {
     @ApiModelProperty(value = "重新生成次数")
     int resetCount;
 
+    @ApiModelProperty(value = "人工错误原因")
+    String errorMessage;
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
     public int getResetCount() {
         return resetCount;
     }

+ 15 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TBTask.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.business.entity;
 
 import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -79,11 +80,11 @@ public class TBTask implements Serializable {
     private Boolean enable;
 
     @ApiModelProperty(value = "导入文件名")
-    @TableField(value = "import_file_name")
+    @TableField(value = "import_file_name", updateStrategy = FieldStrategy.IGNORED)
     private String importFileName;
 
     @ApiModelProperty(value = "导入文件路径")
-    @TableField(value = "import_file_path")
+    @TableField(value = "import_file_path", updateStrategy = FieldStrategy.IGNORED)
     private String importFilePath;
 
     @ApiModelProperty(value = "导出文件路径")
@@ -119,6 +120,18 @@ public class TBTask implements Serializable {
     @TableField(value = "version")
     private int version;
 
+    @ApiModelProperty(value = "人工错误")
+    @TableField(value = "error_message", updateStrategy = FieldStrategy.IGNORED)
+    private String errorMessage;
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
     public int getVersion() {
         return version;
     }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TBTaskService.java

@@ -146,7 +146,7 @@ public interface TBTaskService extends IService<TBTask> {
      * 更新任务状态
      */
     @Async("taskThreadPool")
-    public void updateStatus();
+    public void updateStatus() throws IOException;
 
     /**
      * 重新生成pdf失败任务

+ 27 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBTaskServiceImpl.java

@@ -315,13 +315,35 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
      */
     @Override
     @Transactional
-    public void updateStatus() {
-        UpdateWrapper<TBTask> tbTaskQueryWrapper = new UpdateWrapper<>();
-        tbTaskQueryWrapper.lambda().set(TBTask::getStatus, TaskStatusEnum.FINISH)
+    public void updateStatus() throws IOException {
+        //不是自动生成pdf的全部改为失败
+        UpdateWrapper<TBTask> tbTaskUpdateWrapper = new UpdateWrapper<>();
+        tbTaskUpdateWrapper.lambda().set(TBTask::getStatus, TaskStatusEnum.FINISH)
                 .set(TBTask::getSummary, "系统提交:网络异常或程序异常中断!")
                 .set(TBTask::getResult, TaskResultEnum.ERROR)
-                .isNotNull(TBTask::getStatus).ne(TBTask::getStatus, TaskStatusEnum.FINISH);
-        this.update(tbTaskQueryWrapper);
+                .isNotNull(TBTask::getStatus).ne(TBTask::getStatus, TaskStatusEnum.FINISH)
+                .ne(TBTask::getType, TaskTypeEnum.CREATE_PDF);
+        this.update(tbTaskUpdateWrapper);
+
+        QueryWrapper<TBTask> tbTaskQueryWrapper = new QueryWrapper<>();
+        tbTaskQueryWrapper.lambda().eq(TBTask::getType, TaskTypeEnum.CREATE_PDF)
+                .ne(TBTask::getStatus, TaskStatusEnum.FINISH)
+                .ne(TBTask::getResult, TaskResultEnum.SUCCESS).or().isNull(TBTask::getResult)
+                .orderByDesc(TBTask::getStatus);
+        List<TBTask> tbTasks = this.list(tbTaskQueryWrapper);
+        if (Objects.nonNull(tbTasks) && tbTasks.size() > 0) {
+            for (TBTask tbTask : tbTasks) {
+                Map<String, Object> map = new HashMap<>();
+                if (Objects.nonNull(tbTask.getRemark())) {
+                    JSONArray jsonArray = JSONArray.parseArray(tbTask.getRemark());
+                    ArraysParams arraysParams = new ArraysParams(jsonArray.toArray(new Long[jsonArray.size()]));
+                    map.computeIfAbsent("examDetailCourseIds", v -> Arrays.asList(arraysParams.getIds()));
+                }
+                map.computeIfAbsent(SystemConstant.TASK, v -> tbTask);
+                map.computeIfAbsent(SystemConstant.USER, v -> sysUserService.getById(tbTask.getCreateId()));
+                asyncCreatePdfTempleteService.createPdf(map, null);
+            }
+        }
     }
 
     /**

+ 16 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncCreatePdfTempleteService.java

@@ -6,22 +6,24 @@ import com.qmth.distributed.print.business.entity.TBTask;
 import com.qmth.distributed.print.business.enums.TaskResultEnum;
 import com.qmth.distributed.print.business.enums.TaskStatusEnum;
 import com.qmth.distributed.print.business.service.TBTaskService;
-import com.qmth.distributed.print.business.templete.create.AsyncCreateTaskTemplete;
 import com.qmth.distributed.print.business.templete.callback.CallbackCreatePdf;
+import com.qmth.distributed.print.business.templete.create.AsyncCreateTaskTemplete;
 import com.qmth.distributed.print.business.templete.service.TaskLogicService;
 import com.qmth.distributed.print.common.contant.SpringContextHolder;
 import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
-import org.apache.poi.ss.formula.functions.T;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.text.MessageFormat;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Date;
+import java.util.Map;
+import java.util.Objects;
+import java.util.StringJoiner;
 
 /**
  * @Description: 创建pdf模版
@@ -66,6 +68,16 @@ public class AsyncCreatePdfTempleteService extends AsyncCreateTaskTemplete {
 //                tbTask.setResetCount(new AtomicInteger(tbTask.getResetCount()).incrementAndGet());
 //            }
             if (e instanceof ApiException) {
+                if (((ApiException) e).getCode() == ExceptionResultEnum.PAPER_ERROR.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.PAPER_TYPE_ERROR.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.ATTACHMENT_IS_NULL.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.EXAM_PRINT_IS_NULL.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.EXAM_RULE_IS_NULL.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.EXAM_DETAIL_IS_NULL.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.EXAM_CARD_IS_NULL.getCode()
+                        || ((ApiException) e).getCode() == ExceptionResultEnum.EXAM_TASK_IS_NULL.getCode()) {
+                    tbTask.setErrorMessage(e.getMessage());
+                }
                 ResultUtil.error((ApiException) e, e.getMessage());
             } else {
                 ResultUtil.error(e.getMessage());

+ 1 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -166,6 +166,7 @@ public abstract class AsyncImportTaskTemplete {
                 tbTask.setResultFilePath(tbTask.getImportFilePath());
                 tbTask.setImportFileName(null);
                 tbTask.setImportFilePath(null);
+                tbTask.setErrorMessage(null);
             }
             tbTaskService.updateById(tbTask);
         }

+ 6 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -134,7 +134,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         //查询printPlan
         ExamPrintPlan examPrintPlan = examPrintPlanService.getById(tbTask.getPrintPlanId());
         if (Objects.isNull(examPrintPlan)) {
-            throw ExceptionResultEnum.ERROR.exception("印刷计划为空");
+            throw ExceptionResultEnum.EXAM_PRINT_IS_NULL.exception();
         }
         UpdateWrapper<ExamDetail> examDetailQueryWrapper = new UpdateWrapper<>();
         examDetailQueryWrapper.lambda().eq(ExamDetail::getSchoolId, sysUser.getSchoolId())
@@ -204,7 +204,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         .orderByAsc(ExamTask::getPaperNumber);
                 List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
                 if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
-                    throw ExceptionResultEnum.ERROR.exception("命题任务为空");
+                    throw ExceptionResultEnum.EXAM_TASK_IS_NULL.exception();
                 }
                 Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
 
@@ -218,7 +218,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     //查询题卡
                     ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
                     if (Objects.isNull(examCard)) {
-                        throw ExceptionResultEnum.ERROR.exception("题卡为空");
+                        throw ExceptionResultEnum.EXAM_CARD_IS_NULL.exception();
                     }
                     QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
                     examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
@@ -369,13 +369,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             //查询printPlan
             ExamPrintPlan examPrintPlan = examPrintPlanService.getById(tbTask.getPrintPlanId());
             if (Objects.isNull(examPrintPlan)) {
-                throw ExceptionResultEnum.ERROR.exception("印刷计划为空");
+                throw ExceptionResultEnum.EXAM_PRINT_IS_NULL.exception();
             }
 
             BasicSchool basicSchool = cacheService.schoolCache(examPrintPlan.getSchoolId());
             BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId(schoolId);
             if (Objects.isNull(basicExamRule)) {
-                throw ExceptionResultEnum.ERROR.exception("考务规则为空");
+                throw ExceptionResultEnum.EXAM_RULE_IS_NULL.exception();
             }
 
             //查询examDetail
@@ -389,7 +389,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             }
             List<ExamDetail> examDetailList = detailService.list(examDetailQueryWrapper);
             if (Objects.isNull(examDetailList) || examDetailList.size() == 0) {
-                throw ExceptionResultEnum.ERROR.exception("考务计划为空");
+                throw ExceptionResultEnum.EXAM_DETAIL_IS_NULL.exception();
             }
             Set<Long> attachmentIds = new HashSet<>();
             Set<File> ftlList = new HashSet<>();

+ 7 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -70,7 +70,7 @@ public class CreatePdfUtil {
      */
     public void createCheckIn(ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
         if (Objects.isNull(basicAttachment)) {
-            throw ExceptionResultEnum.ERROR.exception("找不到附件");
+            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
         }
         String type = basicAttachment.getType();
         JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -100,7 +100,7 @@ public class CreatePdfUtil {
      */
     public void createPaperPackage(boolean tag, BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
         if (Objects.isNull(basicAttachment)) {
-            throw ExceptionResultEnum.ERROR.exception("找不到附件");
+            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
         }
         Map<String, Object> htmlMap = new HashMap<>();
         if (Objects.nonNull(examStudentList) && examStudentList.size() > 0) {
@@ -185,7 +185,7 @@ public class CreatePdfUtil {
      */
     public void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
         if (Objects.isNull(basicAttachment)) {
-            throw ExceptionResultEnum.ERROR.exception("找不到附件");
+            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
         }
         Map<String, Object> htmlMap = new HashMap<>();
         if (Objects.nonNull(examStudentList) && examStudentList.size() > 0) {
@@ -368,7 +368,7 @@ public class CreatePdfUtil {
                 Long attachmentId = Long.parseLong((String) (object.get("attachmentId")));
                 BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
                 if (Objects.isNull(basicAttachment)) {
-                    throw ExceptionResultEnum.ERROR.exception("找不到附件");
+                    throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
                 }
                 String name = (String) object.get("name");
                 if (Objects.equals(name.toUpperCase(), paperType.toUpperCase())) {
@@ -400,12 +400,12 @@ public class CreatePdfUtil {
         if (drawRule == DrawRuleEnum.ONE) {
             if (Objects.isNull(unexposedPaperType) || Objects.equals(unexposedPaperType.trim(), "")) {
                 CreatePdfCacheUtil.deletePaperType(key);
-                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
+                throw ExceptionResultEnum.PAPER_ERROR.exception();
             }
         } else {
             if ((Objects.isNull(exposedPaperType) || Objects.equals(exposedPaperType.trim(), "")) && (Objects.isNull(unexposedPaperType) || Objects.equals(unexposedPaperType.trim(), ""))) {
                 CreatePdfCacheUtil.deletePaperType(key);
-                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
+                throw ExceptionResultEnum.PAPER_ERROR.exception();
             }
         }
         String paperType = null;
@@ -447,7 +447,7 @@ public class CreatePdfUtil {
         log.info("getPaperType key:{},paperType:{},lock:{}", key, paperType, lock);
         if (!lock) {
             log.info("getPaperType 未获取到锁,key:{}", key);
-            throw ExceptionResultEnum.ERROR.exception("未获取到试卷类型");
+            throw ExceptionResultEnum.PAPER_TYPE_ERROR.exception();
         }
         return paperType;
     }

+ 1 - 0
distributed-print-business/src/main/resources/db/init-table.sql

@@ -1597,6 +1597,7 @@ CREATE TABLE `t_b_task`  (
   `obj_name` varchar(500) DEFAULT NULL COMMENT '实体名称',
   `reset_count` int DEFAULT '0' COMMENT '重试次数',
   `version` int DEFAULT '0' COMMENT '更新版本号',
+  `error_message` varchar(500) DEFAULT NULL COMMENT '人工错误原因',
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '导入导出任务表' ROW_FORMAT = Dynamic;
 

+ 2 - 1
distributed-print-business/src/main/resources/mapper/TBTaskMapper.xml

@@ -21,7 +21,8 @@
             t.id = tbt.create_id) as createName,
             if(ISNULL(tbt.result_file_path),false,true) as hasResultFile,
             if(ISNULL(tbt.report_file_path),false,true) as hasReportFile,
-            tbt.reset_count as resetCount
+            tbt.reset_count as resetCount,
+            tbt.error_message as errorMessage
             from
             t_b_task tbt
             left join exam_print_plan epp on

+ 16 - 0
distributed-print-common/src/main/java/com/qmth/distributed/print/common/enums/ExceptionResultEnum.java

@@ -61,6 +61,22 @@ public enum ExceptionResultEnum {
 
     SCHOOL_ENABLE(HttpStatus.INTERNAL_SERVER_ERROR, 5000021, "学校已停用"),
 
+    PAPER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 50000022, "当前没有未曝光的卷型"),
+
+    PAPER_TYPE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 50000023, "未获取到试卷类型"),
+
+    ATTACHMENT_IS_NULL(HttpStatus.INTERNAL_SERVER_ERROR, 50000024, "找不到附件"),
+
+    EXAM_PRINT_IS_NULL(HttpStatus.INTERNAL_SERVER_ERROR, 50000025, "印刷计划为空"),
+
+    EXAM_RULE_IS_NULL(HttpStatus.INTERNAL_SERVER_ERROR, 50000026, "考务规则为空"),
+
+    EXAM_DETAIL_IS_NULL(HttpStatus.INTERNAL_SERVER_ERROR, 50000027, "考场数据为空"),
+
+    EXAM_CARD_IS_NULL(HttpStatus.INTERNAL_SERVER_ERROR, 50000028, "题卡为空"),
+
+    EXAM_TASK_IS_NULL(HttpStatus.INTERNAL_SERVER_ERROR, 50000029, "命题任务为空"),
+
     /**
      * 401
      */

+ 3 - 5
distributed-print/src/main/java/com/qmth/distributed/print/api/TBTaskController.java

@@ -7,7 +7,6 @@ import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.bean.params.ArraysParams;
 import com.qmth.distributed.print.business.bean.result.EditResult;
 import com.qmth.distributed.print.business.bean.result.TaskListResult;
-import com.qmth.distributed.print.business.config.DictionaryConfig;
 import com.qmth.distributed.print.business.entity.SysUser;
 import com.qmth.distributed.print.business.entity.TBTask;
 import com.qmth.distributed.print.business.enums.TaskResultEnum;
@@ -28,7 +27,6 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * <p>
@@ -46,8 +44,8 @@ public class TBTaskController {
     @Resource
     TBTaskService tbTaskService;
 
-    @Resource
-    DictionaryConfig dictionaryConfig;
+//    @Resource
+//    DictionaryConfig dictionaryConfig;
 
     @Resource
     AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
@@ -68,7 +66,7 @@ public class TBTaskController {
                 if (Objects.equals(taskListResult.getStatus(), TaskStatusEnum.FINISH.getTitle()) && Objects.equals(taskListResult.getResult(), TaskResultEnum.ERROR.getTitle())
 //                        && taskListResult.getResetCount() >= dictionaryConfig.sysDomain().getAutoCreatePdfResetMaxCount()
                         && Objects.equals(taskListResult.getType(), TaskTypeEnum.CREATE_PDF.getTitle())
-                ) {
+                        && Objects.isNull(taskListResult.getErrorMessage())) {
                     taskListResult.setResetCreatePdf(true);
                 }
             }