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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package foundation.action;
 
import foundation.dao.OperatorCode;
import foundation.dao.bizlogic.IActionProvider;
import foundation.data.entity.Entity;
import foundation.json.IJSONWriter;
import foundation.util.ContentBuilder;
import foundation.util.Util;
 
public class WorkStep implements IWorkStep {
 
    private String key;
    private String dataName;
    private String operator;
    private String onEventCode;
    private Moment moment;
    private String actionName;
    private String stepName;
    private String param;
    private Events fireEvents;
    private boolean active;    
    private int orderNo;
    private ActionMeta action;
 
    
    public WorkStep() {
        active = true;
    }
    
    public WorkStep(String dataName, String operator) {
        this.key = WorkStepKey.getObjectKey(dataName, operator);
        this.dataName = dataName;
        this.operator = operator;
        this.active = true;
    }
    
    public WorkStep(String dataName, String operator, String actionName, Events fireEvents) {
        this.dataName = dataName;
        this.operator = operator;
        this.actionName = actionName;
        this.fireEvents = fireEvents;
        this.active = true;
        
        key = WorkStepKey.getObjectKey(dataName, operator);
    }
        
    public WorkStep(ActionMeta action) {
        this.operator = action.getName();
        this.actionName = action.getName();
        this.action = action;
        this.fireEvents = action.getFireEvents();
        this.active = true;
        
        key = WorkStepKey.getOperatorKey(operator);
    }
 
    public void load(Entity entity) throws Exception {
        dataName = entity.getString("data_name");
        operator = entity.getString("operator");
        onEventCode = entity.getString("on_event_code");
        moment = Moment.parse(entity.getString("moment"));
        actionName = entity.getString("action_name");
        stepName = entity.getString("step_name", "");
        param = entity.getString("step_param");
        active = entity.getBoolean("is_active", true);
        orderNo = entity.getInt("order_no");
        
        if (Util.isEmpty(dataName) && Util.isEmpty(operator)) {
            key = WorkStepKey.getEventKey(moment, onEventCode);
        }
        else {
            key = WorkStepKey.getObjectKey(dataName, operator);
        }
    }
    
    public String getKey() {
        return key;
    }
 
    public String getDataName() {
        return dataName;
    }
 
    public String getOperator() {
        return operator;
    }
 
    public String getOnEventCode() {
        return onEventCode;
    }
 
    public Events getFireEvents() {
        return fireEvents;
    }
    
    public void addFireEvent(String event) {
        if (fireEvents == null) {
            fireEvents = new Events();
        }
        
        fireEvents.addOne(event);
    }
 
    public Moment getMoment() {
        return moment;
    }
 
    public String getActionName() {
        return actionName;
    }
 
    public String getStepName() {
        if (!Util.isEmpty(stepName)) {
            return stepName;
        }
        
        return action.getTitle();
    }
 
    public double getTransactionScore() {
        return action.getTransactionScore();
    }
 
    public String getMethodName() {
        return action.getMethodName();
    }
 
    public boolean isActive() {
        return active;
    }
 
    public int getOrderNo() {
        return orderNo;
    }
 
    public void setAction(ActionMeta action) {
        this.action = action;
        
        if (fireEvents == null && action != null) {
            fireEvents = action.getFireEvents();
        }
    }
 
    public OperatorCode getOperatorCode() {
        if (action == null) {
            return null;
        }
        
        return action.getOperatorCode();
    }
 
    public IActionProvider createActionProvider() {
        if (action == null) {
            return null;
        }
        
        try {
            return action.createProvider();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        
        return null;
    }
 
    public String getParam() {
        return param;
    }
    
    public String getActionParam() { 
        return action.getParam();
    }
 
    public void toString(ContentBuilder result) {
        result.append(actionName);
    }
 
    @Override
    public String toString() {
        return actionName;
    }
 
    public void writeJSONBody(IJSONWriter writer) {
        writer.write("data_name", dataName);
        writer.write("operator", operator);
        writer.write("event_code", onEventCode);
        writer.write("moment", moment.name());
        writer.write("action_name", actionName);
        writer.write("step_name", stepName);
        writer.write("order_no", orderNo);
    }
 
}