我使用以下代码更新Activiti中的任务。
@Service
@Log4j
public class TicketUpdateService {
@Autowired
TaskService taskService;
@Autowired
RuntimeService runtimeService;
@Transactional
public BaseDto updateTicket(TicketHistoryDto historyDto) {
String taskId = historyDto.getTaskId();
runtimeService.setVariable(historyDto.getExecutionId(), "STATE",
historyDto.getTicketState());
if (historyDto.getNotes() != null
&& historyDto.getNotes().trim().length() > 0) {
log.info(" Setting the notes");
taskService.setVariableLocal(taskId, "notes", historyDto
.getNotes().trim());
ticket.setDescription(historyDto.getNotes().trim());
}
/** Update the Ticket Status */
if (historyDto.getTicketStatusInfo() != null) {
log.info(" Setting the Ticket Status as "
+ historyDto.getTicketStatusInfo());
taskService.setVariableLocal(taskId, "ticketStatus",
historyDto.getTicketStatusInfo());
}
taskService.complete(taskId);
} }
我需要使用任务变量来完成任务。为此,我使用以下代码
@Service
@Log4j
public class TicketActivitiServiceImpl{
@Autowired
private TaskService taskService;
public List<Task> getTasks(){
TaskQuery activitiQuery = taskService.createTaskQuery();
// I can able to get the Task based Process variable
if (searchDto.getCategory() != null && searchDto.getCategory() > 0l) {
log.info("Category Id : " + searchDto.getCategory());
activitiQuery.processVariableValueEquals("category",
searchDto.getCategory());
}
if (searchDto.getSubCategory() != null
&& searchDto.getSubCategory() > 0L) {
log.info("Sub Category Id : " + searchDto.getSubCategory());
activitiQuery.processVariableValueEquals("subCategory",
searchDto.getSubCategory());
}
// I am not able to get the task information after including the following code
// I need the task based on Task Variable also
if (searchDto.getTicketStatus() != null
&& !"".equals(searchDto.getTicketStatus().trim())) {
log.info("Ticket status : " + searchDto.getTicketStatus());
activitiQuery.includeTaskLocalVariables()
.taskVariableValueEqualsIgnoreCase("ticketStatus",
searchDto.getTicketStatus().trim());
}
activitiQuery.taskCandidateOrAssigned("" + searchDto.getUserId());
activitiQuery.orderByTaskCreateTime().desc();
List<Task> taskList = activitiQuery.list();
}
}
我需要根据Task变量和Process变量获取Running任务。我能够根据Process变量获取任务,但无法获得任务变量的任务
答案 0 :(得分:0)
我将变量包含为任务变量。完成任务后,所有任务变量都移动到ACT_HI_TASKINST表。但查询尝试从ACT_RU_VARIABLE表中获取值。所以它不适用于下一个任务。
所以我替换了以下代码
taskService.setVariableLocal(taskId, "ticketStatus", historyDto.getTicketStatusInfo());
使用这行代码
taskService.setVariable(taskId, "ticketStatus", historyDto.getTicketStatusInfo());
它将变量作为过程变量插入。不作为任务变量。它在整个过程中都可用
答案 1 :(得分:0)
请注意,可以为给定的执行设置变量的本地变量(请记住,流程实例由执行树组成)。该变量仅在该执行时可见,而在执行树中不高。如果数据不应传播到流程实例级别,或者变量在流程实例中具有某个路径的新值(例如,使用并行路径时),则此功能非常有用。