/// <summary>
        /// 新增接口异常日志信息
        /// </summary>
        /// <param name="info"></param>
        public static void AddInterfaceExceptionlogInfo(InterfaceExceptionlog info)
        {
            IDbConnection  conn  = null;
            IDbCommand     cmd   = null;
            IDbTransaction trans = null;

            try
            {
                IInterfaceExceptionlog dp = DataProvider.DbInterfaceExceptionlogDP;
                conn = DbConnOperation.CreateConnection();
                cmd  = conn.CreateCommand();
                conn.Open();
                trans           = conn.BeginTransaction();
                cmd.Transaction = trans;
                dp.AddInterfaceExceptionlogInfo(cmd, info);
                trans.Commit();
            }
            catch (Exception ex)
            {
                if (null != trans)
                {
                    trans.Rollback();
                }
            }
            finally
            {
                if (null != conn)
                {
                    conn.Close();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 新增接口异常日志信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button13_Click(object sender, EventArgs e)
        {
            InterfaceExceptionlog log = new InterfaceExceptionlog();

            log.ConfigId      = new Guid("ad6fb4e4-96c0-4e15-a072-dd921bcac243");
            log.StateCode     = 500;
            log.ExceptionInfo = "接口连接异常,尝试连接多次超时,不拉不拉不拉不拉";
            log.CreateTime    = DateTime.Now;
            InterfaceExceptionlogOperation.AddInterfaceExceptionlogInfo(log);
        }
        /// <summary>
        /// 添加接口异常日志信息
        /// </summary>
        /// <param name="icmd"></param>
        /// <param name="info"></param>
        public void AddInterfaceExceptionlogInfo(IDbCommand icmd, InterfaceExceptionlog info)
        {
            icmd.Parameters.Clear();
            MySqlCommand cmd = icmd as MySqlCommand;

            cmd.CommandType = CommandType.Text;
            string sql = @"insert into interfaceexceptionlog(ConfigId,StateCode,ExceptionInfo,CreateTime)
                            values('{0}',{1},'{2}','{3}')";

            cmd.CommandText = string.Format(sql, info.ConfigId, info.StateCode, info.ExceptionInfo, info.CreateTime);
            cmd.ExecuteNonQuery();
        }
        /// <summary>
        /// 更新接口实时状态信息、接口异常日志信息业务逻辑
        /// </summary>
        /// <param name="interfaceName">接口名</param>
        /// <param name="applicationName">应用系统名</param>
        /// <param name="server">服务器地址</param>
        /// <param name="stateCode">状态码</param>
        /// <param name="exceptionInfo">接口异常信息内容</param>
        public static void UpdateInterfaceRealtimeInfoWithException(string interfaceName, string applicationName, string server, int stateCode, string exceptionInfo)
        {
            InterfaceRealtimeInfo realtime = InterfaceRealtimeInfoOperation.GetInterfaceRealtimeInfo(interfaceName, applicationName, server);
            InterfaceConfigInfo   config   = InterfaceConfigInfoOperation.GetInterfaceConfigInfo(interfaceName, server);

            if (null != realtime)
            {
                realtime.StateCode  = stateCode;
                realtime.UpdateTime = DateTime.Now;
                InterfaceRealtimeInfoOperation.AddOrUpdateInterceRealtimeInfo(realtime, ModifierType.Update);
            }
            if (!string.IsNullOrEmpty(exceptionInfo))
            {
                InterfaceExceptionlog log = new InterfaceExceptionlog();
                log.ConfigId      = config.Id;
                log.StateCode     = stateCode;
                log.ExceptionInfo = exceptionInfo;
                log.CreateTime    = DateTime.Now;
                InterfaceExceptionlogOperation.AddInterfaceExceptionlogInfo(log);
            }
        }
        /// <summary>
        /// 获取接口异常日志信息列表
        /// </summary>
        /// <param name="icmd"></param>
        /// <param name="fields">字段名</param>
        /// <param name="whereCondition">筛选条件</param>
        /// <returns></returns>
        public List <InterfaceExceptionlog> GetInterfaceExceptionlogList(IDbCommand icmd, string fields, string whereCondition)
        {
            icmd.Parameters.Clear();
            MySqlCommand cmd = icmd as MySqlCommand;

            cmd.CommandType = CommandType.Text;
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(fields))
            {
                sb.AppendFormat("select {0} from interfaceexceptionlog ", fields);
            }
            else
            {
                sb.Append("select * from interfaceexceptionlog ");
            }
            if (!string.IsNullOrEmpty(whereCondition))
            {
                sb.AppendFormat(whereCondition);
            }
            cmd.CommandText = sb.ToString();
            List <InterfaceExceptionlog> list = new List <InterfaceExceptionlog>();
            DataTable dt = new DataTable();

            dt.Load(cmd.ExecuteReader());
            if (dt.Rows.Count > 0)
            {
                InterfaceExceptionlog obj = null;
                foreach (DataRow dr in dt.Rows)
                {
                    obj = new InterfaceExceptionlog();
                    obj.AllParse(dr);
                    if (null != obj)
                    {
                        list.Add(obj);
                    }
                }
            }
            return(list);
        }
        /// <summary>
        /// 获取接口异常日志信息列表(带分页)
        /// </summary>
        /// <param name="icmd"></param>
        /// <param name="fields"></param>
        /// <param name="whereCondition"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List <InterfaceExceptionlog> GetInterfaceExceptionlogPageList(IDbCommand icmd, string fields, string whereCondition, int pageIndex, int pageSize)
        {
            icmd.Parameters.Clear();
            MySqlCommand cmd = icmd as MySqlCommand;

            cmd.CommandType = CommandType.Text;
            StringBuilder sb         = new StringBuilder();
            int           startIndex = (pageIndex - 1) * pageSize;//计算页面下标值

            if (!string.IsNullOrEmpty(fields))
            {
                sb.AppendFormat("select {0} from interfaceexceptionlog ", fields);
            }
            if (!string.IsNullOrEmpty(whereCondition))
            {
                sb.AppendFormat("{0} ", whereCondition);
            }
            sb.AppendFormat("limit {0},{1}", startIndex, pageSize);
            cmd.CommandText = sb.ToString();
            List <InterfaceExceptionlog> list = new List <InterfaceExceptionlog>();
            DataTable dt = new DataTable();

            dt.Load(cmd.ExecuteReader());
            if (dt.Rows.Count > 0)
            {
                InterfaceExceptionlog obj = null;
                foreach (DataRow dr in dt.Rows)
                {
                    obj = new InterfaceExceptionlog();
                    obj.AllParse(dr);
                    if (null != obj)
                    {
                        list.Add(obj);
                    }
                }
            }
            return(list);
        }