获取smartbi流程待办数据
代码块 |
---|
package cn.com.smartbi.workflow;
import smartbi.net.sf.json.JSONArray;
import smartbi.net.sf.json.JSONObject;
import smartbi.sdk.ClientConnector;
import smartbi.sdk.InvokeResult;
import smartbi.sdk.RemoteException;
public class WorkflowAPITest {
public static void main(String[] args) {
String Smartbi_URL = "http://10.10.202.17:19700/smartbi";
ClientConnector conn = new ClientConnector(Smartbi_URL);
InvokeResult result = null;
try {
// 先以指定用户登录smartbi
boolean ret = conn.open("admin", "admin");
if (ret) {
// 获取待办数量
// {"retCode":0,"result":{"startCount":31,"doneCount":11,"todoCount":14},"duration":10}
result = conn.remoteInvoke("WorkflowModule", "allCount", new Object[] { null });
if ("0".equals(result.getOriginalResult().optString("retCode"))) {
JSONObject json = (JSONObject) result.getResult();
System.out.println("待办数:" + json.optInt("todoCount"));
System.out.println("已办数:" + json.optInt("doneCount"));
System.out.println("我的发起数:" + json.optInt("startCount"));
}
// 搜索关键字
String keyword = "";
// 开始页码
int pageNo = 0;
// 每页记录数
int pageSize = Integer.MAX_VALUE;
// 获取待办列表
result = conn.remoteInvoke("WorkflowModule", "todoList", new Object[] { keyword, pageNo, pageSize });
if ("0".equals(result.getOriginalResult().optString("retCode"))) {
JSONArray json = (JSONArray) result.getResult();
if (json.length() > 0) {
System.out.println("待办:" + json.get(0).toString());
}
}
// 获取已办
result = conn.remoteInvoke("WorkflowModule", "doneList", new Object[] { keyword, pageNo, pageSize });
if ("0".equals(result.getOriginalResult().optString("retCode"))) {
JSONArray json = (JSONArray) result.getResult();
if (json.length() > 0) {
System.out.println("已办:" + json.get(0).toString());
}
}
// 获取我的发起
result = conn.remoteInvoke("WorkflowModule", "startList", new Object[] { keyword, pageNo, pageSize });
if ("0".equals(result.getOriginalResult().optString("retCode"))) {
JSONArray json = (JSONArray) result.getResult();
if (json.length() > 0) {
System.out.println("我的发起办:" + json.get(0).toString());
}
}
}
} catch (RemoteException e) {
e.printStackTrace();
} finally {
conn.close();
}
}
}
|
代码块 |
---|
// 待办数据返回结果说明
{
"activity": "节点名称",
"endDate": "结束时间",
"subject": "标题",
"instanceId": "流程实例ID",
"processKey": "流程模板ID",
"createDate": "创建时间",
"owner": "拥有者",
"assignee": "处理人",
"nextTask": "下一节点",
"taskId": "任务ID",
"status": "节点状态"
} |
...
注意事项
- 引入Smartbi
...
- SDK依赖包,详情请参考 服务器端SDK 。
- SDK相关接口说明:https://history.wiki.smartbi.com.cn
...
- /api/javaapiv7/
- 获取待办需要先以指定用户登录,但第三方系统往往没有Smartbi用户的密码,因此需要考虑单点登录问题,详情请参考 单点登录 。
外部URL打开待办处理界面
- 打开待办、已办:http://ip:port/smartbi/vision/workflow/?l=zh_CN#/process?taskId=${0},其中${0}为任务ID(taskId);
- 打开我的发起:http://ip:port/smartbi/vision/workflow/?l=zh_CN#/process?instanceId=${0},其中${0}为流程实例ID(instanceId),可通过owner字段判断是否当前用户发起的。
注意事项
- 注意跨域问题。