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

namespace Stat.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public class ViewContent
    {

        static Stat.IDAL.IViewContent dal = Stat.DALFactory.AbstractFactory.GetInstance().CreateViewContent();
        /// <summary>
        ///Content
        /// </summary>
        /// <param name="model"></param> 
        /// <returns></returns>
        internal static List<Model.ViewItem_Int> GetItem(Model.StatInfo model)
        {
            return dal.GetItem(model);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="roleList"></param>
        /// <returns></returns>
        public static List<Model.StatItem> Get(Model.StatInfo model, IList<Model.WebsiteStructure> roleList)
        {
            string cName = "V_Content_" + 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)
                {
                    model.EndTime = model.StartTime.AddDays(1);
                    //详细数据
                    string[,] arr = new string[roleList.Count, 2];
                    for (int i = 0; i < roleList.Count; i++)
                    {
                        arr[i, 0] = roleList[i].id.ToString();
                        arr[i, 1] = roleList[i].Name;
                    }
                    //一天
                    list = Report.Rp_Int.SingleDay(GetItem(model), arr);
                }
                else
                {
                    //多天
                    list = Report.Rp_Int.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);//从缓存中读取
        }
    }
}
