Ejemplo n.º 1
0
        public JsonResult NotificationMessage(MyMessageInput input)
        {
            string errorMessage = null;

            if (!CheckInputWhenReturnActionResult(ref errorMessage))
            {
                using (var result = new ResponseResult <object>())
                {
                    result.Message   = errorMessage;
                    result.IsSuccess = false;
                    return(new JsonResultEx(result));
                }
            }

            var parameters = ModelHelper.GetPropertyDictionary <MyMessageInput>(input);

            using (var responseResult = PostStandardWithSameControllerAction <MyMessageOutput>(this, parameters))
            {
                if (responseResult.IsSuccess)
                {
                    var articleBaseHost = ConfigHelper.GetAppSetting(DataKey.ArticleStaticPageBasePath);
                    foreach (var item in responseResult.Entity.MsgList)
                    {
                        if (item.NotificationType == 1)//说明是文章
                        {
                            item.NotificationSource = articleBaseHost + item.NotificationSource;
                        }
                    }
                }
                return(new JsonResultEx(responseResult));
            }
        }
Ejemplo n.º 2
0
        public JsonResult MyMessage(MyMessageInput input)
        {
            string errorMessage = null;

            if (!CheckInputWhenReturnActionResult(ref errorMessage))
            {
                using (var result = new ResponseResult <object>())
                {
                    result.Message   = errorMessage;
                    result.IsSuccess = false;
                    return(new JsonResultEx(result));
                }
            }

            var parameters = ModelHelper.GetPropertyDictionary <MyMessageInput>(input);

            using (var responseResult = PostStandardWithSameControllerAction <MyMessageOutput>(this, parameters))
            {
                //if (responseResult.IsSuccess)
                //{
                //    var interval = 0;

                //    int.TryParse(ConfigurationManager.AppSettings[DataKey.AndroidPollingFrequency], out interval);
                //    if (interval == 0)
                //        interval = 1;

                //    responseResult.Entity.Interval = interval;
                //}
                return(new JsonResultEx(responseResult));
            }
        }
Ejemplo n.º 3
0
        public JsonResult MyMessage(MyMessageInput input)
        {
            using (var result = new ResponseResult <MyMessageOutput>())
            {
                var myMessage = new MyMessageOutput();
                result.Entity  = myMessage;
                result.Message = getDataSuccessResult;
                var predicate  = PredicateBuilder.True <T_NOTIFICATION>();
                var curDate    = DateTime.Now;
                var todayStart = new DateTime(curDate.Year, curDate.Month, curDate.Day);
                var todayEnd   = new DateTime(curDate.Year, curDate.Month, curDate.Day, 23, 59, 59);

                Cache cache = ControllerContext.HttpContext.Cache;

                if (cache[DataKey.NotificationPollingFrequency] == null)
                {
                    var notificationPoolingSetting = _systemSettingService.GetAll(p => p.SETTING_ID == DataKey.NotificationPollingFrequency).FirstOrDefault();
                    int poolMinutes = 1;
                    if (notificationPoolingSetting == null || !int.TryParse(notificationPoolingSetting.SETTING_VALUE, out poolMinutes))
                    {
                        result.Entity.Interval = 1;
                    }
                    else
                    {
                        result.Entity.Interval = poolMinutes;
                    }

                    cache.Insert(DataKey.NotificationPollingFrequency, result.Entity.Interval, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration);
                }
                else
                {
                    result.Entity.Interval = int.Parse(Convert.ToString(cache[DataKey.NotificationPollingFrequency]) ?? "1");
                }

                var predicateCommon = predicate.And(m => !m.IsDeleted && !m.IsOnDate && m.CreateTime >= todayStart && m.CreateTime <= todayEnd);
                //公共的推送消息
                var predicateForPublic = predicateCommon.And(m => m.IsPublic);

                //先按用户来查询
                if (input.UserId.HasValue)
                {
                    //个人的推送消息
                    var predicateForPersonal = predicateCommon.And(m => !m.IsPublic && m.TargetUserId == input.UserId.Value);
                    //获取今天已接收的公开推送消息
                    var receivedNotificationList   = _sendNotificationResult.GetAll(p => p.UserId == input.UserId);
                    var receivedNotificationIdList = receivedNotificationList.Select(p => p.MsgId).ToList();
                    //获取今天还可以接收的公开推送消息
                    var validPublicNotificationListPredicate = predicateCommon.And(p => !receivedNotificationIdList.Contains(p.MsgId)).And(p => p.IsPublic);
                    var validPublicNotificationList          = _notificationService.GetAll(validPublicNotificationListPredicate);
                    var myAllNotificationList = new List <T_NOTIFICATION>();

                    #region 公共消息
                    if (validPublicNotificationList != null && validPublicNotificationList.Any())
                    {
                        myAllNotificationList.AddRange(validPublicNotificationList);

                        //标识已经发送的公开消息
                        var haveSentPublicNotificationList = new List <T_SEND_NOTIFICATION_RESULT>();
                        foreach (var notification in validPublicNotificationList)
                        {
                            haveSentPublicNotificationList.Add(new T_SEND_NOTIFICATION_RESULT
                            {
                                MsgId    = notification.MsgId,
                                SendTime = DateTime.Now,
                                UserId   = input.UserId.Value
                            });
                        }

                        _sendNotificationResult.Insert(haveSentPublicNotificationList);
                    }
                    #endregion

                    #region 个人消息
                    //获取针对个人的推送消息列表
                    var personalNotificationList = _notificationService.GetAll(predicateForPersonal);

                    if (personalNotificationList != null && personalNotificationList.Count() > 0)
                    {
                        myAllNotificationList.AddRange(personalNotificationList);

                        personalNotificationList.Select(m => m.IsDeleted = true).Count();

                        //更新个人推送消息的状态
                        _notificationService.Update(personalNotificationList);
                    }
                    #endregion

                    result.Entity.MsgList = Mapper.Map <List <MessageItem> >(myAllNotificationList);

                    return(new JsonResultEx(result));
                }


                //按设备标识来查询(只能获取公共消息)
                var publicNotifications = _notificationService.GetAll(predicateForPublic);
                if (publicNotifications == null || !publicNotifications.Any())
                {
                    return(new JsonResultEx(result));
                }

                var haveSentNotification = _visitNotificationService.GetAll(m => m.SendTime >= todayStart && m.SendTime <= todayEnd && m.OsType == input.OsType && m.DeviceToken == input.DeviceToken);
                if (haveSentNotification == null || !haveSentNotification.Any())
                {
                    var haveSentNotificationIdArray = haveSentNotification.Select(m => m.MsgId).ToArray();
                    var validNotification           = publicNotifications.Except(publicNotifications.Where(m => haveSentNotificationIdArray.Contains(m.MsgId)));
                    result.Entity.MsgList = Mapper.Map <List <MessageItem> >(validNotification);
                    //标识已经推送过了
                    if (validNotification != null && validNotification.Any())
                    {
                        var haveSentNotifications = new List <T_VISITOR_RECEIVED_NOTIFICATION>();
                        foreach (var personalNotification in validNotification)
                        {
                            var notification = new T_VISITOR_RECEIVED_NOTIFICATION
                            {
                                MsgId       = personalNotification.MsgId,
                                DeviceToken = input.DeviceToken,
                                SendTime    = DateTime.Now,
                                OsType      = input.OsType
                            };

                            haveSentNotifications.Add(notification);
                        }

                        _visitNotificationService.Insert(haveSentNotifications);
                        //删除过时的消息
                        _visitNotificationService.Delete(m => m.SendTime < todayStart);
                    }
                }
                return(new JsonResultEx(result));
            }
        }