end-node.ts 2.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 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
import { IPSDEUIEndLogic } from '@ibiz/dynamic-model-api';
import { LogUtil } from 'ibiz-core';
import { LogicReturnType } from '../const/logic-return-type';
import { UIActionContext } from '../uiaction-context';
import { AppUILogicNodeBase } from './logic-node-base';
/**
 * 结束节点
 *
 * @export
 * @class AppUILogicEndNode
 */
export class AppUILogicEndNode extends AppUILogicNodeBase {

    constructor() {
        super();
    }

    /**
     * 执行节点
     *
     * @param {IPSDEUIEndLogic} logicNode 逻辑节点模型数据
     * @param {UIActionContext} actionContext 界面逻辑上下文
     * @memberof AppUILogicEndNode
     */
    public async executeNode(logicNode: IPSDEUIEndLogic, actionContext: UIActionContext) {
        try {
            this.handleEndNode(logicNode, actionContext);
            LogUtil.log(`已完成执行${logicNode?.name}节点,操作参数数据如下:`);
            if (actionContext.paramsMap && (actionContext.paramsMap.size > 0)) {
                for (let [key, value] of actionContext.paramsMap) {
                    LogUtil.log(`${key}:`, value.getReal());
                }
            }
            return { nextNodes: [], actionContext };
        } catch (error: any) {
            throw new Error(`逻辑节点 ${logicNode.name}${error?.message ? error?.message : '发生未知错误!'}`);
        }
    }

    /**
     * 处理结束节点
     *
     * @private
     * @param {IPSDEUIEndLogic} logicNode
     * @param {ActionContext} actionContext
     * @memberof AppUILogicEndNode
     */
    private handleEndNode(logicNode: IPSDEUIEndLogic, actionContext: UIActionContext) {
        const strReturnType: string = logicNode.returnType;
        if (Object.is(strReturnType, LogicReturnType.NONEVALUE) || Object.is(strReturnType, LogicReturnType.NULLVALUE)) {
            actionContext.setResult(null);
        } else if (Object.is(strReturnType, LogicReturnType.SRCVALUE)) {
            actionContext.setResult(logicNode.rawValue);
        } else if (Object.is(strReturnType, LogicReturnType.BREAK)) {
            actionContext.setResult(LogicReturnType.BREAK);
        } else if (Object.is(strReturnType, LogicReturnType.LOGICPARAM) || Object.is(strReturnType, LogicReturnType.LOGICPARAMFIELD)) {
            const returnParam = actionContext.getParam(logicNode.getReturnParam()?.codeName as string);
            if (Object.is(strReturnType, LogicReturnType.LOGICPARAM)) {
                actionContext.setResult(returnParam.getReal());
            } else {
                actionContext.setResult(returnParam.get(logicNode.dstFieldName));
            }
        } else {
            throw new Error(`无法识别的返回值类型${strReturnType}`);
        }
    }
}