feat(REQ-2616) - 定时回调增加变量传递

This commit is contained in:
wangli 2024-08-21 09:33:11 +08:00
parent 5575380783
commit 98bf53a173
6 changed files with 28 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import java.util.Map;
/**
* 为指定业务节点设置倒计时回调
@ -32,4 +33,9 @@ public class BpmnActivityTimeoutCallbackDTO {
*/
@NotBlank(message = "触发时间不能为空格式yyyy-MM-dd HH:mm:ss")
private String endTime;
/**
* 用于追加或修改现有的变量值
*/
private Map<String, Object> variables;
}

View File

@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import java.util.Map;
/**
* 为指定业务节点设置倒计时在啥时候继续往下流转
@ -31,4 +32,9 @@ public class BpmnActivityTimeoutTriggerDTO {
*/
@NotBlank(message = "触发时间不能为空格式yyyy-MM-dd HH:mm:ss")
private String endTime;
/**
* 用于追加或修改现有的变量值
*/
private Map<String, Object> variables;
}

View File

@ -1,7 +1,7 @@
package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.common.model.request.bpmn.activity.BpmnActivityTimeoutCallbackDTO;
import cn.axzo.workflow.core.engine.job.AsyncActivityLeaveJobHandler;
import cn.axzo.workflow.core.engine.job.AsyncActivityCallbackJobHandler;
import com.alibaba.fastjson.JSON;
import org.flowable.bpmn.model.TimerEventDefinition;
import org.flowable.common.engine.impl.interceptor.CommandContext;
@ -30,10 +30,12 @@ public class CustomBusinessNodeTimeoutCallbackCmd extends AbstractCommand<Void>
private static final long serialVersionUID = 1L;
private final String triggerId;
private final String endTime;
private final Map<String, Object> variables;
public CustomBusinessNodeTimeoutCallbackCmd(String triggerId, String endTime) {
public CustomBusinessNodeTimeoutCallbackCmd(String triggerId, String endTime, Map<String, Object> variables) {
this.triggerId = triggerId;
this.endTime = endTime;
this.variables = variables;
}
@Override
@ -56,10 +58,10 @@ public class CustomBusinessNodeTimeoutCallbackCmd extends AbstractCommand<Void>
timerEventDefinition.setTimeDate(newEndTime);
TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, executionEntity.getCurrentFlowElement(),
true, executionEntity, AsyncActivityLeaveJobHandler.TYPE, TimerEventHandler.createConfiguration(executionEntity.getCurrentActivityId(),
true, executionEntity, AsyncActivityCallbackJobHandler.TYPE, TimerEventHandler.createConfiguration(executionEntity.getCurrentActivityId(),
timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
if (timerJob != null) {
timerJob.setCustomValues(JSON.toJSONString(new BpmnActivityTimeoutCallbackDTO(triggerId, endTime)));
timerJob.setCustomValues(JSON.toJSONString(new BpmnActivityTimeoutCallbackDTO(triggerId, endTime, variables)));
CommandContextUtil.getTimerJobService().scheduleTimerJob(timerJob);
}
return null;

View File

@ -30,10 +30,12 @@ public class CustomBusinessNodeTimeoutTriggerCmd extends AbstractCommand<Void> i
private static final long serialVersionUID = 1L;
private final String triggerId;
private final String endTime;
private final Map<String, Object> variables;
public CustomBusinessNodeTimeoutTriggerCmd(String triggerId, String endTime) {
public CustomBusinessNodeTimeoutTriggerCmd(String triggerId, String endTime, Map<String, Object> variables) {
this.triggerId = triggerId;
this.endTime = endTime;
this.variables = variables;
}
@Override
@ -59,7 +61,7 @@ public class CustomBusinessNodeTimeoutTriggerCmd extends AbstractCommand<Void> i
true, executionEntity, AsyncActivityLeaveJobHandler.TYPE, TimerEventHandler.createConfiguration(executionEntity.getCurrentActivityId(),
timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
if (timerJob != null) {
timerJob.setCustomValues(JSON.toJSONString(new BpmnActivityTimeoutTriggerDTO(triggerId, endTime)));
timerJob.setCustomValues(JSON.toJSONString(new BpmnActivityTimeoutTriggerDTO(triggerId, endTime, variables)));
CommandContextUtil.getTimerJobService().scheduleTimerJob(timerJob);
}
return null;

View File

@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
@ -52,6 +53,8 @@ public class AsyncActivityCallbackJobHandler extends AbstractJobHandler implemen
if (Objects.isNull(processInstance)) {
throw new WorkflowEngineException(PROCESS_INSTANCE_ID_NOT_EXISTS, task.getProcessInstanceId());
}
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
runtimeService.setVariables(processInstance.getId(), dto.getVariables());
eventDispatcher.dispatchEvent(new BizCallbackEventImpl(BizCallbackEventImpl.BizCallbackEventType.CALLBACK,
task.getTaskDefinitionKey(), task.getName(),

View File

@ -137,7 +137,8 @@ public class BpmnProcessActivityServiceImpl implements BpmnProcessActivityServic
@Override
public Boolean setTimeoutTrigger(BpmnActivityTimeoutTriggerDTO dto) {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new CustomBusinessNodeTimeoutTriggerCmd(dto.getTriggerId(), dto.getEndTime()));
commandExecutor.execute(new CustomBusinessNodeTimeoutTriggerCmd(dto.getTriggerId(), dto.getEndTime(),
dto.getVariables()));
return true;
}
@ -150,7 +151,7 @@ public class BpmnProcessActivityServiceImpl implements BpmnProcessActivityServic
@Override
public Boolean setTimeOutCallback(BpmnActivityTimeoutCallbackDTO dto) {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new CustomBusinessNodeTimeoutCallbackCmd(dto.getTriggerId(), dto.getEndTime()));
commandExecutor.execute(new CustomBusinessNodeTimeoutCallbackCmd(dto.getTriggerId(), dto.getEndTime(), dto.getVariables()));
return true;
}
}