🍣服务开发
# 如何快速开发一个配置化楼层服务(Service)
# 注入 SessionManager
SessionManager
为Cube提供的 Bean对象,该Bean作为Cube的启动入口。使用者可以使用它提供的API快速的集成 Cube带来的能力。
@Resource
private SessionManager sessionManager;
# 开发Service层
/**
* Isv string.
*
* @param bizParam the parameters
* @return the string
*/
public Object execute(BizParam bizParam) {
Transfer transfer = TransferFactory.create((trans) -> {
trans.setContext(bizParam);
trans.setTemplateCode(bizParam.getTemplateCode());
trans.setArrangementRule("test");
return trans;
});
Protocol protocol = sessionManager.buildProtocol(transfer);
/**
* 开始调用流程引擎
*/
HandleResult result = sessionManager.openSession(protocol);
/**
* 拿到该楼层的数据结果
*/
Object reallResult = result.getResult();
return reallResult;
}
# Transfer 介绍
为业务参数到框架参数转换的对象,通过 Transfer
可以将业务参数传递到框架内部。方便Cube内部进行流程处理。
# Protocol 介绍
通过 SessionManager提供的API
可以将转换参数构建为框架使用的协议对象,即为 Protocol
# 开启引擎服务
HandleResult result = sessionManager.openSession(protocol);
# HandleResult 介绍
HandleResult 封装了引擎返回结果、执行状态、返回结果等信息。
@Data
@Builder
public class HandleResult<T> {
private T result;
private boolean success;
private Integer code;
/**
* The type Exception.
*/
@Data
@Builder
public static class Exception {
private String message;
private Integer code;
private Exception exception;
}
}
帮助我们改善此文档 (opens new window)
上次更新: 2022/09/03, 20:56:28