/// <summary> /// 上传设备运行状态 /// </summary> public void UpdateDeviceState() { try { List <TerminalInfoV2> terminalList = TerminalOperatorService.GetAllTeminalInfo(); foreach (TerminalInfoV2 terminal in terminalList) { //TODO: IDevice.UpdateDeviceStatus(terminal.ClientNo, terminal.StatusUpdateTime); } } catch (Exception ex) { // SeatManage.SeatManageComm.WriteLog.Write(string.Format("上传设备运行状态失败:{0}", ex.Message)); } }
/// <summary> /// 授权,如果设置为服务器授权,则不管是否在线都要联网获取授权 /// </summary> public void Empower() { try { //如果设置为服务器授权,则不管是否在线都要联网获取授权。 if (ServiceSet.Empower == EmpowerMode.Server) { try { //从Advert服务器上获取时间,以判断 是否能够连接到公司服务器上 DateTime?dt = DateTime.Now; //如果有值说明能够连接到服务器上,进行授权。 if (dt.HasValue) { List <TerminalInfoV2> terminalList = TerminalOperatorService.GetAllTeminalInfo(); foreach (TerminalInfoV2 terminal in terminalList) { terminal.EmpowerLoseEfficacyTime = ServiceDateTime.Now.AddDays(7); TerminalOperatorService.UpdateTeminalSetting(terminal); } } } catch { } } else if (ServiceSet.Empower == EmpowerMode.Local) { List <TerminalInfoV2> terminalList = TerminalOperatorService.GetAllTeminalInfo(); foreach (TerminalInfoV2 terminal in terminalList) { terminal.EmpowerLoseEfficacyTime = ServiceDateTime.Now.AddDays(7); TerminalOperatorService.UpdateTeminalSetting(terminal); } } } 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)); } }
/// <summary> /// 获取该学校的终端信息 /// </summary> public void GetDevice() { try { if (ServiceSet.IsOnline) { //媒体服务器的设备列表 List <AMS_Device> modelList = IDevice.GeDeviceModelBySchoolNum(ServiceSet.SchoolNums, false); Dictionary <string, AMS_Device> ModelDic = new Dictionary <string, AMS_Device>(); foreach (AMS_Device item in modelList) { ModelDic.Add(item.Number, item); } //学校的设备列表 List <TerminalInfoV2> oldModelList = TerminalOperatorService.GetAllTeminalInfo(); Dictionary <string, TerminalInfoV2> oldModelDic = new Dictionary <string, TerminalInfoV2>(); foreach (TerminalInfoV2 item in oldModelList) { oldModelDic.Add(item.ClientNo, item); } //判断是否存在num foreach (KeyValuePair <string, AMS_Device> item in ModelDic) { if (oldModelDic.Keys.Contains(item.Key)) { if (!item.Value.IsDel.Value) { TerminalInfoV2 terminal = TerminalOperatorService.GetTeminalSetting(item.Value.Number); //terminal.Describe = item.Value.Describe; terminal.EmpowerLoseEfficacyTime = ServiceDateTime.Now.AddDays(7); TerminalOperatorService.UpdateTeminalSetting(terminal); } else { AMS_Terminal.DeleteTerminal(item.Key); } } else { if (!item.Value.IsDel.Value) { TerminalInfoV2 terminal = new TerminalInfoV2(); //terminal.Describe = item.Value.Describe; terminal.EmpowerLoseEfficacyTime = ServiceDateTime.Now.AddDays(7); terminal.ClientNo = item.Value.Number; terminal.IsUpdatePlayList = false; TerminalOperatorService.AddTeminalInfo(terminal); } } if (item.Value.Flag.Value) { item.Value.Flag = false; IDevice.UpdateDeviceModel(item.Value); } } //判断是否存在非法No foreach (KeyValuePair <string, TerminalInfoV2> item in oldModelDic) { if (!ModelDic.Keys.Contains(item.Key)) { AMS_Terminal.DeleteTerminal(item.Key); } } } else { SystemAuthorization saModel = SeatManage.Bll.SystemAuthorizationOperation.GetSystemAuthorization(); if (saModel == null || saModel.SchoolNum != SeatManage.Bll.Registry.GetSchoolNum()) { WriteLog.Write("获取授权文件失败!"); return; } List <TerminalInfoV2> oldModelList = TerminalOperatorService.GetAllTeminalInfo(); Dictionary <string, TerminalInfoV2> oldModelDic = oldModelList.ToDictionary(item => item.ClientNo); foreach (var item in from item in oldModelDic from v in saModel.SeatClientList.Where(v => item.Key == v.Key) select item) { item.Value.EmpowerLoseEfficacyTime = ServiceDateTime.Now.AddDays(7); TerminalOperatorService.UpdateTeminalSetting(item.Value); } foreach (var item in from item in oldModelDic let isExist = saModel.SeatClientList.Any(v => item.Key == v.Key) where !isExist select item) { AMS_Terminal.DeleteTerminal(item.Key); } foreach (var item in from item in saModel.SeatClientList let isExist = oldModelDic.Any(v => item.Key == v.Key) where !isExist select item) { TerminalInfoV2 terminal = new TerminalInfoV2(); terminal.EmpowerLoseEfficacyTime = ServiceDateTime.Now.AddDays(7); terminal.ClientNo = item.Key; terminal.IsUpdatePlayList = false; TerminalOperatorService.AddTeminalInfo(terminal); } } } catch (Exception ex) { WriteLog.Write(string.Format("获取学校终端信息失败:{0}", ex.Message)); } }
/// <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)); } }