%APP_DELOGIC%-logic-base.ts.ftl 12.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<#ibiztemplate>
TARGET=PSAPPDELOGIC
</#ibiztemplate>
<#if item.getPSDELogicNodes()??>
    <#list item.getPSDELogicNodes() as delogicNode>
         <#if delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "DEACTION">
            <#if delogicNode.getDstPSAppDataEntity()?? && delogicNode.getDstPSAppDEAction()??>
            <#assign targetEntity = delogicNode.getDstPSAppDataEntity() />
                <#if !P.exists("importService", targetEntity.getId(), "")>
import ${srfclassname('${targetEntity.getCodeName()}')}Service from '@/service/${srffilepath2(targetEntity.getCodeName())}/${srffilepath2(targetEntity.getCodeName())}-service';
                </#if>
            </#if>
         </#if>
    </#list>
</#if>
import { Verify } from '@/utils/verify/verify';

<#-- 设置参数 -->
<#macro setParam logicNode>
<#if logicNode.getPSDELogicNodeParams()??>
<#list logicNode.getPSDELogicNodeParams() as logicparam>
tony001's avatar
tony001 committed
22 23 24 25
<#if logicparam.getDstPSDELogicParam()?? && logicparam.getDstFieldName()?? && logicparam.getSrcValueType()??>
<#-- 源参数 -->
<#if logicparam.getSrcPSDELogicParam()??><#assign srcParam = logicparam.getSrcPSDELogicParam() /></#if>
<#-- 源参数属性名称 -->
26 27
<#if logicparam.getSrcFieldName()??>
<#assign srcFieldParamName = logicparam.getSrcFieldName() />
28
<#if srcParam?? && srcParam.getParamPSAppDataEntity?? && srcParam.getParamPSAppDataEntity()?? && srcParam.getParamPSAppDataEntity().getPSAppDEField(srcFieldParamName,true)??>
29 30 31
<#assign srcFieldParam=srfcaseformat(srcParam.getParamPSAppDataEntity().getPSAppDEField(srcFieldParamName,true).getCodeName()?lower_case,'l_u2lC') />
<#else>
<#assign srcFieldParam= logicparam.getSrcFieldName()?lower_case />
32 33
</#if>
</#if>
tony001's avatar
tony001 committed
34 35 36
<#-- 目标参数 -->
<#assign dstParam = logicparam.getDstPSDELogicParam() />
<#-- 目标参数属性名称 -->
37
<#assign dstFieldParamName = logicparam.getDstFieldName() />
38
<#if dstParam?? && dstParam.getParamPSAppDataEntity?? && dstParam.getParamPSAppDataEntity()?? && dstParam.getParamPSAppDataEntity().getPSAppDEField(dstFieldParamName,true)??>
39 40 41
<#assign dstFieldParam=srfcaseformat(dstParam.getParamPSAppDataEntity().getPSAppDEField(dstFieldParamName,true).getCodeName()?lower_case,'l_u2lC') />
<#else>
<#assign dstFieldParam= logicparam.getDstPSDELogicParam()?lower_case />
42
</#if>
tony001's avatar
tony001 committed
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
<#-- 源逻辑参数 -->
    let tempDstParam${logicparam_index}Context:any = this.paramsMap.get('${dstParam.getCodeName()}').context?this.paramsMap.get('${dstParam.getCodeName()}').context:{};
    let tempDstParam${logicparam_index}Data:any = this.paramsMap.get('${dstParam.getCodeName()}').data?this.paramsMap.get('${dstParam.getCodeName()}').data:{};
<#if logicparam.getSrcValueType() =="SRCDLPARAM">
    let tempSrcParam${logicparam_index}Data:any = this.paramsMap.get('${srcParam.getCodeName()}').data?this.paramsMap.get('${srcParam.getCodeName()}').data:{};
    <#if dstParam.getParamPSAppDataEntity?? &&  dstParam.getParamPSAppDataEntity()?? && dstFieldParam == dstParam.getParamPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case>
    Object.assign(tempDstParam${logicparam_index}Context,{${dstParam.getParamPSAppDataEntity().getCodeName()?lower_case}:tempSrcParam${logicparam_index}Data['${srcFieldParam}']});
    </#if>
    Object.assign(tempDstParam${logicparam_index}Data,{${dstFieldParam}:tempSrcParam${logicparam_index}Data['${srcFieldParam}']});
<#-- 应用上下文 -->
<#elseif logicparam.getSrcValueType() =="APPDATA">
    <#if dstParam.getParamPSAppDataEntity?? &&  dstParam.getParamPSAppDataEntity()?? && dstFieldParam == dstParam.getParamPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case>
    Object.assign(tempDstParam${logicparam_index}Context,{${dstParam.getParamPSAppDataEntity().getCodeName()?lower_case}:context['${srcFieldParam}']});
    </#if>
    Object.assign(tempDstParam${logicparam_index}Data,{${dstFieldParam}:context['${srcFieldParam}']});
<#-- 数据上下文 -->
<#elseif logicparam.getSrcValueType() =="DATACONTEXT">
    <#if dstParam.getParamPSAppDataEntity?? &&  dstParam.getParamPSAppDataEntity()?? && dstFieldParam == dstParam.getParamPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case>
    Object.assign(tempDstParam${logicparam_index}Context,{${dstParam.getParamPSAppDataEntity().getCodeName()?lower_case}:params['${srcFieldParam}']});
    </#if>
    Object.assign(tempDstParam${logicparam_index}Data,{${dstFieldParam}:params['${srcFieldParam}']});
<#-- 直接值 -->
<#elseif logicparam.getSrcValueType() =="SRCVALUE">
    <#if dstParam.getParamPSAppDataEntity?? &&  dstParam.getParamPSAppDataEntity()?? && dstFieldParam == dstParam.getParamPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case>
    Object.assign(tempDstParam${logicparam_index}Context,{${dstParam.getParamPSAppDataEntity().getCodeName()?lower_case}:${logicparam.getSrcValue()}});
    </#if>
    Object.assign(tempDstParam${logicparam_index}Data,{${dstFieldParam}:"${logicparam.getSrcValue()}"});
</#if>
    this.paramsMap.set('${dstParam.getCodeName()}',{data:tempDstParam${logicparam_index}Data,context:tempDstParam${logicparam_index}Context});
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
</#if>
</#list>
</#if>
</#macro>

<#-- 调用下一节点处理逻辑 -->
<#macro executeNext logicNode>
<#if logicNode.getPSDELogicLinks()??>
<#list logicNode.getPSDELogicLinks() as logiclink>
<#if logiclink.getDstPSDELogicNode()??>
<#assign nextnode = logiclink.getDstPSDELogicNode() />
<#list item.getPSDELogicLinks() as curLink >
<#if curLink.getId() == logiclink.getId()>
<#assign curIndex = curLink_index/>
</#if>
</#list>
        if(this.compute${curIndex}Cond(params)){
            return this.execute${nextnode.codeName}(context,params,isloading);   
        }
</#if>
</#list>
<#else>
tony001's avatar
tony001 committed
94
        return this.paramsMap.get(this.defaultParamName).data;
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
</#if>
</#macro>

<#-- 获取判断条件 -->
<#macro getCond item><#if item.getLogicType() == 'GROUP'><#if item.isNotMode()>!(</#if><#if item.getPSDELogicLinkConds()??><#list item.getPSDELogicLinkConds() as subLogic><#if subLogic_index gt 0><#if item.getGroupOP() == 'AND'> && </#if><#if item.getGroupOP() == 'OR'> || </#if></#if><@getCond subLogic /></#list></#if><#if item.isNotMode()>)</#if><#elseif item.getLogicType() == 'SINGLE'>Verify.testCond(params.${item.getDstFieldName()?lower_case}, '${item.getCondOP()}', '${item.getValue()}')</#if></#macro>

/**
 * ${item.name}
 *
 * @export
 * @class ${srfclassname('${item.getCodeName()}')}LogicBase
 */
export default class ${srfclassname('${item.getCodeName()}')}LogicBase {

    /**
     * 名称
     * 
     * @memberof  ${srfclassname('${item.getCodeName()}')}LogicBase
     */
    private name:string ="${item.codeName}";

    /**
     * 唯一标识
     * 
     * @memberof  ${srfclassname('${item.getCodeName()}')}LogicBase
     */
    private id:string = "${item.id}";

    /**
     * 默认参数名称
     * 
     * @memberof  ${srfclassname('${item.getCodeName()}')}LogicBase
     */
    private defaultParamName:string = "${item.getDefaultParamName()}";

tony001's avatar
tony001 committed
130 131 132 133 134 135 136
    /**
     * 参数集合
     * 
     * @memberof  ${srfclassname('${item.getCodeName()}')}LogicBase
     */
    private paramsMap:Map<string,any> = new Map();

137 138 139 140 141 142 143
    /**
     * Creates an instance of  ${srfclassname('${item.getCodeName()}')}LogicBase.
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}LogicBase
     */
    constructor(opts: any = {}) {
tony001's avatar
tony001 committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
        this.initParams(opts);
    }

    /**
     * 初始化参数集合
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}LogicBase
     */
    public initParams(opts:any){
    <#if item.getPSDELogicParams?? && item.getPSDELogicParams()??>
    <#list item.getPSDELogicParams() as logicParam>
        <#if logicParam.isDefault()>
        this.paramsMap.set('${logicParam.getCodeName()}',opts);
        <#else>
        this.paramsMap.set('${logicParam.getCodeName()}',{});
        </#if>
    </#list>
    </#if>
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    }

<#if item.getPSDELogicLinks()??>
<#list item.getPSDELogicLinks() as curLink>

    /**
     * 计算${curLink_index}节点结果
     * 
     * @param params 传入参数
     */
    public compute${curLink_index}Cond(params:any):boolean{
    <#if curLink.getPSDELogicLinkGroupCond()??>
        <#assign linkCond = curLink.getPSDELogicLinkGroupCond() />
        if(<@getCond linkCond />){
           return true;
        }else{
            return false;
        }
    <#else>
        return true;
    </#if>  
    }
</#list>
</#if>

    /**
     * 执行逻辑
     * 
     * @param context 应用上下文
     * @param params 传入参数
     */
    public onExecute(context:any,params:any,isloading:boolean){
        return this.execute${item.getStartPSDELogicNode().codeName}(context,params,isloading);
    }

<#if item.getPSDELogicNodes()??>
    <#list item.getPSDELogicNodes() as delogicNode>

    <#-- 开始节点 -->
    <#if delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "BEGIN">
    /**
    * ${delogicNode.getName()}
    * 
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        //开始节点
        <@setParam delogicNode />
        <@executeNext delogicNode />
    }
    <#-- 行为处理节点 -->
    <#elseif delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "DEACTION">
    /**
    * ${delogicNode.getName()}
    * 
    * @param context 应用上下文
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        // 行为处理节点
        <@setParam delogicNode  />
        <#if delogicNode.getDstPSAppDataEntity()?? && delogicNode.getDstPSAppDEAction()??>
        <#assign targetEntity = delogicNode.getDstPSAppDataEntity() />
        <#assign deAction = delogicNode.getDstPSAppDEAction() />
        let result: any;
tony001's avatar
tony001 committed
228 229 230 231 232
        <#if delogicNode.getDstPSDELogicParam()??>
        let actionParam:any = this.paramsMap.get('${delogicNode.getDstPSDELogicParam().getCodeName()}');
        <#else>
        let actionParam:any = this.paramsMap.get(this.defaultParamName);
        </#if>
233 234
        const targetService:${srfclassname('${targetEntity.getCodeName()}')}Service = new ${srfclassname('${targetEntity.getCodeName()}')}Service();
        if (targetService['${deAction.getCodeName()}'] && targetService['${deAction.getCodeName()}'] instanceof Function) {
tony001's avatar
tony001 committed
235
            result = await targetService['${deAction.getCodeName()}'](actionParam.context,actionParam.data, false);
236 237
        }
        if(result && result.status == 200){
tony001's avatar
tony001 committed
238 239
            Object.assign(actionParam.data,result.data);
                <@executeNext delogicNode />
240 241 242 243 244 245 246 247 248 249 250 251 252
        }
        </#if>
    }
    <#-- 准备参数节点 -->
    <#elseif delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "PREPAREPARAM">
    /**
    * ${delogicNode.getName()}
    * 
    * @param context 应用上下文
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        // 准备参数节点
tony001's avatar
tony001 committed
253 254
            <@setParam delogicNode />
            <@executeNext delogicNode />
255 256 257 258 259 260 261 262 263 264 265
    }
    <#-- 开始流程节点 -->
    <#elseif delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "STARTWF">
    /**
    * ${delogicNode.getName()}
    * 
    * @param context 应用上下文
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        // 开始流程节点
tony001's avatar
tony001 committed
266
        return this.paramsMap.get(this.defaultParamName).data;
267 268 269 270 271 272 273 274 275 276 277
    }
    <#-- 异常捕获节点  -->
    <#elseif delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "THROWEXCEPTION">
    /**
    * ${delogicNode.getName()}
    * 
    * @param context 应用上下文
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        // 异常捕获节点
tony001's avatar
tony001 committed
278
        return this.paramsMap.get(this.defaultParamName).data;
279 280 281 282 283 284 285 286 287 288 289
    }
    <#-- 前端插件  -->
    <#elseif delogicNode.getLogicNodeType()?? && delogicNode.getLogicNodeType() == "PFPLUGIN">
    /**
    * ${delogicNode.getName()}
    * 
    * @param context 应用上下文
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        // 前端插件
tony001's avatar
tony001 committed
290
        return this.paramsMap.get(this.defaultParamName).data;
291 292 293 294 295 296 297 298 299 300 301
    }
    <#else>
    /**
    * ${delogicNode.getName()}
    * 
    * @param context 应用上下文
    * @param params 传入参数
    */
    private async execute${delogicNode.codeName}(context:any,params:any,isloading:boolean){
        // ${delogicNode.getLogicNodeType()}暂未支持
        console.log("${delogicNode.getLogicNodeType()}暂未支持");
tony001's avatar
tony001 committed
302
        return this.paramsMap.get(this.defaultParamName).data;
303 304 305 306 307 308 309
    }
    </#if>
    </#list>
</#if>


}