/// <summary> /// [内容] -- 点赞 /// </summary> private EMsgContent_Praize praizeToContent(MsgSubmitPraize msgSubmitPraize) { var submitPraize = msgSubmitPraize.SubmitPraize; var bi = _bookRepository.getBookSimple_ByCode(submitPraize.bookCode); if (bi == null) { throw new Exception("消息服务[praizeToContent]:没有找到书本Code"); } EMsgContent_Praize msgContent = new EMsgContent_Praize { BookCode = bi.Code, BookName = bi.Title, BookUrl = bi.CoverUrl, PraizeTarget = submitPraize.praizeTarget, }; string content = ""; ResSimple res = null; switch (msgContent.PraizeTarget) { case PraizeTarget.Resource: res = _resourceReponsitory.getSimpleByCode(submitPraize.refCode); // content = res.ResType == ResType.BookOss ?$"[文件]-{res.OrigFileName}" :$"[URL]-{res.Url}"; msgContent.RefId = res.Code; break; case PraizeTarget.Comment: EComment_Res comment = _commentRepository.GetByKey(Convert.ToInt64(submitPraize.refCode)).Result; content = comment.content; msgContent.RefId = comment.Id.ToString(); msgContent.CommentId = comment.Id; msgContent.OrigContent = content; res = _resourceReponsitory.getSimpleByCode(submitPraize.parentRefCode); break; case PraizeTarget.CommentReply: ECommentReply_Res reply = _commentReplyRepository.GetByKey(Convert.ToInt64(submitPraize.refCode)).Result; content = reply.content; msgContent.CommentId = reply.commentId; msgContent.ReplyId = reply.Id; msgContent.RefId = reply.Id.ToString(); msgContent.OrigContent = content; res = _resourceReponsitory.getSimpleByCommentId(Convert.ToInt64(submitPraize.parentRefCode)); break; } if (res == null) { throw new Exception("消息服务[praizeToContent]:没有找到资源信息"); } msgContent.ResCode = res.Code; msgContent.ResName = res.ShowName; return(msgContent); }
/// <summary> /// 创建点赞消息 /// </summary> /// <param name="msgSubmitPraize"></param> public void CreateNotification_Praize(MsgSubmitPraize msgSubmitPraize) { // Console.WriteLine("start CreateNotification_Praize"); var submitPraize = msgSubmitPraize.SubmitPraize; //没有新的点赞需要通知的 if (msgSubmitPraize.PraizeId <= 0) { return; } if (string.IsNullOrEmpty(submitPraize.userId)) { throw new CCException("非法人员 userId is null "); } if (string.IsNullOrEmpty(submitPraize.refCode)) { throw new CCException("refCode is null"); } //检查消息内容 EMsgContent_Praize existContent = _msgPraizeRepository.GetContentPraize_Sync(submitPraize.refCode, submitPraize.praizeTarget); if (existContent == null) //不存在 { //新内容 existContent = praizeToContent(msgSubmitPraize); existContent.Id = _msgPraizeRepository.AddContentPraize_Sync(existContent); } //检查消息是否发送 bool IsExistMsg = _msgPraizeRepository.ExistMsgPraize_Sync(submitPraize.refCode, submitPraize.praizeTarget, msgSubmitPraize.SubmitPraize.userId); if (IsExistMsg) { return; //已经发送过就退出 } else { EMsgInfo_Praize msg = praizeToMsg(msgSubmitPraize); if (msg == null) { return; } // //检查发送者和接受者是否同一人 if (msg.ReceiveUserId == msg.SendUserId) { return; } var transResult = _msgPraizeRepository.Db.Ado.UseTran(() => { //新消息 msg.RefId = existContent.RefId; _msgPraizeRepository.AddNoIdentity_Sync(msg); //总数 _msgInfoOverviewRepository.UpdateNotificateToUnRead(NotificationType.praize, msg.ReceiveUserId); }); if (!transResult.IsSuccess) { throw new Exception(transResult.ErrorMessage); } } // Console.WriteLine("end CreateNotification_Praize"); }
public long AddContentPraize_Sync(EMsgContent_Praize content) { var insertable = Db.Insertable <EMsgContent_Praize>(content); return(insertable.ExecuteReturnBigIdentity()); }