Example #1
0
        /// <summary>
        /// 任务执行的内容
        /// </summary>
        /// <param name="taskDetail">任务配置状态信息</param>
        public void Execute(TaskDetail taskDetail)
        {
            IEnumerable<IReminderInfoAccessor> reminderInfoTypeAccessors = DIContainer.Resolve<IEnumerable<IReminderInfoAccessor>>();
            //提醒信息类型查询实例集合
            IEnumerable<IReminderSender> reminderSenders = DIContainer.Resolve<IEnumerable<IReminderSender>>();
            //发送提醒实例集合
            ReminderService reminderService = new ReminderService();//提醒业务逻辑实例
            ReminderSettings reminderSettings = reminderSettingsManager.Get();//站点提醒设置
            ConcurrentDictionary<int, ConcurrentDictionary<long, List<UserReminderInfo>>> waitSendDict = new ConcurrentDictionary<int, ConcurrentDictionary<long, List<UserReminderInfo>>>();
            //遍历各种提醒信息类型
            RWLock.EnterWriteLock();
            foreach (var reminderInfoTypeAccessor in reminderInfoTypeAccessors)
            {
                int reminderInfoTypeId = reminderInfoTypeAccessor.ReminderInfoTypeId;
                ReminderInfoType reminderInfoType = ReminderInfoType.Get(reminderInfoTypeAccessor.ReminderInfoTypeId);
                if (reminderInfoType == null)
                    continue;
                //查询该信息类型下的提醒信息集合
                IEnumerable<UserReminderInfo> userReminderInfos = reminderInfoTypeAccessor.GetUserReminderInfos();
                foreach (var userReminderInfo in userReminderInfos.ToList())
                {
                    if (userReminderInfo.UserId <= 0)
                        continue;
                    foreach (var reminderMode in ReminderMode.GetAll())
                    {
                        int reminderModeId = reminderMode.ModeId;

                        UserReminderSettings userReminderSettings = reminderService.GetUserReminderSettings(userReminderInfo.UserId, reminderModeId, reminderInfoTypeId);
                        if (userReminderSettings == null)
                            continue;
                        //1.	判断用户是否启用了提醒并可以使用该提醒方式;
                        if (!userReminderSettings.IsEnabled)
                            continue;

                        if (!waitSendDict.ContainsKey(reminderModeId))
                            waitSendDict[reminderModeId] = new ConcurrentDictionary<long, List<UserReminderInfo>>();
                        if (!waitSendDict[reminderModeId].ContainsKey(userReminderInfo.UserId))
                            waitSendDict[reminderModeId][userReminderInfo.UserId] = new List<UserReminderInfo>();

                        //2.	从用户设置中取发送提醒时间阈值,遍历提醒信息集合筛选出超过此值的提醒信息集合;
                        IEnumerable<ReminderInfo> reminderInfos = userReminderInfo.ReminderInfos.ToList();

                        reminderInfos = reminderInfos.Where(n => n.DateCreated.AddMinutes(userReminderSettings.ReminderThreshold) <= DateTime.UtcNow).ToList();
                        //3.	再判断是否重复提醒用户
                        if (userReminderSettings.IsRepeated)
                        {
                            //   根据相应提醒记录的最后提醒时间和当前时间求差值是否大于重复提醒时间间隔进行筛选,如果提醒记录不存在也应筛选出
                            IEnumerable<ReminderRecord> records = reminderService.GetRecords(userReminderInfo.UserId, reminderModeId, reminderInfoTypeId);
                            reminderInfos = reminderInfos.Where(n =>
                                                      {
                                                          ReminderRecord record = records.FirstOrDefault(m => m.ObjectId == n.ObjectId);
                                                          if (record == null)
                                                              return true;
                                                          TimeSpan ts = DateTime.UtcNow - record.LastReminderTime;
                                                          return ts.TotalMinutes > userReminderSettings.RepeatInterval;
                                                      }).ToList();
                            if (reminderInfos.Count() == 0)
                                continue;
                            IEnumerable<long> objectIds = reminderInfos.Select(n => n.ObjectId);
                            //更新最后提醒时间
                            reminderService.UpdateRecoreds(userReminderInfo.UserId, reminderModeId, reminderInfoTypeId, objectIds);
                        }
                        else
                        {
                            // 根据是否提醒过筛选发送提醒信息集合
                            reminderInfos = reminderInfos.Where(n => !reminderService.IsExits(userReminderInfo.UserId, reminderModeId, reminderInfoTypeId, n.ObjectId)).ToList();
                            if (reminderInfos.Count() == 0)
                                continue;
                            //创建提醒记录
                            reminderService.CreateRecords(userReminderInfo.UserId, reminderModeId, reminderInfoTypeId, reminderInfos.Select(n => n.ObjectId));
                        }

                        userReminderInfo.SetReminderInfos(reminderInfos.ToList());
                        //生成处理地址
                        userReminderInfo.ProcessUrl = reminderInfoTypeAccessor.GetProcessUrl(userReminderInfo.UserId);

                        waitSendDict[reminderModeId][userReminderInfo.UserId].Add(userReminderInfo);
                    }
                }
            }
            RWLock.ExitWriteLock();

            if (waitSendDict != null && waitSendDict.Count > 0)
            {
                foreach (var reminderSender in reminderSenders)
                {
                    if (!waitSendDict.ContainsKey(reminderSender.ReminderModeId))
                    {
                        continue;
                    }

                    foreach (KeyValuePair<long, List<UserReminderInfo>> pair in waitSendDict[reminderSender.ReminderModeId])
                    {
                        //发送提醒
                        reminderSender.SendReminder(pair.Value);
                    }
                }
            }
        }
        private void DeleteUserEventMoudle_After(IUser sender, DeleteUserEventArgs eventArgs)
        {
            IUserService userService = DIContainer.Resolve<IUserService>();

            #region 数据
            //清除应用数据
            applicationService.DeleteUser(sender.UserId, eventArgs.TakeOverUserName, eventArgs.TakeOverAll);

            //删除用户信息
            new UserProfileService().Delete(sender.UserId);

            //清除用户内容计数数据
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.ClearOwnerData(sender.UserId);

            //清除用户关于分类的数据
            CategoryService categoryService = new CategoryService();
            categoryService.CleanByUser(sender.UserId);

            //清除用户动态
            ActivityService activityService = new ActivityService();
            activityService.CleanByUser(sender.UserId);

            //清除用户评论
            new CommentService().DeleteUserComments(sender.UserId, false);

            #endregion

            #region 消息

            //清除用户关于私信的数据
            MessageService messageService = new MessageService();
            messageService.ClearSessionsFromUser(sender.UserId);

            //清除请求的用户数据
            InvitationService invitationService = new InvitationService();
            invitationService.CleanByUser(sender.UserId);

            //清除通知的用户数据
            NoticeService noticeService = new NoticeService();
            noticeService.CleanByUser(sender.UserId);

            InviteFriendService inviteFriendService = new InviteFriendService();
            inviteFriendService.CleanByUser(sender.UserId);

            //清除站外提醒的用户数据
            ReminderService reminderService = new ReminderService();
            reminderService.CleanByUser(sender.UserId);

            #endregion

            #region 关注/访客

            //清除用户关于关注用户的数据
            FollowService followService = new FollowService();
            followService.CleanByUser(sender.UserId);

            //清除访客记录的用户数据
            VisitService visitService = new VisitService(string.Empty);
            visitService.CleanByUser(sender.UserId);

            #endregion

            #region 帐号

            //清除帐号绑定数据
            var accountBindingService = new AccountBindingService();
            var accountBindings = new AccountBindingService().GetAccountBindings(sender.UserId);
            foreach (var accountBinding in accountBindings)
            {
                accountBindingService.DeleteAccountBinding(accountBinding.UserId, accountBinding.AccountTypeKey);
            }

            #endregion

            #region 装扮

            //调整皮肤文件使用次数
            var user = userService.GetFullUser(sender.UserId);
            if (user == null)
                return;
            var presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            string defaultThemeAppearance = string.Join(",", presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);
            if (!user.IsUseCustomStyle)
                new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, !string.IsNullOrEmpty(user.ThemeAppearance) ? user.ThemeAppearance : defaultThemeAppearance);

            #endregion
        }