RuntimeService runtimeService = processEngine.getRuntimeService();
// runtimeService.getCommandExecutor().setConnection(dbgr.getConnection());
TaskService taskService = processEngine.getTaskService();
if(this.taskId!=null&&!this.taskId.equals("")){
//TaskInstance taskInstance=commandContext.getTaskManager().findTaskById(this.taskId);
ExpandTaskCommand expandTaskCommand=new ExpandTaskCommand();
expandTaskCommand.setCommandType("submit");
expandTaskCommand.setTaskComment(this.taskComment);
expandTaskCommand.setTaskId(this.taskId);
expandTaskCommand.setUserCommandId(this.userCommandId);
expandTaskCommand.setTransientVariables(transientVariables);
expandTaskCommand.setBusinessKey(businessKey);
expandTaskCommand.setInitiator(initiator);
if(this.agent!=null&&!this.agent.equals("")){
expandTaskCommand.setAgent(this.agent);
}
taskService.expandTaskComplete(expandTaskCommand, null);
return null;
}else{
StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand();
startProcessInstanceCommand.setProcessDefinitionKey(processDefinitionKey);
startProcessInstanceCommand.setBusinessKey(businessKey);
startProcessInstanceCommand.setStartAuthor(initiator);
startProcessInstanceCommand.setTransientVariables(transientVariables);
// startProcessInstanceCommand.setVariables(Variables);
ProcessInstance processInstanceQueryTo = runtimeService
.noneStartProcessInstance(startProcessInstanceCommand);
// 任务第一步提交完还需找到一个待办事宜再执行掉才算真正完成
String processInstanceId = processInstanceQueryTo.getId();
TaskQuery taskQuery = taskService.createTaskQuery()
.processInstanceId(processInstanceId);
//先去找独占任务没有的话就去找共享任务并完成他
List<TaskInstance> taskQueryList = taskQuery.taskAssignee(initiator).taskNotEnd()
.list();
for (TaskInstance instanceQueryTo : taskQueryList) {
//String nodeId = instanceQueryTo.getNodeId();
//String processDefinitionId = instanceQueryTo
// .getProcessDefinitionId();
//List<TaskCommandInst> commandList = taskService.getTaskCommandById(processDefinitionId, nodeId);
//TaskCommandInst userCommand = commandList.get(0);
ExpandTaskCommand expandTaskCommand=new ExpandTaskCommand();
expandTaskCommand.setCommandType("submit");
expandTaskCommand.setTaskComment(this.taskComment);
expandTaskCommand.setTaskId(instanceQueryTo.getId());
expandTaskCommand.setUserCommandId(this.userCommandId);
expandTaskCommand.setTransientVariables(transientVariables);
expandTaskCommand.setBusinessKey(businessKey);
expandTaskCommand.setInitiator(initiator);
if(this.agent!=null&&!this.agent.equals("")){
expandTaskCommand.setAgent(this.agent);
}
taskService.expandTaskComplete(expandTaskCommand, null);
}
if (taskQueryList.size() <= 0) {
TaskQuery taskQueryNew=taskService.createTaskQuery().processInstanceId(processInstanceId);
List<TaskInstance> taskQueryCandidateList = taskQueryNew.taskCandidateUser(initiator).taskNotEnd().list();
for (TaskInstance instanceQueryTo : taskQueryCandidateList) {
ExpandTaskCommand expandTaskCommandClaim=new ExpandTaskCommand();
expandTaskCommandClaim.setCommandType("claim");
expandTaskCommandClaim.setTaskId(instanceQueryTo.getId());
taskService.expandTaskComplete(expandTaskCommandClaim, null);
//taskService.claim(instanceQueryTo.getId(), initiator);
//String nodeId = instanceQueryTo.getNodeId();
//String processDefinitionId = instanceQueryTo
// .getProcessDefinitionId();
//List<TaskCommandInst> commandList = taskService
// .getTaskCommandById(processDefinitionId, nodeId);
//TaskCommandInst userCommand = commandList.get(0);
ExpandTaskCommand expandTaskCommand=new ExpandTaskCommand();
expandTaskCommand.setCommandType("submit");
expandTaskCommand.setTaskComment(this.taskComment);
expandTaskCommand.setTaskId(instanceQueryTo.getId());
expandTaskCommand.setUserCommandId(this.userCommandId);
expandTaskCommand.setTransientVariables(transientVariables);
expandTaskCommand.setBusinessKey(businessKey);
expandTaskCommand.setInitiator(initiator);
if(this.agent!=null&&!this.agent.equals("")){
expandTaskCommand.setAgent(this.agent);
}
taskService.expandTaskComplete(expandTaskCommand, null);