网站地图
  
  高级搜索
  首页   技术论坛   博客 派计划   产品中心   资源中心   银弹在线   商城  





查询当前环节符合条件的后续环节列表    
#1楼
给作者发送短消息 给作者发送短消息 实名会员 
查看用户其他信息
总分 2509 分
财富 2622 goCom币
威望 2460
排名 第 11 名
段位 新手必读

【适用范围】
 适用的EOS版本,相关的操作系统/数据库/应用服务器环境
【问题描述和定位】
【解决方案和步骤】

查询当前环节符合条件的后续环节列表:
1)  如果存在默认连线,则肯定会触发;
2)  如果是复杂表达式则直接获取表达式内容;
3)  简单表达式:
a.       当操作符是==(等于)、!=(不等于)时,不需要考虑对比值是普通字符串,还是数值,同一当字符串处理;
当操作符其它,是>=(大于等于)、>(大于)、<(小于)、<=(小于等于)时,要进行数值比较。
代码实现如下:
publicstatic String[] queryNextActivityList(long processInstID,WFConnector[] wfconnectors){
       
        int len = wfconnectors.length;
        String[] activityList = new String[len];
       
        if(wfconnectors==null||len == 0)
            return activityList;
 
        WFProcessInstInternal processInstInternal = ServiceFactory.getInstancePool().findProcessInstanceByID(processInstID);
        WFRelativeDataContextEntity relativeDataContext = processInstInternal.getProcessInstContext().getRelativeDataContextEntity();
        IDataContext context = relativeDataContext.getDataContext();
                       
        String condition = "";
        WFConnector wfconnector = new WFConnector();
               
        for(int i = 0; i< len; i++){
            wfconnector = wfconnectors[i];
           
            if(wfconnector.isDefault()){//如果存在默认连线,则肯定会触发
                activityList[i] = wfconnector.getDestActID();
            }else{
                if(!wfconnector.isSimpleExpression()){//是否复杂表达式
                    condition = wfconnector.getComplexExpression();//如果是复杂表达式则直接获取表达式内容
                }else{//简单表达式
                    String leftValue = wfconnector.getLeftValue();
                    String operator = wfconnector.getOperator();
                    String rightValue = wfconnector.getRightValue();
                    String rightValueType = wfconnector.getRightValueType();
                   
                    if(!rightValueType.equals("constant")){//右值是变量,获取变量的值
                        rightValue = context.getString(rightValue);
                    }
                   
                    if(operator.equals("EQ")){
                        operator = "==";
                    }elseif(operator.equals("NE")){
                        operator = "!=";
                    }elseif(operator.equals("GT")){
                        operator = ">";
                    }elseif(operator.equals("GE")){
                        operator = ">=";
                    }elseif(operator.equals("LT")){
                        operator = "<";
                    }elseif(operator.equals("LE")){
                        operator = "<=";
                    }
                   
                    if(operator.equals("equal")){                  
                        condition = "context.get(\"" + leftValue + "\").equals(\"" + rightValue + "\")";
                    }elseif(operator.equals("not-equal")){                   
                        condition = "!(context.get(\"" + leftValue + "\").equals(\"" + rightValue + "\"))";
                    }elseif(operator.equals("is-null")){                 
                        condition = "context.get(\"" + leftValue + "\") == null";
                    }elseif(operator.equals("not-null")){                
                        condition = "context.get(\"" + leftValue + "\") != null";
                    }elseif(operator.equals("null-empty")){                  
                        condition = "context.get(\"" + leftValue + "\") == null || context.get(\"" + leftValue + "\") == \"\"";
                    }elseif(operator.equals("not-null-empty")){                  
                        condition = "context.get(\"" + leftValue + "\") != null || context.get(\"" + leftValue + "\") != \"\"";
                    }elseif(operator.equals("==")||operator.equals("!=")){//当操作符是==(等于)、!=(不等于)时,不需要考虑对比值是普通字符串,还是数值,同一当字符串处理
                        condition = "context.get(\"" + leftValue + "\") " + operator + " \"" + rightValue + "\"";
                    }else{//当操作符其它,是>=(大于等于)、>(大于)、<(小于)、<=(小于等于)时,要进行数值比较
                        condition = "context.getLong(\"" + leftValue + "\") " + operator + " new Long(\"" + rightValue + "\").longValue()";                    
                    }                  
                }
               
                //为防止表达式存在',替换为",如context.getString('a')
                condition=condition.replace("'", "\"");
               
                Interpreter interpreter=new Interpreter();
               
                try{
                    interpreter.set("context", context);                   
                    Boolean b = (Boolean)interpreter.eval(condition);
                    if(b){
                        activityList[i] = wfconnector.getDestActID();
                    }              
                }catch(Exception e){
                    System.err.println("eval condition="+condition+" error! Reason:"+e.getMessage());
                }
            }  
        }
       
        return activityList;
}
 


【备注】

 




发表回复
账号用户名   密码   登录
内容:url email imgsrc image code quote
范例 Example
bold italic underline linethrough   


 [更多...]