P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package foundation.state;
 
import foundation.action.ActionContext;
import foundation.data.entity.Entity;
import foundation.json.IJSONWriter;
import foundation.state.approve.ApproveRuntime;
import foundation.token.IOnlineUser;
import foundation.util.Util;
 
public class StatePoint {
    
    private StateMachine machine;
    private String id;
    private String key;
    private String operator;
    private StateOperate stateOperate;
    private String fromCode;
    private String toCode;
    private String endCode;
    private String stepId;
    private String remark;
    private String remoteFromCode;
    private String remoteToCode;
    private State fromState;
    private State toState;
    private State endState;
    private boolean fireAppproveFlow;
    private ApproveRuntime approveFlow;
    
    
    public StatePoint() {
        
    }
 
    public void load(Entity entity) throws Exception {
        this.id = entity.getString("id");
        this.operator = entity.getString("operator");
        this.stateOperate = StateOperate.parse(operator);
        this.fromCode = entity.getString("from_code");
        this.toCode = entity.getString("to_code");
        this.endCode = entity.getString("end_code");
        this.stepId = entity.getString("approve_id");
        this.remark = entity.getString("remark");
        this.remoteFromCode = entity.getString("remote_from_code");
        this.remoteToCode = entity.getString("remote_to_code");
        
        this.key = createKey(fromCode, operator);
        fireAppproveFlow = !Util.isEmpty(stepId);
    }
 
    public static String createKey(String fromCode, String operator) {
        String result = fromCode  + "-" + operator;
        result = result.toLowerCase();
        return result;
    }
    
    public ApproveRuntime getSteps(IOnlineUser user, ActionContext context) throws Exception {
        //1. 如果没有审批步骤,直接返回
        if (approveFlow == null) {
            return null;
        }
        
        //2. 如果有审批步骤,需要根据步骤类型返回步骤(固定列表、销售架构、销售总监、大区经理)
        ApproveRuntime result = approveFlow.getRuntime(user, context);
        return result;
    }
 
    public StateMachine getMachine() {
        return machine;
    }
 
    public void setMachine(StateMachine machine) {
        this.machine = machine;
    }
 
    public String getId() {
        return id;
    }
 
    public String getOperator() {
        return operator;
    }
 
    public StateOperate getStateOperate() {
        return stateOperate;
    }
 
    public String getFromCode() {
        return fromCode;
    }
 
    public String getToCode() {
        return toCode;
    }
 
    public String getEndCode() {
        return endCode;
    }
    
    public String getRemoteFromCode() {
        return remoteFromCode;
    }
 
    public String getRemoteToCode() {
        return remoteToCode;
    }
 
    public void setFromState(State fromState) {
        this.fromState = fromState;
    }
 
    public void setToState(State toState) {
        this.toState = toState;
    }
    
    public void setEndState(State endState) {
        this.endState = endState;
    }
 
    public State getFromState() {
        return fromState;
    }
 
    public State getToState() {
        return toState;
    }
 
    public State getEndState() {
        return endState;
    }
    
    public DetailState getFirstDetailState() {
        if (approveFlow == null) {
            return null;
        }
 
        return approveFlow.getFirstDetailState();
    }
    
    public String getFromName() {
        if (fromState == null) {
            return null;
        }
        
        return fromState.getName();
    }
    
    public String getKey() {
        return key;
    }
 
    public boolean isFireAppproveFlow() {
        return fireAppproveFlow;
    }
 
    public String getStepId() {
        return stepId;
    }
 
    public void setApproveFlow(ApproveRuntime flow) {
        this.approveFlow = flow;
    }
    
    public void writeJSON(IJSONWriter writer) {
        writer.beginObject();
 
        writer.write("machine_id", machine.getId());
        writer.write("machine_name", machine.getName());
        writer.write("from_code", fromCode);
        writer.write("operator", operator);
        writer.write("from_code", fromCode);
        writer.write("to_code", toCode);
        writer.write("end_code", endCode);
        writer.write("remark", remark);
        writer.write("approve_id", stepId);
        
        writer.endObject();
    }
}