李林
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
58
59
package com.chinaztt.mes.plan.state.masterproductionschedule;
 
import com.chinaztt.mes.plan.entity.MasterProductionSchedule;
import com.chinaztt.mes.plan.entity.OperationTaskProduce;
import com.chinaztt.mes.plan.mapper.MasterProductionScheduleMapper;
import com.chinaztt.mes.plan.mapper.OperationTaskProduceMapper;
import com.chinaztt.mes.plan.state.masterproductionschedule.constant.MasterProductionScheduleEvents;
import com.chinaztt.mes.plan.state.masterproductionschedule.constant.MasterProductionScheduleStateStringValues;
import lombok.AllArgsConstructor;
import org.springframework.messaging.Message;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Component;
 
/**
 * @author ZTT
 */
@AllArgsConstructor
@Component
@WithStateMachine(id = "masterproductionscheduleStateMachine")
public class MasterProductionScheduleStateListener {
    private MasterProductionScheduleMapper masterProductionScheduleMapper;
 
    /**
     * 待处理
     */
    @OnTransition(target = MasterProductionScheduleStateStringValues.PENDING)
    public boolean pending(StateMachine stateMachine, Message<MasterProductionScheduleEvents> msg) {
        MasterProductionSchedule masterProductionSchedule = (MasterProductionSchedule) msg.getHeaders().get("masterProductionSchedule");
        masterProductionSchedule.setState(MasterProductionScheduleStateStringValues.PENDING);
        masterProductionScheduleMapper.updateById(masterProductionSchedule);
        return true;
    }
 
 
    /**
     * 已处理
     */
    @OnTransition(target = MasterProductionScheduleStateStringValues.PROCESSED)
    public boolean pend(StateMachine stateMachine, Message<MasterProductionScheduleEvents> msg) {
        MasterProductionSchedule masterProductionSchedule = (MasterProductionSchedule) msg.getHeaders().get("masterProductionSchedule");
        masterProductionSchedule.setState(MasterProductionScheduleStateStringValues.PROCESSED);
        masterProductionScheduleMapper.updateById(masterProductionSchedule);
        return true;
    }
 
    /**
     * 取消,作废
     */
    @OnTransition(target = MasterProductionScheduleStateStringValues.CANCELED)
    public boolean cancal(StateMachine stateMachine, Message<MasterProductionScheduleEvents> msg) {
        MasterProductionSchedule masterProductionSchedule = (MasterProductionSchedule) msg.getHeaders().get("masterProductionSchedule");
        masterProductionSchedule.setState(MasterProductionScheduleStateStringValues.CANCELED);
        masterProductionScheduleMapper.updateById(masterProductionSchedule);
        return true;
    }
 
}