throw new ApplicationException("会签任务ID不能为空!");
if( users == null )
throw new ApplicationException("会签用户不能为空!");
Task task = getTask(taskId);
if( task == null )
throw new ApplicationException("任务ID["+taskId+"]不存在!");
if( StringUtils.isEmpty(operator) ){
operator = task.getAssignee();
log.warn("会签操作人为空,使用任务签收人[{}]",task.getAssignee());
}
StringBuffer message = new StringBuffer("添加会签人[");
int i = 0;
//对用户不能重复添加会签
List<Task> subTasks = taskService.getSubTasks(taskId); //子任务
Map<String,Task> subTaskMap = new HashMap<String,Task>();
if( subTasks != null && subTasks.size() > 0 ){
for(Task item: subTasks){
subTaskMap.put(item.getAssignee(), item);
}
}
for( String user:users ){
if( task.getAssignee().equals(user) )
throw new ApplicationException("不能添加自己["+user+"]为会签人");
if( subTaskMap.get(user) != null )
throw new ApplicationException("任务已添加会签人["+user+"]");
TaskEntity subTask = (TaskEntity)taskService.newTask();
subTask.setParentTaskId(taskId); //上级Task
subTask.setName( task.getName() + "-["+user+"]会签");
subTask.setAssignee( user ); //会签用户
subTask.setProcessDefinitionId( task.getProcessDefinitionId() );
subTask.setProcessInstanceId( task.getProcessInstanceId() );
subTask.setDescription("会签");
taskService.saveTask(subTask);
message.append((i==0?"":",") +user);
++i;
}
message.append("]");
taskLogManager.save(task.getProcessInstanceId(),task.getId()
,ExecutionType.SIGN, operator, message.toString());
}