using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

namespace Stat.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public class ViewPage
    {
        static Stat.IDAL.IViewUrlPage dal = Stat.DALFactory.AbstractFactory.GetInstance().CreateViewUrlPage();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <remarks>只计算单天数据</remarks>
        public static List<Model.StatItem> Get(Model.StatInfo model)
        {
            string cName = "V_PvTop_" + model.WebID + "_" + model.StartTime;
            if (HttpContext.Current.Cache.Get(cName) == null)
            {
                // List<Model.StatItem> list = dal.GetList(model);

                List<Model.StatItem> list = new List<Model.StatItem>();
                //
                if (list == null || list.Count < 1)
                {
                    //详细数据
                    list = Report.Rp_vPage.SingleDay(GetItem(model));
                }
                else
                {
                    //过往数据
                    list = Report.Rp_String.MultiDay(list);
                }
                //                
                HttpContext.Current.Cache.Insert(cName, list, null, DateTime.MaxValue, TimeSpan.FromSeconds(3.0), System.Web.Caching.CacheItemPriority.Low, null);
                return list;
            }
            return (List<Model.StatItem>)HttpContext.Current.Cache.Get(cName);//从缓存中读取
        }
        /// <summary>
        /// PV Stat
        /// </summary>
        /// <param name="model"></param> 
        /// <returns></returns>
        internal static List<Model.ViewItem_String> GetItem(Model.StatInfo model)
        {
            return dal.GetItem(model);
        }
    }
}