关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、3102411850 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 7798|回复: 0

JBPM3动态分支的实现

[复制链接]
发表于 2014-8-28 22:31:36 | 显示全部楼层 |阅读模式
1,大领导分发文件给中层领导(不同部门),中层领导发给下属,部门下属看完,提交汇总到秘书处


有朋友也遇到这方面的问题,我就贴个贴子,不再一一回复了,参考了论坛上的一些资料,代码如下:

public class ForkManageActionHandler implements ActionHandler {
public void execute(ExecutionContext executionContext) throws Exception {
  
  ProcessInstance pi = executionContext.getProcessInstance();
  ContextInstance ci = executionContext.getContextInstance();
  Token rootToken = pi.getRootToken();
  ForkVariableVo  forkVariableVo = (ForkVariableVo)ci.getVariable(Constants.FORK_VARIABLE_VO);
   
  //角色发送和多人签收分支
  if(forkVariableVo.isRoleSend() && forkVariableVo.isMorePeopleSign()){
   
   Node node = rootToken.getNode();
   List<String> sendUserList = new ArrayList<String>() ;
   List<ForkedTransition> forkTransitions = new ArrayList<ForkedTransition>();
   Map<String,String> roleSendAndMorePeopleMap = forkVariableVo.getRoleSendAndMorePeople();
   
   for(int j=0;j<node.getLeavingTransitions().size();j++){
    Transition trans = (Transition)node.getLeavingTransitions().get(j);
   
    //考虑到有多个角色发送和多人签收的分支情况,MAP过滤,获取动态分支用户
    String activityId = trans.getName() ;
    if(roleSendAndMorePeopleMap.get(activityId)!=null){
     if(forkVariableVo.mOfficeTargetUser.get(activityId)!=null){
      sendUserList = (List<String>)forkVariableVo.mOfficeTargetUser.get(activityId);
     }else{
      sendUserList = (List<String>)forkVariableVo.noMOfficeTargetUser.get(activityId);
     }
    }
    if(sendUserList ==null || sendUserList.size() ==0){
     continue;
    }
    //创建分支Token及Transition
    for(int i=1; i<sendUserList.size(); i++){
     String tokenName = this.getTokenName(rootToken,  activityId, i);
     Token loopToken = new Token(rootToken,tokenName);
     loopToken.setTerminationImplicit(true);
     executionContext.getJbpmContext().getSession().save(loopToken);
     
     ExecutionContext newExecutionContext = new ExecutionContext(
       loopToken);
     //newExecutionContext.getContextInstance().createVariable(String.valueOf(i),
     //(String)sendUserList.get(i), loopToken);

     // 记录下每一transition
     ForkedTransition forkTransition = new ForkedTransition();
     forkTransition.executionContext = newExecutionContext;
     forkTransition.transition = trans;
     forkTransitions.add(forkTransition);
    }
    sendUserList = null ;
   }
   for (ForkedTransition forkTransition : forkTransitions) {
    node.leave(forkTransition.executionContext, forkTransition.transition);
   }
  }
}
/**
  * 获取Token名称
  * @param parent
  * @param transitionName
  * @param loopIndex
  * @return
  */
protected String getTokenName(Token parent, String transitionName,int loopIndex) {
  String tokenName = null;
  if (transitionName != null) {
   if (!parent.hasChild(transitionName)) {
    tokenName = transitionName;
   } else {
    int i = 2;
    tokenName = transitionName + Integer.toString(i);
    while (parent.hasChild(tokenName)) {
     i++;
     tokenName = transitionName + Integer.toString(i);
    }
   }
  } else {
   // 没有转向
   int size = (parent.getChildren() != null ? parent.getChildren()
     .size() + 1 : 1);
   tokenName = Integer.toString(size);
  }
  return tokenName + "." + loopIndex;
}

private class ForkedTransition {  
  private ExecutionContext executionContext;
  private Transition transition;
}
}
在FORK节点的node-enter中配置该ACTION类,凭借原来那条分支,根据发送的用户的LIST,动态去构建TOKEN,每个TOKEN指向其原分支上的transition,中间那部分角色发送是我自己的需求而写的,重要的是创建分支这一部分。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表