public MessageCode JobUpdateKpi() { var onlineList = OnlineCore.GetOnlineList(); if (onlineList != null && onlineList.Count > 0) { foreach (var guid in onlineList) { MatchDataHelper.GetManagerKpi(guid); } } return(MessageCode.Success); }
bool UpdateActive() { if (!syncTable) { syncUpdating = true; lockCache.EnterWriteLock(); syncUpdating = false; try { lock (lockWrite) { cacheTable.Clear(); bool flagCacheReset = syncCacheReset; List <Guid> removeList = new List <Guid>(); foreach (var kvp in cacheActive) { var actObj = kvp.Value; //if (actObj.ManagerId.ToString() == "") //{ // int a = 0; // string s = a.ToString(); //} DataRow row = cacheTable.NewRow(); int inactMinutes = (int)DateTime.Now.Subtract(actObj.ActiveTime).TotalMinutes; int actMinutes = (int)actObj.ActiveTime.Subtract(actObj.GuildInTime).TotalMinutes; if (actMinutes < 0) { actMinutes = 0; } bool isOnLine = (inactMinutes < OnlineConfig.TIMEOffLineMinutes); row[cacheTable.ManagerIdColumn.ColumnName] = actObj.ManagerId; row[cacheTable.LoginTimeColumn.ColumnName] = actObj.LoginTime; row[cacheTable.GuildInTimeColumn.ColumnName] = actObj.GuildInTime; row[cacheTable.ActiveTimeColumn.ColumnName] = actObj.ActiveTime; row[cacheTable.ActiveFlagColumn.ColumnName] = isOnLine; row[cacheTable.ResetFlagColumn.ColumnName] = 1; row[cacheTable.CntOnlineMinutesColumn.ColumnName] = isOnLine ? 0 : actMinutes; row[cacheTable.CurOnlineMinutesColumn.ColumnName] = isOnLine ? actMinutes : 0; row[cacheTable.StatusColumn.ColumnName] = 0; row[cacheTable.LoginIpColumn.ColumnName] = ""; row[cacheTable.RowTimeColumn.ColumnName] = DateTime.Now; row[cacheTable.TotalOnlineMinutesColumn.ColumnName] = actObj.TotalOnlineMinutes; cacheTable.Rows.Add(row); if (isOnLine) { if (flagCacheReset) { actObj.GuildInTime = DateTime.Now; actObj.ActiveTime = DateTime.Now; actObj.CntOnlineMinutes = 0; actObj.CurOnlineMinutes = 0; } } else { removeList.Add(kvp.Key); } } syncTable = true; if (flagCacheReset) { syncCacheReset = false; } for (int i = 0; i < removeList.Count; i++) { cacheActive.Remove(removeList[i]); } OnlineCore.LogoutOnline(removeList); } } catch (Exception ex) { SystemlogMgr.Error("GetCacheData", ex); } finally { lockCache.ExitWriteLock(); } } lock (lockWrite) { try { OnlineSqlHelper.UpdateActive(cacheTable); cacheTable.Clear(); syncTable = false; if (syncDBReset) { OnlineSqlHelper.ResetActive(OnlineConfig.PROCBatchSize); syncDBReset = false; } return(true); } catch (Exception ex) { SystemlogMgr.Error("UpdateActive", ex); return(false); } } }
void UpdateActiveCache(Guid managerId) { if (syncClose || syncUpdating) { return; } OnlineInfoEntity actObj = null; if (lockCache.TryEnterReadLock(OnlineConfig.TIMEWaitLock)) { try { cacheActive.TryGetValue(managerId, out actObj); } finally { lockCache.ExitReadLock(); } } if (actObj == null) { if (lockCache.TryEnterWriteLock(OnlineConfig.TIMEWaitLock)) { try { OnlineInfoEntity newObj = new OnlineInfoEntity(managerId, DateTime.Now); cacheActive[managerId] = newObj; OnlineCore.LoginOnline(managerId); } finally { lockCache.ExitWriteLock(); } } } else { bool isCrossDay = false; DateTime curTime = DateTime.Now; DateTime today = curTime.Date; if (lockCache.TryEnterReadLock(OnlineConfig.TIMEWaitLock)) { try { lock (actObj) { if (!actObj.IsHandlerCrossDay && actObj.GuildInTime.Date.AddDays(1) == today)//跨天 { actObj.IsHandlerCrossDay = true; isCrossDay = true; } actObj.ActiveTime = curTime; } } finally { lockCache.ExitReadLock(); } } if (isCrossDay) { try { var manager = ManagerCore.Instance.GetManager(managerId); if (manager == null) { return; } NbUserMgr.UpdateContinueday(manager.Idx, manager.Account, today.AddDays(-1), today); } catch (Exception ex) { LogHelper.Insert(ex); } } } }