/// <summary> /// 根据指定积分分类获取积分项目中的积分 /// </summary> /// <param name="pointItem">积分项目</param> /// <returns><remarks>key=PointCategory,value=Points</remarks>积分分类-积分字典</returns> private Dictionary <PointCategory, int> GetPointCategory2PointsDictionary(PointItem pointItem) { Dictionary <PointCategory, int> dictionary = new Dictionary <PointCategory, int>(); foreach (var category in GetPointCategories()) { int points = 0; if (category.CategoryKey == PointCategoryKeys.Instance().ExperiencePoints()) { points = pointItem.ExperiencePoints; } else if (category.CategoryKey == PointCategoryKeys.Instance().ReputationPoints()) { points = pointItem.ReputationPoints; } else if (category.CategoryKey == PointCategoryKeys.Instance().TradePoints()) { points = pointItem.TradePoints; } else if (category.CategoryKey == "TradePoints2") { points = pointItem.TradePoints2; } else if (category.CategoryKey == "TradePoints3") { points = pointItem.TradePoints3; } else if (category.CategoryKey == "TradePoints4") { points = pointItem.TradePoints4; } dictionary[category] = points; } return(dictionary); }
//关于缓存期限: //1、PointItem实体、列表 使用CachingExpirationType.RelativelyStable //2、PointCategory实体、列表 使用CachingExpirationType.RelativelyStable //3、PointRecord实体、列表 使用正常的缓存策略 //4、积分记录的所有积分类型都是0,则不创建 #region 积分变更及记录 /// <summary> /// 依据规则增减积分 /// </summary> /// <param name="userId">增减积分的UserId</param> /// <param name="pointItemKey">积分项目标识</param> /// <param name="description">积分记录描述</param> public void GenerateByRole(long userId, string pointItemKey, string description) { //1、依据pointItemKey查找积分项目,如果未找到则中断执行; PointItem pointItem = GetPointItem(pointItemKey); if (pointItem == null) { return; } if (pointItem.ExperiencePoints == 0 && pointItem.ReputationPoints == 0 && pointItem.TradePoints == 0) { return; } //2、检查用户当日各类积分是否达到限额,如果达到限额则不加积分,如果未达到则更新当日积分限额 Dictionary <string, int> dictionary = pointStatisticRepository.UpdateStatistic(userId, GetPointCategory2PointsDictionary(pointItem)); //如果用户当日各类积分都超出限额,则不产生积分 if (dictionary.Count(n => n.Value != 0) == 0) { return; } //3、按照pointItemKey对应的积分项目,生成积分记录,并对用户积分额进行增减; int experiencePoints = dictionary[PointCategoryKeys.Instance().ExperiencePoints()]; int reputationPoints = dictionary[PointCategoryKeys.Instance().ReputationPoints()]; int tradePoints = dictionary[PointCategoryKeys.Instance().TradePoints()]; int tradePoints2 = 0; int tradePoints3 = 0; int tradePoints4 = 0; if (dictionary.ContainsKey("TradePoints2")) { tradePoints2 = dictionary["TradePoints2"]; } if (dictionary.ContainsKey("TradePoints3")) { tradePoints3 = dictionary["TradePoints3"]; } if (dictionary.ContainsKey("TradePoints4")) { tradePoints4 = dictionary["TradePoints4"]; } PointRecord pointRecord = new PointRecord(userId, pointItem.ItemName, description, experiencePoints, reputationPoints, tradePoints); pointRecord.TradePoints2 = tradePoints2; pointRecord.TradePoints3 = tradePoints3; pointRecord.TradePoints4 = tradePoints4; pointRecordRepository.Insert(pointRecord); IUserService userService = DIContainer.Resolve <IUserService>(); userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints, tradePoints2, tradePoints3, tradePoints4); CountService countService = new CountService(TenantTypeIds.Instance().User()); countService.ChangeCount(CountTypes.Instance().ReputationPointsCounts(), userId, userId, pointRecord.ReputationPoints); }
/// <summary> /// 新建实体时使用 /// </summary> public static PointItem New() { PointItem pointItem = new PointItem() { ItemName = string.Empty, Description = string.Empty }; return(pointItem); }
/// <summary> /// 带参构造器 /// </summary> /// <param name="userId"></param> /// <param name="pointItem"></param> /// <param name="description"></param> public PointRecord(long userId, PointItem pointItem, string description) { this.UserId = userId; this.PointItemName = pointItem.ItemName; this.Description = description; this.ExperiencePoints = pointItem.ExperiencePoints; this.ReputationPoints = pointItem.ReputationPoints; this.TradePoints = pointItem.TradePoints; this.TradePoints2 = pointItem.TradePoints2; this.TradePoints3 = pointItem.TradePoints3; this.TradePoints4 = pointItem.TradePoints4; this.IsIncome = pointItem.ExperiencePoints > 0 || pointItem.ReputationPoints > 0 || pointItem.TradePoints > 0; DateCreated = DateTime.UtcNow; }
/// <summary> /// 根据指定积分分类获取积分项目中的积分 /// </summary> /// <param name="pointItem">积分项目</param> /// <returns><remarks>key=PointCategory,value=Points</remarks>积分分类-积分字典</returns> private Dictionary<PointCategory, int> GetPointCategory2PointsDictionary(PointItem pointItem) { Dictionary<PointCategory, int> dictionary = new Dictionary<PointCategory, int>(); foreach (var category in GetPointCategories()) { int points = 0; if (category.CategoryKey == PointCategoryKeys.Instance().ExperiencePoints()) points = pointItem.ExperiencePoints; else if (category.CategoryKey == PointCategoryKeys.Instance().ReputationPoints()) points = pointItem.ReputationPoints; else if (category.CategoryKey == PointCategoryKeys.Instance().TradePoints()) points = pointItem.TradePoints; else if (category.CategoryKey == "TradePoints2") points = pointItem.TradePoints2; else if (category.CategoryKey == "TradePoints3") points = pointItem.TradePoints3; else if (category.CategoryKey == "TradePoints4") points = pointItem.TradePoints4; dictionary[category] = points; } return dictionary; }
/// <summary> /// 更新积分项目 /// </summary> /// <param name="pointItem">待更新的积分项目</param> public void UpdatePointItem(PointItem pointItem) { //注意:ItemId、ApplicationId、ItemName、DisplayOrder不允许修改 pointItemRepository.Update(pointItem); }
/// <summary> /// 新建实体时使用 /// </summary> public static PointItem New() { PointItem pointItem = new PointItem() { ItemName = string.Empty, Description = string.Empty }; return pointItem; }