/** * * @Description (跳转任意目标节点) * @author feizhou * @Date 2018年3月28日上午10:23:00 * @version 1.0.0 * @param map * taskId,destTaskKey,rejectMessage,outcome */ public void skipStipulationTask(Map map) { String taskId = (String) map.get("taskId"); // 目标任务key String destTaskKey = (String) map.get("destTaskKey"); //审批消息 String rejectMessage = (String) map.get("rejectMessage"); //流程线 String outcome = (String) map.get("outcome"); //业务的用户ID String uid = (String) map.get("uid"); //审批消息 String message = (String) map.get("message"); // 使用任务ID,获取任务信息 Task taskEntity = getTask(taskId); // 获得当前任务的流程实例ID String processInstanceId = taskEntity.getProcessInstanceId(); // 获得当前任务的流程定义ID String processDefinitionId = taskEntity.getProcessDefinitionId(); // 当前任务key String currtaskDefKey = taskEntity.getTaskDefinitionKey(); // 获得当前活动节点和驳回的目标节点"draft" ActivityImpl currActiviti = null;// 当前活动节点 ActivityImpl destActiviti = null;// 驳回目标节点 currActiviti = getActivityImpl(currtaskDefKey, processDefinitionId); destActiviti = getActivityImpl(destTaskKey, processDefinitionId); // 保存当前活动节点的流程流出参数 List hisPvmTransitionList = new ArrayList (0); for (PvmTransition pvmTransition : currActiviti.getOutgoingTransitions()) { hisPvmTransitionList.add(pvmTransition); } // 清空当前活动节点的所有流出项 currActiviti.getOutgoingTransitions().clear(); // 为当前节点动态创建新的流出项 TransitionImpl newTransitionImpl = currActiviti.createOutgoingTransition(); // 为当前活动节点新的流出项指定为目标流程节点 newTransitionImpl.setDestination(destActiviti); // 保存驳回意见 taskEntity.setDescription(rejectMessage);// 设置驳回意见 taskService.saveTask(taskEntity); /** * 注意:添加批注的时候,由于Activiti底层代码是使用: String userId = * Authentication.getAuthenticatedUserId(); CommentEntity comment = new * CommentEntity(); comment.setUserId(userId); * 所有需要从Session中获取当前登录人,作为该任务的办理人(审核人),对应act_hi_comment表中的User_ID的字段, * 不添加审核人,该字段为null * 所以要求,添加配置执行使用Authentication.setAuthenticatedUserId();添加当前任务的审核人 */ Authentication.setAuthenticatedUserId(uid); taskService.addComment(taskId, processInstanceId, message); // 设定驳回标志 Map variables = new HashMap (0); variables.put("outcome", outcome); // 执行当前任务驳回到目标任务draft taskService.complete(taskEntity.getId(), variables); // 清除目标节点的新流入项 destActiviti.getIncomingTransitions().remove(newTransitionImpl); // 清除原活动节点的临时流程项 currActiviti.getOutgoingTransitions().clear(); // 还原原活动节点流出项参数 currActiviti.getOutgoingTransitions().addAll(hisPvmTransitionList); }
/** * * @Description (通过任务key,获取对应的节点信息) * @author feizhou * @Date 2018年3月28日下午1:53:29 * @version 1.0.0 * @param taskKey * @return */ public ActivityImpl getActivityImpl(String destTaskKey, String processDefinitionId) { // 获得当前流程的定义模型 ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(processDefinitionId); // 获得当前流程定义模型的所有任务节点 List activitilist = processDefinition.getActivities(); // 获得当前活动节点和驳回的目标节点"draft" ActivityImpl descActiviti = null;// 当前活动节点 for (ActivityImpl activityImpl : activitilist) { // 获取节点对应的key String taskKey = activityImpl.getId(); // 确定当前活动activiti节点 if (destTaskKey.equals(taskKey)) { descActiviti = activityImpl; break; } } return descActiviti; }