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);
|
}
|
|
}
|