| | |
| | | import org.flowable.common.engine.api.FlowableObjectNotFoundException; |
| | | import org.flowable.common.engine.impl.identity.Authentication; |
| | | import org.flowable.engine.ProcessEngineConfiguration; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.history.HistoricActivityInstance; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.history.HistoricProcessInstanceQuery; |
| | |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.SpringContextUtils; |
| | | import org.jeecg.modules.flowable.apithird.business.dto.FlowMyBusinessDto; |
| | |
| | | import org.jeecg.modules.flowable.domain.dto.FlowTaskDto; |
| | | import org.jeecg.modules.flowable.domain.dto.FlowViewerDto; |
| | | import org.jeecg.modules.flowable.domain.vo.FlowTaskVo; |
| | | import org.jeecg.modules.flowable.domain.vo.WorkTaskDataVo; |
| | | import org.jeecg.modules.flowable.factory.FlowServiceFactory; |
| | | import org.jeecg.modules.flowable.flow.CustomProcessDiagramGenerator; |
| | | import org.jeecg.modules.flowable.flow.FindNextNodeUtil; |
| | |
| | | private IFlowThirdService iFlowThirdService; |
| | | @Autowired |
| | | FlowMyBusinessServiceImpl flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | /** |
| | | * 完成任务 |
| | | * |
| | |
| | | flowTaskVo.setTaskId(business.getTaskId()); |
| | | return findReturnTaskList(flowTaskVo); |
| | | } |
| | | |
| | | /** |
| | | * 结束流程 |
| | | * @param processInstanceId 流程实例 ID |
| | | * @param deleteReason 定义删除原因 |
| | | */ |
| | | public Result<?> end(String processInstanceId, String deleteReason) { |
| | | try { |
| | | // 强制结束流程实例 |
| | | runtimeService.deleteProcessInstance(processInstanceId, deleteReason); |
| | | // 删除关联流程的业务 |
| | | FlowMyBusiness flowMyBusiness=flowMyBusinessService.getFlowMyBusiness(processInstanceId); |
| | | flowMyBusinessService.removeById(flowMyBusiness.getId()); |
| | | System.out.println("Process instance with ID " + processInstanceId + " has been forcefully ended."); |
| | | } catch (Exception e) { |
| | | System.err.println("Failed to force end process instance: " + e.getMessage()); |
| | | } |
| | | |
| | | // 关闭流程引擎 |
| | | processEngine.close(); |
| | | return Result.OK("流程已结束"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取所有可回退的节点 |
| | | * |
| | |
| | | HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() |
| | | .processInstanceId(flowTaskDto.getProcInsId()) |
| | | .singleResult(); |
| | | SysUser startUser = iFlowThirdService.getUserByUsername(historicProcessInstance.getStartUserId()); |
| | | flowTaskDto.setStartUserId(startUser.getUsername()); |
| | | flowTaskDto.setStartUserName(startUser.getRealname()); |
| | | List<String> departNamesByUsername = iFlowThirdService.getDepartNamesByUsername(historicProcessInstance.getStartUserId()); |
| | | flowTaskDto.setStartDeptName(CollUtil.join(departNamesByUsername,",")); |
| | | if(historicProcessInstance != null) { |
| | | SysUser startUser = iFlowThirdService.getUserByUsername(historicProcessInstance.getStartUserId()); |
| | | if(startUser == null) { |
| | | flowTaskDto.setStartUserId(""); |
| | | flowTaskDto.setStartUserName(""); |
| | | }else { |
| | | flowTaskDto.setStartUserId(startUser.getUsername()); |
| | | flowTaskDto.setStartUserName(startUser.getRealname()); |
| | | } |
| | | List<String> departNamesByUsername = iFlowThirdService.getDepartNamesByUsername(historicProcessInstance.getStartUserId()); |
| | | flowTaskDto.setStartDeptName(CollUtil.join(departNamesByUsername,",")); |
| | | } |
| | | }); |
| | | IPage<FlowTaskDto> flowTaskDtoIPage = new Page<>(); |
| | | flowTaskDtoIPage.setRecords(list); |
| | |
| | | return Result.OK(flowNextDto); |
| | | } |
| | | |
| | | @Override |
| | | public WorkTaskDataVo getPreviousFlowInfo(String dataId) { |
| | | FlowMyBusiness flowMyBusiness = flowMyBusinessService.getByDataId(dataId); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("未找到流程数据!"); |
| | | } |
| | | |
| | | String taskId = flowMyBusiness.getTaskId(); |
| | | String processInstanceId = flowMyBusiness.getProcessInstanceId(); |
| | | WorkTaskDataVo taskDataVo = new WorkTaskDataVo(); |
| | | // 如果当前任务ID为空,则尝试从历史任务中获取最后一个完成的任务 |
| | | if (StringUtils.isBlank(taskId)) { |
| | | List<HistoricTaskInstance> historicTasks = historyService |
| | | .createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .orderByTaskCreateTime() |
| | | .desc() |
| | | .list(); |
| | | |
| | | if (CollectionUtils.isEmpty(historicTasks)) { |
| | | throw new JeecgBootException("找不到历史任务记录"); |
| | | } |
| | | |
| | | HistoricTaskInstance lastTask = historicTasks.get(0); |
| | | buildWorkTaskDataVo(taskDataVo, lastTask.getId(), lastTask.getName(), lastTask.getCreateTime()); |
| | | } else { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).active().singleResult(); |
| | | if (task == null) { |
| | | throw new JeecgBootException("找不到对应任务"); |
| | | } else { |
| | | buildWorkTaskDataVo(taskDataVo, task.getId(), task.getName(), task.getCreateTime()); |
| | | } |
| | | } |
| | | return taskDataVo; |
| | | } |
| | | |
| | | private void buildWorkTaskDataVo(WorkTaskDataVo taskDataVo, String id, String name, Date createTime) { |
| | | taskDataVo.setId(id); |
| | | taskDataVo.setName(name); |
| | | taskDataVo.setCreateTime(createTime); |
| | | HistoricActivityInstance previousNode = flowMyBusinessService.getPreviousNode(id); |
| | | if (previousNode != null) { |
| | | taskDataVo.setPreNode(previousNode.getActivityName()); |
| | | taskDataVo.setPreNodeAssignee(previousNode.getAssignee()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下一个节点信息,流程定义上的节点信息 |
| | | * @param taskId 当前节点id |