| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package com.qqflow.engine.domain.flow.statemachine;
- import com.qqflow.engine.domain.flow.enums.ProcessEvent;
- import com.qqflow.engine.domain.flow.enums.ProcessStatus;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.statemachine.config.EnableStateMachineFactory;
- import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
- import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
- import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
- import java.util.EnumSet;
- @Configuration
- @EnableStateMachineFactory
- public class ProcessInstanceStateMachineConfig extends StateMachineConfigurerAdapter<ProcessStatus, ProcessEvent> {
- @Override
- public void configure(StateMachineStateConfigurer<ProcessStatus, ProcessEvent> states) throws Exception {
- states.withStates()
- .initial(ProcessStatus.PENDING_RECEIVE)
- .states(EnumSet.allOf(ProcessStatus.class));
- }
- @Override
- public void configure(StateMachineTransitionConfigurer<ProcessStatus, ProcessEvent> transitions) throws Exception {
- this.configureActiveTransitions(transitions);
- this.configureTerminalTransitions(transitions);
- }
- private void configureActiveTransitions(StateMachineTransitionConfigurer<ProcessStatus, ProcessEvent> transitions) throws Exception {
- transitions
- .withExternal()
- .source(ProcessStatus.PENDING_RECEIVE).target(ProcessStatus.PENDING).event(ProcessEvent.RECEIVE)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING).target(ProcessStatus.APPROVED).event(ProcessEvent.APPROVE)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING).target(ProcessStatus.REJECTED).event(ProcessEvent.REJECT)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING).target(ProcessStatus.RETURNED).event(ProcessEvent.RETURN)
- .and()
- .withExternal()
- .source(ProcessStatus.RETURNED).target(ProcessStatus.PENDING).event(ProcessEvent.RECEIVE);
- }
- private void configureTerminalTransitions(StateMachineTransitionConfigurer<ProcessStatus, ProcessEvent> transitions) throws Exception {
- transitions
- .withExternal()
- .source(ProcessStatus.APPROVED).target(ProcessStatus.COMPLETED).event(ProcessEvent.COMPLETE)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING_RECEIVE).target(ProcessStatus.REVOKED).event(ProcessEvent.REVOKE)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING).target(ProcessStatus.REVOKED).event(ProcessEvent.REVOKE)
- .and()
- .withExternal()
- .source(ProcessStatus.RETURNED).target(ProcessStatus.REVOKED).event(ProcessEvent.REVOKE)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING_RECEIVE).target(ProcessStatus.TERMINATED).event(ProcessEvent.TERMINATE)
- .and()
- .withExternal()
- .source(ProcessStatus.PENDING).target(ProcessStatus.TERMINATED).event(ProcessEvent.TERMINATE);
- }
- }
|