protected async Task UpdateNoticeAsync(NoticePublishInput input) { var noticemodel = await _noticeTextRepository.GetAll().FirstOrDefaultAsync(r => r.Id == input.Id); if (noticemodel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "数据异常"); } else { noticemodel.Title = input.Title; noticemodel.MsgConent = input.Content; noticemodel.NoticeDepartmentIds = input.NoticeDepartmentIds; noticemodel.NoticeGroupIds = input.NoticeGroupIds; noticemodel.NoticeUserIds = input.NoticeUserIds; await _noticeTextRepository.UpdateAsync(noticemodel); //var logservice = Abp.AbpBootstrapper.Create<Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve<Logapp.ILogAppService>(); //await logservice.CreateOrUpdateLogV2("更新公告", string.Format("更新公告,标题:{0}", input.Title), SystemLogTypes.日常办公.ToString()); } }
/// <summary> /// 发布通知公告 和 发布公司新闻 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task CreateOrUpdateNotice(NoticePublishInput input) { var userids = new List <long>(); if (string.IsNullOrWhiteSpace(input.NoticeUserIds) == false) { userids.AddRange(Array.ConvertAll(input.NoticeUserIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), new Converter <string, long>(ite => long.Parse(ite)))); } if (string.IsNullOrWhiteSpace(input.NoticeGroupIds) == false) { var groupids = Array.ConvertAll(input.NoticeGroupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), new Converter <string, Guid>(ite => Guid.Parse(ite))); //var tmpuserids = _projectAuditGroupUserRepository.GetAll().Where(ite => groupids.Contains(ite.GroupId)).Select(ite => ite.UserId).ToList(); //userids.AddRange(tmpuserids); } if (string.IsNullOrWhiteSpace(input.NoticeDepartmentIds) == false) { var govids = Array.ConvertAll(input.NoticeDepartmentIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), new Converter <string, Guid>(ite => Guid.Parse(ite))); foreach (var g in govids) { int count = 0; //var users = _projectBaseRepository.GetUsersWithCurrentAndUnderOrg(g, 100, 1, out count).Select(ite => ite.Id); //userids.AddRange(users); } } if (userids.Count > 0) { userids = userids.Distinct().ToList(); //var onlineClients = _onlineClientManager.GetAllClients().Where(p => p.UserId.HasValue && userids.Contains(p.UserId.Value)).ToList(); //_noticeCommunicator.SendNoticeToClient(onlineClients, null, input.Title, input.Content, link: "Mpa/DailyOfficeNotice"); } if (input.Id.HasValue) { await UpdateNoticeAsync(input); } else { await CreateNotice(input, userids); } }
protected async Task CreateNotice(NoticePublishInput input, List <long> users = null) { if (input.Id.HasValue) { } var userId = AbpSession.GetUserId(); var textId = await _noticeTextRepository.InsertAndGetIdAsync(new NoticeTexts { CreationTime = DateTime.Now, ExpireTime = new DateTime(2099, 09, 09), MsgConent = input.Content, NoticeType = input.NoticeType, ProjectId = null, Title = input.Title, SendUserId = userId, NoticeDepartmentIds = input.NoticeDepartmentIds, NoticeGroupIds = input.NoticeGroupIds, NoticeUserIds = input.NoticeUserIds, NoticeAllUserIds = users == null ? null : string.Join(",", users) }); if (input.NoticeType == (int)SystemNoticeType.通知公告 && users.Count == 0) { input.IsAllRecive = true; } if (input.NoticeType == (int)SystemNoticeType.公司新闻) { await _noticeLogRepository.InsertAsync(new NoticeLogs { TextId = textId, ReceiveId = userId, Status = 1, NoticeType = input.NoticeType, CreationTime = DateTime.Now }); } else if (input.NoticeType == (int)SystemNoticeType.通知公告) { if (input.IsAllRecive) { await _noticeLogRepository.InsertAsync(new NoticeLogs { TextId = textId, ReceiveId = userId, Status = 1, NoticeType = input.NoticeType, CreationTime = DateTime.Now }); } else { if (users.Count > 0) { foreach (var item in users) { await _noticeLogRepository.InsertAsync(new NoticeLogs { TextId = textId, ReceiveId = item, Status = 1, NoticeType = input.NoticeType, CreationTime = DateTime.Now }); } } } } else { } //日志功能暂时屏蔽 //var logservice = Abp.AbpBootstrapper.Create<Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve<Logapp.ILogAppService>(); //await logservice.CreateOrUpdateLogV2("发布公告", string.Format("发布公告,标题:{0}", input.Title), SystemLogTypes.日常办公.ToString()); await CurrentUnitOfWork.SaveChangesAsync(); var onlineClients = new List <IOnlineClient>(); if (input.NoticeType == (int)SystemNoticeType.通知公告 && !input.IsAllRecive) { onlineClients = _onlineClientManager.GetAllClients().Where(p => p.UserId != userId && users.Contains(p.UserId.Value)).ToList(); } else { onlineClients = _onlineClientManager.GetAllClients().Where(p => p.UserId != userId).ToList(); } _noticeCommunicator.SendNoticeToClient(onlineClients, null, input.Title, string.Empty); }