String userId = SecurityUtils.getUsername();
//通过传过来的任务id去查找流程实例id
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
//流程实例id
String processid = task.getProcessInstanceId();
//通过流程实例id获取业务id,BUSINESS_KEY
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processid).singleResult();
// 对businessKey做处理,拿到业务id
String businessKey = processInstance.getBusinessKey();
String deptNo = auditService.queryDeptNoByProcessInstanceId(processid).replace("[\"", "").replace("\"]", "");
String businessId = businessKey + ":" + deptNo;
//添加审批意见及填写审批意见人员
Authentication.setAuthenticatedUserId(userId);
taskService.addComment(taskId, processid, opin);
// 获取所有历史任务(按创建时间升序)
List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processid)
.orderByTaskCreateTime()
.asc()
.list();
if (null == hisTaskList || hisTaskList.size() < 2) {
CommUtils.throwClientException("退回评分失败!");
}
// 填报节点任务
HistoricTaskInstance startTask = hisTaskList.get(0);
// 部门审批节点任务
HistoricTaskInstance currentTask = hisTaskList.get(hisTaskList.size() - 1);
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
logger.info(startTask.getTaskDefinitionKey());
// 获取填报活动节点
FlowNode startFlowNode = (FlowNode) bpmnModel.getFlowElement(startTask.getTaskDefinitionKey());
// 获取部门审批活动节点
FlowNode currentFlowNode = (FlowNode) bpmnModel.getFlowElement(currentTask.getTaskDefinitionKey());
// 临时保存当前活动的原始方向
List<SequenceFlow> originalSequenceFlowList = new ArrayList<>();
originalSequenceFlowList.addAll(currentFlowNode.getOutgoingFlows());
// 清理活动方向
currentFlowNode.getOutgoingFlows().clear();
// 建立新方向
SequenceFlow newSequenceFlow = new SequenceFlow();
newSequenceFlow.setId("newSequenceFlowId");
newSequenceFlow.setSourceFlowElement(currentFlowNode);
newSequenceFlow.setTargetFlowElement(startFlowNode);
List<SequenceFlow> newSequenceFlowList = new ArrayList<>();
newSequenceFlowList.add(newSequenceFlow);
// 当前节点指向新的方向
currentFlowNode.setOutgoingFlows(newSequenceFlowList);
taskService.complete(taskId);
// 重新查询当前任务
Task nextTask = taskService.createTaskQuery().processInstanceId(processid).singleResult();
if (null != nextTask) {
taskService.setAssignee(nextTask.getId(), startTask.getAssignee());
}
// 恢复原始方向
currentFlowNode.setOutgoingFlows(originalSequenceFlowList);
activiti流程节点驳回处理方式
于 2023-06-25 09:44:44 首次发布