/// <summary>
        /// 开始计算
        /// </summary>
        private void Statistics()
        {
            try
            {
                List <ReadingRoomInfo> rooms = ClientConfigOperate.GetReadingRooms(null);
                DateTime sdt = SeatUsageDataOperating.GetLastRoomFlowStatisticsDate();
                if (sdt <= DateTime.Parse("2000-1-1"))
                {
                    return;
                }
                sdt = sdt.AddDays(1);
                while (true)
                {
                    //获取进出记录
                    List <EnterOutLogInfo> enterOutLogList = T_SM_EnterOutLog_bak.GetStatisticsLogsByDate(sdt);
                    if (enterOutLogList.Count <= 0 && sdt >= ServiceDateTime.Now.Date.AddDays(-1))
                    {
                        break;
                    }
                    Dictionary <string, SeatManage.ClassModel.RoomFlowStatistics> roomDir = rooms.ToDictionary(room => room.No, room => new SeatManage.ClassModel.RoomFlowStatistics());

                    //基本数据及排序处理
                    foreach (ReadingRoomInfo room in rooms)
                    {
                        roomDir[room.No].StatisticsDate = sdt;
                        roomDir[room.No].ReadingRoomNo  = room.No;
                        for (int i = 0; i < 24; i++)
                        {
                            roomDir[room.No].BespeakCheckFlowDic.Add(i, 0);
                            roomDir[room.No].ComeBackFlowDic.Add(i, 0);
                            roomDir[room.No].ContinueFlowDic.Add(i, 0);
                            roomDir[room.No].EnterFlowDic.Add(i, 0);
                            roomDir[room.No].LeaveFlowDic.Add(i, 0);
                            roomDir[room.No].OnSeatDic.Add(i, 0);
                            roomDir[room.No].OutFlowDic.Add(i, 0);
                            roomDir[room.No].ReselectFlowDic.Add(i, 0);
                            roomDir[room.No].SelectFlowDic.Add(i, 0);
                            roomDir[room.No].ShortLeaveFlowDic.Add(i, 0);
                            roomDir[room.No].WaitSelectFlowDic.Add(i, 0);
                        }
                    }
                    foreach (EnterOutLogInfo eol in enterOutLogList)
                    {
                        //记录类型
                        switch (eol.EnterOutState)
                        {
                        case EnterOutLogType.BookingConfirmation:
                            roomDir[eol.ReadingRoomNo].BespeakCheckFlowDic[eol.EnterOutTime.Hour]++;
                            roomDir[eol.ReadingRoomNo].EnterFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ComeBack:
                            roomDir[eol.ReadingRoomNo].ComeBackFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ContinuedTime:
                            roomDir[eol.ReadingRoomNo].ContinueFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.Leave:
                            roomDir[eol.ReadingRoomNo].LeaveFlowDic[eol.EnterOutTime.Hour]++;
                            roomDir[eol.ReadingRoomNo].OutFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ReselectSeat:
                            roomDir[eol.ReadingRoomNo].ReselectFlowDic[eol.EnterOutTime.Hour]++;
                            roomDir[eol.ReadingRoomNo].EnterFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.SelectSeat:
                            roomDir[eol.ReadingRoomNo].SelectFlowDic[eol.EnterOutTime.Hour]++;
                            roomDir[eol.ReadingRoomNo].EnterFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ShortLeave:
                            roomDir[eol.ReadingRoomNo].ShortLeaveFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.WaitingSuccess:
                            roomDir[eol.ReadingRoomNo].WaitSelectFlowDic[eol.EnterOutTime.Hour]++;
                            roomDir[eol.ReadingRoomNo].EnterFlowDic[eol.EnterOutTime.Hour]++;
                            break;
                        }
                    }
                    foreach (SeatManage.ClassModel.RoomFlowStatistics roomFS in roomDir.Values)
                    {
                        foreach (KeyValuePair <int, int> item in roomFS.BespeakCheckFlowDic)
                        {
                            roomFS.BespeakCheckFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.ComeBackFlowDic)
                        {
                            roomFS.ComeBackFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.ContinueFlowDic)
                        {
                            roomFS.ContinueFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.EnterFlowDic)
                        {
                            roomFS.EnterFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.LeaveFlowDic)
                        {
                            roomFS.LeaveFlow += item.Key + ":" + item.Value + ";";
                        }

                        foreach (KeyValuePair <int, int> item in roomFS.OutFlowDic)
                        {
                            roomFS.OutFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.ReselectFlowDic)
                        {
                            roomFS.ReselectFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.SelectFlowDic)
                        {
                            roomFS.SelectFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.ShortLeaveFlowDic)
                        {
                            roomFS.ShortLeaveFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.WaitSelectFlowDic)
                        {
                            roomFS.WaitSelectFlow += item.Key + ":" + item.Value + ";";
                        }
                        //计算在座人数
                        for (int i = 0; i < 24; i++)
                        {
                            roomFS.OnSeatDic[i] = i > 0 ? roomFS.OnSeatDic[i - 1] + roomFS.EnterFlowDic[i] - roomFS.OutFlowDic[i] : roomFS.EnterFlowDic[i] - roomFS.OutFlowDic[i];
                        }
                        foreach (KeyValuePair <int, int> item in roomFS.OnSeatDic)
                        {
                            roomFS.OnSeat += item.Key + ":" + item.Value + ";";
                        }
                        if (!SeatUsageDataOperating.AddRoomFlowStatistics(roomFS))
                        {
                            WriteLog.Write(string.Format("数据统计服务:添加阅览室:{0} {1} 人流量统计出错", roomFS.ReadingRoomNo, roomFS.StatisticsDate));
                            throw new Exception(string.Format("数据统计服务:添加阅览室:{0} {1} 人流量统计出错", roomFS.ReadingRoomNo, roomFS.StatisticsDate));
                        }
                    }

                    sdt = sdt.AddDays(1);
                    if (sdt >= ServiceDateTime.Now.Date)
                    {
                        break;
                    }
                    roomDir = null;
                }
                WriteLog.Write("数据统计服务:统计阅览室完成人流量完成");
            }

            catch (Exception ex)
            {
                WriteLog.Write(string.Format("数据统计服务:统计阅览室人流量失败:{0}", ex.Message));
            }
        }
        /// <summary>
        /// 开始计算
        /// </summary>
        private void Statistics()
        {
            try
            {
                List <TerminalInfoV2> terminals = TerminalOperatorService.GetAllTeminalInfo();
                DateTime sdt = SeatUsageDataOperating.GetLastTerminalUsageStatisticsDate();
                if (sdt <= DateTime.Parse("2000-1-1"))
                {
                    return;
                }
                sdt = sdt.AddDays(1);
                while (true)
                {
                    //获取进出记录
                    List <EnterOutLogInfo> enterOutLogList = T_SM_EnterOutLog_bak.GetStatisticsLogsByDate(sdt);
                    if (enterOutLogList.Count <= 0 && sdt >= ServiceDateTime.Now.Date.AddDays(-1))
                    {
                        break;
                    }
                    List <SeatManage.ClassModel.TerminalUsageStatistics> ftsList = SeatUsageDataOperating.GetTerminalUsageStatisticsist(null, sdt.AddDays(-1).Date, sdt.Date.AddSeconds(-1));
                    Dictionary <string, SeatManage.ClassModel.TerminalUsageStatistics> terminalDir = terminals.ToDictionary(u => u.ClientNo, u => new SeatManage.ClassModel.TerminalUsageStatistics());

                    //基本数据及排序处理
                    foreach (TerminalInfoV2 terminal in terminals)
                    {
                        terminalDir[terminal.ClientNo].StatisticsDate = sdt;
                        terminalDir[terminal.ClientNo].TerminalNo     = terminal.ClientNo;
                    }
                    foreach (EnterOutLogInfo eol in enterOutLogList.FindAll(u => !string.IsNullOrEmpty(u.TerminalNum) && u.Flag == Operation.Reader))
                    {
                        if (!terminalDir.ContainsKey(eol.TerminalNum))
                        {
                            continue;
                        }
                        terminalDir[eol.TerminalNum].RushCardCount++;
                        //记录类型
                        switch (eol.EnterOutState)
                        {
                        case EnterOutLogType.BookingConfirmation:
                            terminalDir[eol.TerminalNum].CheckBespeakCount++;
                            break;

                        case EnterOutLogType.ComeBack:
                            terminalDir[eol.TerminalNum].ComeBackCount++;
                            break;

                        case EnterOutLogType.ContinuedTime:
                            terminalDir[eol.TerminalNum].ContinueTimeCount++;
                            break;

                        case EnterOutLogType.Leave:
                            terminalDir[eol.TerminalNum].LeaveCount++;
                            break;

                        case EnterOutLogType.ReselectSeat:
                            terminalDir[eol.TerminalNum].ReselectSeatCount++;
                            break;

                        case EnterOutLogType.SelectSeat:
                            terminalDir[eol.TerminalNum].SelectSeatCount++;
                            break;

                        case EnterOutLogType.ShortLeave:
                            terminalDir[eol.TerminalNum].ShortLeaveCount++;
                            break;

                        case EnterOutLogType.WaitingSuccess:
                            terminalDir[eol.TerminalNum].WaitSeatCount++;
                            break;
                        }
                    }

                    foreach (SeatManage.ClassModel.TerminalUsageStatistics terminalUS in terminalDir.Values)
                    {
                        SeatManage.ClassModel.TerminalUsageStatistics fts = ftsList.Find(u => u.TerminalNo == terminalUS.TerminalNo);
                        TerminalInfoV2 terminal = terminals.Find(u => u.ClientNo == terminalUS.TerminalNo);
                        if (fts != null)
                        {
                            terminalUS.IsChangePage         = terminal.LastPrintTimes != fts.BeforePagePrintCount ? 1 : 0;
                            terminalUS.NowPagePrintCount    = terminal.PrintedTimes;
                            terminalUS.BeforePagePrintCount = terminal.LastPrintTimes;
                            terminalUS.TodayPrintCount      = terminal.LastPrintTimes != fts.BeforePagePrintCount ? terminal.LastPrintTimes - fts.NowPagePrintCount + terminal.PrintedTimes : terminal.PrintedTimes - fts.NowPagePrintCount;
                        }
                        else
                        {
                            terminalUS.IsChangePage         = 0;
                            terminalUS.NowPagePrintCount    = terminal.PrintedTimes;
                            terminalUS.BeforePagePrintCount = terminal.LastPrintTimes;
                            terminalUS.TodayPrintCount      = 0;
                        }


                        if (!SeatUsageDataOperating.AddTerminalUsageStatistics(terminalUS))
                        {
                            WriteLog.Write(string.Format("数据统计服务:添加终端:{0} {1} 使用情况统计出错", terminalUS.TerminalNo, terminalUS.StatisticsDate));
                            throw new Exception(string.Format("数据统计服务:添加终端:{0} {1} 使用情况统计出错", terminalUS.TerminalNo, terminalUS.StatisticsDate));
                        }
                    }

                    sdt = sdt.AddDays(1);
                    if (sdt >= ServiceDateTime.Now.Date)
                    {
                        break;
                    }
                    terminalDir = null;
                }
                WriteLog.Write("数据统计服务:统计终端使用情况完成");
            }

            catch (Exception ex)
            {
                WriteLog.Write(string.Format("数据统计服务:统计阅终端人流量失败:{0}", ex.Message));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 开始计算
        /// </summary>
        private void Statistics()
        {
            try
            {
                List <ReadingRoomInfo> rooms = ClientConfigOperate.GetReadingRooms(null);
                DateTime sdt = SeatUsageDataOperating.GetLastRoomUsageStatisticsDate();
                if (sdt <= DateTime.Parse("2000-1-1"))
                {
                    return;
                }
                sdt = sdt.AddDays(1);
                while (true)
                {
                    //获取进出记录
                    List <EnterOutLogInfo>         enterOutLogList  = T_SM_EnterOutLog_bak.GetStatisticsLogsByDate(sdt);
                    List <BespeakLogInfo>          bespeakLogList   = T_SM_SeatBespeak.GetBespeakList(null, null, sdt, 0, null);
                    List <ViolationRecordsLogInfo> violationLogList = T_SM_ViolateDiscipline.GetViolationRecords(null, null, sdt.ToShortDateString(), sdt.Date.AddDays(1).AddSeconds(-1).ToString(), LogStatus.None, LogStatus.None);
                    //List<BlackListInfo> blacklistList = T_SM_Blacklist.GetAllBlackListInfo(null, LogStatus.None, sdt.ToShortDateString(), sdt.Date.AddDays(1).AddSeconds(-1).ToString());
                    if (enterOutLogList.Count <= 0 && bespeakLogList.Count <= 0 && violationLogList.Count <= 0 && sdt >= ServiceDateTime.Now.Date.AddDays(-1))
                    {
                        break;
                    }
                    Dictionary <string, SeatManage.ClassModel.RoomUsageStatistics> roomDir = rooms.ToDictionary(room => room.No, room => new SeatManage.ClassModel.RoomUsageStatistics());

                    //基本数据及排序处理
                    foreach (ReadingRoomInfo room in rooms)
                    {
                        roomDir[room.No].StatisticsDate  = sdt;
                        roomDir[room.No].ReadingRoomNo   = room.No;
                        roomDir[room.No].SeatAllCount    = room.SeatList.Seats.Count;
                        roomDir[room.No].OpenTime        = DateTime.Parse(room.Setting.GetRoomOpenTimeByDate(sdt).BeginTime);
                        roomDir[room.No].CloseTime       = DateTime.Parse(room.Setting.GetRoomOpenTimeByDate(sdt).EndTime);
                        roomDir[room.No].RoomUsageTime   = (int)(roomDir[room.No].CloseTime - roomDir[room.No].OpenTime).TotalMinutes;
                        roomDir[room.No].SeatUsageCount  = enterOutLogList.FindAll(u => u.ReadingRoomNo == room.No).GroupBy(u => u.SeatNo).Count();
                        roomDir[room.No].UsedReaderCount = enterOutLogList.FindAll(u => u.ReadingRoomNo == room.No).GroupBy(u => u.CardNo).Count();
                        roomDir[room.No].CanBesapeakSeat = room.Setting.SeatBespeak.BespeakArea.BespeakType == BespeakAreaType.Percentage ? (int)room.Setting.SeatBespeak.BespeakArea.Scale * room.SeatList.Seats.Count : room.SeatList.Seats.Count(u => u.Value.CanBeBespeak);
                        roomDir[room.No].BespeakedSeat   = bespeakLogList.FindAll(u => u.ReadingRoomNo == room.No).GroupBy(u => u.SeatNo).Count();
                    }
                    foreach (ViolationRecordsLogInfo vrl in violationLogList)
                    {
                        roomDir[vrl.ReadingRoomID].ViolationRecordCount++;
                        switch (vrl.EnterFlag)
                        {
                        case ViolationRecordsType.BookingTimeOut:
                            roomDir[vrl.ReadingRoomID].VRBookingTimeOut++;
                            break;

                        case ViolationRecordsType.LeaveByAdmin:
                            roomDir[vrl.ReadingRoomID].VRLeaveByAdmin++;
                            break;

                        case ViolationRecordsType.LeaveNotReadCard:
                            roomDir[vrl.ReadingRoomID].VRLeaveNotReadCard++;
                            break;

                        case ViolationRecordsType.SeatOutTime:
                            roomDir[vrl.ReadingRoomID].VRSeatOutTime++;
                            break;

                        case ViolationRecordsType.ShortLeaveByAdminOutTime:
                            roomDir[vrl.ReadingRoomID].VRShortLeaveByAdminOutTime++;
                            break;

                        case ViolationRecordsType.ShortLeaveByReaderOutTime:
                            roomDir[vrl.ReadingRoomID].VRShortLeaveByReaderOutTime++;
                            break;

                        case ViolationRecordsType.ShortLeaveByServiceOutTime:
                            roomDir[vrl.ReadingRoomID].VRShortLeaveByServiceOutTime++;
                            break;

                        case ViolationRecordsType.ShortLeaveOutTime:
                            roomDir[vrl.ReadingRoomID].VRShortLeaveOutTime++;
                            break;
                        }
                    }
                    //预约记录处理
                    foreach (BespeakLogInfo bli in bespeakLogList)
                    {
                        roomDir[bli.ReadingRoomNo].AllBespeakCount++;
                        if (bli.BsepeakTime.Date == bli.SubmitTime.Date)
                        {
                            switch (bli.BsepeakState)
                            {
                            case BookingStatus.Cencaled:
                                switch (bli.CancelPerson)
                                {
                                case Operation.Admin:
                                case Operation.Reader:
                                    roomDir[bli.ReadingRoomNo].NowDayBespeakCancel++;
                                    break;

                                case Operation.Service:
                                    roomDir[bli.ReadingRoomNo].NowDayBespeakOverTime++;
                                    break;
                                }
                                break;

                            case BookingStatus.Confinmed:
                                roomDir[bli.ReadingRoomNo].NowDayBespeakCheck++;
                                break;
                            }
                            roomDir[bli.ReadingRoomNo].NowDayBespeakCount++;
                        }
                        else
                        {
                            switch (bli.BsepeakState)
                            {
                            case BookingStatus.Cencaled:
                                switch (bli.CancelPerson)
                                {
                                case Operation.Admin:
                                case Operation.Reader:
                                    roomDir[bli.ReadingRoomNo].BespeakCancel++;
                                    break;

                                case Operation.Service:
                                    roomDir[bli.ReadingRoomNo].BespeakOverTime++;
                                    break;
                                }
                                break;

                            case BookingStatus.Confinmed:
                                roomDir[bli.ReadingRoomNo].BespeakCheck++;
                                break;
                            }
                            roomDir[bli.ReadingRoomNo].BespeakCount++;
                        }
                    }
                    foreach (EnterOutLogInfo eol in enterOutLogList)
                    {
                        //刷卡次数
                        if (!string.IsNullOrEmpty(eol.TerminalNum) && !(eol.EnterOutState == EnterOutLogType.ContinuedTime && eol.Flag == Operation.Service))
                        {
                            roomDir[eol.ReadingRoomNo].RushCardOperatingCount++;
                        }
                        //记录类型
                        switch (eol.EnterOutState)
                        {
                        case EnterOutLogType.BookingConfirmation:
                            roomDir[eol.ReadingRoomNo].CheckBespeakCount++;
                            if (string.IsNullOrEmpty(eol.TerminalNum))
                            {
                                roomDir[eol.ReadingRoomNo].CkeckBespeakInOtherClient++;
                            }
                            else
                            {
                                roomDir[eol.ReadingRoomNo].CheckBespeakInSeatClient++;
                            }
                            break;

                        case EnterOutLogType.ComeBack:
                            roomDir[eol.ReadingRoomNo].ComeBackCount++;
                            switch (eol.Flag)
                            {
                            case Operation.Admin:
                                roomDir[eol.ReadingRoomNo].ComeBackByAdmin++;
                                break;

                            case Operation.OtherReader:
                                roomDir[eol.ReadingRoomNo].ComeBackByOtherReader++;
                                break;

                            case Operation.Reader:
                                roomDir[eol.ReadingRoomNo].ComeBackByReader++;
                                if (string.IsNullOrEmpty(eol.TerminalNum))
                                {
                                    roomDir[eol.ReadingRoomNo].ComeBackInOtherClient++;
                                }
                                else
                                {
                                    roomDir[eol.ReadingRoomNo].ComeBackInSeatClient++;
                                }
                                break;
                            }
                            EnterOutLogInfo slEOL = enterOutLogList.FindLast(u => u.EnterOutState == EnterOutLogType.ShortLeave && u.EnterOutLogNo == eol.EnterOutLogNo && u.EnterOutTime < eol.EnterOutTime);
                            if (slEOL != null)
                            {
                                roomDir[eol.ReadingRoomNo].ShortLeaveTime += (int)(slEOL.EnterOutTime - eol.EnterOutTime).TotalMinutes;
                            }
                            break;

                        case EnterOutLogType.ContinuedTime:
                            roomDir[eol.ReadingRoomNo].ContinueTimeCount++;
                            switch (eol.Flag)
                            {
                            case Operation.Service:
                                roomDir[eol.ReadingRoomNo].ContinueTimeByService++;
                                break;

                            case Operation.Reader:
                                roomDir[eol.ReadingRoomNo].ContinueTimeByReader++;
                                if (string.IsNullOrEmpty(eol.TerminalNum))
                                {
                                    roomDir[eol.ReadingRoomNo].ContinueTimeInOtherClient++;
                                }
                                else
                                {
                                    roomDir[eol.ReadingRoomNo].ContinueTimeInSeatClient++;
                                }
                                break;
                            }
                            break;

                        case EnterOutLogType.Leave:
                            roomDir[eol.ReadingRoomNo].LeaveCount++;
                            roomDir[eol.ReadingRoomNo].ReaderUsageCount++;
                            switch (eol.Flag)
                            {
                            case Operation.Service:
                                roomDir[eol.ReadingRoomNo].LeaveByService++;
                                break;

                            case Operation.Admin:
                                roomDir[eol.ReadingRoomNo].LeaveByAdmin++;
                                break;

                            case Operation.Reader:
                                roomDir[eol.ReadingRoomNo].LeaveByReader++;
                                if (string.IsNullOrEmpty(eol.TerminalNum))
                                {
                                    roomDir[eol.ReadingRoomNo].LeaveInOtherClient++;
                                }
                                else
                                {
                                    roomDir[eol.ReadingRoomNo].LeaveInSeatClient++;
                                }
                                break;
                            }
                            EnterOutLogInfo enterEOL = enterOutLogList.Find(u => (u.EnterOutState == EnterOutLogType.BookingConfirmation || u.EnterOutState == EnterOutLogType.ReselectSeat || u.EnterOutState == EnterOutLogType.SelectSeat || u.EnterOutState == EnterOutLogType.WaitingSuccess) && u.EnterOutLogNo == eol.EnterOutLogNo);
                            if (enterEOL != null)
                            {
                                roomDir[eol.ReadingRoomNo].SeatUsageTime += (int)(eol.EnterOutTime - enterEOL.EnterOutTime).TotalMinutes;
                            }
                            break;

                        case EnterOutLogType.ReselectSeat:
                            roomDir[eol.ReadingRoomNo].ReselectSeatCount++;
                            if (string.IsNullOrEmpty(eol.TerminalNum))
                            {
                                roomDir[eol.ReadingRoomNo].ReselectSeatInOtherClient++;
                            }
                            else
                            {
                                roomDir[eol.ReadingRoomNo].ReselectSeatInSeatClient++;
                            }
                            break;

                        case EnterOutLogType.SelectSeat:
                            roomDir[eol.ReadingRoomNo].SelectSeatCount++;
                            switch (eol.Flag)
                            {
                            case Operation.Admin:
                                roomDir[eol.ReadingRoomNo].SelectSeatByAdmin++;
                                break;

                            case Operation.Reader:
                                roomDir[eol.ReadingRoomNo].SelectSeatByReader++;
                                if (string.IsNullOrEmpty(eol.TerminalNum))
                                {
                                    roomDir[eol.ReadingRoomNo].SelectSeatInOtherClient++;
                                }
                                else
                                {
                                    roomDir[eol.ReadingRoomNo].SelectSeatInSeatClient++;
                                }
                                break;
                            }
                            break;

                        case EnterOutLogType.ShortLeave:
                            roomDir[eol.ReadingRoomNo].ShortLeaveCount++;
                            switch (eol.Flag)
                            {
                            case Operation.OtherReader:
                                roomDir[eol.ReadingRoomNo].ShortLeaveByOtherReader++;
                                break;

                            case Operation.Service:
                                roomDir[eol.ReadingRoomNo].ShortLeaveByService++;
                                break;

                            case Operation.Admin:
                                roomDir[eol.ReadingRoomNo].ShortLeaveByAdmin++;
                                break;

                            case Operation.Reader:
                                roomDir[eol.ReadingRoomNo].ShortLeaveByReader++;
                                if (string.IsNullOrEmpty(eol.TerminalNum))
                                {
                                    roomDir[eol.ReadingRoomNo].ShortLeaveInOtherClient++;
                                }
                                else
                                {
                                    roomDir[eol.ReadingRoomNo].ShortLeaveInSeatClient++;
                                }
                                break;
                            }
                            break;

                        case EnterOutLogType.WaitingSuccess:
                            roomDir[eol.ReadingRoomNo].WaitSeatCount++;
                            break;
                        }
                    }
                    foreach (SeatManage.ClassModel.RoomUsageStatistics roomUS in roomDir.Values.Where(roomUS => !SeatUsageDataOperating.AddRoomUsageStatistics(roomUS)))
                    {
                        WriteLog.Write(string.Format("数据统计服务:添加阅览室:{0} {1} 数据统计出错", roomUS.ReadingRoomNo, roomUS.StatisticsDate));
                        throw new Exception(string.Format("数据统计服务:添加阅览室:{0} {1} 数据统计出错", roomUS.ReadingRoomNo, roomUS.StatisticsDate));
                    }
                    sdt = sdt.AddDays(1);
                    if (sdt >= ServiceDateTime.Now.Date)
                    {
                        break;
                    }
                    roomDir = null;
                }
                WriteLog.Write("数据统计服务:统计阅览室完成使用情况完成");
            }

            catch (Exception ex)
            {
                WriteLog.Write(string.Format("数据统计服务:统计阅览室使用情况失败:{0}", ex.Message));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 开始计算
        /// </summary>
        private void Statistics()
        {
            try
            {
                List <TerminalInfoV2> terminals = TerminalOperatorService.GetAllTeminalInfo();
                DateTime sdt = SeatUsageDataOperating.GetLastTerminalFlowStatisticsDate();
                if (sdt <= DateTime.Parse("2000-1-1"))
                {
                    return;
                }
                sdt = sdt.AddDays(1);
                while (true)
                {
                    //获取进出记录
                    List <EnterOutLogInfo> enterOutLogList = T_SM_EnterOutLog_bak.GetStatisticsLogsByDate(sdt);
                    if (enterOutLogList.Count <= 0 && sdt >= ServiceDateTime.Now.Date.AddDays(-1))
                    {
                        break;
                    }
                    Dictionary <string, SeatManage.ClassModel.TerminalFlowStatistics> terminalDir = terminals.ToDictionary(u => u.ClientNo, u => new SeatManage.ClassModel.TerminalFlowStatistics());

                    //基本数据及排序处理
                    foreach (TerminalInfoV2 terminal in terminals)
                    {
                        terminalDir[terminal.ClientNo].StatisticsDate = sdt;
                        terminalDir[terminal.ClientNo].TerminalNo     = terminal.ClientNo;
                        for (int i = 0; i < 24; i++)
                        {
                            terminalDir[terminal.ClientNo].CheckBespeakFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].ComeBackFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].ContinueTimeFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].LeaveFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].ReselectSeatFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].RushCardFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].SelectSeatFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].ShortLeaveFlowDic.Add(i, 0);
                            terminalDir[terminal.ClientNo].WaitSeatFlowDic.Add(i, 0);
                        }
                    }
                    foreach (EnterOutLogInfo eol in enterOutLogList.FindAll(u => !string.IsNullOrEmpty(u.TerminalNum) && u.Flag == Operation.Reader))
                    {
                        if (!terminalDir.ContainsKey(eol.TerminalNum))
                        {
                            continue;
                        }
                        terminalDir[eol.TerminalNum].RushCardFlowDic[eol.EnterOutTime.Hour]++;
                        //记录类型
                        switch (eol.EnterOutState)
                        {
                        case EnterOutLogType.BookingConfirmation:
                            terminalDir[eol.TerminalNum].CheckBespeakFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ComeBack:
                            terminalDir[eol.TerminalNum].ComeBackFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ContinuedTime:
                            terminalDir[eol.TerminalNum].ContinueTimeFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.Leave:
                            terminalDir[eol.TerminalNum].LeaveFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ReselectSeat:
                            terminalDir[eol.TerminalNum].ReselectSeatFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.SelectSeat:
                            terminalDir[eol.TerminalNum].SelectSeatFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.ShortLeave:
                            terminalDir[eol.TerminalNum].ShortLeaveFlowDic[eol.EnterOutTime.Hour]++;
                            break;

                        case EnterOutLogType.WaitingSuccess:
                            terminalDir[eol.TerminalNum].WaitSeatFlowDic[eol.EnterOutTime.Hour]++;
                            break;
                        }
                    }
                    foreach (SeatManage.ClassModel.TerminalFlowStatistics terminalFS in terminalDir.Values)
                    {
                        foreach (KeyValuePair <int, int> item in terminalFS.CheckBespeakFlowDic)
                        {
                            terminalFS.CheckBespeakFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.ComeBackFlowDic)
                        {
                            terminalFS.ComeBackFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.ContinueTimeFlowDic)
                        {
                            terminalFS.ContinueTimeFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.LeaveFlowDic)
                        {
                            terminalFS.LeaveFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.ReselectSeatFlowDic)
                        {
                            terminalFS.ReselectSeatFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.SelectSeatFlowDic)
                        {
                            terminalFS.SelectSeatFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.ShortLeaveFlowDic)
                        {
                            terminalFS.ShortLeaveFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.WaitSeatFlowDic)
                        {
                            terminalFS.WaitSeatFlow += item.Key + ":" + item.Value + ";";
                        }
                        foreach (KeyValuePair <int, int> item in terminalFS.RushCardFlowDic)
                        {
                            terminalFS.RushCardFlow += item.Key + ":" + item.Value + ";";
                        }
                        if (!SeatUsageDataOperating.AddTerminalFlowStatistics(terminalFS))
                        {
                            WriteLog.Write(string.Format("数据统计服务:添加终端:{0} {1} 人流量统计出错", terminalFS.TerminalNo, terminalFS.StatisticsDate));
                            throw new Exception(string.Format("数据统计服务:添加终端:{0} {1} 人流量统计出错", terminalFS.TerminalNo, terminalFS.StatisticsDate));
                        }
                    }

                    sdt = sdt.AddDays(1);
                    if (sdt >= ServiceDateTime.Now.Date)
                    {
                        break;
                    }
                    terminalDir = null;
                }
                WriteLog.Write("数据统计服务:统计终端人流量完成");
            }

            catch (Exception ex)
            {
                WriteLog.Write(string.Format("数据统计服务:统计阅终端人流量失败:{0}", ex.Message));
            }
        }