Ejemplo n.º 1
0
 /// <summary>
 /// 1.统计上月访问量,存入表LoginCount
 /// 2.删除本月之前的12个月的访问ip信息,
 /// </summary>
 public void DealLoginInfo()
 {
     //当前月的初始日期
     DateTime firstDayOfThisMonth= new DateTime(DateTime.Now.Year,DateTime.Now.Month,1);
     DateTime start;
     DateTime end;
     int loginInfoCount;
     for (var i = 1; i <= 12; i++)  //处理过去一年的登录记录
     {
         start = firstDayOfThisMonth.AddMonths(-i);
         end = firstDayOfThisMonth.AddMonths(-i + 1) ;
         if (this.LoginInfoService.GetCount(end) == 0) //当前月之前不存在任何登陆记录,则退出循环
         {
             break;
         }
         loginInfoCount = this.LoginInfoService.GetCount(start,end);
         if (loginInfoCount != 0)
         {
             //统计该月访问来量,存入LoginCount表
             MonthLoginCount monthLoginCount = new MonthLoginCount
             {
                 Count = loginInfoCount,
                 YearMonth = start
             };
             this.MonthLoginCountService.AddMonthLoginCount(monthLoginCount);
             //然后删除该月份记录
             IEnumerable<LoginInfo> loginInfos = this.LoginInfoService.GetLoginInfoByTime(start,end);
             this.LoginInfoService.DeleteLoginInfos(loginInfos);
         }
     }
 }
 public void AddMonthLoginCount(MonthLoginCount monthLoginCount)
 {
     this.Repository.AddMonthLoginCount(monthLoginCount);
 }