浏览代码

修复先导考务数据后走流程的问题

wangliang 2 年之前
父节点
当前提交
af2a36415e

+ 42 - 47
distributed-print-business/src/main/java/com/qmth/distributed/print/business/activiti/custom/listener/ProcessEventListener.java

@@ -9,29 +9,24 @@ import com.qmth.distributed.print.business.entity.TFFlowLog;
 import com.qmth.distributed.print.business.enums.CustomFlowMultipleUserApproveTypeEnum;
 import com.qmth.distributed.print.business.service.ActivitiService;
 import com.qmth.distributed.print.business.service.BasicMessageService;
-import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.teachcloud.common.bean.params.ApproveUserResult;
 import com.qmth.teachcloud.common.contant.SpringContextHolder;
 import com.qmth.teachcloud.common.contant.SystemConstant;
-import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.FlowApproveOperationEnum;
 import com.qmth.teachcloud.common.enums.MessageEnum;
 import com.qmth.teachcloud.common.enums.TFCustomTypeEnum;
 import com.qmth.teachcloud.common.service.SysUserService;
 import com.qmth.teachcloud.common.util.RedisUtil;
-import org.activiti.engine.HistoryService;
 import org.activiti.engine.TaskService;
 import org.activiti.engine.delegate.event.ActivitiEvent;
 import org.activiti.engine.delegate.event.ActivitiEventListener;
 import org.activiti.engine.delegate.event.ActivitiProcessStartedEvent;
-import org.activiti.engine.history.HistoricVariableInstance;
 import org.activiti.engine.task.Task;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
-import java.io.IOException;
 import java.io.Serializable;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -73,54 +68,54 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
             case PROCESS_COMPLETED:
                 // 流程结束
                 log.info("流程结束_PROCESS_COMPLETED:ProcessInstanceId:{},ExecutionId:{},ProcessDefinitionId:{}", event.getProcessInstanceId(), event.getExecutionId(), event.getProcessDefinitionId());
-                HistoryService historyService = SpringContextHolder.getBean(HistoryService.class);
-                SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
-                ActivitiService activitiService = SpringContextHolder.getBean(ActivitiService.class);
-                PrintCommonService printCommonService = SpringContextHolder.getBean(PrintCommonService.class);
-
-                List<HistoricVariableInstance> historicVariableInstanceList = historyService.createHistoricVariableInstanceQuery().processInstanceId(event.getProcessInstanceId()).list();
-                if (Objects.nonNull(historicVariableInstanceList) && historicVariableInstanceList.size() > 0) {
-                    tfFlowLog = null;
-                    tfFlowApprove = null;
-                    Object object = null;
-                    for (HistoricVariableInstance h : historicVariableInstanceList) {
-                        if (Objects.equals(h.getVariableName(), SystemConstant.APPROVE_TF_FLOW_APPROVE)) {
-                            tfFlowApprove = (TFFlowApprove) h.getValue();
-                            Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程流转记录为空"));
-                            log.info("tfFlowApprove.getStatus():{}", tfFlowApprove.getStatus());
-                        }
-                        if (Objects.equals(h.getVariableName(), SystemConstant.APPROVE_TF_FLOW_LOG)) {
-                            tfFlowLog = (TFFlowLog) h.getValue();
-                            Optional.ofNullable(tfFlowLog).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程审批日志为空"));
-                            log.info("tfFlowLog.getApproveOperation():{}", tfFlowLog.getApproveOperation());
-                        } else if (Objects.equals(h.getVariableName(), SystemConstant.OBJECT_DATA)) {
-                            object = h.getValue();
-                            Optional.ofNullable(object).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("实体数据为空"));
-                        }
-                        if (Objects.nonNull(object) && Objects.nonNull(tfFlowLog)) {
-                            break;
-                        }
-                    }
-                    if (Objects.nonNull(tfFlowLog.getObjectTable())) {
-                        if (Objects.equals(tfFlowLog.getObjectTable(), TFCustomTypeEnum.ELECTRON_FLOW.getTable())) {//如果是命题任务交卷
-                            //取命题老师ID
-                            SysUser sysUser = sysUserService.getById(((ExamTask) object).getUserId());
-                            try {
-                                printCommonService.checkData(((ExamTask) object).getSchoolId(), ((ExamTask) object).getExamId(), ((ExamTask) object).getCourseCode(), ((ExamTask) object).getPaperNumber(), sysUser);
-                            } catch (IOException e) {
-                                throw ExceptionResultEnum.ERROR.exception("生成pdf失败");
-                            }
-                        }
-                    }
-                }
+//                HistoryService historyService = SpringContextHolder.getBean(HistoryService.class);
+//                SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
+//                ActivitiService activitiService = SpringContextHolder.getBean(ActivitiService.class);
+//                PrintCommonService printCommonService = SpringContextHolder.getBean(PrintCommonService.class);
+//
+//                List<HistoricVariableInstance> historicVariableInstanceList = historyService.createHistoricVariableInstanceQuery().processInstanceId(event.getProcessInstanceId()).list();
+//                if (Objects.nonNull(historicVariableInstanceList) && historicVariableInstanceList.size() > 0) {
+//                    tfFlowLog = null;
+//                    tfFlowApprove = null;
+//                    Object object = null;
+//                    for (HistoricVariableInstance h : historicVariableInstanceList) {
+//                        if (Objects.equals(h.getVariableName(), SystemConstant.APPROVE_TF_FLOW_APPROVE)) {
+//                            tfFlowApprove = (TFFlowApprove) h.getValue();
+//                            Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程流转记录为空"));
+//                            log.info("tfFlowApprove.getStatus():{}", tfFlowApprove.getStatus());
+//                        }
+//                        if (Objects.equals(h.getVariableName(), SystemConstant.APPROVE_TF_FLOW_LOG)) {
+//                            tfFlowLog = (TFFlowLog) h.getValue();
+//                            Optional.ofNullable(tfFlowLog).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程审批日志为空"));
+//                            log.info("tfFlowLog.getApproveOperation():{}", tfFlowLog.getApproveOperation());
+//                        } else if (Objects.equals(h.getVariableName(), SystemConstant.OBJECT_DATA)) {
+//                            object = h.getValue();
+//                            Optional.ofNullable(object).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("实体数据为空"));
+//                        }
+//                        if (Objects.nonNull(object) && Objects.nonNull(tfFlowLog)) {
+//                            break;
+//                        }
+//                    }
+//                    if (Objects.nonNull(tfFlowLog.getObjectTable())) {
+//                        if (Objects.equals(tfFlowLog.getObjectTable(), TFCustomTypeEnum.ELECTRON_FLOW.getTable())) {//如果是命题任务交卷
+//                            //取命题老师ID
+//                            SysUser sysUser = sysUserService.getById(((ExamTask) object).getUserId());
+//                            try {
+//                                printCommonService.checkData(((ExamTask) object).getSchoolId(), ((ExamTask) object).getExamId(), ((ExamTask) object).getCourseCode(), ((ExamTask) object).getPaperNumber(), sysUser);
+//                            } catch (IOException e) {
+//                                throw ExceptionResultEnum.ERROR.exception("生成pdf失败");
+//                            }
+//                        }
+//                    }
+//                }
                 break;
             case TASK_COMPLETED:
                 // 任务被完成了。它会在ENTITY_DELETE事件之前触发。当任务是流程一部分时,事件会在流程继续运行之前, 后续事件将是ACTIVITY_COMPLETE,对应着完成任务的节点。
                 log.info("流程任务完成_TASK_COMPLETED:ProcessInstanceId:{},ExecutionId:{},ProcessDefinitionId:{}", event.getProcessInstanceId(), event.getExecutionId(), event.getProcessDefinitionId());
                 TaskService taskService = SpringContextHolder.getBean(TaskService.class);
-                sysUserService = SpringContextHolder.getBean(SysUserService.class);
+                SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
                 basicMessageService = SpringContextHolder.getBean(BasicMessageService.class);
-                activitiService = SpringContextHolder.getBean(ActivitiService.class);
+                ActivitiService activitiService = SpringContextHolder.getBean(ActivitiService.class);
                 RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
 
                 Task task = taskService.createTaskQuery().executionId(event.getExecutionId()).singleResult();

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

@@ -1889,26 +1889,26 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                 }
 
                 //TODO 测试流程暂时屏蔽
-//               if (!CollectionUtils.isEmpty(errorClassIds)) {
-//                    Map<String, List<String>> finalMap = new HashMap<>();
-//                    StringJoiner stringJoiner = new StringJoiner(",");
-//                    List<BasicClazz> basicClazzList = basicClazzService.listByIds(errorClassIds);
-//                    for (BasicClazz basicClazz : basicClazzList) {
-//                        String key = usedClassIdsMap.get(basicClazz.getId().toString());
-//                        List<String> value;
-//                        if (finalMap.containsKey(key)) {
-//                            value = finalMap.get(key);
-//                        } else {
-//                            value = new ArrayList<>();
-//                        }
-//                        value.add(basicClazz.getClazzName());
-//                        finalMap.put(key, value);
-//                    }
-//                    for (Map.Entry<String, List<String>> entry : finalMap.entrySet()) {
-//                        stringJoiner.add("考试对象[" + String.join(",", entry.getValue()) + "]已被" + entry.getKey() + "选择");
-//                    }
-//                    throw ExceptionResultEnum.ERROR.exception(stringJoiner.toString());
-//                }
+                if (!CollectionUtils.isEmpty(errorClassIds)) {
+                    Map<String, List<String>> finalMap = new HashMap<>();
+                    StringJoiner stringJoiner = new StringJoiner(",");
+                    List<BasicClazz> basicClazzList = basicClazzService.listByIds(errorClassIds);
+                    for (BasicClazz basicClazz : basicClazzList) {
+                        String key = usedClassIdsMap.get(basicClazz.getId().toString());
+                        List<String> value;
+                        if (finalMap.containsKey(key)) {
+                            value = finalMap.get(key);
+                        } else {
+                            value = new ArrayList<>();
+                        }
+                        value.add(basicClazz.getClazzName());
+                        finalMap.put(key, value);
+                    }
+                    for (Map.Entry<String, List<String>> entry : finalMap.entrySet()) {
+                        stringJoiner.add("考试对象[" + String.join(",", entry.getValue()) + "]已被" + entry.getKey() + "选择");
+                    }
+                    throw ExceptionResultEnum.ERROR.exception(stringJoiner.toString());
+                }
             }
 
             if (Objects.nonNull(examTask.getFlowId())) {

+ 28 - 7
distributed-print/src/main/java/com/qmth/distributed/print/api/TFCustomFlowController.java

@@ -15,13 +15,8 @@ import com.qmth.distributed.print.business.bean.params.CustomFlowParam;
 import com.qmth.distributed.print.business.bean.params.CustomFlowRenameParam;
 import com.qmth.distributed.print.business.bean.params.FlowTaskApproveParam;
 import com.qmth.distributed.print.business.bean.result.*;
-import com.qmth.distributed.print.business.entity.TFCustomFlow;
-import com.qmth.distributed.print.business.entity.TFCustomFlowEntity;
-import com.qmth.distributed.print.business.entity.TFFlowApprove;
-import com.qmth.distributed.print.business.service.ActivitiService;
-import com.qmth.distributed.print.business.service.TFCustomFlowEntityService;
-import com.qmth.distributed.print.business.service.TFCustomFlowService;
-import com.qmth.distributed.print.business.service.TFFlowApproveService;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
@@ -32,6 +27,7 @@ import com.qmth.teachcloud.common.enums.FlowStatusEnum;
 import com.qmth.teachcloud.common.enums.TFCustomTypeEnum;
 import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
 import com.qmth.teachcloud.common.service.CommonCacheService;
+import com.qmth.teachcloud.common.service.SysUserService;
 import com.qmth.teachcloud.common.util.*;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
@@ -46,6 +42,7 @@ import javax.annotation.Resource;
 import javax.validation.Valid;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
+import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -85,6 +82,15 @@ public class TFCustomFlowController {
     @Resource
     TFCustomFlowEntityService tfCustomFlowEntityService;
 
+    @Resource
+    SysUserService sysUserService;
+
+    @Resource
+    PrintCommonService printCommonService;
+
+    @Resource
+    ExamTaskService examTaskService;
+
     @ApiOperation(value = "保存和发布流程")
     @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
     @RequestMapping(value = "/save", method = RequestMethod.POST)
@@ -179,6 +185,21 @@ public class TFCustomFlowController {
         map.computeIfAbsent(SystemConstant.APPROVE_USER_IDS, v -> flowTaskApproveParam.getApproveUserIds());
         activitiService.taskApprove(map);
         activitiService.sendFlowTaskApproveMsg(map);
+        TFFlowLog tfFlowLog = (TFFlowLog) map.get(SystemConstant.APPROVE_TF_FLOW_LOG);
+        TFFlowApprove tfFlowApprove = (TFFlowApprove) map.get(SystemConstant.APPROVE_TF_FLOW_APPROVE);
+        if (Objects.nonNull(tfFlowLog.getObjectTable())) {
+            if (Objects.equals(tfFlowLog.getObjectTable(), TFCustomTypeEnum.ELECTRON_FLOW.getTable())
+                    && tfFlowApprove.getStatus() == FlowStatusEnum.FINISH) {//如果是命题任务交卷
+                ExamTask examTask = examTaskService.getById(tfFlowLog.getObjectId());
+                //取命题老师ID
+                SysUser sysUser = sysUserService.getById(examTask.getUserId());
+                try {
+                    printCommonService.checkData(examTask.getSchoolId(), examTask.getExamId(), examTask.getCourseCode(), examTask.getPaperNumber(), sysUser);
+                } catch (IOException e) {
+                    throw ExceptionResultEnum.ERROR.exception("生成pdf失败");
+                }
+            }
+        }
         return ResultUtil.ok(true);
     }