Create alias for conditions in Drools Decision tab

2019-09-11 01:56发布

Attached is my decision table, where in I'm using sv2.SV202_CompMedProcedId.get("SV202-02") several times in my condition.

Is there any way that we can create an alias for sv2.SV202_CompMedProcedId.get("SV202-02") (for example, S) and use that alias in my condition instead of using the entire line every time?enter image description here

CONDITION
sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '70010' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '76499' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '76506' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '76999' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77001' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77032' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77051' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77059' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77071' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77084' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77261' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77999' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '78000' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '79999'

where sv2 is the object and SV2 is the class

2条回答
Summer. ? 凉城
2楼-- · 2019-09-11 02:08

Yes, you can use an alias. Change your condition to:

$s : sv2.SV202_CompMedProcedId.get("SV202-02").Value >= '70010' && $s <= '76499' || $s >= '76506' && $s <= '76999' || $s >= '77001' && $s <= '77032' || $s >= '77051' && $s <= '77059' || $s >= '77071' && $s <= '77084' || $s >= '77261' && $s <= '77999' || $s >= '78000' && $s <= '79999'

查看更多
冷血范
3楼-- · 2019-09-11 02:18

If this is frequent enough you might write and import a static Java (!) function:

public boolean isInRanges( Comparable value, Comparable... bounds ){
    for( int i = 0; i < bounds.length; i += 2 ){
        if( bounds[i].compareTo(value) <= 0 &&
            value.compareTo(bounds[i+1]) <= 0 ) return true; 
    }
    return false;
}

The simple call is obvious.

You can't use a DRL function: AFAIK, the vararg notation isn't implemented (but check).

查看更多
登录 后发表回答