diff --git a/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs b/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs index 408d9348d..fa20819fd 100644 --- a/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs +++ b/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs @@ -159,10 +159,14 @@ namespace IRaCIS.Core.Application.MassTransit.Recurring var confirmUserIdList = datalist.Select(t => t.ConfirmUserId).Distinct().ToList(); var userinfoList = await _identityUserRepository.Where(x => confirmUserIdList.Contains(x.Id)).ToListAsync(); + int index= 1; foreach (var userinfo in userinfoList) { + string msg = $"{index}生效通知,邮箱:{userinfo.EMail},姓名{userinfo.UserName},"; + index++; try { + var messageToSend = new MimeMessage(); //发件地址 messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail)); @@ -191,14 +195,16 @@ namespace IRaCIS.Core.Application.MassTransit.Recurring messageToSend, emailConfigFunc); await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); + msg += "发送成功"; } catch (Exception) { - + msg += "发送失败"; } + Console.WriteLine(msg); } } diff --git a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs index 5a1c520e4..dbd815f8a 100644 --- a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc; using UserRole = IRaCIS.Core.Domain.Models.UserRole; using IRaCIS.Core.Application.MassTransit.Consumer; using MassTransit.Mediator; +using Microsoft.Extensions.DependencyInjection; namespace IRaCIS.Core.Application.Services { @@ -23,6 +24,7 @@ namespace IRaCIS.Core.Application.Services IScopedMediator _mediatorScoped, IRepository _systemDocumentAttachmentRepository, IRepository _identityUserRepository, + IServiceScopeFactory serviceScopeFactory, IRepository _systemDocConfirmedUserRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, ISystemDocumentService { @@ -175,10 +177,18 @@ namespace IRaCIS.Core.Application.Services }); + Task.Run(async () => + { + // 创建独立作用域 + using (var scope = serviceScopeFactory.CreateScope()) + { + // 从新作用域解析服务 + var mediator = scope.ServiceProvider.GetRequiredService(); + await mediator.Publish(new SystemDocumentPublishEvent { Ids = inDto.Ids }); + } + }); - _mediatorScoped.Publish(new SystemDocumentPublishEvent() { Ids = inDto.Ids }); - return ResponseOutput.Result(true); }