李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
    }
 
}