| | |
| | | import org.jeecg.modules.flowable.apithird.common.constant.ProcessConstants; |
| | | import org.jeecg.modules.flowable.apithird.common.enums.FlowComment; |
| | | import org.jeecg.modules.flowable.apithird.common.exception.CustomException; |
| | | import org.jeecg.modules.flowable.apithird.entity.ActStatus; |
| | | import org.jeecg.modules.flowable.apithird.entity.SysUser; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | | import org.jeecg.modules.flowable.apithird.service.IFlowThirdService; |
| | |
| | | taskService.saveTask(task); |
| | | } |
| | | SysUser loginUser = iFlowThirdService.getLoginUser(); |
| | | //判断用户是否有权限 |
| | | if (!task.getAssignee().equals(loginUser.getUsername())){ |
| | | return Result.error("当前用户无权限"); |
| | | } |
| | | if (DelegationState.PENDING.equals(task.getDelegationState())) { |
| | | taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.DELEGATE.getType(), taskVo.getComment()); |
| | | //taskService.resolveTask(taskVo.getTaskId(), taskVo.getValues()); |
| | |
| | | System.out.println("taskVo.getTaskId()--->taskVo.getInstanceId()--->FlowComment.NORMAL.getType()--->taskVo.getComment()"+taskVo.getTaskId() + "---" + taskVo.getInstanceId() + "---" + FlowComment.NORMAL.getType() + "---"+taskVo.getComment() ); |
| | | taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.NORMAL.getType(), taskVo.getComment()); |
| | | taskService.setAssignee(taskVo.getTaskId(), loginUser.getUsername()); |
| | | //taskService.complete(taskVo.getTaskId(), taskVo.getValues()); |
| | | } |
| | | /*======================审批结束 回调以及关键数据保存======================*/ |
| | | //业务数据id |
| | |
| | | |
| | | if (task2!=null && task.getTaskDefinitionKey().equals(task2.getTaskDefinitionKey())){ |
| | | // * 当前节点是会签节点,没有走完 |
| | | business.setActStatus(ActStatus.doing) |
| | | .setTaskId(task2.getId()) |
| | | business.setTaskId(task2.getId()) |
| | | // .setActStatus(ActStatus.doing) |
| | | .setDoneUsers(doneUserList.toJSONString()) |
| | | ; |
| | | String todoUsersStr = business.getTodoUsers(); |
| | |
| | | // 前端传入候选人 |
| | | collect_username = candidateUsers; |
| | | } |
| | | business.setActStatus(ActStatus.doing) |
| | | business |
| | | .setTaskId(task2.getId()) |
| | | // .setActStatus(ActStatus.doing) |
| | | .setTaskNameId(nextTask.getId()) |
| | | .setTaskName(nextTask.getName()) |
| | | .setPriority(nextTask.getPriority()) |
| | |
| | | |
| | | } else { |
| | | // **没有下一个节点,流程已经结束了 |
| | | business.setActStatus(ActStatus.pass) |
| | | business |
| | | .setDoneUsers(doneUserList.toJSONString()) |
| | | .setTodoUsers("") |
| | | .setTaskId("") |
| | |
| | | if (flowCallBackService!=null)flowCallBackService.afterFlowHandle(business); |
| | | return Result.OK(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result completeByDateId(FlowTaskVo flowTaskVo){ |
| | | return this.complete(flowTaskVo); |
| | | } |
| | | |
| | | @Override |
| | | public void taskRejectByDataId(FlowTaskVo flowTaskVo){ |
| | | FlowMyBusiness business = flowMyBusinessService.getByDataId(flowTaskVo.getDataId()); |
| | |
| | | if (!doneUserList.contains(loginUser.getUsername())){ |
| | | doneUserList.add(loginUser.getUsername()); |
| | | } |
| | | business.setActStatus(ActStatus.reject) |
| | | business |
| | | .setTaskId(task2.getId()) |
| | | // .setActStatus(ActStatus.reject) |
| | | .setTaskNameId(task2.getTaskDefinitionKey()) |
| | | .setTaskName(task2.getName()) |
| | | .setDoneUsers(doneUserList.toJSONString()) |
| | |
| | | //**跳转到目标节点 |
| | | List<Task> task2List = taskService.createTaskQuery().processInstanceId(business.getProcessInstanceId()).active().list(); |
| | | Task targetTask = task2List.get(0); |
| | | business.setActStatus(ActStatus.reject) |
| | | business |
| | | .setTaskId(targetTask.getId()) |
| | | // .setActStatus(ActStatus.reject) |
| | | .setTaskNameId(targetTask.getTaskDefinitionKey()) |
| | | .setTaskName(targetTask.getName()) |
| | | .setPriority(targetTask.getPriority()+"") |
| | |
| | | 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) { |