diff --git a/IRaCIS.Core.Application/MassTransit/Recurring/Schedule/RecurringEvent.cs b/IRaCIS.Core.Application/MassTransit/Recurring/Schedule/RecurringEvent.cs index 490e84478..31f3fb943 100644 --- a/IRaCIS.Core.Application/MassTransit/Recurring/Schedule/RecurringEvent.cs +++ b/IRaCIS.Core.Application/MassTransit/Recurring/Schedule/RecurringEvent.cs @@ -42,13 +42,19 @@ public class UrgentIRUnReadTaskRecurringEvent : DomainEvent /// public class SystemDocumentErverDayEvent : DomainEvent { - + } public class SystemDocumentPublishEvent : DomainEvent { public List Ids { get; set; } + + /// + /// 新增的需要发送邮件的用户角色ID列表 + /// 如果为null或空,则发送给所有相关角色 + /// + public List NewUserTypeIds { get; set; } } diff --git a/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs b/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs index 3516ec8ce..11f18dcc2 100644 --- a/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs +++ b/IRaCIS.Core.Application/MassTransit/Recurring/SystemDocumentConsumer.cs @@ -150,11 +150,13 @@ namespace IRaCIS.Core.Application.MassTransit.Recurring public async Task Consume(ConsumeContext context) { - var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; var systemDocQuery = from sysDoc in _systemDocumentRepository.AsQueryable(false).Where(x => context.Message.Ids.Contains(x.Id)) - from identityUser in _identityUserRepository.AsQueryable(false).Where(t => t.Status == UserStateEnum.Enable && t.UserRoleList.Where(t => t.IsUserRoleDisabled == false).Any(t => sysDoc.NeedConfirmedUserTypeList.AsQueryable().Any(c => c.NeedConfirmUserTypeId == t.UserTypeId))) + from identityUser in _identityUserRepository.AsQueryable(false) + .Where(t => t.Status == UserStateEnum.Enable && t.UserRoleList.Where(t => t.IsUserRoleDisabled == false) + .Any(t => sysDoc.NeedConfirmedUserTypeList.AsQueryable().Any(c => c.NeedConfirmUserTypeId == t.UserTypeId))) + .WhereIf(context.Message.NewUserTypeIds != null && context.Message.NewUserTypeIds.Any(), t => t.UserRoleList.Any(z => context.Message.NewUserTypeIds.Contains(z.UserTypeId))) select new UnionDocumentWithConfirmInfoView() { IsSystemDoc = true, diff --git a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs index 80c499a9c..3bc9c7fdc 100644 --- a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs @@ -1,6 +1,6 @@ //-------------------------------------------------------------------- // 此代码由T4模板自动生成 byzhouhang 20210918 -// 生成时间 2022-01-05 09:17:03 +// 生成时间 2022-01-05 09:17:03 // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- @@ -17,7 +17,7 @@ namespace IRaCIS.Core.Application.Services { /// /// SystemDocumentService - /// + /// [ApiExplorerSettings(GroupName = "Trial")] public class SystemDocumentService(IRepository _systemDocumentRepository, IRepository _userRoleRepository, @@ -57,7 +57,7 @@ namespace IRaCIS.Core.Application.Services /// public async Task AddOrUpdateSystemDocumentAttachment(SystemDocumentAttachmentAddOrEdit addOrEditSystemDocumentAttachment) { - + var entity = await _systemDocumentAttachmentRepository.InsertOrUpdateAsync(addOrEditSystemDocumentAttachment, true); @@ -130,6 +130,11 @@ namespace IRaCIS.Core.Application.Services } + // 保存修改前的状态和需要确认的用户类型列表 + bool beforeIsPublish = document.IsPublish; + bool beforeIsDeleted = document.IsDeleted; + var beforeUserTypeIds = document.NeedConfirmedUserTypeList.Select(x => x.NeedConfirmUserTypeId).ToList(); + _mapper.Map(addOrEditSystemDocument, document); #region 之前区分路径文件夹 现在不区分废弃 @@ -153,9 +158,38 @@ namespace IRaCIS.Core.Application.Services #endregion - var success = await _systemDocumentRepository.SaveChangesAsync(); + // 检查是否需要发送邮件给新增的角色 + if (beforeIsPublish && document.IsPublish && !beforeIsDeleted && !document.IsDeleted) + { + // 找出新增的用户角色ID + var newUserTypeIds = addOrEditSystemDocument.NeedConfirmedUserTypeIdList + .Where(id => !beforeUserTypeIds.Contains(id)) + .ToList(); + + if (newUserTypeIds.Any()) + { + // 发送邮件给新增的角色 + Console.WriteLine("开始 发送系统文档更新邮件给新增角色"); + + Task.Run(async () => + { + // 创建独立作用域 + using (var scope = serviceScopeFactory.CreateScope()) + { + // 从新作用域解析服务 + var mediator = scope.ServiceProvider.GetRequiredService(); + // 只发送给新增的角色 + await mediator.Publish(new SystemDocumentPublishEvent { + Ids = new List { document.Id }, + NewUserTypeIds = newUserTypeIds + }); + } + }); + } + } + return ResponseOutput.Ok(document.Id.ToString()); } @@ -267,7 +301,7 @@ namespace IRaCIS.Core.Application.Services AttachmentCount=sysDoc.SystemDocumentAttachmentList.Where(z=>!z.OffLine).Count(), IsSystemDoc = true, CurrentStaffTrainDays=sysDoc.CurrentStaffTrainDays, - NewStaffTrainDays = sysDoc.NewStaffTrainDays, + NewStaffTrainDays = sysDoc.NewStaffTrainDays, Id = sysDoc.Id, UserCreateTime= user.CreateTime, CreateTime = sysDoc.CreateTime,