/// <summary> /// 推送消息给别名用户 /// </summary> /// <param name="request">request.PushUsers 以,分隔的多个别名</param> /// <returns></returns> public SnsResponse JpushSendToAlias(SnsRequest request) { PushPayload pushPayload = GetPushPayload(request); var userlist = request.PushUsers.Split(','); //写记录 System.Threading.Tasks.Task.Run(() => { JpushLog _model = new JpushLog(); _model.CreateTime = DateTime.Now; _model.PushId = request.UserId; _model.IsToAll = 0; _model.BePushId = request.PushUsers; _model.PushMsg = request.PushMsg; if (request.PushExtras != null) { _model.ParamString = request.PushExtras.ToString(); } _jpushLog.Insert(_model); }); SnsResponse response = new SnsResponse(); int splitSize = _defaultPushGroupSize; //分割的块大小 Object[] subAry = StringToolsHelper.splitAry(userlist, splitSize); //分割后的子块数组 //分批次推送操作 for (int i = 0; i < subAry.Length; i++) { string[] aryItem = (string[])subAry[i]; var itemStr = string.Join(",", aryItem); try { pushPayload.audience = Audience.s_alias(aryItem); var result = JPushClient.SendPush(pushPayload); response.JpushMsgId = result.msg_id; #region 推送日志 //System.Threading.Tasks.Task.Run(() => //{ // //写日志 // Logger.Error("SnsService———>JpushSendToAlias:" + string.Format("认证用户发送jpush用户ID列表:{0}", itemStr)); //}); #endregion } catch (Exception e) { //Logger.Error("SnsService———>JpushSendToAlias:" + string.Format("认证用户发送jpush:{0},提供的错误信息:{1},id列表:{2}", e.Message, ((cn.jpush.api.common.APIRequestException)e).ErrorMessage, itemStr)); } //休息一秒 避免:Request times of the app_key exceed the limit of current time window System.Threading.Thread.Sleep(100); } return(response); }
public ResponseModel<List<JourneyArticleDTO>> GetJourneyArticleListById(int Business_Id=0, int Page_Index = 1, int Page_Size = 20) { var result = new ResponseModel<List<JourneyArticleDTO>>(); result.error_code = Result.SUCCESS; result.total_count = 0; //if (Business_Id <= 0) //{ // result.error_code = Result.ERROR; // result.message = "参数有误"; // return result; //} var articleResult = new List<JourneyArticle>(); int total_count = 0; if (Business_Id > 0) { articleResult = _journeyArticleService.GetByBusinessId(Business_Id, Page_Index, Page_Size, out total_count); } else { var allList = _journeyArticleService.GetAll(); total_count = allList.Count; articleResult = allList.Skip(Page_Size * (Page_Index - 1)).Take(Page_Size).ToList(); } List<JourneyArticleDTO> articleList = new List<JourneyArticleDTO>(); if (articleResult != null && articleResult.Count > 0) { foreach (var item in articleResult) { articleList.Add(new JourneyArticleDTO() { user_id = item.UserId, journey_article_id = item.JourneyArticleId, name = item.Name, reads = item.Reads, likes = item.Likes, user_name = item.User == null ? "" : item.User.NickName, create_time = item.CreateTime.ToString("yyyy-MM-dd"), path = item.BaseImage == null ? "" : item.BaseImage.Source + item.BaseImage.Path, content = StringToolsHelper.HtmlToText(item.Content), content_html = item.Content } ); } } result.data = articleList; return result; }
public ResponseModel<JourneyArticleDTO> GetJourneyArticleDetailById(int JourneyArticle_Id, int Module,int User_Id) { var result = new ResponseModel<JourneyArticleDTO>(); result.error_code = Result.SUCCESS; result.total_count = 0; if (JourneyArticle_Id <= 0) { result.error_code = Result.ERROR; result.message = "参数有误"; return result; } JourneyArticleDTO article = new JourneyArticleDTO(); var userLike = _userLikesService.GetByIds(JourneyArticle_Id, User_Id); var articleResult = _journeyArticleService.GetById(JourneyArticle_Id); if (userLike != null && articleResult != null) { articleResult.Reads += 1; _journeyArticleService.Update(articleResult); article.journey_article_id = articleResult.JourneyArticleId; article.name = articleResult.Name; article.reads = articleResult.Reads; article.likes = articleResult.Likes; article.user_name = articleResult.User == null ? "" : articleResult.User.NickName; article.create_time = articleResult.CreateTime.ToString("yyyy-MM-dd"); article.path = articleResult.BaseImage == null ? "" : articleResult.BaseImage.Source + articleResult.BaseImage.Path; article.content = StringToolsHelper.HtmlToText(articleResult.Content); article.content_html = articleResult.Content; article.is_like = (int)EnumHelp.IsLike.点赞; } else if (articleResult != null) { articleResult.Reads += 1; _journeyArticleService.Update(articleResult); article.journey_article_id = articleResult.JourneyArticleId; article.name = articleResult.Name; article.reads = articleResult.Reads; article.likes = articleResult.Likes; article.user_name = articleResult.User == null ? "" : articleResult.User.NickName; article.create_time = articleResult.CreateTime.ToString("yyyy-MM-dd"); article.path = articleResult.BaseImage == null ? "" : articleResult.BaseImage.Source + articleResult.BaseImage.Path; article.content = StringToolsHelper.HtmlToText(articleResult.Content); article.content_html = articleResult.Content; article.is_like = (int)EnumHelp.IsLike.未点赞; } else { result.message = "文章不存在"; result.data = article; return result; } var journeyArticleAll = _journeyArticleService.GetAll(); var recomlist = new List<RecommandArticle>(); if (journeyArticleAll != null) { var nextResult = journeyArticleAll.Where(c => c.JourneyArticleId > articleResult.JourneyArticleId && c.BusinessInfoId == articleResult.BusinessInfoId && c.IsDelete == (int)IsDeleteEnum.有效 && c.Status == (int)EnabledEnum.有效&&c.Module== Module).OrderBy(c => c.JourneyArticleId).FirstOrDefault(); var lastResult = journeyArticleAll.Where(c => c.JourneyArticleId < articleResult.JourneyArticleId && c.BusinessInfoId == articleResult.BusinessInfoId && c.IsDelete == (int)IsDeleteEnum.有效 && c.Status == (int)EnabledEnum.有效 && c.Module == Module).OrderByDescending(c => c.JourneyArticleId).FirstOrDefault(); article.last_article_id = lastResult == null ? 0 : lastResult.JourneyArticleId; article.last_article_name = lastResult == null ? "" : lastResult.Name; article.next_article_name = nextResult == null ? "" : nextResult.Name; article.next_article_id = nextResult == null ? 0 : nextResult.JourneyArticleId; //var nextResult = journeyArticleAll.Fetch(c => c.Id > searchResult.Id && c.IsDelete == Model.IsDeleteEnum.否 && c.Status == Model.StatusEnum.有效).OrderBy(c => c.Id).FirstOrDefault(); //var lastResult = _sylArticleRepository.Fetch(c => c.Id < searchResult.Id && c.IsDelete == Model.IsDeleteEnum.否 && c.Status == Model.StatusEnum.有效).OrderByDescending(c => c.Id).FirstOrDefault(); //result.LastArticleId = lastResult == null ? 0 : lastResult.Id; //result.NextArticleId = nextResult == null ? 0 : nextResult.Id; var articleIds = journeyArticleAll.Where(c => c.JourneyArticleId != JourneyArticle_Id && c.BusinessInfoId == articleResult.BusinessInfoId && c.IsDelete == (int)IsDeleteEnum.有效 && c.Status == (int)EnabledEnum.有效 && c.Module == Module).Select(c => c.JourneyArticleId).ToArray(); Random random = new Random(); int[] rarticleIds = new int[3]; int count = 0; if (articleIds.Length > 3) { while (count < 3) { int id = random.Next(0, articleIds.Length); if (rarticleIds.Contains(id)) { continue; } rarticleIds[count] = id; count++; } } else { for (int i = 0; i < articleIds.Length; i++) { rarticleIds[i] = articleIds[i]; } } var recomsearchlist = journeyArticleAll.Where(c => rarticleIds.Contains(c.JourneyArticleId)).ToList(); if (recomsearchlist != null && recomsearchlist.Count > 0) { foreach (var item in recomsearchlist) { recomlist.Add(new RecommandArticle() { journey_article_id = item.JourneyArticleId, name = item.Name, reads = item.Reads, likes = item.Likes, user_name = item.User == null ? "" : item.User.NickName, create_time = item.CreateTime.ToString("yyyy-MM-dd"), path = item.BaseImage == null ? "" : item.BaseImage.Source + item.BaseImage.Path, user_id = item.UserId }); } } } article.recommand_article_list = recomlist; result.data = article; return result; }