Exemplo n.º 1
0
        private IList <SqlBuildModel> SqlBuilderModel(string scriptCode, IDictionary <string, object> parameters, object bodyJson)
        {
            Lua lua = this.GetLua();
            var res = LuaScriptRunner.ExecuteLuaScript(lua, scriptCode, parameters, bodyJson);
            IList <SqlBuildModel> result = new List <SqlBuildModel>();

            for (var i = 0; i < res.Length; i++)
            {
                var item = res[i];
                if (item is LuaTable)
                {
                    var            table         = (LuaTable)item;
                    var            extraParams   = LuaScriptRunner.LuaTableToCSharpData <IDictionary <string, object> >(table["ExtraParams"]);
                    var            sqlParameters = RequestDataHelper.MergeDictionary(parameters, extraParams);//合并附加参数到sql执行参数中
                    IList <object> relationKeys  = LuaScriptRunner.LuaTableToCSharpData <IList <object> >(table["RelationKeys"]);
                    long           codeKind      = table["CodeKind"] == null ? 0 : (long)table["CodeKind"];
                    string         key           = (string)table["Key"];
                    var            model         = new SqlBuildModel {
                        Sql = (string)table["Sql"], Parameters = sqlParameters, CodeKind = codeKind, RelationKeys = relationKeys, Key = key
                    };
                    result.Add(model);
                    this.ChildSqlBuilderModel(parameters, model, LuaScriptRunner.LuaTableToCSharpData <object>(table["Children"]));
                }
                else
                {
                    throw new CustomException(99, "构建SQL的脚本返回有误");
                }
            }
            return(result);
        }
Exemplo n.º 2
0
 public override object LuaExecuteSql(string sql, int codeKind, LuaTable table)
 {
     try
     {
         IDictionary <string, object> parameters = LuaScriptRunner.LuaTableToCSharpData <IDictionary <string, object> >(table);
         object result    = this.ExecuteSql(sql, codeKind, parameters);
         string luaScript = LuaScriptRunner.ToLuaScript(result);
         Lua    lua       = GetLua();
         var    returns   = lua.DoString("return " + luaScript);
         return(returns[0]);
     }
     catch
     {
         _logger.LogError("Lua执行SQL语句异常");
         throw;
     }
 }
Exemplo n.º 3
0
 //lua中调用此方法执行已配置的内部或者外部接口
 public override object LuaInvokeDynamicApi(string code, LuaTable table)
 {
     try
     {
         IDictionary <string, object> parameters = LuaScriptRunner.LuaTableToCSharpData <IDictionary <string, object> >(table);
         object result    = this.DynamicFetch(code, parameters);
         string luaScript = LuaScriptRunner.ToLuaScript(result);
         Lua    lua       = GetLua();
         var    returns   = lua.DoString("return " + luaScript);
         return(returns[0]);
     }
     catch
     {
         _logger.LogError("Lua调用接口异常");
         throw;
     }
 }