浏览代码

3.4.5 20250605 流程bug

xiaofei 2 周之前
父节点
当前提交
bad67f0234

+ 47 - 68
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -211,60 +211,39 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Transactional
     @Override
     public ExamTask assignUser(ExamTask examTask) {
-        ExamStatusEnum examStatusEnum = ExamStatusEnum.DRAFT;
-        Long flowId = null;
-        UpdateWrapper<ExamTask> updateWrapper = new UpdateWrapper<>();
         ExamTask task = this.getById(examTask.getId());
-        // 指派命题老师
-        if (task.getStatus().name().equals(ExamStatusEnum.DRAFT.name())) {
-            if (!task.getEnable()) {
-                throw ExceptionResultEnum.ERROR.exception("命题任务已禁用,不能指派命题老师");
-            }
-
-            if (Objects.nonNull(examTask.getUserId())) {
-                examStatusEnum = ExamStatusEnum.STAGE;
-                Map<String, Object> map = SystemConstant.buildFlowVar(examTask.getId(),
-                        examTask,
-                        TFCustomTypeEnum.ELECTRON_FLOW,
-                        examTask.getUserId(),
-                        true);
-                map = activitiService.customFlowStart(map);
-                flowId = SystemConstant.convertIdToLong((String) map.get(SystemConstant.FLOW_ID));
-                map.computeIfAbsent(SystemConstant.FLOW_JOIN_TYPE, v -> FlowJoinTypeEnum.NEW);
-                tfFlowJoinService.saveOrUpdate(map);
-                examTask.setFlowId(flowId);
-            }
+        if (task == null) {
+            throw ExceptionResultEnum.ERROR.exception("命题任务不存在,请刷新页面");
         }
-        // 更改命题老师
-        else if (task.getStatus().name().equals(ExamStatusEnum.STAGE.name())) {
-            if (task.getEnable()) {
-                throw ExceptionResultEnum.ERROR.exception("命题任务禁用后,才能更改命题老师");
-            }
 
-            if (examTask.getUserId() == null) {
-                examStatusEnum = ExamStatusEnum.DRAFT;
-            } else {
-                examStatusEnum = ExamStatusEnum.STAGE;
-
-                if (examTask.getUserId().longValue() != task.getUserId().longValue()) {
-                    Map<String, Object> map = SystemConstant.buildFlowVar(examTask.getId(),
-                            examTask,
-                            TFCustomTypeEnum.ELECTRON_FLOW,
-                            examTask.getUserId(),
-                            true);
-                    map = activitiService.customFlowStart(map);
-                    flowId = SystemConstant.convertIdToLong((String) map.get(SystemConstant.FLOW_ID));
-                    map.computeIfAbsent(SystemConstant.FLOW_JOIN_TYPE, v -> FlowJoinTypeEnum.NEW);
+        if (ExamStatusEnum.DRAFT.equals(task.getStatus()) && !task.getEnable()) {
+            throw ExceptionResultEnum.ERROR.exception("命题任务已禁用,不能指派命题老师");
+        } else if (ExamStatusEnum.STAGE.equals(task.getStatus()) && task.getEnable()) {
+            throw ExceptionResultEnum.ERROR.exception("命题任务需要先禁用,再更改命题老师");
+        }
 
-                    tfFlowJoinService.deleteByObjectIdAndFlowId(examTask.getId(), null);
-                    tfFlowJoinService.saveOrUpdate(map);
-                    examTask.setFlowId(flowId);
-                } else {
-                    flowId = task.getFlowId();
-                }
-            }
+        ExamStatusEnum examStatusEnum = ExamStatusEnum.DRAFT;
+        Long flowId = task.getFlowId();
+        if (Objects.nonNull(examTask.getUserId()) && !examTask.getUserId().equals(task.getUserId())) {
+            examStatusEnum = ExamStatusEnum.STAGE;
+
+            Map<String, Object> map = SystemConstant.buildFlowVar(examTask.getId(),
+                    examTask,
+                    TFCustomTypeEnum.ELECTRON_FLOW,
+                    examTask.getUserId(),
+                    true);
+            map = activitiService.customFlowStart(map);
+            flowId = SystemConstant.convertIdToLong((String) map.get(SystemConstant.FLOW_ID));
+            if (flowId == null) {
+                throw ExceptionResultEnum.ERROR.exception("发起流程失败,请刷新页面重试");
+            }
+            map.computeIfAbsent(SystemConstant.FLOW_JOIN_TYPE, v -> FlowJoinTypeEnum.NEW);
+            tfFlowJoinService.deleteByObjectIdAndFlowId(examTask.getId(), null);
+            tfFlowJoinService.saveOrUpdate(map);
+            examTask.setFlowId(flowId);
         }
 
+        UpdateWrapper<ExamTask> updateWrapper = new UpdateWrapper<>();
         updateWrapper.lambda().set(ExamTask::getUserId, examTask.getUserId())
                 .set(ExamTask::getStatus, examStatusEnum)
                 .set(ExamTask::getFlowId, flowId)
@@ -695,6 +674,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         return examTaskImportResultDto;
     }
 
+    @Transactional
     @Override
     public List<ExamTask> saveBatch(ExamTask task) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
@@ -707,20 +687,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             throw ExceptionResultEnum.ERROR.exception("导入批次号不能为空,请重新导入");
         }
 
+        // 配置信息
+        BasicPrintConfig basicPrintConfig = basicPrintConfigService.getByExamId(examId);
+
         List<ExamTask> list = new ArrayList<>();
         List<ExamTaskImportTaskUserDto> userList = task.getUsers();
 
         StringJoiner stringJoiner = new StringJoiner(",");
         for (ExamTaskImportTaskUserDto dto : userList) {
-            // 配置信息
-            BasicPrintConfig basicPrintConfig = basicPrintConfigService.getByExamId(examId);
-            Long cardRuleId = basicPrintConfig.getCardRuleId();
-
             ExamTask examTask = new ExamTask();
             examTask.setSchoolId(task.getSchoolId());
             examTask.setCourseId(dto.getCourseId());
             examTask.setExamId(examId);
-            examTask.setCardRuleId(cardRuleId);
+            examTask.setCardRuleId(basicPrintConfig.getCardRuleId());
 
             String paperNumber = StringUtils.trim(dto.getPaperNumber());
             if (StringUtils.isNotBlank(paperNumber)) {
@@ -745,15 +724,10 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             // 取课程所在机构
             BasicCourse basicCourse = basicCourseService.getById(examTask.getCourseId());
             examTask.setTeachingRoomId(basicCourse.getTeachingRoomId());
-
-            Long userId = dto.getUserId();
-            if (userId != null) {
-                examTask.setUserId(userId);
-                examTask.setStatus(ExamStatusEnum.STAGE);
-            } else {
-                examTask.setStatus(ExamStatusEnum.DRAFT);
-            }
-            examTask.setReview(basicPrintConfig.getReview());
+            examTask.setUserId(dto.getUserId());
+            // 默认新建
+            examTask.setStatus(ExamStatusEnum.DRAFT);
+            examTask.setReview(basicPrintConfig.getReview() == null ? true : basicPrintConfig.getReview());
             examTask.setSource(ExamTaskSourceEnum.ASSIGN);
             list.add(examTask);
         }
@@ -762,23 +736,28 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         if (stringJoiner.toString().length() > 0) {
             throw ExceptionResultEnum.ERROR.exception(stringJoiner.toString());
         }
-        this.saveBatch(list);
+
         for (ExamTask examTask : list) {
-            if (Objects.nonNull(examTask.getReview()) && examTask.getReview() && Objects.nonNull(examTask.getUserId()) && Objects.isNull(examTask.getFlowId())) {
+            if (examTask.getReview() && Objects.nonNull(examTask.getUserId()) && Objects.isNull(examTask.getFlowId())) {
                 Map<String, Object> map = SystemConstant.buildFlowVar(examTask.getId(),
                         examTask,
                         TFCustomTypeEnum.ELECTRON_FLOW,
                         examTask.getUserId(),
                         true);
                 map = activitiService.customFlowStart(map);
-                examTask.setFlowId(SystemConstant.convertIdToLong((String) map.get(SystemConstant.FLOW_ID)));
+                Long flowId = SystemConstant.convertIdToLong((String) map.get(SystemConstant.FLOW_ID));
+                if(Objects.isNull(flowId)){
+                    throw ExceptionResultEnum.ERROR.exception("命题任务未发起流程,请重新导入");
+                }
+                examTask.setFlowId(flowId);
+                // 创建流程后,更新状态为待命题
+//                examTask.setStatus(Objects.nonNull(flowId) ? ExamStatusEnum.STAGE : examTask.getStatus());
                 map.computeIfAbsent(SystemConstant.FLOW_JOIN_TYPE, v -> FlowJoinTypeEnum.NEW);
                 tfFlowJoinService.saveOrUpdate(map);
-                examTask.updateInfo(sysUser.getId());
-                this.updateById(examTask);
                 activitiService.sendFlowStartMsg(examTask.getFlowId());
             }
         }
+        this.saveBatch(list);
         return list;
     }
 
@@ -927,7 +906,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                     ExamTaskPaperData examTaskPaperData = examTaskPaperDataService.selectByMultiId(examTaskPaperDataPram);
                     ExamTaskPaperData examTaskPaperDataUuidPram = new ExamTaskPaperData(examTask.getExamId(), paperInfoVo.getUuid(), paperInfoVo.getPaperId());
                     ExamTaskPaperData examTaskPaperDataUuid = examTaskPaperDataService.selectByMultiId(examTaskPaperDataUuidPram);
-                    if(examTaskPaperDataUuid != null || (examTaskPaperData != null && !paperInfoVo.getUuid().equals(examTaskPaperData.getUuid()))){
+                    if (examTaskPaperDataUuid != null || (examTaskPaperData != null && !paperInfoVo.getUuid().equals(examTaskPaperData.getUuid()))) {
                         examTaskPaperDataService.deleteByMultiId(examTaskPaperDataPram);
                     }
                     UpdateWrapper<ExamTaskPaperData> updateWrapper1 = new UpdateWrapper<>();