/// <summary> /// 获取阶段计数 /// </summary> /// <param name="countType">计数类型</param> /// <param name="dayCount">阶段计数统计天数,一定要和注册时的天数进行对应才能正常获取到</param> /// <param name="objectId">计数对象Id</param> public int GetStageCount(string countType, int dayCount, long objectId) { string stageCountType = StageCountTypeManager.Instance(tenantTypeId).GetStageCountType(countType, dayCount); int count = countRepository.Get(tenantTypeId, stageCountType, objectId); return(count > 0 ? count : 0); }
/// <summary> /// 获取计数对象Id排行集合 /// </summary> /// <param name="topNumber"></param> /// <param name="countType">计数类型</param> /// <param name="dayCount">阶段计数类型的天数(非阶段计数类型请输入null)</param> /// <param name="ownerId">拥有者Id</param> /// <returns>计数对象Id集合</returns> public IEnumerable <long> GetTops(int topNumber, string countType, int?dayCount = null, long?ownerId = null) { if (dayCount != null && dayCount.Value > 0) { countType = StageCountTypeManager.Instance(tenantTypeId).GetStageCountType(countType, dayCount.Value); } //按照统计数倒序排序 return(countRepository.GetTops(topNumber, tenantTypeId, countType, ownerId)); }
/// <summary> /// 获取计数对象Id排行分页集合 /// </summary> /// <param name="countType">计数类型</param> /// <param name="dayCount">阶段计数类型的天数(非阶段计数类型请输入null)</param> /// <param name="ownerId">拥有者Id</param> /// <param name="pageIndex">页码</param> public PagingEntityIdCollection Gets(string countType, int?dayCount = null, long?ownerId = null, int?pageIndex = 1) { if (dayCount != null && dayCount.Value > 0) { countType = StageCountTypeManager.Instance(tenantTypeId).GetStageCountType(countType, dayCount.Value); } //按照统计数倒序排序 return(countRepository.Gets(tenantTypeId, countType, ownerId, pageIndex ?? 1)); }
/// <summary> /// 通过tenantTypeId获取StageCountTypeManager实例 /// </summary> /// <param name="tenantTypeId">tenantTypeId</param> public static StageCountTypeManager Instance(string tenantTypeId) { if (stageCountTypeManagers.ContainsKey(tenantTypeId)) { return(stageCountTypeManagers[tenantTypeId]); } else { lock (lockObject) { StageCountTypeManager StageCountTypeManager = new StageCountTypeManager(tenantTypeId); stageCountTypeManagers[tenantTypeId] = StageCountTypeManager; return(StageCountTypeManager); } } }
/// <summary> /// 通过tenantTypeId获取StageCountTypeManager实例 /// </summary> /// <param name="tenantTypeId">tenantTypeId</param> public static StageCountTypeManager Instance(string tenantTypeId) { if (stageCountTypeManagers.ContainsKey(tenantTypeId)) { return stageCountTypeManagers[tenantTypeId]; } else { lock (lockObject) { StageCountTypeManager StageCountTypeManager = new StageCountTypeManager(tenantTypeId); stageCountTypeManagers[tenantTypeId] = StageCountTypeManager; return StageCountTypeManager; } } }
/// <summary> /// 任务执行的内容 /// </summary> /// <param name="taskDetail">任务配置状态信息</param> public void Execute(TaskDetail taskDetail) { SystemDataService systemDataService = new SystemDataService(); foreach (var perDayTenantTypeId in StageCountTypeManager.GetAllTenantTypeIds()) { var stageCountTypeManager = StageCountTypeManager.Instance(perDayTenantTypeId); ConcurrentDictionary <string, List <int> > allStageCountTypes = stageCountTypeManager.GetAllStageCountTypes(); foreach (var base2StageCountType in allStageCountTypes) { //批量更新计数表中的阶段计数 Dictionary <string, int> countType2Days = base2StageCountType.Value.ToDictionary(n => stageCountTypeManager.GetStageCountType(base2StageCountType.Key, n), n => n); new CountRepository().UpdateStageCountPerDay(perDayTenantTypeId, base2StageCountType.Key, countType2Days); //删除每日计数表中的过期的历史计数记录 int maxValue = stageCountTypeManager.GetMaxDayCount(base2StageCountType.Key); new CountRepository().DeleteTrashCountPerDays(perDayTenantTypeId, base2StageCountType.Key, maxValue); } } }
/// <summary> /// 更新计数 /// </summary> /// <param name="countType">计数类型(不允许是阶段计数类型)</param> /// <param name="objectId">计数对象Id</param> /// <param name="ownerId">拥有者Id</param> /// <param name="changeCount">变化数</param> /// <param name="isRealTime">是否立即更新显示计数</param> /// <remarks>若同时使用了每日计数,则会同时更新每日计数,以及该计数类型相关的阶段计数</remarks> public void ChangeCount(string countType, long objectId, long ownerId, int changeCount = 1, bool isRealTime = false) { IList <string> stageCountTypes = StageCountTypeManager.Instance(tenantTypeId).GetStageCountTypes(countType); countRepository.ChangeCount(tenantTypeId, countType, objectId, ownerId, changeCount, stageCountTypes, isRealTime); }
/// <summary> /// 注册阶段计数 /// </summary> /// <param name="countType">基础阶段计数</param> /// <param name="stageDays">阶段计数统计天数集合</param> public void RegisterStageCount(string countType, params int[] stageDays) { StageCountTypeManager.Instance(tenantTypeId).AddStageCounts(countType, stageDays); }
/// <summary> /// 获取阶段计数类型 /// </summary> /// <param name="countType">计数类型</param> /// <param name="dayCount">阶段计数统计天数,一定要和注册时的天数进行对应才能正常获取到</param> public string GetStageCountType(string countType, int dayCount) { return(StageCountTypeManager.Instance(tenantTypeId).GetStageCountType(countType, dayCount)); }