/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { ForumNewTopicCountList topicCountList = new ForumNewTopicCountList { ForumIdList = new List <int>(0), NewTopicCountList = new List <int>(0) }; List <ForumTopicCount> forumsUpdated = BbsBiz.GetForumsNewTopicCountList(context.UserId, context.DeviceId).ToList(); foreach (var item in forumsUpdated) { if (item.TopicCount > 0) { topicCountList.ForumIdList.Add(item.ForumId); topicCountList.NewTopicCountList.Add(item.TopicCount); } } if (topicCountList.ForumIdList.Count > 0) { context.Flush <ForumNewTopicCountList>(topicCountList); } else { context.Flush(); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length != 4) { context.Flush(RespondCode.CmdDataLack); return; } int topicId = BitConverter.ToInt32(cmdData.Reverse(), 0); if (Compiled.Debug) { cmdData.Debug("=== Bbs.QueryTopicDetail 上行数据 ==="); topicId.Debug("=== Bbs.QueryTopicDetail 上行数据 ==="); } TopicInfo topicInfo = BbsBiz.GetTopicInfoById(topicId, true); if (null != topicInfo) { context.Flush <TopicDetail>(topicInfo.ToTopicDetail(context.UserId)); } else { context.Flush(RespondCode.DataInvalid); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length == 0) { context.Flush(RespondCode.CmdDataLack); return; } TopicQuery query = cmdData.ProtoBufDeserialize<TopicQuery>(); if (Compiled.Debug) query.Debug("=== Bbs.QueryUserTopic 上行数据 ==="); if (query.OwnerId == 0 || query.OwnerId == context.UserId) { context.Flush(RespondCode.DataInvalid); return; } query.AttachContent = string.Empty; query.ForumId = 0; query.HasBestAnswer = true; query.Keyword = string.Empty; query.OrderType = OrderType.Default; UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); TopicQueryConditions condition = new TopicQueryConditions(userCache.UserSite, query, 1); PageResult<TopicInfo> pageResult = BbsBiz.GetPageTopicList(condition, query.QueryIndex, query.QuerySize); //TopicList topicList = pageResult.ToTopicList(); context.Flush<TopicList>(pageResult.ToTopicList()); }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length == 0) { context.Flush(RespondCode.CmdDataLack); return; } BestReplyForm form = cmdData.ProtoBufDeserialize <BestReplyForm>(); if (Compiled.Debug) { form.Debug("=== Bbs.SetBestReply 上行数据 ==="); } int userId = context.UserId; int topicId = form.TopicId; int replyId = form.ReplyId; TopicInfo topicInfo = BbsBiz.GetTopicInfoById(topicId); PostInfo postInfo = BbsBiz.GetPostInfoById(replyId); if (topicInfo == null || postInfo == null) { context.Flush(RespondCode.DataInvalid); return; } if (postInfo.TopicId != topicId) { context.Flush(RespondCode.DataInvalid); return; } if (!topicInfo.IsQuestion && topicInfo.Reward == 0) { context.Flush(RespondCode.ShowError, "该帖子不能设置最佳回复!"); return; } //能设置最佳回复的,帖子一定是当前用户自己发,而被设置的跟帖一定不是当前用户发的。 if (topicInfo.UserId != userId || postInfo.UserId == userId) { context.Flush(RespondCode.ShowError, "只能在自己发布的帖子中将非自己发布的跟帖设置为最佳回复!"); return; } if (topicInfo.BestAnswerId > 0) { context.Flush(RespondCode.ShowError, "该帖子已有最佳回复!"); return; } BbsBiz.SetTopicBestReply(topicInfo, postInfo); context.Flush(); }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { List <ForumInfo> forumsUpdated = BbsBiz.GetUpdatedForumsList(context.UserId, context.DeviceId).ToList(); if (forumsUpdated.Count > 0) { context.Flush <ForumList>(new ForumList { DataList = forumsUpdated.Select(u => u.ToForum()).ToList() }); } else { context.Flush(); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length == 0) { context.Flush(RespondCode.CmdDataLack); return; } TopicQuery query = cmdData.ProtoBufDeserialize <TopicQuery>(); if (Compiled.Debug) { query.Debug("=== Bbs.QueryMyRepliedTopic 上行数据 ==="); } PageResult <TopicInfo> pageResult = BbsBiz.GetUserRepliedTopicPageList(context.UserId, query.QueryIndex, query.QuerySize); context.Flush <TopicList>(pageResult.ToTopicList()); }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length != 4) { context.Flush(RespondCode.CmdDataLack); return; } int topicId = BitConverter.ToInt32(cmdData.Reverse(), 0); if (Compiled.Debug) { cmdData.Debug("=== Bbs.FavouredTopic 上行数据 ==="); topicId.Debug("=== Bbs.FavouredTopic 上行数据 ==="); } int userId = context.UserId; TopicInfo topicInfo = BbsBiz.GetTopicInfoById(topicId); if (null == topicInfo) { context.Flush(RespondCode.DataInvalid); return; } if (topicInfo.UserId == userId) { context.Flush(RespondCode.ShowError, "不能给自己点赞!"); return; } if (BbsBiz.UserFavouredTopic(userId, topicId)) { context.Flush(RespondCode.ShowError, "请勿重复点赞!"); return; } BbsBiz.FavouredTopic(userId, topicId); context.Flush(); }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length == 0) { context.Flush(RespondCode.CmdDataLack); return; } ReplyQuery query = cmdData.ProtoBufDeserialize <ReplyQuery>(); if (Compiled.Debug) { query.Debug("=== Bbs.QueryReply 上行数据 ==="); } int topicId = query.TopicId; PageResult <PostInfo> pageResult = BbsBiz.GetPageReplyList(topicId, query.QueryIndex, query.QuerySize); context.Flush <ReplyList>(pageResult.ToReplyList(context.UserId)); }
/// <summary> /// 从 TopicInfo 提取 TopicDetail /// </summary> /// <param name="topicInfo"></param> /// <param name="userId">当前用户编号,用于判断当前用户是否为帖子的发布者</param> /// <returns></returns> internal static TopicDetail ToTopicDetail(this TopicInfo topicInfo, int userId) { TopicDetail topic = new TopicDetail { Id = topicInfo.TopicId, Title = topicInfo.Title, Owner = UserBiz.ReadUserCacheInfo(topicInfo.UserId).ToUserBase(), IsRefined = topicInfo.IsRefined, TopicType = topicInfo.Reward > 0 ? TopicType.Reward : (topicInfo.IsQuestion ? TopicType.Questions : TopicType.Normal), RewardCount = topicInfo.Reward, HasBestAnswer = topicInfo.BestAnswerId > 0, FavouredCount = topicInfo.FavouredCount, RepliedCount = topicInfo.RepliedCount, PublishTime = topicInfo.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"), AttachContent = topicInfo.AttachContent, AttrChangedMark = topicInfo.AttrChangedMark, ExpChanged = topicInfo.ExpChanged, VirtualCoinChanged = topicInfo.VirtualCoinChanged, IFavoured = true, BestReply = null, Content = topicInfo.Content.GetTopicContentList(), IsAllowReply = topicInfo.IsAllowReply }; if (userId != topicInfo.UserId) { topic.IFavoured = BbsBiz.UserFavouredTopic(userId, topicInfo.TopicId); } if (topic.HasBestAnswer) { PostInfo post = BbsBiz.GetPostInfoById(topicInfo.BestAnswerId); if (null != post) { topic.BestReply = post.ToReplyDetail(userId); } } return(topic); }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { byte[] cmdData = context.CmdData; if (cmdData.Length == 0) { context.Flush(RespondCode.CmdDataLack); return; } TopicQuery query = cmdData.ProtoBufDeserialize <TopicQuery>(); if (Compiled.Debug) { query.Debug("=== Bbs.QueryTopic 上行数据 ==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); TopicQueryConditions condition = new TopicQueryConditions(userCache.UserSite, query, 1); PageResult <TopicInfo> pageResult = BbsBiz.GetPageTopicList(condition, query.QueryIndex, query.QuerySize); //TopicList topicList = pageResult.ToTopicList(); context.Flush <TopicList>(pageResult.ToTopicList()); }
/// <summary> /// 从 PostInfo 中提取 ReplyDetail /// </summary> /// <param name="postInfo"></param> /// <param name="userId">当前用户编号,用于判断当前用户是否为帖子的发布者</param> /// <returns></returns> internal static ReplyDetail ToReplyDetail(this PostInfo postInfo, int userId) { ReplyDetail reply = new ReplyDetail { Id = postInfo.PostId, Owner = UserBiz.ReadUserCacheInfo(postInfo.UserId).ToUserBase(), Content = postInfo.Content.GetTopicContentList(), IsBestAnswer = postInfo.IsBestReply, FavouredCount = postInfo.FavouredCount, PublishTime = postInfo.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"), ExpChanged = postInfo.ExpChanged, VirtualCoinChanged = postInfo.VirtualCoinChanged, IFavoured = true, SetBestDate = "", TargetUser = null }; if (userId != postInfo.UserId) { reply.IFavoured = BbsBiz.UserFavouredPost(userId, postInfo.PostId); } if (postInfo.IsBestReply) { reply.SetBestDate = postInfo.SetBestDate.ToString("yyyy-MM-dd HH:mm:ss"); } /* * if (postInfo.ReplyForUserId > 0) * { * reply.TargetUser = UserBiz.ReadUserCacheInfo(postInfo.ReplyForUserId).ToUserBase(); * } */ return(reply); }
/// <summary> /// /// </summary> /// <param name="topicForm"></param> /// <param name="context"></param> private static void CreateTopic(TopicForm topicForm, DataContext context) { int userId = context.UserId; UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); int schoolId = userCache.UserSite; UserRole userRole = (UserRole)userCache.UserRole; #region 基本校验 ForumInfo forumInfo = BbsBiz.GetForumInfoById(topicForm.ForumId, schoolId); if (null == forumInfo) { context.Flush(RespondCode.ShowError, "版块不存在!"); return; } Forum forum = forumInfo.ToForum(); if (forum.PostRole == PostRole.Forbidden) { context.Flush(RespondCode.ShowError, "版块不允许发帖!"); return; } if (forum.PostRole == PostRole.NotStudent && userRole != UserRole.Teacher && userRole != UserRole.CustomerService) { context.Flush(RespondCode.ShowError, "版块没有发帖权限!"); return; } if ((forum.AllowTopicType & topicForm.TopicType) != topicForm.TopicType) { context.Flush(RespondCode.ShowError, "发帖类型不被允许!"); return; } //悬赏 int reward = 0; if (topicForm.TopicType == TopicType.Reward && topicForm.RewardCount > 0) { if (userCache.VirtualCoinCount < reward) { reward = userCache.VirtualCoinCount; } } //是否带有声音、图片文件 bool hasVoice = topicForm.Voices != null && topicForm.Voices.Count > 0; bool hasImage = topicForm.Image != null && topicForm.Image.Count > 0; bool hasMediaFiles = hasVoice || hasImage; //敏感关键词 List <string> filters = FilterHelper.GetSensitiveWords().ToList(); //标题 string title = (topicForm.Title ?? string.Empty).Trim(); if (string.IsNullOrEmpty(title)) { title = "无题"; } else { if (filters.Count > 0) { title = title.ReplaceSensitiveWord(filters); } } //内容 string content = (topicForm.Content ?? string.Empty).Trim(); string intro = ""; if (!string.IsNullOrEmpty(content)) { if (filters.Count > 0) { content = content.ReplaceSensitiveWord(filters); } intro = content.Length > 200 ? (content.Substring(0, 200) + "...") : content; if (!hasMediaFiles) { content = string.Format("<TopicContent><Text>{0}</Text></TopicContent>", content); } } #endregion #region 数据组装 DateTime dtNow = DateTime.Now; TopicFullInfo topicInfo = new TopicFullInfo { ForumId = topicForm.ForumId, SchoolId = schoolId, UserId = userId, AttachContent = (topicForm.AttachContent ?? string.Empty).Trim(), Title = title, Content = content, Intro = intro, Icon = "", Voice = "", Remark = "", Reward = reward, IsQuestion = topicForm.TopicType == TopicType.Questions, IsAllowReply = true, IsStick = false, IsRefined = false, AttrChangedMark = "", ExpChanged = 0, VirtualCoinChanged = 0, BestAnswerId = 0, FavouredCount = 0, RepliedCount = 0, RepliedUserIds = "", LastRepliedDate = dtNow, ViewCount = 0, FavoritedCount = 0, Status = 0, CreateDate = dtNow, ManageMark = "", LastManageDate = dtNow }; #endregion //创建帖子 BbsBiz.CreateTopic(topicInfo); if (topicInfo.TopicId > 0) { #region 处理声音、图片等文件,并更新帖子内容 if (hasMediaFiles) { List <string> voiceNodeList = new List <string>(0); string extName, url; if (hasVoice) { int voiceTime; foreach (MediaDetail voice in topicForm.Voices) { if (voice.Data != null && voice.Data.Length > 0) { extName = (voice.Name ?? ".mp3").Trim().ToLower(); voiceTime = 0; int.TryParse(voice.Attr ?? "0", out voiceTime); url = voice.Data.SaveMediaFile(FileTarget.Topic, topicInfo.TopicId, Utility.MediaType.Audio, extName); if (!string.IsNullOrEmpty(url)) { voiceNodeList.Add(string.Format("<Voice Url=\"{0}\" Duration=\"{1}\"></Voice>", url, voiceTime)); } } } } List <string> imageNodeList = new List <string>(0); List <string> imageUrlList = new List <string>(0); if (hasImage) { foreach (MediaDetail image in topicForm.Image) { if (image.Data != null && image.Data.Length > 0) { extName = (image.Name ?? ".jpg").Trim().ToLower(); url = image.Data.SaveMediaFile(FileTarget.Topic, topicInfo.TopicId, Utility.MediaType.Image, extName); if (!string.IsNullOrEmpty(url)) { Tuple <int, int> imageSize = url.GetImageSize(); int w = imageSize.Item1, h = imageSize.Item2; if (w > 0 && h > 0) { if (w > 480) { h = (int)((double)h * (double)((double)w / (double)480)); w = 480; } imageUrlList.Add(url); imageNodeList.Add(string.Format("<Image ThumbUrl=\"{0}\" ImageUrl=\"{1}\" Width=\"{2}\" Height=\"{3}\"></Image>", url, url, w, h)); } } } } } string voiceContent = string.Empty; if (voiceNodeList.Count > 0) { voiceContent = string.Join(string.Empty, voiceNodeList); } string textContent = string.Empty; if (!string.IsNullOrEmpty(content)) { textContent = string.Format("<Text>{0}</Text>", content); } string imageContent = string.Empty; if (imageNodeList.Count > 0) { imageContent = string.Join(string.Empty, imageNodeList); } topicInfo.Content = string.Format("<TopicContent>{0}{1}{2}</TopicContent>", voiceContent, textContent, imageContent); if (voiceNodeList.Count > 0) { topicInfo.Voice = voiceNodeList[0]; } if (imageUrlList.Count > 0) { topicInfo.Icon = imageUrlList[0]; } //更新帖子内容 BbsBiz.UpdateTopicContent(topicInfo); } #endregion context.Flush(BitConverter.GetBytes(topicInfo.TopicId).Reverse()); } else { context.Flush(RespondCode.ExecError); } }
/// <summary> /// /// </summary> /// <param name="replyForm"></param> /// <param name="context"></param> private static void CreateReply(ReplyForm replyForm, DataContext context) { int userId = context.UserId; UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); int schoolId = userCache.UserSite; #region 基本校验 TopicInfo topicInfo = BbsBiz.GetTopicInfoById(replyForm.TopicId); if (null == topicInfo) { context.Flush(RespondCode.DataInvalid); return; } if (!topicInfo.IsAllowReply) { context.Flush(RespondCode.ShowError, "该帖子不允许回复!"); return; } //是否带有声音、图片文件 bool hasVoice = replyForm.Voices != null && replyForm.Voices.Count > 0; bool hasImage = replyForm.Image != null && replyForm.Image.Count > 0; bool hasMediaFiles = hasVoice || hasImage; //敏感关键词 List <string> filters = FilterHelper.GetSensitiveWords().ToList(); //内容 string content = (replyForm.Content ?? string.Empty).Trim(); if (!string.IsNullOrEmpty(content)) { if (filters.Count > 0) { content = content.ReplaceSensitiveWord(filters); } if (!hasMediaFiles) { content = string.Format("<TopicContent><Text>{0}</Text></TopicContent>", content); } } #endregion #region 数据组装 DateTime dtNow = DateTime.Now; PostFullInfo postInfo = new PostFullInfo { TopicId = replyForm.TopicId, ForumId = topicInfo.ForumId, SchoolId = schoolId, UserId = userId, Content = content, FavouredCount = 0, ReplyForUserId = replyForm.TargetId, IsBestReply = false, SetBestDate = dtNow, ExpChanged = 0, VirtualCoinChanged = 0, Status = 0, Remark = "", CreateDate = dtNow, ManageMark = "", LastManageDate = dtNow }; #endregion //创建跟帖 BbsBiz.CreateReply(postInfo); if (postInfo.PostId > 0) { #region 处理声音、图片等文件,并更新帖子内容 if (hasMediaFiles) { List <string> voiceNodeList = new List <string>(0); string extName, url; if (hasVoice) { int voiceTime; foreach (MediaDetail voice in replyForm.Voices) { if (voice.Data != null && voice.Data.Length > 0) { extName = (voice.Name ?? ".mp3").Trim().ToLower(); voiceTime = 0; int.TryParse(voice.Attr ?? "0", out voiceTime); url = voice.Data.SaveMediaFile(FileTarget.Post, postInfo.PostId, Utility.MediaType.Audio, extName); if (!string.IsNullOrEmpty(url)) { voiceNodeList.Add(string.Format("<Voice Url=\"{0}\" Duration=\"{1}\"></Voice>", url, voiceTime)); } } } } List <string> imageNodeList = new List <string>(0); if (hasImage) { foreach (MediaDetail image in replyForm.Image) { if (image.Data != null && image.Data.Length > 0) { extName = (image.Name ?? ".jpg").Trim().ToLower(); url = image.Data.SaveMediaFile(FileTarget.Post, postInfo.PostId, Utility.MediaType.Image, extName); if (!string.IsNullOrEmpty(url)) { Tuple <int, int> imageSize = url.GetImageSize(); int w = imageSize.Item1, h = imageSize.Item2; if (w > 0 && h > 0) { if (w > 480) { h = (int)((double)h * (double)((double)w / (double)480)); w = 480; } imageNodeList.Add(string.Format("<Image ThumbUrl=\"{0}\" ImageUrl=\"{1}\" Width=\"{2}\" Height=\"{3}\"></Image>", url, url, w, h)); } } } } } string voiceContent = string.Empty; if (voiceNodeList.Count > 0) { voiceContent = string.Join(string.Empty, voiceNodeList); } string textContent = string.Empty; if (!string.IsNullOrEmpty(content)) { textContent = string.Format("<Text>{0}</Text>", content); } string imageContent = string.Empty; if (imageNodeList.Count > 0) { imageContent = string.Join(string.Empty, imageNodeList); } postInfo.Content = string.Format("<TopicContent>{0}{1}{2}</TopicContent>", voiceContent, textContent, imageContent); //更新帖子内容 BbsBiz.UpdatePostContent(postInfo); } #endregion context.Flush(BitConverter.GetBytes(postInfo.PostId).Reverse()); } else { context.Flush(RespondCode.ExecError); } }