SessionStatusChangingInterceptor end state statuses update

This commit is contained in:
ialbert 2025-07-10 16:37:03 +03:00
parent fd7ea384cb
commit 7bac2a31f9

View file

@ -4,10 +4,14 @@ import java.time.Instant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.state.PseudoState;
import org.springframework.statemachine.state.PseudoStateKind;
import org.springframework.statemachine.state.State;
import org.springframework.statemachine.support.StateMachineInterceptorAdapter;
import org.springframework.statemachine.transition.Transition;
import org.springframework.stereotype.Component;
import ru.clearing.classes.statics.data.misc.Session;
import ru.spcex.clearing.error.ClearingRuntimeException;
@ -39,6 +43,28 @@ public class SessionStatusChangingInterceptor extends StateMachineInterceptorAda
this.messageResolver = messageResolver;
}
@Override
public void postStateChange(State<TaskType, SsnEvent> state, Message<SsnEvent> message, Transition<TaskType, SsnEvent> transition, StateMachine<TaskType, SsnEvent> stateMachine, StateMachine<TaskType, SsnEvent> rootStateMachine) {
try {
if (state == null) {
return;
}
PseudoState<TaskType, SsnEvent> pseudo = state.getPseudoState();
if (pseudo == null || pseudo.getKind() != PseudoStateKind.END) {
return;
}
Session session = stateMachine.getExtendedState().get(DataEnum.session, Session.class);
session.setWorkflowStatus(WorkflowStatus.Blocked.getKey());
session.setSessionStatus(SessionStatus.CLOS.getKey());
session.setUpdated(Instant.now());
ssnImdg.update(session);
} catch (Exception e) {
if (!stateMachine.hasStateMachineError()) {
stateMachine.setStateMachineError(e);
}
log.error("{} {}", stateMachine.getId(), ExceptionUtils.getStackTrace(e));
}
}
@Override
public StateContext<TaskType, SsnEvent> preTransition(StateContext<TaskType, SsnEvent> ctx) {