Esempio n. 1
0
        public ActionResult Detail(SeeAboutModel model, string code = "", int pageid = 1)
        {
            List <IMongoQuery> queries = new List <IMongoQuery>();

            queries.Add(Query.EQ("interface_code", new BsonString(code)));
            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.serviceno_uid))
                {
                    queries.Add(Query.EQ("serviceno_uid", new BsonString(model.serviceno_uid)));
                }
                if (!string.IsNullOrEmpty(model.visited_time))
                {
                    queries.Add(Query.GTE("visited_time", CUtil.CDate(model.visited_time)));
                }
            }
            else
            {
                model = new SeeAboutModel();
            }
            ViewBag.seeAboutModel = model;
            ViewBag.Code          = code;
            var serachResult = mongoh.GetCollection <ModUApiUseLogFind>().FindByAnd(queries)
                               .MOrderByDescending(m => m.visited_time).MToPagedList(pageid, 10);

            return(View(serachResult));
        }
        public ActionResult ToExcel(string servicenouid = "", string visitedtime = "")
        {
            if (string.IsNullOrEmpty(servicenouid))
            {
                return(Content(Util.JsHistoryBack("请输入频道账号")));
            }
            List <IMongoQuery> queries = new List <IMongoQuery>();

            queries.Add(Query.NE("", new BsonString("")));
            if (!string.IsNullOrEmpty(servicenouid))
            {
                queries.Add(Query.EQ("serviceno_uid", new BsonString(servicenouid)));
            }
            if (!string.IsNullOrEmpty(visitedtime))
            {
                queries.Add(Query.GTE("visited_time", CUtil.CDate(visitedtime)));
            }
            var modUApiUseLogFindList = mongoh.GetCollection <ModUApiUseLogFind>().FindByAnd(queries)
                                        .MOrderByDescending(m => m.visited_time).ToList();

            #region 赋值datatable
            DataTable dt = new DataTable();
            dt.Columns.Add("频道账号", typeof(string));
            dt.Columns.Add("接口名称", typeof(string));
            dt.Columns.Add("查询参数", typeof(string));
            dt.Columns.Add("访问时间", typeof(string));
            dt.Columns.Add("访问IP", typeof(string));
            foreach (var item in modUApiUseLogFindList)
            {
                DataRow dr = dt.NewRow();
                dr[0] = item.serviceno_uid;
                dr[1] = item.interface_code;
                dr[2] = item.request_data;
                dr[3] = item.visited_time;
                dr[4] = item.visited_ip;
                dt.Rows.Add(dr);
            }
            int totalCount = 0;
            int theMonth   = 0;
            int thetoday   = 0;
            TimeCount(ref totalCount, ref theMonth, ref thetoday, modUApiUseLogFindList);
            DataRow drs = dt.NewRow();
            drs[0] = " 合计  " + totalCount;
            drs[1] = "  本月调用次数 " + theMonth;
            drs[2] = "  今日调用次数 " + thetoday;
            dt.Rows.Add(drs);
            #endregion
            string pathfile = Request.PhysicalApplicationPath + "UploadFiles";
            if (!System.IO.Directory.Exists(pathfile))
            {
                System.IO.Directory.CreateDirectory(pathfile);
            }
            string ExcelNpoiUtil_Name = "频道账号调用统计_" + DateTime.Now.ToString("hhmmss");

            ExcelNpoiUtil.ExportExcel(dt, Server.MapPath("~/UploadFiles/") + "" + ExcelNpoiUtil_Name + "" + ".xls", false);
            return(Content(Util.JsHistoryBack("已下载")));
        }
        //
        // GET: /DownCount/
        public ActionResult Index(SeeAboutModel model, int pageid = 1)
        {
            List <IMongoQuery> queries = new List <IMongoQuery>();

            queries.Add(Query.NE("", new BsonString("")));
            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.serviceno_uid))
                {
                    queries.Add(Query.EQ("serviceno_uid", new BsonString(model.serviceno_uid)));
                }
                if (!string.IsNullOrEmpty(model.visited_time))
                {
                    queries.Add(Query.GTE("visited_time", CUtil.CDate(model.visited_time)));
                }
            }
            else
            {
                model = new SeeAboutModel();
            }
            ViewBag.SearchCondtion = model;
            var serachResult = mongoh.GetCollection <ModUApiUseLogFind>().FindByAnd(queries)
                               .MOrderByDescending(m => m.visited_time).MToPagedList(pageid, 20);
            int    totalCount         = 0;
            int    theMonth           = 0;
            int    thetoday           = 0;
            string serviceno_uid_name = "";

            if (!string.IsNullOrEmpty(model.serviceno_uid))//仅限于某个频道号的统计
            {
                List <IMongoQuery> newqueries = new List <IMongoQuery>();
                newqueries.Add(Query.EQ("serviceno_uid", new BsonString(model.serviceno_uid)));
                var newserachResult = mongoh.GetCollection <ModUApiUseLogFind>().FindByAnd(newqueries).ToList();
                TimeCount(ref totalCount, ref theMonth, ref thetoday, newserachResult);
                serviceno_uid_name = model.serviceno_uid;
            }
            ViewBag.TotalCount       = totalCount;
            ViewBag.TheMonth         = theMonth;
            ViewBag.Thetoday         = thetoday;
            ViewBag.ServicenoUidName = serviceno_uid_name;
            return(View(serachResult));
        }
Esempio n. 4
0
        //
        // GET: /Counter/

        /*用户使用接口次数统计
         *查询接口日志记录表,已记录每个接口的访问信息
         */
        public ActionResult Index(FormCollection form)
        {
            string interfacecode = form["interface_code"] ?? "";
            MongoCollection <ModUApiInterfaceList> uapinter = mongoh.GetCollection <ModUApiInterfaceList>();

            #region 统计当月,今日,合计调用次数
            DateTime      MonthlyFirstDate = DateTime.Parse(DateTime.Today.ToString("yyyy-MM-01"));
            List <object> objarray         = new List <object>();
            objarray.Add("$visited_time");
            objarray.Add(new BsonDateTime(MonthlyFirstDate));
            DateTime      TodayFirstDate = DateTime.Parse(DateTime.Today.ToString("yyyy-MM-dd"));
            List <object> objarrayToday  = new List <object>();
            objarrayToday.Add("$visited_time");
            objarrayToday.Add(new BsonDateTime(TodayFirstDate));
            BsonDocument group = new BsonDocument
            {
                {
                    "$group", new BsonDocument {
                        {
                            "_id", "$interface_code"
                        },
                        {
                            "MonthlyNum", new BsonDocument {
                                {
                                    "$sum", new BsonDocument {
                                        {
                                            "$cond", new BsonDocument
                                            {
                                                {
                                                    "if", new BsonDocument("$gte", new BsonArray(objarray.ToArray()))
                                                }
                                                ,
                                                { "then", 1 }
                                                ,
                                                { "else", 0 }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        {
                            "TodayNum", new BsonDocument {
                                {
                                    "$sum", new BsonDocument {
                                        {
                                            "$cond", new BsonDocument
                                            {
                                                {
                                                    "if", new BsonDocument("$gte", new BsonArray(objarrayToday.ToArray()))
                                                }
                                                ,
                                                { "then", 1 }
                                                ,
                                                { "else", 0 }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        {
                            "TotalNum", new BsonDocument {
                                {
                                    "$sum", 1
                                }
                            }
                        }
                    }
                }
            };
            #endregion
            AggregateArgs args = new AggregateArgs();
            args.Pipeline = new List <BsonDocument> {
                group
            };
            var bsonDocumentlist = mongoh.GetCollection <ModUApiUseLogFind>().Aggregate(args).ToList();
            if (string.IsNullOrEmpty(interfacecode))
            {
                foreach (var item in bsonDocumentlist)
                {
                    interfacecode = item["_id"].ToString();
                    break;
                }
            }
            #region 统计本周流程图
            DateTime           dt        = DateTime.Now;
            DateTime           starweek  = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")));
            string             endtime   = dt.ToString("yyyy-MM-dd 23:59:59");
            string             begintime = starweek.ToString("yyyy-MM-dd 00:00:00");
            List <IMongoQuery> queries   = new List <IMongoQuery>();
            if (!string.IsNullOrEmpty(interfacecode))
            {
                queries.Add(Query.EQ("interface_code", new BsonString(interfacecode)));
            }
            queries.Add(Query.GTE("visited_time", CUtil.CDate(begintime)));
            queries.Add(Query.LTE("visited_time", CUtil.CDate(endtime)));
            var serachResult = mongoh.GetCollection <ModUApiUseLogFind>().FindByAnd(queries).ToList();
            var curveChart   = (from b in serachResult
                                orderby b.visited_time
                                group b by b.visited_time.Date into b
                                select new CurveChart
            {
                amount = b.Count().ToString(),
                date = b.Key
            }).ToList();
            string amount = "";
            string date   = "";
            if (curveChart.Count > 0)
            {
                foreach (var item in curveChart)
                {
                    amount += item.amount + ",";
                    date   += item.date.ToString("yyyyMMdd") + ",";
                }
            }
            amount = amount.TrimEnd(',');
            #endregion
            ViewBag.BsonDocumentlist     = bsonDocumentlist;
            ViewBag.interfacecode        = interfacecode;
            ViewBag.ModUApiInterfaceList = uapinter.FindAll().ToList();
            ViewBag.Amount = amount;
            ViewBag.Date   = date;
            return(View());
        }