package com.chinaztt.mes.technology.state.structure;
|
|
import com.chinaztt.mes.technology.entity.Structure;
|
import com.chinaztt.mes.technology.mapper.StructureMapper;
|
import com.chinaztt.mes.technology.state.routing.constant.RoutingEvents;
|
import com.chinaztt.mes.technology.state.routing.constant.RoutingStateStringValues;
|
import lombok.AllArgsConstructor;
|
import org.springframework.messaging.Message;
|
import org.springframework.statemachine.annotation.OnTransition;
|
import org.springframework.statemachine.annotation.WithStateMachine;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* @Author: zhangxy
|
* @Date: 2020-08-24 9:51
|
*/
|
@AllArgsConstructor
|
@Component
|
@WithStateMachine(id = "structureStateMachine")
|
public class StructureStateListener {
|
|
private StructureMapper structureMapper;
|
|
|
/**
|
* 接受
|
*/
|
@OnTransition(source = RoutingStateStringValues.DRAFT, target = RoutingStateStringValues.ACCEPTED)
|
public boolean accept(Message<RoutingEvents> msg) {
|
Structure structure = (Structure) msg.getHeaders().get("structure");
|
structure.setState(RoutingStateStringValues.ACCEPTED);
|
structureMapper.updateById(structure);
|
return true;
|
}
|
|
|
/**
|
* 作废
|
*/
|
@OnTransition(source = RoutingStateStringValues.ACCEPTED, target = RoutingStateStringValues.CANCELLED)
|
public boolean cancel(Message<RoutingEvents> msg) {
|
Structure structure = (Structure) msg.getHeaders().get("structure");
|
structure.setState(RoutingStateStringValues.CANCELLED);
|
structureMapper.updateById(structure);
|
return true;
|
}
|
|
|
@OnTransition(source = RoutingStateStringValues.ACCEPTED, target = RoutingStateStringValues.DRAFT)
|
public boolean revoke(Message<RoutingEvents> msg) {
|
Structure structure = (Structure) msg.getHeaders().get("structure");
|
structure.setState(RoutingStateStringValues.DRAFT);
|
structureMapper.updateById(structure);
|
return true;
|
}
|
|
}
|