using System;
using System.Collections.Generic;
using System.Web;
namespace Stat.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public class ViewDomain
    {
        static Stat.IDAL.IViewDomain dal = Stat.DALFactory.AbstractFactory.GetInstance().CreateViewDomain();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Juju 2011-10-27</returns>
        public static List<Model.StatItem> Get(Model.StatInfo model)
        {
            string cName = "V_Domain_" + model.WebID + "_" + model.StartTime + "_" + model.EndTime;
            if (HttpContext.Current.Cache.Get(cName) == null)
            {

                List<Model.StatItem> list = dal.GetList(model);
                //
                if (list == null || list.Count < 1)
                    list = Report.Rp_String.SingleDay(GetItem(model));
                else
                    list = Report.Rp_String.MultiDay(list);
                //
                foreach (Model.StatItem item in list)
                {
                    item.Name = item.Name ?? "直接输入域名或书签";
                    item.Name = item.Name.Length < 2 ? "直接输入域名或书签" : item.Name;
                }
                //
                HttpContext.Current.Cache.Insert(cName, list, null, DateTime.MaxValue, TimeSpan.FromSeconds(10.0), System.Web.Caching.CacheItemPriority.Low, null);
                return list;
            }
            return (List<Model.StatItem>)HttpContext.Current.Cache.Get(cName);//从缓存中读取
        }
        /// <summary>
        /// 获取来路域名
        /// </summary>
        /// <param name="model"></param> 
        /// <returns></returns>
        internal static List<Model.ViewItem_String> GetItem(Model.StatInfo model)
        {
            return dal.GetItem(model);
        }
    }
}