// 获取两个值的比较结果
export default {
    execute: async function(){
        console.log("进入 “获取两个值的比较结果” 前端公式");
        if(arguments && arguments[0] && arguments[0].length == 3){
            //选择的字段
            let firstParam = arguments[0][0], secondParam = arguments[0][1], thirdParam = arguments[0][2], result = false,
            firstValue = await this.getParamValue(firstParam), operator = await this.getParamValue(secondParam), thirdValue = await this.getParamValue(thirdParam)
            if (firstValue && thirdValue) {
                // 根据比较运算符获取比较结果
                switch(operator) {
                    case '>':
                        result = firstValue > thirdValue
                        break;
                    case '<':
                        result = firstValue < thirdValue
                        break;
                    case '=':
                        result = firstValue == thirdValue
                        break;
                    case '<>':
                        result = firstValue != thirdValue
                        break;
                    case '>=':
                        result = firstValue >= thirdValue
                        break;
                    case '<=':
                        result = firstValue <= thirdValue
                        break;
                    default:
                        break;
                }
            }
            return result ? 1 : -1
        }else{
            return -1;
        }
    },
    /**
     * 获取
     */
    async getParamValue(param) {
        let paramValue = '', itemLink = ''
        // 参数为空时退出
        if (param) {
            if(param instanceof BillDataNode) {
                itemLink = param.FieldTableCode + "." + param.FieldCode
                paramValue = param.dynamicNodeFactory.methodJson.GetFieldData('', itemLink, '')
            } else if (param instanceof StaticDataNode) {
                paramValue = param.StaticValue
            } else if (param instanceof FunctionNode) {
                paramValue = await this.getFuncResult(param)
            }
        }
        return paramValue
    },
    // 获取公式获取结果
    async getFuncResult(obj) {
        let funcResult = obj.getResult(), result = ''
        if(funcResult instanceof AbstractData) {
            await funcResult.Value.then(res => {
                result = res
            })
        }
        return result
    },
    getResultType:function(){
        return FMR.ConstDataTypes.General;
    }
}