根据当前Task创建一个新的Task,注意同时也要创建历史Task。
@Test
void createTask() {
Task currentTask = null;
TaskEntity taskEntity = (TaskEntity)taskService.newTask();
taskEntity.setCategory(currentTask.getCategory());
taskEntity.setDescription(currentTask.getDescription());
taskEntity.setTenantId(currentTask.getTenantId());
taskEntity.setAssignee(currentTask.getAssignee());
taskEntity.setName(currentTask.getName());
taskEntity.setProcessDefinitionId(currentTask.getProcessDefinitionId());
taskEntity.setProcessInstanceId(currentTask.getProcessInstanceId());
taskEntity.setTaskDefinitionId(currentTask.getTaskDefinitionId());
taskEntity.setPriority(currentTask.getPriority());
taskEntity.setCreateTime(new Date());
taskService.saveTask(taskEntity);
Command<Boolean> updateHistoryTaskCmd = new Command<Boolean>() {
@Override
public Boolean execute(CommandContext commandContext) {
HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();
HistoricTaskInstanceEntity historicTask = historicTaskService.getHistoricTask(taskEntity.getId());
historicTask.setProcessDefinitionId(currentTask.getProcessDefinitionId());
historicTask.setProcessInstanceId(currentTask.getProcessInstanceId());
historicTask.setCreateTime(new Date());
historicTaskService.updateHistoricTask(historicTask, true);
return true;
}
};
managementService.executeCommand(updateHistoryTaskCmd);
}