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