コード例 #1
0
        public ActionResult Index(string node = "", string tablepartition = "", string daypartition = "", string mqid = "", bool isclick = false, int pageIndex = 1, int pageSize = 30)
        {
            ViewBag.mqid           = mqid;
            ViewBag.node           = node;
            ViewBag.tablepartition = tablepartition; ViewBag.daypartition = daypartition; ViewBag.isclick = isclick;
            int count = 0;
            IList <tb_messagequeue_model>     list     = new List <tb_messagequeue_model>();
            PagedList <tb_messagequeue_model> pageList = new PagedList <tb_messagequeue_model>(list, pageIndex, pageSize, count);

            if (!string.IsNullOrWhiteSpace(node))
            {
                using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
                {
                    conn.Open();
                    string tablename        = PartitionRuleHelper.GetTableName(Convert.ToInt32(tablepartition), DateTime.ParseExact(daypartition, "yyMMdd", CultureInfo.InvariantCulture));
                    tb_messagequeue_dal dal = new tb_messagequeue_dal(); dal.TableName = tablename;
                    list     = dal.GetPageList(conn, pageIndex, pageSize, mqid, ref count);
                    pageList = new PagedList <tb_messagequeue_model>(list, pageIndex, pageSize, count);
                }
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView("List", pageList));
            }
            return(View(pageList));
        }
コード例 #2
0
        public ActionResult Add(tb_messagequeue_model model, string node, string tablepartition, string daypartition)
        {
            DateTime serverdate = DateTime.Now;

            using (DbConn conn = DbConfig.CreateConn(DataConfig.MqManage))
            {
                conn.Open();
                serverdate = conn.GetServerDate();
            }
            using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
            {
                conn.Open();
                model.sqlcreatetime = serverdate;
                model.mqcreatetime  = DateTime.Now;
                string tablename = PartitionRuleHelper.GetTableName(Convert.ToInt32(tablepartition), DateTime.ParseExact(daypartition, "yyMMdd", CultureInfo.InvariantCulture));
                var    dal       = new tb_messagequeue_dal(); dal.TableName = tablename;
                if (dal.Add(conn, tablename, model))
                {
                    return(RedirectToAction("index"));
                }
                else
                {
                    ModelState.AddModelError("Error", "更新错误");
                    return(View(model));
                }
            }
        }
コード例 #3
0
        public ActionResult Update(tb_messagequeue_model model, string node, long id)
        {
            ViewBag.node = node;
            var mqidinfo = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetMQIDInfo(Convert.ToInt64(id));

            ViewBag.tablepartition = mqidinfo.TablePartition; ViewBag.daypartition = mqidinfo.Day.ToString("yyMMdd");
            string tablename = PartitionRuleHelper.GetTableName(mqidinfo.TablePartition, mqidinfo.Day);
            var    dal       = new tb_messagequeue_dal(); dal.TableName = tablename;

            using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
            {
                conn.Open();
                tb_messagequeue_model result = dal.GetModel(conn, id, tablename);
                if (result != null)
                {
                    result.message = model.message;
                    result.state   = model.state;
                    result.source  = model.source;
                    if (dal.Update(conn, result, tablename))
                    {
                        return(RedirectToAction("Index", new { node = node, tablepartition = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.PartitionNameRule(mqidinfo.TablePartition), daypartition = mqidinfo.Day.ToString("yyMMdd"), mqid = id }));
                    }
                }
                ModelState.AddModelError("Error", "更新错误");
                return(View(result));
            }
        }
コード例 #4
0
 public JsonResult GetDayList(string node, string tablepartition)
 {
     try
     {
         string mqpath = "";
         using (DbConn conn = DbConfig.CreateConn(DataConfig.MqManage))
         {
             conn.Open();
             tb_mqpath_dal mqpathdal = new tb_mqpath_dal();
             var           model     = mqpathdal.GetByPartitionID(conn, PartitionRuleHelper.GetPartitionID(new PartitionIDInfo()
             {
                 DataNodePartition = Convert.ToInt32(node), TablePartition = Convert.ToInt32(tablepartition)
             }));
             if (model != null)
             {
                 mqpath = model.mqpath;
             }
         }
         using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
         {
             conn.Open();
             var array = new tb_messagequeue_dal().GetDayPartitions(conn, Convert.ToInt32(tablepartition)).Select(c => c.ToString("yyMMdd")).ToList();
             if (array != null && array.Count > 0)
             {
                 return(Json(new { array, mqpath }, JsonRequestBehavior.AllowGet));
             }
             return(Json("", JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json("", JsonRequestBehavior.AllowGet));
     }
 }
コード例 #5
0
        /// <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;
            }));
        }
コード例 #6
0
 public ActionResult Update(long id, string node)
 {
     using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
     {
         conn.Open();
         ViewBag.node = node;
         var mqidinfo = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetMQIDInfo(Convert.ToInt64(id));
         ViewBag.tablepartition = mqidinfo.TablePartition; ViewBag.daypartition = mqidinfo.Day.ToString("yyMMdd");
         string tablename            = PartitionRuleHelper.GetTableName(mqidinfo.TablePartition, mqidinfo.Day);
         var    dal                  = new tb_messagequeue_dal(); dal.TableName = tablename;
         tb_messagequeue_model model = dal.GetModel(conn, id, tablename);
         return(View(model));
     }
 }
コード例 #7
0
 public ActionResult Delete(long id, string node)
 {
     using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
     {
         conn.Open();
         var    mqidinfo  = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetMQIDInfo(Convert.ToInt64(id));
         string tablename = PartitionRuleHelper.GetTableName(mqidinfo.TablePartition, mqidinfo.Day);
         var    dal       = new tb_messagequeue_dal(); dal.TableName = tablename;
         if (dal.SetState(conn, id, (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMessageState.Deleted))
         {
             return(Json(new { code = 1, msg = "删除成功" }));
         }
         return(Json(new { code = -1, msg = "删除失败" }));
     }
 }
コード例 #8
0
        /// <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;
            }));
        }
コード例 #9
0
 public JsonResult GetPartitionList(string node)
 {
     try
     {
         using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
         {
             conn.Open();
             var array = new tb_messagequeue_dal().GetTablePartitions(conn).Select(c => XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.PartitionNameRule(c)).ToList();
             if (array != null && array.Count > 0)
             {
                 return(Json(array, JsonRequestBehavior.AllowGet));
             }
             return(Json("", JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json("", JsonRequestBehavior.AllowGet));
     }
 }
コード例 #10
0
        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);
        }
コード例 #11
0
 public ActionResult Add(tb_mqpath_partition_model model)
 {
     try
     {
         using (DbConn conn = DbConfig.CreateConn(DataConfig.MqManage))
         {
             try
             {
                 conn.Open();
                 conn.BeginTransaction();
                 model.state          = (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMqPathPartitionState.Running;
                 model.partitionindex = new tb_mqpath_partition_dal().GetMaxPartitionIndexOfMqPath(conn, model.mqpathid) + 1;
                 if (new tb_mqpath_dal().Get(conn, model.mqpathid) == null)
                 {
                     throw new Exception("无法找到队列");
                 }
                 if (new tb_mqpath_partition_dal().GetByPartitionId(conn, model.partitionid) != null)
                 {
                     throw new Exception("分区已被使用");
                 }
                 if (new tb_mqpath_partition_dal().CheckMaxPartitionIndexOfMqPathIsRunning(conn, model.mqpathid) == false)
                 {
                     throw new Exception("最后的分区未处于正常使用状态,若分区正在待删状态,请删除完毕后新增分区。");
                 }
                 if (new tb_mqpath_partition_dal().Add2(conn, model))
                 {
                     new tb_partition_dal().UpdateIsUsed(conn, 1, model.partitionid);
                     var partitioninfo = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetPartitionIDInfo(model.partitionid);
                     //创建3天的表
                     var serverdate = conn.GetServerDate().Date;
                     for (int i = 0; i < 3; i++)
                     {
                         var currentdate = serverdate.AddDays(i);
                         var tablename   = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetTableName(partitioninfo.TablePartition, currentdate);//
                         SqlHelper.ExcuteSql(DataConfig.DataNodeParConn(partitioninfo.DataNodePartition + ""), (c) =>
                         {
                             bool exsit = c.TableIsExist(tablename);
                             if (exsit != true)
                             {
                                 string cmd = DataConfig.MQCreateTableSql.Replace("{tablepartiton}", XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.PartitionNameRule(partitioninfo.TablePartition))
                                              .Replace("{daypartition}", currentdate.ToString("yyMMdd")).Replace("{datanodepartiton}", XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.PartitionNameRule(partitioninfo.DataNodePartition));
                                 c.ExecuteSql(cmd, new List <XXF.Db.ProcedureParameter>());
                             }
                         });
                     }
                     conn.Commit();
                 }
                 else
                 {
                     throw new Exception("更新错误");
                 }
             }
             catch (Exception exp)
             {
                 conn.Rollback();
                 throw exp;
             }
         }
         ReStartQuque(model.mqpathid);
         return(RedirectToAction("index"));
     }
     catch (Exception e)
     {
         ModelState.AddModelError("Error", e.Message);
         return(View(model));
     }
 }