diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/demo/DemoTimerInspectHandler.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/demo/DemoTimerInspectHandler.java index c48ef173e..b3889fa43 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/demo/DemoTimerInspectHandler.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/demo/DemoTimerInspectHandler.java @@ -7,6 +7,7 @@ import org.dromara.warm.flow.core.entity.EventWait; import org.dromara.warm.flow.core.enums.EventType; import org.dromara.warm.flow.core.service.impl.EventRuntimeHandler; import org.dromara.warm.flow.core.timer.EventTaskHandler; +import org.dromara.warm.flow.core.workflow.context.WorkflowContext; import org.dromara.workflow.common.ConditionalOnEnable; import org.springframework.stereotype.Component; @@ -46,8 +47,10 @@ public class DemoTimerInspectHandler implements EventTaskHandler { if (isInspectTimerStart(wait)) { // 这里应该使用业务的id demo使用自动生成id 需要用户自行替换 String businessId = String.valueOf(IdWorker.getId()); + WorkflowContext context = new WorkflowContext(); + context.setHandler(FlowEngine.getFlowConfig().getSystemHandler()); FlowEngine.insService().startByTimer(businessId, wait.getDefinitionId(), - wait.getNodeCode(), null, null); + wait.getNodeCode(), null, context); log.info("定时启动示例已自动发起审批: businessId={}", businessId); return; } diff --git a/ruoyi-modules/ruoyi-workflow/src/test/java/org/dromara/workflow/demo/DemoTimerInspectHandlerTest.java b/ruoyi-modules/ruoyi-workflow/src/test/java/org/dromara/workflow/demo/DemoTimerInspectHandlerTest.java index ec1408851..f2edb2a94 100644 --- a/ruoyi-modules/ruoyi-workflow/src/test/java/org/dromara/workflow/demo/DemoTimerInspectHandlerTest.java +++ b/ruoyi-modules/ruoyi-workflow/src/test/java/org/dromara/workflow/demo/DemoTimerInspectHandlerTest.java @@ -1,16 +1,19 @@ package org.dromara.workflow.demo; import org.dromara.warm.flow.core.FlowEngine; +import org.dromara.warm.flow.core.config.WarmFlow; import org.dromara.warm.flow.core.entity.Definition; import org.dromara.warm.flow.core.entity.EventWait; import org.dromara.warm.flow.core.enums.EventType; import org.dromara.warm.flow.core.service.DefService; import org.dromara.warm.flow.core.service.InsService; +import org.dromara.warm.flow.core.workflow.context.WorkflowContext; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.MockedStatic; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; @@ -32,17 +35,22 @@ class DemoTimerInspectHandlerTest { DefService defService = mock(DefService.class); when(defService.getById(12L)).thenReturn(definition); InsService insService = mock(InsService.class); + WarmFlow flowConfig = mock(WarmFlow.class); + when(flowConfig.getSystemHandler()).thenReturn("0"); try (MockedStatic engine = mockStatic(FlowEngine.class)) { engine.when(FlowEngine::defService).thenReturn(defService); engine.when(FlowEngine::insService).thenReturn(insService); + engine.when(FlowEngine::getFlowConfig).thenReturn(flowConfig); assertDoesNotThrow(() -> new DemoTimerInspectHandler().handle(wait)); ArgumentCaptor businessId = ArgumentCaptor.forClass(String.class); - verify(insService).startByTimer(businessId.capture(), eq(12L), eq("timerStart"), isNull(), isNull()); + ArgumentCaptor context = ArgumentCaptor.forClass(WorkflowContext.class); + verify(insService).startByTimer(businessId.capture(), eq(12L), eq("timerStart"), isNull(), context.capture()); assertTrue(businessId.getValue().matches("[0-9]+")); assertTrue(Long.parseLong(businessId.getValue()) > 0); + assertEquals("0", context.getValue().getHandler()); } } }