activiti6撤销审批

本文详细介绍了如何在SpringBoot项目中集成Activiti 6,处理审批流程中审批人误操作的撤销需求,包括查询任务、历史记录、修改流程方向并完成撤销操作的代码片段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

撤销审批

需求

在springboot整合activiti6实现审批的同时,如果申请申请人提交申请之后,中间审批人误批,需要实现撤销审批!!!

代码

@ResponseBody
@PostMapping("/chexiao")
@Transactional
public String chexiao(String sid) throws Exception {
	//上面的sid只是我的业务需要,可不用管
	List<suppliesinoutTodoItem> suppliesinouttodoitem = outdoorTodoItemService.selectBizTodoItemBySId1(sid);
	//此处的taskid我是通过业务查出来的,指的是提交人提交或者审批人审批之后产生的任务id
	String taskid = null;
	if(suppliesinouttodoitem.size() > 0){
		taskid = suppliesinouttodoitem.get(0).getTaskId();
	}
//        System.out.println(taskid);
	//通过taskid查询出当前的任务
	Task task = taskService.createTaskQuery().taskId(taskid).singleResult();
	if (task == null) {
		//throw new ServiceException("流程未启动或已执行完成,无法撤回");
		return "500";
	}else{
//            List<HistoricTaskInstance> htlist = historyService.createHistoricTaskInstanceQuery()
//                    .processDefinitionId(task.getProcessDefinitionId()).list();
		//通过instancedid查询历史
		List<HistoricTaskInstance> htlist = historyService.createHistoricTaskInstanceQuery().processInstanceId(task.getProcessInstanceId()).list();
		String myTaskId = null;
		HistoricTaskInstance myTask = null;

		String uname = ShiroUtils.getLoginName();
		for (HistoricTaskInstance hti : htlist) {
		//此处的uname表示的是节点对应的处理人名
			if ((hti.getAssignee() != null) && hti.getAssignee().equals(uname)) {
				myTaskId = hti.getId();
				myTask = hti;
				break;
			}
		}

		if (myTask == null) {
			throw new ServiceException("该任务非当前用户提交,无法撤回");
		}

		String processDefinitionId = myTask.getProcessDefinitionId();
		BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);

		String myActivityId = null;
		List<HistoricActivityInstance> haiList =
				historyService
						.createHistoricActivityInstanceQuery()
						.executionId(myTask.getExecutionId())
						.finished()
						.list();

		for (HistoricActivityInstance hai : haiList) {
			if (myTaskId.equals(hai.getTaskId())) {
				myActivityId = hai.getActivityId();
				break;
			}
		}

		FlowNode myFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(myActivityId);
		Execution execution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
		String activityId = execution.getActivityId();
		System.out.println(activityId);
		FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
		//记录原活动方向
		List<SequenceFlow> oriSequenceFlows = new ArrayList<SequenceFlow>();
		oriSequenceFlows.addAll(flowNode.getOutgoingFlows());
		//清理活动方向
		flowNode.getOutgoingFlows().clear();
		//建立新方向
		List<SequenceFlow> newSequenceFlowList = new ArrayList<SequenceFlow>();
		SequenceFlow newSequenceFlow = new SequenceFlow();
		newSequenceFlow.setId("newSequenceFlowId");
		newSequenceFlow.setSourceFlowElement(flowNode);
		newSequenceFlow.setTargetFlowElement(myFlowNode);
		newSequenceFlowList.add(newSequenceFlow);
		flowNode.setOutgoingFlows(newSequenceFlowList);
		Authentication.setAuthenticatedUserId(ShiroUtils.getLoginName());
		taskService.addComment(task.getId(), task.getProcessInstanceId(), "撤回");
		//完成任务
		List<Task> taskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).active().list();
		taskService.complete(task.getId());
		//撤销的节点任务
		List<Task> taskList1 = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).active().list();
		//需要处理biz里面的数据
		//删除撤销之前提交之后产生的数据
		String aaa = taskList.get(0).getId();
		outdoorTodoItemService.deleteBizTodoItemBytaskid(aaa);
		List<suppliesinoutTodoItem> suppliesinouttodoitem1 = outdoorTodoItemService.selectBizTodoItemBySId1(sid);
		suppliesinoutTodoItem sm = suppliesinouttodoitem1.get(0);
		sm.setTaskId(taskList1.get(0).getId());
		sm.setTaskName(taskList1.get(0).getTaskDefinitionKey());
		sm.setNodeName(taskList1.get(0).getName());
		sm.setIsView("0");
		sm.setIsHandle("0");
		sm.setHandleUserId(null);
		sm.setHandleUserName(null);
		sm.setHandleTime(null);
		outdoorTodoItemService.updateBizTodoItem(sm);

		//恢复原方向
		flowNode.setOutgoingFlows(oriSequenceFlows);
		return "200";
	}
}
}

大佬勿喷,欢迎提意见建议评论!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值