/// <summary> /// 取得已消费的数量 /// </summary> /// <param name="conn"></param> /// <param name="lastMqId"></param> /// <returns></returns> public long GetMsgCount(DbConn conn, long lastMqId) { return(SqlHelper.Visit((ps) => { MQIDInfo info = PartitionRuleHelper.GetMQIDInfo(lastMqId); string sql = "SELECT SUM(mqcount) FROM [tb_partition_messagequeue_report] WITH(NOLOCK) WHERE [day]<@day AND partitionid=@partitionid"; ps.Add("@day", info.Day); ps.Add("@partitionid", PartitionRuleHelper.GetPartitionID(new PartitionIDInfo() { DataNodePartition = info.DataNodePartition, TablePartition = info.TablePartition })); string tableName = PartitionRuleHelper.GetTableName(info.TablePartition, info.Day); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); long msgCount = 0; if (obj != DBNull.Value && obj != null) { msgCount = LibConvert.ObjToInt64(obj); } long lastCount = 0; using (DbConn nodeConn = DbConfig.CreateConn(DataConfig.DataNodeParConn(PartitionRuleHelper.PartitionNameRule(info.DataNodePartition)))) { nodeConn.Open(); var dal = new tb_messagequeue_dal(); dal.TableName = tableName; lastCount = dal.GetLastDayMsgCount(nodeConn, lastMqId); } return msgCount + lastCount; })); }
/// <summary> /// 取得未消费的数量 /// </summary> /// <param name="lastMqId"></param> /// <returns></returns> public long GetNonMsgCount(DbConn conn, long lastMqId) { return(SqlHelper.Visit((ps) => { MQIDInfo info = PartitionRuleHelper.GetMQIDInfo(lastMqId); var currentday = conn.GetServerDate().Date; string sql = "SELECT SUM(mqcount) FROM [tb_partition_messagequeue_report] WITH(NOLOCK) WHERE [day]>@day AND partitionid=@partitionid AND [day]<>@currentday"; ps.Add("@day", info.Day); ps.Add("@currentday", currentday); ps.Add("@partitionid", PartitionRuleHelper.GetPartitionID(new PartitionIDInfo() { DataNodePartition = info.DataNodePartition, TablePartition = info.TablePartition })); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); long msgCount = 0; if (obj != DBNull.Value && obj != null) { msgCount = LibConvert.ObjToInt64(obj); } long firstCount = 0; long lastCount = 0; using (DbConn nodeConn = DbConfig.CreateConn(DataConfig.DataNodeParConn(PartitionRuleHelper.PartitionNameRule(info.DataNodePartition)))) { nodeConn.Open(); string firsttableName = PartitionRuleHelper.GetTableName(info.TablePartition, info.Day); var msgDal = new tb_messagequeue_dal(); msgDal.TableName = firsttableName; firstCount = msgDal.GetLastDayNonMsgCount(nodeConn, lastMqId); if (info.Day != currentday)//不是今天 { string lasttableName = PartitionRuleHelper.GetTableName(info.TablePartition, currentday); var dal = new tb_messagequeue_dal(); dal.TableName = lasttableName; long maxmqid = dal.GetMaxID(nodeConn); if (lastMqId == 0) { lastCount = 0; } else { lastCount = dal.GetLastDayMsgCount(nodeConn, maxmqid); } } } //最后一天剩余 return msgCount + firstCount + lastCount; })); }
/// <summary> /// 取得已消费的数量 /// </summary> /// <param name="conn"></param> /// <param name="lastMqId"></param> /// <returns></returns> public long GetMsgCount(DbConn conn, long lastMqId) { return SqlHelper.Visit((ps) => { MQIDInfo info = PartitionRuleHelper.GetMQIDInfo(lastMqId); string sql = "SELECT SUM(mqcount) FROM [tb_partition_messagequeue_report] WITH(NOLOCK) WHERE [day]<@day AND partitionid=@partitionid"; ps.Add("@day", info.Day); ps.Add("@partitionid", PartitionRuleHelper.GetPartitionID(new PartitionIDInfo() { DataNodePartition = info.DataNodePartition, TablePartition = info.TablePartition })); string tableName = PartitionRuleHelper.GetTableName(info.TablePartition, info.Day); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); long msgCount = 0; if (obj != DBNull.Value && obj != null) { msgCount = LibConvert.ObjToInt64(obj); } long lastCount = 0; using (DbConn nodeConn = DbConfig.CreateConn(DataConfig.DataNodeParConn(PartitionRuleHelper.PartitionNameRule(info.DataNodePartition)))) { nodeConn.Open(); var dal = new tb_messagequeue_dal(); dal.TableName = tableName; lastCount = dal.GetLastDayMsgCount(nodeConn, lastMqId); } return msgCount + lastCount; }); }
/// <summary> /// 取得未消费的数量 /// </summary> /// <param name="lastMqId"></param> /// <returns></returns> public long GetNonMsgCount(DbConn conn, long lastMqId) { return SqlHelper.Visit((ps) => { MQIDInfo info = PartitionRuleHelper.GetMQIDInfo(lastMqId); var currentday = conn.GetServerDate().Date; string sql = "SELECT SUM(mqcount) FROM [tb_partition_messagequeue_report] WITH(NOLOCK) WHERE [day]>@day AND partitionid=@partitionid AND [day]<>@currentday"; ps.Add("@day", info.Day); ps.Add("@currentday", currentday); ps.Add("@partitionid", PartitionRuleHelper.GetPartitionID(new PartitionIDInfo() { DataNodePartition = info.DataNodePartition, TablePartition = info.TablePartition })); object obj = conn.ExecuteScalar(sql, ps.ToParameters()); long msgCount = 0; if (obj != DBNull.Value && obj != null) { msgCount = LibConvert.ObjToInt64(obj); } long firstCount = 0; long lastCount = 0; using (DbConn nodeConn = DbConfig.CreateConn(DataConfig.DataNodeParConn(PartitionRuleHelper.PartitionNameRule(info.DataNodePartition)))) { nodeConn.Open(); string firsttableName = PartitionRuleHelper.GetTableName(info.TablePartition, info.Day); var msgDal = new tb_messagequeue_dal(); msgDal.TableName = firsttableName; firstCount = msgDal.GetLastDayNonMsgCount(nodeConn, lastMqId); if (info.Day != currentday)//不是今天 { string lasttableName = PartitionRuleHelper.GetTableName(info.TablePartition, currentday); var dal = new tb_messagequeue_dal(); dal.TableName = lasttableName; long maxmqid = dal.GetMaxID(nodeConn); if (lastMqId == 0) lastCount = 0; else lastCount = dal.GetLastDayMsgCount(nodeConn, maxmqid); } } //最后一天剩余 return msgCount + firstCount + lastCount; }); }