Beispiel #1
0
        //查询访客明细
        public List <VisitorInfo> VisitorDetail(int siteId)
        {
            List <VisitorInfo> list = new List <VisitorInfo>();
            var visitor             = work.CreateRepository <VisitorInfo>().GetPageList(p => p.WebInfo.Id == siteId).ToList();

            return(visitor);
        }
Beispiel #2
0
 public static List <UserInfo> GetUserId(Expression <Func <UserInfo, bool> > where)
 {
     using (WorkOfUnit work = new WorkOfUnit())
     {
         var model = work.CreateRepository <UserInfo>().GetList(where).ToList();
         return(model);
     }
 }
 /// <summary>
 /// 获取所有大类
 /// </summary>
 /// <returns></returns>
 public static List <LgClass> GetAllLg()
 {
     using (WorkOfUnit work = new WorkOfUnit())
     {
         var query = work.CreateRepository <LgClass>().GetList(m => m.Lock == 0).ToList();
         return(query);
     }
 }
 /// <summary>
 /// 根据大类获取小类
 /// </summary>
 /// <param name="lg_Id"></param>
 /// <returns></returns>
 public static List <SmClass> GetSm(int lg_Id)
 {
     using (WorkOfUnit work = new WorkOfUnit())
     {
         var query = work.CreateRepository <SmClass>().GetList(m => m.Lg.Id == lg_Id && m.Lock == 0).ToList();
         return(query);
     }
 }
 /// <summary>
 /// 根据表达式树获取资讯数量
 /// </summary>
 /// <returns></returns>
 public static int GetCountByWhere(Expression <Func <Information, bool> > where)
 {
     using (WorkOfUnit work = new WorkOfUnit())
     {
         var query = work.CreateRepository <Information>().GetList(where).ToList();
         return(query.Count);
     }
 }
Beispiel #6
0
 /// <summary>
 /// 判断用户是否存在
 /// </summary>
 /// <param name="where"></param>
 /// <returns></returns>
 public static int GetNameAndPwdByWhere(Expression <Func <UserInfo, bool> > where)
 {
     using (WorkOfUnit work = new WorkOfUnit())
     {
         //判断用户是否存在
         var model = work.CreateRepository <UserInfo>().GetList(where).ToList();
         return(model.Count);
     }
 }
 public static List <Information> GetMationPageByWhere(
     Expression <Func <Information, bool> > where, string order, int pageIndex, int pageSize)
 {
     using (WorkOfUnit work = new WorkOfUnit())
     {
         var query = work.CreateRepository <Information>().GetPageList(
             where, order: order, pageIndex: pageIndex, pageSize: pageSize).ToList();
         return(query);
     }
 }
        /// <summary>
        /// 根据id删除资讯实体
        /// </summary>
        /// <param name="id"></param>
        public static ReturnInfo DeleteConsultById(int id)
        {
            ReturnInfo    rif = new ReturnInfo();
            StringBuilder sb  = new StringBuilder();

            using (WorkOfUnit work = new WorkOfUnit())
            {
                try
                {
                    //假如存在外键约束则先删除关联数据
                    var img = work.CreateRepository <RmationImg>().GetList(m => m.Information.Id == id);
                    if (img.Count() != 0)
                    {
                        foreach (var item in img)
                        {
                            try
                            {
                                work.CreateRepository <RmationImg>().Delete(item.Id);
                                rif.IsSuccess = work.Save() >= 1;
                            }
                            catch (Exception ex)
                            {
                                item.Lock = 1;
                                work.CreateRepository <RmationImg>().Update(item);
                                rif.IsSuccess = work.Save() >= 1;
                                sb.Append("删除失败" + item.Id + ":" + ex.Message);
                                continue;
                            }
                        }
                    }
                    work.CreateRepository <Information>().Delete(id);
                    rif.IsSuccess = work.Save() >= 1;
                }
                catch (Exception ex)
                {
                    rif.IsSuccess = false;
                    sb.Append(ex.Message);
                }
            }
            rif.ErrorInfo = sb.ToString();
            return(rif);
        }
Beispiel #9
0
        protected void Session_End()
        {
            DateTime startTime, endTime;
            //接受后台传递的Idid = Session["id"].ToString() == null ? 0 : int.Parse(Session["id"].ToString());
            var id = 0;

            id = int.Parse(Session["id"].ToString());
            if (id != 0)
            {
                List <VisitorInfo> list = work.CreateRepository <VisitorInfo>().GetList().ToList();
                var model = list.Where(p => p.Id == int.Parse(id.ToString())).FirstOrDefault();
                int vid   = 0;
                vid                 = model.Id;
                startTime           = model.AccessTime;
                model.AccessEndTime = DateTime.Now;
                endTime             = model.AccessEndTime;
                TimeSpan ts1      = new TimeSpan(startTime.Ticks);
                TimeSpan ts2      = new TimeSpan(endTime.Ticks);
                TimeSpan ts       = ts1.Subtract(ts2).Duration();
                string   aa       = ts.ToString();
                string   H        = aa.Split(':')[0].ToString();
                string   M        = aa.Split(':')[1].ToString();
                string   S        = aa.Split(':')[2].ToString();
                Double   Duration = Double.Parse(H) * 3600 + Double.Parse(M) * 60 + Double.Parse(S);
                model.Duration = Duration;
                work.CreateRepository <VisitorInfo>().Update(model);
                int    sum      = work.CreateRepository <VisitorInfo>().GetCount(m => m.Id != 0);
                double duration = work.CreateRepository <VisitorInfo>().GetCount();
                duration = list.Sum(a => a.Duration);
                work.CreateRepository <VisitorInfo>().Update(model);
                List <WebInfo> weblist = work.CreateRepository <WebInfo>().GetList().ToList();
                var            web     = weblist.Where(p => p.Id == model.WebInfo.Id).FirstOrDefault();
                //平均时长
                double sc = duration / sum;
                //WebPv.WebTS = d         uration / sum;
                web.WebTS = (sc).ToString();
                work.CreateRepository <WebInfo>().Update(web);
                work.Save();
            }
        }
        public IEnumerable <object> Get(string key, string VisitPage, string IpAddress, string Address)
        {
            try
            {
                WebInfo web = work.CreateRepository <WebInfo>().GetFirst(m => m.WebKey == key);
                if (web != null)
                {
                    #region 获取访客信息&添加访客信息
                    //搜索引擎来源
                    var se = System.Web.HttpContext.Current.Request.UserAgent;
                    //获取浏览器信息
                    //火狐浏览器
                    if (se.Contains("Firefox"))
                    {
                        se = "火狐";
                    }
                    //谷歌浏览器
                    else if (se.Contains("Chrome"))
                    {
                        se = "谷歌";
                    }
                    //Safari浏览器(苹果浏览器)
                    else if (se.Contains("Version"))
                    {
                        se = "苹果";
                    }
                    //Opera浏览器
                    else if (se.Contains("Opera"))
                    {
                        se = "Opera";
                    }
                    //LBBROWSER浏览器(猎豹)
                    else if (se.Contains("LBBROWSER"))
                    {
                        se = "猎豹";
                    }
                    //sougou浏览器(sougou)
                    else if (se.Contains("MetaSr"))
                    {
                        se = "搜狗";
                    }
                    //Maxthon浏览器(傲游)
                    else if (se.Contains("Maxthon"))
                    {
                        se = "傲游";
                    }
                    //因特网浏览器
                    else
                    {
                        se = "未知";
                    }
                    VisitorInfo vist = new VisitorInfo();
                    vist.AccessTime    = DateTime.Now;
                    vist.VisitPage     = VisitPage;
                    vist.IpAddress     = IpAddress;
                    vist.VisitSE       = se;
                    vist.WebInfo       = web;
                    vist.Address       = Address;
                    vist.Age           = 0;
                    vist.AccessEndTime = DateTime.Now;

                    //判断用户是否访问一个就退出
                    if (IsPostUrl == string.Empty)
                    {
                        IsPostUrl = VisitPage;
                    }
                    if (IsPostUrl != VisitPage)
                    {
                        vist.PageNumber = 1;
                    }
                    //随机生成标识码(identification code) 32位字符
                    string IC = Guid.NewGuid().ToString("N");
                    var    bo = work.CreateRepository <VisitorInfo>().GetList(m => m.IC == IC);
                    if (bo.Count() > 0)
                    {
                        IC = Guid.NewGuid().ToString("N");
                    }
                    vist.IC = IC;

                    //判断用户是否相同用户
                    List <VisitorInfo> alikeCount = work.CreateRepository <VisitorInfo>().GetList(
                        m => m.IpAddress == vist.IpAddress
                        ).ToList();
                    //通过ip地址保证访客数计算
                    if (alikeCount.Count() == 0)
                    {
                        work.CreateRepository <VisitorInfo>().Insert(vist);
                        work.Save();
                        List <VisitorInfo> list = work.CreateRepository <VisitorInfo>().GetList().ToList();
                        var model = list.Where(p => p.IC == IC).FirstOrDefault();
                        int id    = 0; id = model.Id;
                        HttpContext.Current.Session["id"] = id;
                    }
                    else
                    {
                        foreach (var item in alikeCount)
                        {
                            TimeSpan span = DateTime.Now - item.AccessEndTime;
                            //判断该ip地址访客访问时间是否超过24小时
                            int temp = Convert.ToInt32(span.TotalHours);
                            if (temp >= 24 && item.Lock == 0)
                            {
                                item.Lock = 1;
                                work.CreateRepository <VisitorInfo>().Update(item);
                                work.Save();
                                work.CreateRepository <VisitorInfo>().Insert(vist);
                                work.Save();
                                List <VisitorInfo> list = work.CreateRepository <VisitorInfo>().GetList().ToList();
                                var model = list.Where(p => p.IC == IC).FirstOrDefault();
                                int id    = 0; id = model.Id;
                                HttpContext.Current.Session["id"] = id;
                            }
                        }
                    }

                    #endregion

                    #region 获取PV信息&添加PV信息
                    FlowComputer flow = new FlowComputer();
                    flow.VisitPage = VisitPage;
                    flow.WebHost   = System.Web.HttpContext.Current.Request.Url.Host.ToString();
                    string str = HttpContext.Current.Request.UrlReferrer.ToString();
                    //判断是否搜索引擎链接
                    if (searchkey.IsSearchEnginesGet(str))
                    {
                        //取得搜索关键字
                        flow.SearchTerms = searchkey.SearchKey(str);
                        //取得搜索引擎名称
                        flow.VisitSE = searchkey.EngineName;
                    }
                    else
                    {
                        flow.SearchTerms = "其他";
                        flow.VisitSE     = vist.VisitSE;
                    }
                    flow.CurrentTime = DateTime.Now;
                    flow.WebInfo     = web;
                    lock (flow)
                    {
                        work.CreateRepository <FlowComputer>().Insert(flow);
                        work.Save();
                    }
                    #endregion

                    //web = work.CreateRepository<WebInfo>().GetFirst(m => m.WebKey == key);//获取pv
                    web.WebPv = web.WebPv + 1;
                    web.WebUv = work.CreateRepository <VisitorInfo>().GetCount(m => m.WebInfo.Id == web.Id);
                    int     rate       = work.CreateRepository <VisitorInfo>().GetCount(m => m.PageNumber == 0);
                    decimal rateResult = Math.Round((decimal)rate / web.WebPv, 4);
                    if (rateResult >= 1)
                    {
                        rateResult = 1;
                    }
                    web.BounceRate = (rateResult * 100).ToString().Length >= 5 ? (rateResult * 100).ToString().Substring(0, 4) + "%" : (rateResult * 100).ToString() + "%";
                    List <VisitorInfo> webuv = work.CreateRepository <VisitorInfo>().GetList().ToList();//获取uv
                    for (int i = 0; i < webuv.Count(); i++)
                    {
                        for (int j = webuv.Count() - 1; j > i; j--)
                        {
                            if (webuv[i].IpAddress == webuv[j].IpAddress)
                            {
                                webuv.RemoveAt(j);
                            }
                        }
                    }
                    web.IpCount = webuv.Count;//获取ip数 去重
                    lock (web)
                    {
                        work.CreateRepository <WebInfo>().Update(web);
                        work.Save();
                    }
                }
                else
                {
                    //var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                    //{
                    //    Content = new StringContent(string.Format("没有找到Key={0}的密钥", key)),
                    //    ReasonPhrase = "object is not found"
                    //};
                    //throw new HttpResponseException(resp);
                }
            }
            catch (Exception ex)
            {
                //var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                //{
                //    Content = new StringContent(string.Format("没有找到Key={0}的密钥", key)),
                //    ReasonPhrase = "object is not found"
                //};
                //throw new HttpResponseException(resp);
                return(new object[] { "" + ex });

                throw ex;
            }
            return(new object[] { "持行成功" });
        }
        /// <summary>
        /// 删除资讯分类
        /// </summary>
        /// <param name="p_id"></param>
        /// <param name="f_id"></param>
        /// <returns></returns>
        public static ReturnInfo DeleteClassById(int p_id, int f_id)//需考虑情况:可能操作者选择了大类,现在情况操作者选择了小类
        {
            ReturnInfo    rif   = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            List <int>    arrId = new List <int>();

            using (WorkOfUnit work = new WorkOfUnit())
            {
                try
                {
                    //判断是否是父级 如果不是父级
                    if (f_id != 0)
                    {
                        //假如存在外键约束则先删除关联数据
                        var smQuery = work.CreateRepository <SmClass>().GetList(m => m.Id == p_id);
                        if (smQuery.Count() != 0)
                        {
                            foreach (var item in smQuery.ToList())
                            {
                                #region 获取资讯
                                //var mQuery = work.CreateRepository<Information>().GetList(m => m.Sm.Id == item.Id);
                                if (item.Information.Count() != 0)
                                {
                                    foreach (var mation in item.Information.ToList())
                                    {
                                        arrId.Add(mation.Id);
                                    }
                                }
                                #endregion
                            }
                            if (arrId.Count() != 0)
                            {
                                foreach (var item in arrId)
                                {
                                    //删除资讯
                                    var query = DeleteConsultById(item);
                                    rif.IsSuccess = query.IsSuccess;
                                    sb.Append(query.ErrorInfo);
                                }
                            }
                            foreach (var sm in smQuery.ToList())
                            {
                                try
                                {
                                    //删除资讯小类
                                    work.CreateRepository <SmClass>().Delete(sm);
                                    rif.IsSuccess = work.Save() >= 1;
                                }
                                catch (Exception ex)
                                {
                                    sm.Lock = 1;
                                    work.CreateRepository <SmClass>().Update(sm);
                                    work.Save();
                                    sb.Append("删除失败" + sm.Id + ":" + ex.Message);
                                    continue;
                                }
                            }
                        }
                    }
                    //如果是父级
                    if (f_id == 0)
                    {
                        var lgQuery = work.CreateRepository <LgClass>().GetEntityById(p_id);
                        //假如存在外键约束则先删除关联数据
                        var smQuery = work.CreateRepository <SmClass>().GetList(m => m.Lg.Id == lgQuery.Id);
                        if (smQuery.Count() != 0)
                        {
                            foreach (var item in smQuery.ToList())
                            {
                                #region 获取资讯
                                //var mQuery = work.CreateRepository<Information>().GetList(m => m.Sm.Id == item.Id);
                                if (item.Information.Count() != 0)
                                {
                                    foreach (var mation in item.Information.ToList())
                                    {
                                        arrId.Add(mation.Id);
                                    }
                                }
                                #endregion
                            }
                            if (arrId.Count() != 0)
                            {
                                foreach (var item in arrId)
                                {
                                    //删除资讯
                                    var query = DeleteConsultById(item);
                                    rif.IsSuccess = query.IsSuccess;
                                    sb.Append(query.ErrorInfo);
                                }
                            }
                            foreach (var sm in smQuery.ToList())
                            {
                                try
                                {
                                    //删除资讯小类
                                    work.CreateRepository <SmClass>().Delete(sm);
                                    rif.IsSuccess = work.Save() >= 1;
                                }
                                catch (Exception ex)
                                {
                                    sm.Lock = 1;
                                    work.CreateRepository <SmClass>().Update(sm);
                                    work.Save();
                                    sb.Append("删除失败" + sm.Id + ":" + ex.Message);
                                    continue;
                                }
                            }
                        }
                        try
                        {
                            //删除资讯大类
                            work.CreateRepository <LgClass>().Delete(lgQuery);
                            rif.IsSuccess = work.Save() >= 1;
                        }
                        catch (Exception ex)
                        {
                            rif.IsSuccess = false;
                            sb.Append(ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    rif.IsSuccess = false;
                    sb.Append(ex.Message);
                }
                rif.ErrorInfo = sb.ToString();
            }
            return(rif);
        }
        //public ActionResult GetReportData(int day)
        //{
        //    try
        //    {
        //        var webList = work.CreateRepository<WebInfo>().GetList(m => m.Id == webId).Select(m => new
        //        {
        //            Id = m.Id,
        //            WebPv = m.WebPv,
        //            WebUv = m.WebUv,
        //            BounceRate = m.BounceRate,
        //            IpCount = m.IpCount,
        //            WebTS = m.WebTS,
        //            WebDomain = m.WebDomain,
        //            WebConversion = m.WebConversion,
        //            WebKey = m.WebKey
        //        }).FirstOrDefault();
        //        //当前日期
        //        DateTime current = DateTime.Now.AddDays(day);
        //        var today = GetVistiorByDay(current, webList.Id);
        //        //昨天日期
        //        DateTime preterite = DateTime.Now.AddDays(day);
        //        var yesterday = GetVistiorByDay(preterite, webList.Id);

        //        return Json(new { today, yesterday, siteId = webId.ToString(), users = user.UserName.ToString() }, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception ex)
        //    {

        //        throw ex;
        //    }
        //}

        /// <summary>
        /// 根据指定日期计算统计流量
        /// </summary>
        /// <param name="startTime">设置时间</param>
        /// <param name="site">网站id</param>
        /// <returns></returns>
        public WebInfo GetVistiorByDay(DateTime startTime, int site)
        {
            WebInfo web = new WebInfo();

            try
            {
                List <VisitorInfo> vistio = work.CreateRepository <VisitorInfo>().GetList(
                    m => DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site
                    ).ToList();
                //获取pv量,根据条件时间&网站id
                web.WebPv = work.CreateRepository <FlowComputer>().GetList(
                    m => DbFunctions.DiffDays(m.CurrentTime, startTime) == 0 && m.WebInfo.Id == site
                    ).Count();
                //获取uv值,根据条件时间&网站id
                web.WebUv = work.CreateRepository <VisitorInfo>().GetList(
                    m => DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site
                    ).Count();
                //获取ip数 去重
                List <VisitorInfo> webuv = work.CreateRepository <VisitorInfo>().GetList(
                    m => DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site
                    ).ToList();
                for (int i = 0; i < webuv.Count(); i++)
                {
                    for (int j = webuv.Count() - 1; j > i; j--)
                    {
                        if (webuv[i].IpAddress == webuv[j].IpAddress)
                        {
                            webuv.RemoveAt(j);
                        }
                    }
                }
                web.IpCount = webuv.Count;
                //计算跳出率,根据条件时间&网站id
                int rate = work.CreateRepository <VisitorInfo>().GetCount(
                    m => m.PageNumber == 0 && DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site);
                //int sumPv = work.CreateRepository<WebInfo>().GetList(m => m.UserInfo.Id == site).FirstOrDefault().WebPv;
                //int sumUv = work.CreateRepository<VisitorInfo>().GetCount(
                //    m => DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site);
                decimal rateResult = Math.Round((decimal)rate / web.WebPv, 4);
                if (rateResult >= 1)
                {
                    rateResult = 1;
                }
                web.BounceRate = (rateResult * 100).ToString().Length >= 5 ?
                                 (rateResult * 100).ToString().Substring(0, 4) + "%" : (rateResult * 100).ToString() + "%";
                //计算转换次数,根据条件时间&网站id
                web.WebConversion = 0;
                //计算平均时长,根据条件时间&网站id
                int sumDuration = work.CreateRepository <VisitorInfo>().GetCount(
                    m => DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site);
                double duration = work.CreateRepository <VisitorInfo>().GetCount(
                    m => DbFunctions.DiffDays(m.AccessTime, startTime) == 0 && m.WebInfo.Id == site);
                duration = vistio.Sum(a => a.Duration);
                int      averageTime = (int)Math.Ceiling(Convert.ToDouble(duration / sumDuration));
                TimeSpan ts          = new TimeSpan(0, 0, averageTime);
                web.WebTS = ts.ToString();

                if (web.WebTS.Contains("-24855.03:14:08"))
                {
                    web.WebTS = "00:00:00";
                }
            }
            catch (Exception ex)
            {
                web.IpCount       = 0;
                web.WebConversion = 0;
                web.WebDomain     = "";
                web.WebPv         = 0;
                web.WebTS         = "00:00:00";
                web.WebUv         = 0;
                web.BounceRate    = "0%";
                return(web);

                throw ex;
            }
            return(web);
        }