/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { int userId = context.UserId; byte[] cmdData = context.CmdData; if (cmdData.Length == 4) { userId = BitConverter.ToInt32(cmdData.Reverse(), 0); } if (Compiled.Debug) { cmdData.Debug("=== User.QueryUserExt 上行数据==="); userId.Debug("=== User.QueryUserExt 上行数据==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); if (null != userCache) { if (userId != context.UserId) { UserPagePvLog log = new UserPagePvLog { UserId = userId, VisitorId = context.UserId, CreateDate = DateTime.Now }; LogsBiz.CreateLogs <UserPagePvLog>(log); } context.Flush <UserExt>(userCache.ToUserExt()); } else { context.Flush(RespondCode.DataInvalid); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { int userId = context.UserId; byte[] cmdData = context.CmdData; if (cmdData.Length == 4) { userId = BitConverter.ToInt32(cmdData.Reverse(), 0); } if (Compiled.Debug) { cmdData.Debug("=== User.QueryUserBase 上行数据==="); userId.Debug("=== User.QueryUserBase 上行数据==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); if (null != userCache) { context.Flush <UserBase>(userCache.ToUserBase()); } 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; } CourseQuery query = cmdData.ProtoBufDeserialize <CourseQuery>(); if (Compiled.Debug) { query.Debug("=== School.QueryCourses 请求数据 ==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); if (userCache.UserSite > 0) { PageResult <CourseBase> pageResult = SchoolBiz.GetSchoolCoursePageList(userCache.UserSite, query.QueryIndex, query.QuerySize); CourseList result = new CourseList { RecordCount = pageResult.RecordCount, QueryIndex = pageResult.PageIndex, QuerySize = pageResult.PageSize, IndexCount = pageResult.PageCount, DataList = pageResult.Data.Select(c => c.ToCourseInfo()).ToList() }; context.Flush <CourseList>(result); return; } 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; } GroupQuery query = cmdData.ProtoBufDeserialize <GroupQuery>(); if (Compiled.Debug) { query.Debug("=== Social.GroupFind 上行数据==="); } string keyword = query.Keyword ?? string.Empty; string interest = null == query.Interest ? string.Empty : query.Interest.ToString(); UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); PageResult <int> pageResult = SocialBiz.GroupFind(keyword, interest, query.OnlyLessMax, context.UserId, userCache.UserSite, query.QueryIndex, query.QuerySize); GroupList result = new GroupList { RecordCount = pageResult.RecordCount, QueryIndex = pageResult.PageIndex, QuerySize = pageResult.PageSize, IndexCount = pageResult.PageCount, DataList = pageResult.Data.Select(id => SocialBiz.ReadGroupCacheInfo(id).ToGroupBase()).ToList() }; context.Flush <GroupList>(result); }
/// <summary> /// 创建跟帖信息 /// </summary> /// <param name="postInfo"></param> public static void CreateReply(PostFullInfo postInfo) { BbsConfig config = BbsConfigs.GetBbsConfigCache(); postInfo.Status = config.PostIsAudited ? 1 : 0; BbsData.CreateReply(postInfo); //发布成功,并且为即时显示的(如果默认未审核,则以下操作需要在管理后台进行第一次通过审核操作时执行) if (postInfo.PostId > 0 && postInfo.Status == 1) { if (config.CreatePostExpChanged != 0) { UserBiz.UpdateUserExp(postInfo.UserId, config.CreatePostExpChanged, "发布跟帖"); } if (config.CreatePostCoinChanged != 0) { UserBiz.UpdateUserCoin(postInfo.UserId, config.CreatePostCoinChanged, "发布跟帖"); } UserBiz.SetUserCacheInfo(postInfo.UserId); //如果被回复的目标用户关注了跟帖发布人,并且接收提醒消息,此处应该PUSH消息给被回复的目标用户 if (postInfo.UserId != postInfo.ReplyForUserId && postInfo.ReplyForUserId > 0) { UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(postInfo.ReplyForUserId); if (userCache.RemindTopicBeReply && SocialBiz.AlreadyBeFollowed(postInfo.ReplyForUserId, postInfo.UserId)) { //Todo postInfo.ReplyForUserId } } } }
/// <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; } ApplyForm form = cmdData.ProtoBufDeserialize <ApplyForm>(); if (Compiled.Debug) { form.Debug("=== Extend.ApplySubmit 请求数据 ==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); ApplyInfo applyInfo = new ApplyInfo { UserId = context.UserId, SchoolId = userCache.UserSite, UserName = form.Name ?? string.Empty, Telphone = form.Telphone ?? string.Empty, AreaCity = null == form.City ? string.Empty : form.City.ToString(), CourseId = form.CourseId, SourceAd = form.SourceAd, Comment = string.Empty, CreateDate = DateTime.Now }; if (string.IsNullOrEmpty(applyInfo.UserName) || string.IsNullOrEmpty(applyInfo.Telphone) || string.IsNullOrEmpty(applyInfo.AreaCity)) { context.Flush(RespondCode.DataInvalid); return; } ExtendBiz.SubmitApply(applyInfo); if (applyInfo.Id < 0) { context.Flush(RespondCode.ExecError); return; } StringSingle result = new StringSingle(); if (applyInfo.Id > 0) { result.Data = "报名成功!请保持报名电话畅通,我们将在一个工作日内和您电话联系!"; } else { result.Data = "您的报名信息已在处理中,请保持报名电话畅通,我们将在一个工作日内和您电话联系!"; } context.Flush <StringSingle>(result); }
/// <summary> /// 更新用户应用设置 /// </summary> /// <param name="userOptions"></param> public static void SetUserAppOptions(UserOptions userOptions) { UserData.UpdateUserAppOptions(userOptions); UserCacheInfo userCache = ReadUserCacheInfo(userOptions.UserId); userCache.RemindPrivateMessage = userOptions.RemindPrivateMessage; userCache.RemindGroupMessage = userOptions.RemindGroupMessage; userCache.RemindBeFollowed = userOptions.RemindBeFollowed; userCache.RemindTopicBeReply = userOptions.RemindTopicBeReply; SetUserCacheInfo(userOptions.UserId, userCache); }
/// <summary> /// 获取用户基本账户信息 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static UserAccount GetUserAccount(int userId) { UserCacheInfo userCache = ReadUserCacheInfo(userId); UserVaildInfo uVaildInfo = UserData.GetUserVaildInfo(userCache.UserName, UserAccess.App); return(new UserAccount { UserId = userId, Password = uVaildInfo.Password, PasswordSalt = uVaildInfo.PasswordSalt }); }
/// <summary> /// 从数据库读取用于缓存的用户信息 /// </summary> /// <param name="userId">目标用户编号</param> /// <returns>用于缓存的用户信息</returns> public static UserCacheInfo GetUserInfoForCache(int userId) { using (DbCommander cmd = new DbCommander(DbConn.ReadDb, "SP_Users_GetUserInfoForCache", CommandType.StoredProcedure)) { cmd.AddInputParameters("UserId", userId); UserCacheInfo resultData = null; using (IDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { resultData = new UserCacheInfo { UserId = (int)reader["UserId"], UserName = (string)reader["UserName"], NickName = (string)reader["NickName"], RealName = (string)reader["RealName"], BackIcon = (string)reader["BackIcon"], HeadIcon = (string)reader["HeadIcon"], Signature = (string)reader["Signature"], Gender = (int)reader["Gender"], Area = (string)reader["Area"], Birthday = (DateTime)reader["Birthday"], UserAge = (int)reader["UserAge"], Interests = (string)reader["Interests"], UserSite = (int)reader["UserSite"], UserRole = (int)reader["UserRole"], UserAccess = (int)reader["UserAccess"], ExpScore = (int)reader["ExpScore"], ExpLevel = (int)reader["ExpLevel"], GradeName = (string)reader["GradeName"], GradeIcon = (string)reader["GradeIcon"], VirtualCoinCount = (int)reader["VirtualCoinCount"], FansCount = (int)reader["FansCount"], FollowedCount = (int)reader["FollowedCount"], TopicCount = (int)reader["TopicCount"], ReplyCount = (int)reader["ReplyCount"], RemindPrivateMessage = (bool)reader["RemindPrivateMessage"], RemindGroupMessage = (bool)reader["RemindGroupMessage"], RemindBeFollowed = (bool)reader["RemindBeFollowed"], RemindTopicBeReply = (bool)reader["RemindTopicBeReply"], OSPlatform = (int)reader["Platform"], DeviceToken = (string)reader["Token"], StudNo = (string)reader["StudNo"], ClassInfo = (string)reader["ClassInfo"], Comment = (string)reader["Comment"], IsTrial = (bool)reader["IsTrial"] }; } reader.Close(); } return(resultData); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); int userSite = userCache.UserSite; string appChannel = context.ReqChannel; var ads = ExtendBiz.GetTopAdverts(appChannel, userSite, 5); AdvertList adList = new AdvertList { DataList = ads.Select(a => a.ToAdvert()).ToList() }; context.Flush <AdvertList>(adList); }
/// <summary> /// 将用户缓存信息写入缓存(异步) /// </summary> /// <param name="userId">目标用户编号</param> /// <param name="userCache">缓存数据</param> public static async void SetUserCacheInfo(int userId, UserCacheInfo userCache = null) { await Task.Run(() => { UserCacheInfo cacheInfo = userCache == null ? ReadUserCacheInfoFromDb(userId) : userCache; if (null != cacheInfo) { new UserCacheData { UserId = cacheInfo.UserId, CacheData = cacheInfo.ProtoBufSerialize <UserCacheInfo>() } } .UserCacheStorage(); });
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { int days = 0; byte[] cmdData = context.CmdData; if (cmdData.Length == 4) { days = BitConverter.ToInt32(cmdData.Reverse(), 0); } if (days < 0) { days = 0; } if (Compiled.Debug) { cmdData.Debug("=== School.QueryMyTimeTable 请求数据 ==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); if (userCache.UserSite > 0) { TimeTableList result = new TimeTableList(); if (userCache.IsTrial) { result.Message = "抱歉,您尚未报名成为正式学员,暂无课表!"; //可更换为约定的状态码,客户端可根据该状态码动态绘制界面功能,比如提示报名等 context.Flush <TimeTableList>(result); return; } List <CoursesOneDay> lessonList = GetLessonList(context.UserId, userCache.UserSite, days); if (lessonList.Count == 0) { //可更换为约定的状态码,客户端可根据该状态码动态绘制界面功能,比如提示咨询客服等 result.Message = days == 0 ? "抱歉,您的课表尚未排出!" : string.Format("抱歉,{0}天内您暂无上课安排!"); context.Flush <TimeTableList>(result); return; } result.CoursesOneDay = lessonList; context.Flush <TimeTableList>(result); } else { context.Flush(RespondCode.DataInvalid); } }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); if (userCache.UserSite > 0) { var scUserIds = SchoolBiz.GetSchoolUserIds(userCache.UserSite, (int)UserRole.CustomerService); CustomerServiceList csList = new CustomerServiceList { DataList = scUserIds.Select(id => UserBiz.ReadUserCacheInfo(id).ToUserBase()).ToList() }; context.Flush <CustomerServiceList>(csList); return; } context.Flush(RespondCode.DataInvalid); }
/// <summary> /// 命令执行 /// </summary> /// <param name="context"></param> public override void Execute(DataContext context) { UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); if (userCache.UserSite > 0) { SchoolBase schoolBaseInfo = SchoolBiz.GetSchoolBaseInfo(userCache.UserSite); if (null != schoolBaseInfo) { context.Flush <SchoolInfo>(schoolBaseInfo.ToSchoolInfo()); return; } } context.Flush(RespondCode.DataInvalid); }
/// <summary> /// 创建群组 /// </summary> /// <param name="userId"></param> /// <param name="groupName"></param> /// <param name="interest"></param> /// <param name="iconData"></param> /// <param name="iconExtName"></param> /// <returns></returns> public static GroupInfo CreateGroup(int userId, string groupName, string interest, byte[] iconData, string iconExtName) { SocialConfig config = SocialConfigs.GetSocialConfigCache(); GroupInfo groupInfo = new GroupInfo { GroupName = groupName, GroupIcon = config.DefaultGroupIcon, Comment = string.Empty, CreatorId = userId, GroupType = 0, InterestCode = interest, QuickJoinCode = string.Empty, MaxMemberCount = config.GroupMaxMemberCount < 1 ? 20 : config.GroupMaxMemberCount, MemberCount = 0, CreateDate = DateTime.Now }; UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); SocialData.CreateGroup(groupInfo, userCache.UserSite); if (groupInfo.GroupId > 0) { //更新快速加入码和图标 groupInfo.QuickJoinCode = Convert.ToBase64String(groupInfo.GroupId.GetIntOffsetBytes()).TrimEnd('=').ToUpper(); string iconUrl = iconData.SaveMediaFile(FileTarget.Group, groupInfo.GroupId, MediaType.Image, iconExtName); if (!string.IsNullOrEmpty(iconUrl)) { groupInfo.GroupIcon = iconUrl; } SocialData.UpdateGroupInfo(groupInfo); //缓存群信息和成员列表信息 groupInfo.MemberCount++; SetGroupCacheInfo(groupInfo.GroupId, groupInfo); List <UserCacheInfo> memberList = new List <UserCacheInfo>(1) { UserBiz.ReadUserCacheInfo(userId) }; SetGroupMembersCacheInfo(groupInfo.GroupId, memberList); return(groupInfo); } return(null); }
/// <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; } Personal personal = cmdData.ProtoBufDeserialize <Personal>(); if (Compiled.Debug) { personal.Debug("=== User.SetPersonal 上行数据==="); } UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); DateTime birthDay = (personal.BirthDay ?? string.Empty).Parse <DateTime>(); if (birthDay == default(DateTime)) { birthDay = DateTime.Now.AddYears(-18); } UserInfo userInfo = new UserInfo { UserId = context.UserId, NickName = personal.NickName ?? string.Empty, Signature = personal.Signature ?? string.Empty, Gender = (int)personal.Gender, Birthday = birthDay, Area = personal.City == null ? string.Empty : personal.City.ToString(), Interests = personal.Interest == null ? string.Empty : personal.Interest.ToString() }; UserBiz.UpdateUserInfo(userInfo); //更改了个人兴趣组,可以重新推送群组信息给用户 if (!userCache.Area.Equals(userInfo.Area) && !string.IsNullOrEmpty(userInfo.Area)) { //Todo } context.Flush(); }
/// <summary> /// 提取联系人内容 /// </summary> /// <param name="node"></param> /// <returns></returns> private static ContactContent GetContactContent(this XmlNode node) { ContactContent content = new ContactContent { ShowText = node.InnerText.Trim() }; string user = node.Attributes["User"] == null ? "0" : node.Attributes["User"].Value; int userId = 0; if (int.TryParse(user, out userId) && userId > 0) { UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(userId); if (userCache != null) { content.UserData = userCache.ToUserBase(); } } return(content); }
/// <summary> /// 从缓存中读取用户缓存信息 /// </summary> /// <param name="userId">目标用户编号</param> /// <returns>用户缓存信息</returns> public static UserCacheInfo ReadUserCacheInfo(int userId) { UserCacheData cacheData = userId.GetUserCacheFromStorage(); if (null != cacheData && null != cacheData.CacheData && cacheData.CacheData.Length > 0) { return(cacheData.CacheData.ProtoBufDeserialize <UserCacheInfo>()); } UserCacheInfo cacheInfo = ReadUserCacheInfoFromDb(userId); if (null == cacheInfo) { return(cacheInfo); } cacheData = new UserCacheData { UserId = cacheInfo.UserId, CacheData = cacheInfo.ProtoBufSerialize <UserCacheInfo>() }; cacheData.UserCacheStorage(); return(cacheInfo); }
/// <summary> /// 输出登录结果 /// </summary> /// <param name="context">当前请求上下文应答实例</param> /// <param name="uVaildInfo">用户验证信息</param> internal static void FlushResult(DataContext context, UserVaildInfo uVaildInfo) { UserCacheInfo userCacheInfo = UserBiz.ReadUserCacheInfoFromDb(uVaildInfo.UserId); AuthResult authResult = new AuthResult { UserId = uVaildInfo.UserId, DeviceChanged = context.DeviceId == uVaildInfo.LastLoginDeviceId, SessionId = uVaildInfo.UserId.GetSessionId(), UserBase = userCacheInfo.ToUserBase() }; //缓存用户会话状态 authResult.SessionId.SetSession(uVaildInfo.UserId, ExpiredConfigs.GetSessionExpired()); //缓存用户信息 UserBiz.SetUserCacheInfo(uVaildInfo.UserId, userCacheInfo); //用户登录事件 SignInEvents(authResult, uVaildInfo); //输出请求响应 context.Flush <AuthResult>(authResult); }
/// <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> /// /// </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); } }
/// <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="context"></param> public override void Execute(DataContext context) { UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId); context.Flush <AppOptions>(userCache.ToAppOptions()); }