%DE%%ITEM%RuleFlow.bpmn.ftl 9.3 KB
Newer Older
ibizdev's avatar
ibizdev committed
1 2 3 4 5 6 7 8 9
<#ibiztemplate>
TARGET=PSDELOGIC
</#ibiztemplate>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:g="http://www.jboss.org/drools/flow/gpd" xmlns:tns="http://www.jboss.org/drools" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.mvel.org/2.0" id="Definition" name="" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
    <process id="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.service.logic.${de.codeName?lower_case}${item.getCodeName()?lower_case}" isClosed="false" isExecutable="true" name="ScoreRule" processType="Private" tns:packageName="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.service.logic.${de.codeName?lower_case}${item.getCodeName()?lower_case}">
        <extensionElements>
            <tns:import name="java.util.Map" />
            <tns:import name="org.springframework.util.StringUtils"/>
sq3536's avatar
sq3536 committed
10
            <tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
ibizdev's avatar
ibizdev committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        <#assign logicName=(de.codeName+item.codeName)?lower_case>
        <#comment>插入逻辑参数</#comment>
        <#if item.getPSDELogicParams?? && item.getPSDELogicParams()??>
            <#list item.getPSDELogicParams() as logicParam>
                <#if logicParam.getParamPSDataEntity?? && logicParam.getParamPSDataEntity()??>
                    <#assign ParamPSDataEntity=logicParam.getParamPSDataEntity()>
        <tns:global identifier="${logicName+logicParam.codeName?lower_case}" type="${pub.getPKGCodeName()}.core.${ParamPSDataEntity.getPSSystemModule().codeName?lower_case}.domain.${ParamPSDataEntity.codeName}" />
                <#else>
                </#if>
            </#list>
        </#if>
        </extensionElements>
            <#comment>绘制处理节点</#comment>
            <#if item.getPSDELogicNodes?? && item.getPSDELogicNodes()??>
                <#list item.getPSDELogicNodes() as logicNode>
                    <#if logicNode.getLogicNodeType()=='BEGIN'>
     <startEvent id="${logicNode.getId()}" isInterrupting="true"/>
                    <#else>
     <businessRuleTask activiti:exclusive="true" g:ruleFlowGroup="${logicName+logicNode.getCodeName()?lower_case}" id="${logicNode.getId()}" implementation="http://www.jboss.org/drools/rule" name="${logicNode.getName()}"/>
                    </#if>
                    <#if !(logicNode.getPSDELogicLinks()??)><#comment>是否为流程最后一个处理节点,若为最后一个处理节点则生成End节点</#comment>
     <endEvent id="${logicNode.getId()}_End" name="End"/>
     <sequenceFlow id="${logicNode.getId()}_End_Line" sourceRef="${logicNode.getId()}" targetRef="${logicNode.getId()}_End"/><#comment>生成流程最后一个处理节点与End节点之间的连线</#comment>
                    </#if>
                </#list>
            </#if>
          <#comment>绘制节点连线</#comment>
          <#if item.getPSDELogicLinks?? && item.getPSDELogicLinks()??>
              <#list item.getPSDELogicLinks() as LogicLink>
                  <#assign sourceNodeid=LogicLink.getSrcPSDELogicNode().getId()>
                  <#if LogicLink.getPSDELogicLinkGroupCond?? && LogicLink.getPSDELogicLinkGroupCond()??><#comment>判断连接线含有条件,若有条件,则将源节点指向网关</#comment>
                      <#assign sourceNodeid="gateway-"+LogicLink.getSrcPSDELogicNode().getId()>
                  </#if>
     <sequenceFlow id="${LogicLink.getId()}" sourceRef="${sourceNodeid}" targetRef="${LogicLink.getDstPSDELogicNode().getId()}">
        <#if LogicLink.getPSDELogicLinkGroupCond?? && LogicLink.getPSDELogicLinkGroupCond()??><#comment>连接线含有条件</#comment>
            <conditionExpression  language="http://www.jboss.org/drools/rule" ><![CDATA[
             <#comment>准备逻辑参数</#comment>
                <#if item.getPSDELogicParams?? && item.getPSDELogicParams()??>
                    <#list item.getPSDELogicParams() as logicParam>
                        <#if logicParam.getParamPSDataEntity?? && logicParam.getParamPSDataEntity()??>
                            <#assign ParamPSDataEntity=logicParam.getParamPSDataEntity()>
            $${logicName+logicParam.codeName?lower_case}:${ParamPSDataEntity.codeName}();
                        <#else>
            $${logicName+logicParam.codeName?lower_case}:Map();
                        </#if>
                    </#list>
                    <#assign strExpCond=getConditionExpression(item)>
            eval(${strExpCond});<#comment>在fact中寻找与global中对应参数</#comment>
                </#if>
            <#assign LogicLinkCond=LogicLink.getPSDELogicLinkGroupCond()>
            <#assign strGroupCond=getGroupCond(LogicLinkCond)>
                eval${strGroupCond}
                ]]>
            </conditionExpression>
        </#if>
     </sequenceFlow>
              </#list>
          </#if>
      <#comment>生成交互网关节点</#comment>
          <#if item.getPSDELogicLinks?? && item.getPSDELogicLinks()??>
              <#list item.getPSDELogicLinks() as LogicLink>
                  <#if LogicLink.getPSDELogicLinkGroupCond?? && LogicLink.getPSDELogicLinkGroupCond()??><#comment>连接线含有条件</#comment>
                      <#assign  gatewayid="gateway-"+LogicLink.getSrcPSDELogicNode().getId()>
                      <#if !P.exists("gateway",gatewayid)>
                          <#comment>绘制网关</#comment>
    <exclusiveGateway id="${gatewayid}" name="Gateway" gatewayDirection="Diverging" default="${gatewayid}_End_Line"></exclusiveGateway>
                          <#comment>绘制网关与源节点的连线</#comment>
    <sequenceFlow id="${LogicLink.getId()}-gatewayline" sourceRef="${LogicLink.getSrcPSDELogicNode().getId()}" targetRef="${gatewayid}"></sequenceFlow>
                      </#if>
                      <#comment>绘制网关默认结束节点</#comment>
                      <#if !P.exists("gateway-end",gatewayid)>
    <sequenceFlow id="${gatewayid}_End_Line" sourceRef="${gatewayid}" targetRef="${gatewayid}_End"/><#comment>生成流程最后一个处理节点与End节点之间的连线</#comment>
    <endEvent id="${gatewayid}_End" name="End"/>
                      </#if>
                  </#if>
              </#list>
          </#if>
    </process>
</definitions>

<#comment>获取组合条件表达式</#comment>
<#function getGroupCond LogicLinkCond>
    <#assign strRuleCond="(">
    <#if LogicLinkCond.getPSDELogicLinkConds?? && LogicLinkCond.getPSDELogicLinkConds()??><#comment>判断是否有组条件</#comment>
sq3536's avatar
sq3536 committed
95
        <#assign conn=LogicLinkCond.getGroupOP()?replace("AND","&&")?replace("OR","||")>
ibizdev's avatar
ibizdev committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        <#list LogicLinkCond.getPSDELogicLinkConds() as childLogicLinkCond><#comment>组条件,递归</#comment>
            <#if childLogicLinkCond.getPSDELogicLinkConds?? && childLogicLinkCond.getPSDELogicLinkConds()??>
                <#assign strRuleCond=strRuleCond+getGroupCond(childLogicLinkCond)>//getGroupCond
            <#else>
                <#assign strRuleCond=strRuleCond+getFieldCond(childLogicLinkCond)>//getFieldCond
            </#if>
            <#if childLogicLinkCond_has_next>
                <#assign strRuleCond=strRuleCond+conn>//拼接连接符
            </#if>
        </#list>
    </#if>
    <#assign strRuleCond=strRuleCond+")">
    <#return strRuleCond/>
</#function>

<#comment>获取单项条件表达式</#comment>
<#function getFieldCond LogicLinkCond>
    <#assign fieldCond="(" >
    <#assign condBody="">
    <#assign targetParam=LogicLinkCond.getDstLogicParam()><#comment>目标参数</#comment>
    <#assign targetFieldName=LogicLinkCond.getDstFieldName()><#comment>目标属性名称</#comment>
sq3536's avatar
sq3536 committed
117
    <#assign targetDEField=((targetParam.getParamPSDataEntity().getPSDEField(targetFieldName,true))!'')><#comment>目标属性</#comment>
ibizdev's avatar
ibizdev committed
118 119 120
    <#assign targetDBValueOP=LogicLinkCond.getPSDBValueOPId()><#comment>表达式</#comment>
    <#assign targetValue=LogicLinkCond.getValue()><#comment>值项</#comment>
    <#if targetDEField!=''>
sq3536's avatar
sq3536 committed
121
            targetFieldName=srfcaseformat(targetDEField.codeName,'l_u2lC') ;
ibizdev's avatar
ibizdev committed
122
    </#if>
sq3536's avatar
sq3536 committed
123
    <#assign condBody="RuleUtils.test($"+logicName+targetParam.getCodeName()?lower_case+".get(\""+targetFieldName+"\"),\""+targetDBValueOP+"\","+"\""+targetValue+"\")">
ibizdev's avatar
ibizdev committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    <#assign fieldCond=fieldCond+condBody >
    <#assign fieldCond=fieldCond+")" >
    <#return fieldCond/>
</#function>

<#comment>获取conditionExpression</#comment>
<#function getConditionExpression LogicParams>
    <#assign expressionCond="" >
    <#list LogicParams.getPSDELogicParams() as logicParam>
        <#assign condBody="">
        <#if logicParam.getParamPSDataEntity?? && logicParam.getParamPSDataEntity()??>
            <#assign condBody='$'+logicName+logicParam.codeName?lower_case+'=='+logicName+logicParam.codeName?lower_case>
            <#if logicParam_has_next>
                <#assign condBody=condBody+" && ">
            </#if>
        <#else>
           //暂未实现
        </#if>
        <#assign expressionCond=expressionCond+condBody >
    </#list>
    <#return expressionCond/>
</#function>