public async Task <IActionResult> PushSomeBodyAndInsertDbAsync([FromBody] MessagePushSomBodyDTO model) { if (model == null) { return(Forbid()); } //入库操作 int messageid = await _messageService.PushSomeBodyAndInsertDbAsync(model); if (messageid == 0) { return(Forbid()); } //消息推送操作 var users = SignalRMessageGroups.UserGroups.Where(m => model.UserIds.Contains(m.UserId) && m.GroupName == MessageDefault.GroupName).ToList(); foreach (var item in users) { await _hubContext.Clients.Client(item.ConnectionId).SendAsync(MessageDefault.ReceiveMessage, new { id = messageid, Title = model.Title + ":【" + model.MsgJson + "】", model.Link, IsSystem = 1, CreateTime = DateTime.Now.ToTimeStamp() }); } return(Ok()); }
/// <summary> /// //对某些人进行消息推送并入库 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task UrgeSendSignalR(MessagePushSomBodyDTO model) { string url = string.Format(_appSettings.Value.MsApplication.url + _appSettings.Value.WorkFlow.UrgeSendSignalR); var content = new StringContent(model.ToJson(), System.Text.Encoding.UTF8, "application/json"); var response = await _apiClient.PostAsync(url, content); response.EnsureSuccessStatusCode(); }
public async Task <WorkFlowResult> UrgeAsync([FromBody] UrgeDto urge) { var workflowResult = await _workFlowInstanceService.UrgeAsync(urge); if (!workflowResult.Result) { return(workflowResult); } var urgeTypeArray = urge.UrgeType.Split(',').Where(m => !string.IsNullOrEmpty(m)); List <long> urgeUserList = workflowResult.Data.ToString().Split(',') .Where(m => !string.IsNullOrEmpty(m)) .Select(m => Convert.ToInt64(m)).ToList(); MessagePushSomBodyDTO model = new MessagePushSomBodyDTO { UserIds = urgeUserList, Title = urge.Title, MsgJson = urge.UrgeContent, Sender = urge.Sender.ToInt64(), Link = urge.Link }; foreach (var item in urgeTypeArray) { UrgeType urgeType = (UrgeType)item.ToInt32(); switch (urgeType) { case UrgeType.EMail: UrgeSendEMail(); break; case UrgeType.SMS: UrgeSendSMS(); break; case UrgeType.WeChat: UrgeSendWeChat(); break; case UrgeType.SignalR: default: await UrgeSendSignalR(model); break; } } return(WorkFlowResult.Success()); }
/// <summary> /// 对 某些人进行消息推送并入库 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <int> PushSomeBodyAndInsertDbAsync(MessagePushSomBodyDTO model) { using (var tran = _databaseFixture.Db.BeginTransaction()) { try { OaMessage message = new OaMessage { Content = model.MsgJson, CreateTime = DateTime.Now.ToTimeStamp(), IsDel = 0, IsEnable = 1, IsExecuted = 0, IsLocal = 1, IsSystem = 1, Link = model.Link, CreateUserId = model.Sender, MakerUserId = model.Sender, EndTime = 0, StartTime = 0, FaceUserType = (byte)OaMessageFaceUserType.Users, MsgType = (int)OaMessageType.Push, TargetType = "tab", Title = model.Title }; int id = await _databaseFixture.Db.OaMessage.InsertReturnIdAsync(message, tran); foreach (var item in model.UserIds) { OaMessageUser messageUser = new OaMessageUser { MessageId = id, UserId = item, IsRead = 0 }; await _databaseFixture.Db.OaMessageUser.InsertAsync(messageUser, tran); } tran.Commit(); return(id); } catch (Exception ex) { tran.Rollback(); return(0); } } }
protected async Task UrgeSendSignalR(MessagePushSomBodyDTO model) { await _configService.UrgeSendSignalR(model); }