public IList <tb_messagequeue_model> GetPageList(DbConn conn, int pageIndex, int pageSize, string id, ref int count) { int tempCount = 0; IList <tb_messagequeue_model> list = new List <tb_messagequeue_model>(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder(" WHERE 1=1"); if (!string.IsNullOrWhiteSpace(id)) { where.AppendFormat(" AND id={0}", id); } string sql = string.Format("SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS rownum,* FROM {0} WITH(NOLOCK)", TableName) + where; string countSql = string.Format("SELECT COUNT(1) FROM {0} WITH(NOLOCK)", TableName) + where; object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { tb_messagequeue_model model = CreateModel(dr); list.Add(model); } } return(list); }); count = tempCount; return(result); }
/// <summary> /// nodeList /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="count"></param> /// <returns></returns> public IList <tb_datanode_model> GetPageList(DbConn conn, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <tb_datanode_model> list = new List <tb_datanode_model>(); var result = SqlHelper.Visit((ps) => { string sql = "SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS rownum,* FROM tb_datanode WITH(NOLOCK)"; string countSql = "SELECT COUNT(1) FROM tb_datanode WITH(NOLOCK) "; object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { tb_datanode_model model = CreateModel(dr); list.Add(model); } } return(list); }); count = tempCount; return(result); }
/// <summary> /// 根据节点获取所有的分区集合 /// </summary> /// <param name="conn"></param> /// <param name="node"></param> /// <returns></returns> public IDictionary <int, string> GetMqByPartitionId(DbConn conn, string node) { ICollection <string> array = this.GetDataNodeTableString(conn); IDictionary <int, string> dic = new Dictionary <int, string>(); if (array == null || array.Count <= 0) { return(null); } foreach (var item in array) { IList <string> result = item.Split('_'); if (result != null && result.Count > 3) { int date = LibConvert.ObjToInt(result[3]); string nodeId = result[2].Tostring(); if (!dic.ContainsKey(date) && nodeId.Equals(node)) { dic.Add(date, result[2]); } } } return(dic); }
public static Command CreateModel(DataRow dr) { Command cmd = new Command(); if (dr.Table.Columns.Contains("Id")) { cmd.Id = LibConvert.ObjToInt64(dr["Id"]); } if (dr.Table.Columns.Contains("TaskId")) { cmd.TaskId = LibConvert.ObjToInt64(dr["TaskId"]); } if (dr.Table.Columns.Contains("NodeId")) { cmd.NodeId = LibConvert.ObjToInt64(dr["NodeId"]); } if (dr.Table.Columns.Contains("CommandType")) { cmd.CommandType = (CommandType)LibConvert.ObjToInt(dr["CommandType"]); } if (dr.Table.Columns.Contains("CreateTime")) { cmd.CreateTime = LibConvert.ObjToDateTime(dr["CreateTime"]); } if (dr.Table.Columns.Contains("State")) { cmd.State = LibConvert.ObjToInt(dr["State"]); } return(cmd); }
/// <summary> /// debug日志分页列表 /// </summary> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="count"></param> /// <returns></returns> public IList <tb_debuglog_model> GetPageList(DbConn conn, DateTime?startTime, DateTime?endTime, string mqpathid, string mqpath, string methodname, string info, int pageSize, int pageIndex, ref int count) { int tempCount = 0; var result = SqlHelper.Visit((ps) => { IList <tb_debuglog_model> list = new List <tb_debuglog_model>(); StringBuilder where = new StringBuilder(); List <ProcedureParameter> parameters = new List <ProcedureParameter>(); where.Append(" WHERE 1=1 "); if (startTime != null && endTime != null) { parameters.Add(new ProcedureParameter("startTime", startTime.Value.ToString("yyyy-MM-dd"))); parameters.Add(new ProcedureParameter("endTime", endTime.Value.ToString("yyyy-MM-dd"))); where.Append(" AND createtime>=@startTime AND createtime<=@endTime "); } if (!string.IsNullOrWhiteSpace(mqpathid)) { parameters.Add(new ProcedureParameter("mqpathid", mqpathid)); where.Append(" AND mqpathid=@mqpathid "); } if (!string.IsNullOrWhiteSpace(mqpath)) { parameters.Add(new ProcedureParameter("mqpath", mqpath)); where.Append(" AND mqpath=@mqpath "); } if (!string.IsNullOrWhiteSpace(methodname)) { parameters.Add(new ProcedureParameter("methodname", methodname)); where.Append(" AND methodname like '%'+@methodname+'%' "); } if (!string.IsNullOrWhiteSpace(info)) { parameters.Add(new ProcedureParameter("info", info)); where.Append(" AND info like '%'+@info+'%' "); } StringBuilder sql = new StringBuilder(); sql.Append("SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS rownum,* FROM tb_debuglog WITH(NOLOCK)"); string countSql = string.Concat("SELECT COUNT(1) FROM tb_debuglog WITH(NOLOCK) ", where.ToString()); object obj = conn.ExecuteScalar(countSql, parameters); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, parameters); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { tb_debuglog_model model = CreateModel(dr); list.Add(model); } } return(list); }); count = tempCount; return(result); }
public IList <tb_producterview_model> GetPageList(DbConn conn, string mqpathid, string name, string ip, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <tb_producterview_model> list = new List <tb_producterview_model>(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder("");// WHERE 1=1 if (!string.IsNullOrEmpty(name)) { where.AppendFormat(" AND p.productername LIKE '%{0}%'", name); } if (!string.IsNullOrEmpty(ip)) { where.AppendFormat(" AND p.ip='{0}'", ip); } if (!string.IsNullOrWhiteSpace(mqpathid)) { int temp = 0; if (int.TryParse(mqpathid, out temp)) { where.AppendFormat(" and (p.mqpathid='{0}')", mqpathid); } else { where.AppendFormat(" and (m.mqpath like '%'+'{0}'+'%')", mqpathid); } } string sql = "SELECT ROW_NUMBER() OVER(ORDER BY p.Id DESC) AS rownum,p.*,m.mqpath FROM tb_producter p WITH(NOLOCK),tb_mqpath m WITH(NOLOCK) where p.mqpathid=m.id "; string countSql = "SELECT COUNT(1) FROM tb_producter p WITH(NOLOCK),tb_mqpath m WITH(NOLOCK) where p.mqpathid=m.id " + where; object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { tb_producterview_model model = new tb_producterview_model(); model.ProducterModel = CreateModel(dr); model.mqpath = Convert.ToString(dr["mqpath"]); list.Add(model); } } return(list); }); count = tempCount; return(result); }
public int GetNonProductCount(DbConn conn, int mqPathId, int sec) { return(SqlHelper.Visit((ps) => { string sql = string.Format("SELECT COUNT(1) FROM tb_producter WITH(NOLOCK) WHERE mqpathid=@mqpathid AND datediff(s,lastheartbeat,getdate())>={0}", sec); ps.Add("@mqpathid", mqPathId); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); if (obj != DBNull.Value && obj != null) { return LibConvert.ObjToInt(obj); } return 0; })); }
public int GetLogoutConsumerCount(DbConn conn, int mqpathId) { return(SqlHelper.Visit((ps) => { string sql = "SELECT COUNT(p.consumerclientid) FROM tb_consumer_partition p WITH(NOLOCK),tb_mqpath_partition m WITH(NOLOCK) where p.partitionid=m.partitionid and m.mqpathid=@mqpathid and p.lastconsumertempid not in (select distinct(lastconsumertempid) from tb_consumer WITH(NOLOCK))"; ps.Add("@mqpathid", mqpathId); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); if (obj != DBNull.Value && obj != null) { return LibConvert.ObjToInt(obj); } return 0; })); }
/// <summary> /// 获取消息的数量 /// </summary> /// <param name="conn"></param> /// <param name="tableName"></param> /// <param name="state"></param> /// <returns></returns> public int GetMsgCount(DbConn conn, string tableName, int state) { return(SqlHelper.Visit((ps) => { string sql = string.Format("SELECT COUNT(1) FROM {0} WITH(NOLOCK) WHERE state=@state", tableName); ps.Add("@state", state); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); if (obj != DBNull.Value && obj != null) { return LibConvert.ObjToInt(obj); } return 0; })); }
public int GetMaxPartitionIndex(DbConn conn, int mqpathid) { return(SqlHelper.Visit((ps) => { string sql = "select max(partitionindex) from tb_mqpath_partition p1 WITH(NOLOCK) where p1.mqpathid=@mqpathid"; ps.Add("mqpathid", mqpathid); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); if (obj != DBNull.Value && obj != null) { return LibConvert.ObjToInt(obj); } return 0; })); }
public override int GetIdentity() { DataSet ds = new DataSet(); SqlToDataSet(ds, "select @@identity", null); if (ds.Tables[0].Rows.Count == 0) { return(0); } else { return(LibConvert.ObjToInt(ds.Tables[0].Rows[0][0])); } }
public IList <MqPathModel> GetPageList(DbConn conn, string mqpathid, string mqpath, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <MqPathModel> list = new List <MqPathModel>(); MqPathModel createM = new MqPathModel(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder(" WHERE 1=1"); if (!string.IsNullOrEmpty(mqpath)) { where.AppendFormat(" AND mqpath LIKE '%{0}%'", mqpath); } if (!string.IsNullOrEmpty(mqpathid)) { where.AppendFormat(" AND id = '{0}'", mqpathid); } string sql = "SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS rownum,* FROM tb_mqpath WITH(NOLOCK)"; string countSql = "SELECT COUNT(1) FROM tb_mqpath WITH(NOLOCK)" + where; object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") as t WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { MqPathModel model = createM.CreateModel(dr); model.ProductCount = proDal.GetProductCount(conn, model.id, XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.SystemParamConfig.Producter_HeatBeat_Every_Time); model.NonProductCount = proDal.GetNonProductCount(conn, model.id, XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.SystemParamConfig.Producter_HeatBeat_Every_Time); model.Connsumer = new tb_consumer_partition_dal().GetActiveConsumerCount(conn, model.id); model.NonConnsumer = new tb_consumer_partition_dal().GetLogoutConsumerCount(conn, model.id); model.Partition = parDal.GetPartitionCountByState(conn, (int)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMqPathPartitionState.Running, model.id); model.NonPartition = parDal.GetPartitionCountByState(conn, (int)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMqPathPartitionState.WaitConsumeCompleted, model.id); list.Add(model); } } return(list); }); count = tempCount; return(result); }
public IList <MqPathPartitionModel> GetPageList(DbConn conn, string mqPathid, string partitionId, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <MqPathPartitionModel> list = new List <MqPathPartitionModel>(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder(""); if (!string.IsNullOrWhiteSpace(mqPathid)) { if (!mqPathid.isint()) { where.AppendFormat(" AND m.mqpath like '%'+'{0}'+'%'", mqPathid); } else { where.AppendFormat(" AND m.id ='{0}'", mqPathid); } } if (!string.IsNullOrWhiteSpace(partitionId)) { where.AppendFormat(" AND p.partitionId={0}", partitionId); } string sql = "SELECT ROW_NUMBER() OVER(ORDER BY p.mqpathid DESC,p.[partitionindex] desc) AS rownum,p.*,m.mqpath,(select max(partitionindex) from tb_mqpath_partition p1 where p.mqpathid=p1.mqpathid) as maxpartitionindex FROM tb_mqpath_partition p WITH(NOLOCK),tb_mqpath m with(nolock) where p.mqpathid=m.id"; string countSql = "SELECT COUNT(1) FROM tb_mqpath_partition p WITH(NOLOCK),tb_mqpath m with(nolock) where p.mqpathid=m.id" + where.ToString(); object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { MqPathPartitionModel m = new MqPathPartitionModel(); m.mqpath_partition_model = CreateModel(dr); m.mqpath = Convert.ToString(dr["mqpath"]); m.maxpartitionindex = Convert.ToInt32(dr["maxpartitionindex"]); list.Add(m); } } return(list); }); count = tempCount; return(result); }
public static string DataNodeParConn(string node) { using (DbConn conn = DbConfig.CreateConn(DataConfig.MqManage)) { conn.Open(); tb_datanode_model model = nodeDal.GetModelByPartitionId(conn, LibConvert.ObjToInt(node)); if (model != null) { //string configNodeConn = ConfigConn("DataNodeConnectString"); return(string.Format("server={0};Initial Catalog=dyd_bs_MQ_datanode_{1};User ID={2};Password={3};", model.serverip, XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.PartitionNameRule(LibConvert.ObjToInt(node)) , model.username, model.password)); } return(""); } }
public int SetState(DbConn conn, int partitionid, int state) { return(SqlHelper.Visit((ps) => { string sql = "update tb_mqpath_partition set state=@state WHERE partitionid=@partitionid"; ps.Add("partitionid", partitionid); ps.Add("state", state); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); if (obj != DBNull.Value && obj != null) { return LibConvert.ObjToInt(obj); } return 0; })); }
public int GetPartitionCountByState(DbConn conn, int state, int mqPathId) { return(SqlHelper.Visit((ps) => { string sql = "select COUNT(1) from tb_mqpath_partition WITH(NOLOCK),tb_partition WITH(NOLOCK) where tb_partition.partitionid=tb_mqpath_partition.partitionid and tb_mqpath_partition.state=@state and mqpathid=@mqpathId"; ps.Add("mqpathId", mqPathId); ps.Add("state", state); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); if (obj != DBNull.Value && obj != null) { return LibConvert.ObjToInt(obj); } return 0; })); }
public int GetMaxCommandID(DbConn PubConn) { return(SqlHelper.Visit(ps => { StringBuilder stringSql = new StringBuilder(); stringSql.Append(@"select max(id) from tb_command s where s.commandstate=2"); DataSet ds = new DataSet(); PubConn.SqlToDataSet(ds, stringSql.ToString(), ps.ToParameters()); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { if (!LibConvert.IsDbNull(ds.Tables[0].Rows[0][0])) { return LibConvert.ObjToInt(ds.Tables[0].Rows[0][0]); } } return 0; })); }
/// <summary> /// 根据node节点获取分区节点 /// </summary> /// <param name="conn"></param> /// <param name="nodeId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="count"></param> /// <returns></returns> public IList <tb_partition_model> GetPageList(DbConn conn, string partitionid, int nodeId, int used, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <tb_partition_model> list = new List <tb_partition_model>(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder(" WHERE 1=1 "); string sql = "SELECT ROW_NUMBER() OVER(ORDER BY createtime DESC) AS rownum,* FROM tb_partition WITH(NOLOCK)"; if (nodeId > 0) { string partitionId = this.GetNodePartition(nodeId); where.AppendFormat("AND partitionid LIKE '{0}%' ", partitionId); } if (used >= 0) { where.AppendFormat("AND isused = '{0}' ", used); } if (!string.IsNullOrWhiteSpace(partitionid)) { where.AppendFormat("AND partitionid = '{0}' ", partitionid); } string countSql = string.Concat("SELECT COUNT(1) FROM tb_partition WITH(NOLOCK)", where); object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { tb_partition_model model = CreateModel(dr); list.Add(model); } } return(list); }); count = tempCount; return(result); }
/// <summary> /// 获取所有节点 /// </summary> /// <param name="conn"></param> /// <returns></returns> public IList <string> GetNodeList(DbConn conn) { return(SqlHelper.Visit((ps) => { string sql = "SELECT datanodepartition FROM tb_datanode WITH(NOLOCK) ORDER BY datanodepartition"; IList <string> list = new List <string>(); DataTable dt = conn.SqlToDataTable(sql, null); string temp = string.Empty; if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { int node = LibConvert.ObjToInt(dr["datanodepartition"]); list.Add(XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.PartitionNameRule(node)); } } return list; })); }
public static TaskModel CreateModel(DataRow dr) { TaskModel model = new TaskModel(); if (dr.Table.Columns.Contains("Id")) { model.Id = LibConvert.ObjToInt64(dr["Id"]); } if (dr.Table.Columns.Contains("TaskName")) { model.TaskName = LibConvert.ObjToStr(dr["TaskName"]); } if (dr.Table.Columns.Contains("TaskDescription")) { model.TaskDescription = LibConvert.ObjToStr(dr["TaskDescription"]); } if (dr.Table.Columns.Contains("CategoryId")) { model.CategoryId = LibConvert.ObjToInt64(dr["CategoryId"]); } if (dr.Table.Columns.Contains("NodeId")) { model.NodeId = LibConvert.ObjToInt64(dr["NodeId"]); } if (dr.Table.Columns.Contains("TaskCreateTime")) { model.TaskCreateTime = LibConvert.ObjToDateTime(dr["TaskCreateTime"]); } if (dr.Table.Columns.Contains("TaskUpdateTime")) { model.TaskUpdateTime = LibConvert.ObjToDateTimeOrNull(dr["TaskUpdateTime"]); } if (dr.Table.Columns.Contains("TaskStartTime")) { model.TaskStartTime = LibConvert.ObjToDateTimeOrNull(dr["TaskStartTime"]); } if (dr.Table.Columns.Contains("TaskStopTime")) { model.TaskStopTime = LibConvert.ObjToDateTimeOrNull(dr["TaskStopTime"]); } if (dr.Table.Columns.Contains("TaskCron")) { model.TaskCron = LibConvert.ObjToStr(dr["TaskCron"]); } if (dr.Table.Columns.Contains("TaskState")) { model.TaskState = LibConvert.ObjToInt(dr["TaskState"]); } if (dr.Table.Columns.Contains("TaskClassPath")) { model.TaskClassPath = LibConvert.ObjToStr(dr["TaskClassPath"]); } if (dr.Table.Columns.Contains("TaskFileName")) { model.TaskFileName = LibConvert.ObjToStr(dr["TaskFileName"]); } if (dr.Table.Columns.Contains("TaskClassNamespace")) { model.TaskClassNamespace = LibConvert.ObjToStr(dr["TaskClassNamespace"]); } return(model); }
//static DbPartitionConfigHelper() //{ // try // { // //注册缓存刷新回调和初始化缓存 // var data = RefreashDbPartitionConfigCache(); // bool r = Cache.CacheFileProvider.Register(cachekey, new Cache.CacheFileInfo { IintervalTime = 1000 * 5, CacheData = data, RefreashMethod = DbPartitionConfigHelper.RefreashDbPartitionConfigCache }); // if (r == false) // { // ErrorLog.Write("注册db分区配置缓存失败", null); // } // } // catch (Exception exp) // { // ErrorLog.Write("注册db分区配置出错", exp); // } //} /// <summary> /// 刷新数据从数据库 /// </summary> /// <returns></returns> private static List <tb_dbpartition_config_model> RefreshData(DateTime lastRefeshTime) { List <Model.tb_dbpartition_config_model> tbDbpartitions = new List <tb_dbpartition_config_model>(); var isEnabledDepotsConnectByConfig = XXF.Common.XXFConfig.IsEnabledDepotsConnectByConfig; if (string.IsNullOrWhiteSpace(isEnabledDepotsConnectByConfig) || isEnabledDepotsConnectByConfig.ToLower() == "false") { using (var conn = Db.DbConn.CreateConn(DbType.SQLSERVER, XXF.Common.XXFConfig.ConfigConnectString)) { conn.Open(); tbDbpartitions = new Dal.tb_dbpartition_config_dal().Get(conn, lastRefeshTime); } } else { var alldepotsconfig = System.Configuration.ConfigurationManager.AppSettings.AllKeys.Where(o => o.Contains("DepotsConnect")).ToList(); foreach (var variable in alldepotsconfig) { tb_dbpartition_config_model tbDbpartition = new tb_dbpartition_config_model(); var thisvale = System.Configuration.ConfigurationManager.AppSettings[variable]; tbDbpartition.partitionno = LibConvert.ObjToInt(variable.Split('_')[1]); tbDbpartition.partitiontype = tbDbpartition.partitionno == 1 ? (byte)1 : (byte)2; var arrys = thisvale.Split(';'); foreach (var arry in arrys) { var eachs = arry.Split('='); switch (eachs[0]) { case "server": tbDbpartition.dbserver = eachs[1]; break; case "Initial Catalog": tbDbpartition.dbname = eachs[1]; break; case "User ID": tbDbpartition.dbuser = eachs[1]; break; case "Password": tbDbpartition.dbpass = eachs[1]; break; } } tbDbpartitions.Add(tbDbpartition); } } if (configData == null) { configData = new Dictionary <string, tb_dbpartition_config_model>(); } foreach (var m in tbDbpartitions) { string dicKey = GetDicKey(m.id.ToString()); if (m.isDel) { configData.Remove(dicKey); } else { if (configData.ContainsKey(dicKey)) { configData[dicKey] = m; } else { configData.Add(dicKey, m); } } } List <tb_dbpartition_config_model> data = new List <tb_dbpartition_config_model>(configData.Values); return(data); }
public IList <RegisterdConsumersModel> GetPageList2(DbConn conn, string partitionid, string consumerclientid, string mqpathid, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <RegisterdConsumersModel> list = new List <RegisterdConsumersModel>(); ConsumerModel cm = new ConsumerModel(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder(" WHERE 1=1 "); if (!string.IsNullOrEmpty(consumerclientid)) { if (!consumerclientid.isint()) { where.AppendFormat(" AND (c.client LIKE '%{0}%')", consumerclientid); } else { where.AppendFormat(" AND (c.id = '{0}')", consumerclientid); } } if (!string.IsNullOrEmpty(partitionid)) { where.AppendFormat(" AND (p.partitionid='{0}')", partitionid); } if (!string.IsNullOrEmpty(mqpathid)) { if (!mqpathid.isint()) { where.AppendFormat(" AND (m.mqpath like '%{0}%')", mqpathid); } else { where.AppendFormat(" AND (m.id='{0}')", mqpathid); } } string sql = @"SELECT ROW_NUMBER() OVER(ORDER BY p.consumerclientid DESC,p.partitionindex desc) AS rownum, s.id as tb_consumer_id,tempid as tb_consumer_tempid,s.consumerclientid as tb_consumer_consumerclientid,s.partitionindexs as tb_consumer_partitionindexs ,s.clientname as tb_consumer_clientname,s.lastheartbeat as tb_consumer_lastheartbeat,s.lastupdatetime as tb_consumer_lastupdatetime,s.createtime as tb_consumer_createtime, c.id as tb_consumer_client_id, c.client as tb_consumer_client_client,c.createtime as tb_consumer_client_createtime, p.id as tb_consumer_partition_id,p.consumerclientid as tb_consumer_partition_consumerclientid ,p.partitionindex as tb_consumer_partition_partitionindex,p.partitionid as tb_consumer_partition_partitionid,p.lastconsumertempid as tb_consumer_partition_lastconsumertempid,p.lastmqid as tb_consumer_partition_lastmqid ,p.lastupdatetime as tb_consumer_partition_lastupdatetime,p.createtime as tb_consumer_partition_createtime,m.mqpath as tb_mqpath_mqpath,m.id as tb_mqpath_id from tb_consumer_partition p WITH(NOLOCK) left join tb_consumer s WITH(NOLOCK) on s.tempid=p.lastconsumertempid left join tb_consumer_client c WITH(NOLOCK) on p.consumerclientid=c.id left join tb_mqpath_partition mp with (nolock) on mp.partitionid=p.partitionid left join tb_mqpath m with (nolock) on m.id=mp.mqpathid "; string countSql = "SELECT COUNT(p.id) from tb_consumer_partition p WITH(NOLOCK) left join tb_consumer s WITH(NOLOCK) on s.tempid=p.lastconsumertempid left join tb_consumer_client c WITH(NOLOCK) on p.consumerclientid=c.id left join tb_mqpath_partition mp with (nolock) on mp.partitionid=p.partitionid left join tb_mqpath m with (nolock) on m.id=mp.mqpathid " + where.ToString(); object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { RegisterdConsumersModel model = new RegisterdConsumersModel(dr); model.msgCount = reportDal.GetMsgCount(conn, model.consumerpartitionmodel.lastmqid); model.nonMsgCount = reportDal.GetNonMsgCount(conn, model.consumerpartitionmodel.lastmqid); model.mqpath = dr["tb_mqpath_mqpath"].Tostring(); model.mqpathid = dr["tb_mqpath_id"].Toint(); list.Add(model); } } return(list); }); count = tempCount; return(result); }
public IList <ConsumerModel> GetPageList(DbConn conn, string name, int pageIndex, int pageSize, ref int count) { int tempCount = 0; IList <ConsumerModel> list = new List <ConsumerModel>(); ConsumerModel cm = new ConsumerModel(); var result = SqlHelper.Visit((ps) => { StringBuilder where = new StringBuilder(" WHERE 1=1 "); if (!string.IsNullOrEmpty(name)) { where.AppendFormat(" AND clientname LIKE '%{0}%'", name); } string sql = "SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS rownum,* FROM tb_consumer WITH(NOLOCK)"; string countSql = "SELECT COUNT(1) FROM tb_consumer WITH(NOLOCK) " + where.ToString(); object obj = conn.ExecuteScalar(countSql, null); if (obj != DBNull.Value && obj != null) { tempCount = LibConvert.ObjToInt(obj); } string sqlPage = string.Concat("SELECT * FROM (", sql.ToString(), where.ToString(), ") A WHERE rownum BETWEEN ", ((pageIndex - 1) * pageSize + 1), " AND ", pageSize * pageIndex); DataTable dt = conn.SqlToDataTable(sqlPage, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { ConsumerModel model = cm.CreateModel(dr); IList <tb_consumer_partition_model> consumerList = partitionDal.GetPartitionByConsumerId(conn, model.consumerclientid); if (consumerList != null && consumerList.Count > 0) { IList <ConsumerPartition> partitionList = new List <ConsumerPartition>(); foreach (var item in consumerList) { ConsumerPartition m = new ConsumerPartition(); m.PartitionId = item.partitionid; PartitionIDInfo partitionInfo = PartitionRuleHelper.GetPartitionIDInfo(item.partitionid); string node = string.Empty; if (partitionInfo.DataNodePartition < 10) { node = "0" + partitionInfo.DataNodePartition.Tostring(); } else { node = partitionInfo.DataNodePartition.Tostring(); } using (DbConn nodeConn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node))) { nodeConn.Open(); tb_partition_model partitionModel = new tb_partition_dal().Get(conn, item.partitionid); if (partitionModel != null) { m.IsOnline = partitionModel.isused; } string table = msgDal.GetMaxMqTable(nodeConn, node); m.Msg = msgDal.GetMsgCount(nodeConn, table, 0); m.NonMsg = msgDal.GetMsgCount(nodeConn, table, 1); partitionList.Add(m); } } model.PartitionList = partitionList; } list.Add(model); } } return(list); }); count = tempCount; return(result); }