Ejemplo n.º 1
0
        public override string Execute()
        {
            try
            {
                string rtn = string.Empty;
                foreach (var item in ConfigureEntity.SqlModels)
                {
                    UnResolvedText rawText = new UnResolvedText();
                    rawText.RequestParam = item.FromDs;
                    rawText.RowsType     = item.RowsType;
                    rawText.RawText      = item.SqlText;

                    LogHelper <ExtendSqlAction> .Info("当前未解析参数的功能扩展SQL:" + item.SqlText);

                    //解析完成的sql,Sql语句支持多值
                    string[] sqls = AddinParameterUtils.ReplaceWithParameterValue(rawText);


                    if (sqls.Length > 1)
                    {
                        throw new AddinException(item.SqlText + "功能扩展的SQL语句不支持根据参数展开成多条SQL语句");
                    }

                    string sql = sqls[0];
                    LogHelper <ExtendSqlAction> .Info("已解析完成的功能扩展的SQL" + sql);

                    //包含有空的UI参数则不处理
                    if (AddinParameterUtils.HasEmptyDataUIParameter(sqls))
                    {
                        LogHelper <ExtendSqlAction> .Info("SQL语句有空的UI参数,SQL语句为:" + sql);

                        continue;
                    }

                    //取主键信息?
                    //根据不同SQL类型,
                    if (item.SqlType == EnumSqlOpType.Sql)
                    {
                        rtn = SqlUtils.Execute(Session, sql, 0, 20);
                        //调用出错则记录日志
                    }
                    else if (item.SqlType == EnumSqlOpType.Func)
                    {
                        //调用函数
                        object brtn = SqlUtils.ExecuteFunc(Session, sql);
                        if (brtn != null)
                        {
                            rtn = Convert.ToString(brtn);
                        }
                    }
                }

                return(rtn);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public override bool After(object returnObject, IMethodInvocation invocation)
        {
            try
            {
                bool rtn = false;
                foreach (var item in ConfigureEntity.SqlModels)
                {
                    UnResolvedText rawText = new UnResolvedText();
                    //rawText.RequestParam = item.FromDs;
                    //rawText.RowsType = item.RowsType;
                    rawText.RawText = item.SqlText;


                    //解析完成的sql,Sql语句支持多值
                    string[] sqls = AddinParameterUtils.ReplaceWithParameterValue(rawText);

                    //判断是否有空的UI变量
                    if (AddinParameterUtils.HasEmptyDataUIParameter(sqls))
                    {
                        LogHelper <MethodAfterSqlInterceptor> .Info("SQL语句有空的UI变量:" + sqls[0]);

                        continue;
                    }

                    LogHelper <MethodAfterSqlInterceptor> .Info("解析后的SQL语句记录数为:" + sqls.Length);


                    foreach (var sql in sqls)
                    {
                        LogHelper <MethodAfterSqlInterceptor> .Info("生成的SQL语句:" + sql);

                        //根据不同SQL类型,
                        if (item.SqlType == EnumSqlOpType.Sql)
                        {
                            rtn = SqlUtils.ExecuteUpdate(Session, sql);
                            //调用出错则记录日志
                        }
                        else if (item.SqlType == EnumSqlOpType.Sp)
                        {
                            //调用函数
                            rtn = SqlUtils.ExecuteSP(Session, sql);
                        }
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }