|
本帖最后由 XiaoQLuo 于 2013-9-17 17:08 编辑
案例中实现主流程+子流程+自动环节批转等特性:
简单说明案例中包含:4个流程,主流程没有关联业务数据,其中每个环节都是一个子流程,进入环节自动启动子流程,主流程任务挂起,当子流程结束后唤醒主流程继续流程分别是:
主流程(master),这是一个流程框架,没有相关业务数据
子流程(c1)
子流程(c2)
子流程(c3)
1、主流程UI使用windowFrame控制子流程界面
2、子流程启动时创建主流程,小技巧使用sData2记录关联的子流程的sData1,具体看启动主流程代码(/BIZ/demo/components/logic/code/src/com/justep/demo/DemoUtils.java)- public static void startMasterProcess(String masterProcess, String masterActivity) {
- ActionContext context = ActionUtils.getRequestContext().getActionContext();
- Map<String, Object> relas = (Map<String, Object>) context.getParameter(ProcessConstants.PI_RELATION_VALUE_PARAMETER);
- //启动主流程
- String sData1 = CommonUtils.createGUID();
- String sData2 = null;
- if(null!=relas) sData2 = (String)relas.get("sData1");//把当前的sData1存到主流程的sData2
-
- ProcessControl control = ProcessUtils.startProcessQuery(masterProcess, null, null);
- List<ProcessControlItem> items = control.getFlowTos();
- for(int i = items.size()-1; i>=0; i--){
- if(!masterActivity.equals(items.get(i).getUnit()))
- control.removeFlowTo(items.get(i));//清除多余流转
- }
- ProcessControlItem item = control.getFlowTo(masterActivity);
- item.setSelected(true);
- item.clearExecutors();
- item.addExecutor(new OrgUnit(ContextHelper.getPersonMember().getFID(), ContextHelper.getPersonMember().getFName()));
- Map<String, Object> relations = new HashMap<String, Object>();
- relations.put("sName", "主流程启动-"+masterActivity+"触发");
- relations.put("sData1", sData1);
- relations.put("sData2", sData2);
- Document doc = ProcessUtils.startProcess(masterProcess, relations, control, new ArrayList<String>(), null);
- String task = doc.selectSingleNode("/items/item/task").getText();
-
- //子流程写入主流程任务,用于唤醒
- if(null!=relas){
- relas.put("sData2", task);//记录主流程的任务id
- }
-
- //暂停主流程
- ProcessUtils.suspendProcess(task, null);
- }
复制代码 3、子流程2后自动批转到子流程等待环节- public static void c2AfterAdvance() {
- //获取新任务的id
- Document doc = (Document) ContextHelper.getActionContext().getActionResult();
- String task = doc.selectSingleNode("/items/item/task").getText();
- //继续批转,到等待环节
- ProcessControl control = ProcessUtils.advanceProcessQuery(task);
- ProcessControlItem item = control.getFlowTos().get(0);
- item.clearExecutors();
- //指定相同的执行者
- ProcessControlItem c3item = ProcessUtils.getProcessContext().getProcessControl().getFlowTo("c3");
- for (OrgUnit ou : c3item.getExecutors()) {
- item.addExecutor(ou);
- }
- //批转
- ProcessUtils.advanceProcess(task, control);
- }
复制代码- public static void c3AfterAdvance() {
- //获取新任务的id
- Document doc = (Document) ContextHelper.getActionContext().getActionResult();
- String task = doc.selectSingleNode("/items/item/task").getText();
- //方法1,通过创建任务完成任务转移
- //产生C3流程的入口任务,通过任务的sData1传递当前暂停任务的id,执行人同主流程的执行人
- /*
- ProcessControlItem item = ProcessUtils.getProcessContext().getProcessControl().getFlowTos().get(0);
- Task t = TaskHelper.createTask("创建启动C3的功能任务", "/demo/components/process/c3/c3Process", "c3Activity", "/demo/components/process/c3/c3Activity.w",
- "/demo/components/process/c3/c3Activity.w", task, item.getExecutors(), null);
- t.save();
- */
-
- //方法2,直接产生业务数据,启动C3流程
- ProcessControlItem mitem = ProcessUtils.getProcessContext().getProcessControl().getFlowTos().get(0);
- Table t = KSQL.select("select DEMO_TABLE3.* from DEMO_TABLE3 DEMO_TABLE3 where 1 = 2", null, "/demo/components/data", null);
- t = BizData.create(t, "DEMO_TABLE3", null, null);//产生业务数据
- t.save("/demo/components/data");
- String sData1 = t.iterator().next().getString("DEMO_TABLE3");
-
- ProcessControl control = ProcessUtils.startProcessQuery("/demo/components/process/c3/c3Process", null, null);
- ProcessControlItem item = control.getFlowTos().get(0);
- item.setSelected(true);
- item.clearExecutors();
- for (OrgUnit ou : mitem.getExecutors()) {
- item.addExecutor(ou);
- }
- Map<String, Object> relations = new HashMap<String, Object>();
- relations.put("sName", "C3启动-主流程触发");
- relations.put("sData1", sData1);//写入关联业务数据的id
- relations.put("sData2", task);//写入暂停的任务数据
- ProcessUtils.startProcess("/demo/components/process/c3/c3Process", relations, control, null, null);
- //暂停下一个任务
- ProcessUtils.suspendProcess(task, null);
- }
复制代码 4、子流程3结束唤醒主流程- public static void c3ProcessAfterFinish() {
- //唤醒主流程任务
- DemoUtils.resumeMasterProcess();
- }
复制代码 |
评分
-
查看全部评分
|