| | |
| | | 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("流程已结束"); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有可回退的节点 |
| | | * |
| | |
| | | return Result.OK(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 判断多个任务是否处于同一流程节点 |
| | | * @param taskIds 逗号分隔的任务ID字符串 |
| | | * @return 统一结果封装 |
| | | */ |
| | | @Override |
| | | public Result isSameNode(String taskIds) { |
| | | // 1. 参数校验 |
| | | if (StringUtils.isBlank(taskIds)) { |
| | | return Result.error("任务ID不能为空"); |
| | | } |
| | | |
| | | // 2. 分割任务ID |
| | | String[] taskIdArray = taskIds.split(","); |
| | | if (taskIdArray.length == 0) { |
| | | return Result.error("未提供有效的任务ID"); |
| | | } |
| | | |
| | | // 3. 单任务直接返回true |
| | | if (taskIdArray.length == 1) { |
| | | return Result.ok(true); |
| | | } |
| | | |
| | | // 4. 多任务检查逻辑 |
| | | String referenceNodeId = null; |
| | | String currentNodeId = null; |
| | | for (String taskId : taskIdArray) { |
| | | // 4.1 查询任务实例 |
| | | Task task = taskService.createTaskQuery() |
| | | .taskId(taskId.trim()) |
| | | .singleResult(); |
| | | |
| | | // 4.2 任务不存在处理 |
| | | if (task == null) { |
| | | return Result.error("任务不存在: " + taskId); |
| | | } |
| | | |
| | | // 4.3 获取节点标识(TaskDefinitionKey) |
| | | currentNodeId = task.getTaskDefinitionKey(); |
| | | |
| | | // 4.4 首次遍历初始化参考节点 |
| | | if (referenceNodeId == null) { |
| | | referenceNodeId = currentNodeId; |
| | | continue; |
| | | } |
| | | |
| | | // 4.5 节点不一致直接返回 |
| | | if (!referenceNodeId.equals(currentNodeId)) { |
| | | return Result.ok("节点不一致"); |
| | | } |
| | | } |
| | | |
| | | // 5. 所有任务节点一致 |
| | | return Result.ok(currentNodeId); |
| | | } |
| | | |
| | | /** |
| | | * 代办任务列表 |
| | | * |
| | |
| | | Page page = new Page(pageNum, pageSize); |
| | | String username = iFlowThirdService.getLoginUser().getUsername(); |
| | | flowMyBusinessDto.setCurrentUser(username); |
| | | IPage<FlowTaskDto> flowTaskDtoIPage = flowMyBusinessService.getPageListMyBusiness(page,flowMyBusinessDto); |
| | | flowTaskDtoIPage.getRecords().forEach(flowTaskDto -> { |
| | | // 流程定义信息 |
| | | ProcessDefinition pd = repositoryService.createProcessDefinitionQuery() |
| | | .processDefinitionId(flowTaskDto.getProcessDefinitionId()) |
| | | .singleResult(); |
| | | flowTaskDto.setDeployId(pd.getDeploymentId()); |
| | | flowTaskDto.setProcDefName(pd.getName()); |
| | | flowTaskDto.setProcDefVersion(pd.getVersion()); |
| | | flowTaskDto.setCategory(pd.getCategory()); |
| | | List<FlowTaskDto> list = flowMyBusinessService.ListMyBusiness(flowMyBusinessDto); |
| | | list.forEach(flowTaskDto -> { |
| | | // 流程发起人信息 |
| | | HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() |
| | | .processInstanceId(flowTaskDto.getTaskId()) |
| | | .processInstanceId(flowTaskDto.getProcInsId()) |
| | | .singleResult(); |
| | | SysUser startUser = iFlowThirdService.getUserByUsername(historicProcessInstance.getStartUserId()); |
| | | flowTaskDto.setStartUserId(startUser.getUsername()); |
| | | flowTaskDto.setStartUserName(startUser.getRealname()); |
| | | if (startUser!=null){ |
| | | flowTaskDto.setStartUserId(startUser.getUsername()); |
| | | flowTaskDto.setStartUserName(startUser.getRealname()); |
| | | } |
| | | List<String> departNamesByUsername = iFlowThirdService.getDepartNamesByUsername(historicProcessInstance.getStartUserId()); |
| | | flowTaskDto.setStartDeptName(CollUtil.join(departNamesByUsername,",")); |
| | | flowTaskDto.setTaskId(flowTaskDto.getHisProcInsId()); |
| | | if (flowTaskDto.getTodoUsers() == null){ |
| | | flowTaskDto.setTodoUsers(""); |
| | | }else { |
| | | //去除[] |
| | | flowTaskDto.setTodoUsers(flowTaskDto.getTodoUsers().replaceAll("\\[", "").replaceAll("\\]", "")); |
| | | flowTaskDto.setTodoUsers(flowTaskDto.getTodoUsers().replaceAll("\"", "")); |
| | | } |
| | | }); |
| | | return Result.OK(page); |
| | | IPage<FlowTaskDto> flowTaskDtoIPage = new Page<>(); |
| | | flowTaskDtoIPage.setRecords(list); |
| | | flowTaskDtoIPage.setTotal(page.getTotal()); |
| | | return Result.OK(flowTaskDtoIPage); |
| | | } |
| | | |
| | | private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { |