修改发送邮件逻辑
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
d34be9b07d
commit
814f6fd83c
|
@ -42,13 +42,19 @@ public class UrgentIRUnReadTaskRecurringEvent : DomainEvent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SystemDocumentErverDayEvent : DomainEvent
|
public class SystemDocumentErverDayEvent : DomainEvent
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class SystemDocumentPublishEvent : DomainEvent
|
public class SystemDocumentPublishEvent : DomainEvent
|
||||||
{
|
{
|
||||||
public List<Guid> Ids { get; set; }
|
public List<Guid> Ids { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增的需要发送邮件的用户角色ID列表
|
||||||
|
/// 如果为null或空,则发送给所有相关角色
|
||||||
|
/// </summary>
|
||||||
|
public List<Guid> NewUserTypeIds { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,11 +150,13 @@ namespace IRaCIS.Core.Application.MassTransit.Recurring
|
||||||
|
|
||||||
public async Task Consume(ConsumeContext<SystemDocumentPublishEvent> context)
|
public async Task Consume(ConsumeContext<SystemDocumentPublishEvent> context)
|
||||||
{
|
{
|
||||||
|
|
||||||
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
|
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
|
||||||
var systemDocQuery =
|
var systemDocQuery =
|
||||||
from sysDoc in _systemDocumentRepository.AsQueryable(false).Where(x => context.Message.Ids.Contains(x.Id))
|
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()
|
select new UnionDocumentWithConfirmInfoView()
|
||||||
{
|
{
|
||||||
IsSystemDoc = true,
|
IsSystemDoc = true,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
// 此代码由T4模板自动生成 byzhouhang 20210918
|
// 此代码由T4模板自动生成 byzhouhang 20210918
|
||||||
// 生成时间 2022-01-05 09:17:03
|
// 生成时间 2022-01-05 09:17:03
|
||||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ namespace IRaCIS.Core.Application.Services
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SystemDocumentService
|
/// SystemDocumentService
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiExplorerSettings(GroupName = "Trial")]
|
[ApiExplorerSettings(GroupName = "Trial")]
|
||||||
public class SystemDocumentService(IRepository<SystemDocument> _systemDocumentRepository,
|
public class SystemDocumentService(IRepository<SystemDocument> _systemDocumentRepository,
|
||||||
IRepository<UserRole> _userRoleRepository,
|
IRepository<UserRole> _userRoleRepository,
|
||||||
|
@ -57,7 +57,7 @@ namespace IRaCIS.Core.Application.Services
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IResponseOutput> AddOrUpdateSystemDocumentAttachment(SystemDocumentAttachmentAddOrEdit addOrEditSystemDocumentAttachment)
|
public async Task<IResponseOutput> AddOrUpdateSystemDocumentAttachment(SystemDocumentAttachmentAddOrEdit addOrEditSystemDocumentAttachment)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var entity = await _systemDocumentAttachmentRepository.InsertOrUpdateAsync(addOrEditSystemDocumentAttachment, true);
|
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);
|
_mapper.Map(addOrEditSystemDocument, document);
|
||||||
|
|
||||||
#region 之前区分路径文件夹 现在不区分废弃
|
#region 之前区分路径文件夹 现在不区分废弃
|
||||||
|
@ -153,9 +158,38 @@ namespace IRaCIS.Core.Application.Services
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
var success = await _systemDocumentRepository.SaveChangesAsync();
|
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<IMediator>();
|
||||||
|
// 只发送给新增的角色
|
||||||
|
await mediator.Publish(new SystemDocumentPublishEvent {
|
||||||
|
Ids = new List<Guid> { document.Id },
|
||||||
|
NewUserTypeIds = newUserTypeIds
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ResponseOutput.Ok(document.Id.ToString());
|
return ResponseOutput.Ok(document.Id.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +301,7 @@ namespace IRaCIS.Core.Application.Services
|
||||||
AttachmentCount=sysDoc.SystemDocumentAttachmentList.Where(z=>!z.OffLine).Count(),
|
AttachmentCount=sysDoc.SystemDocumentAttachmentList.Where(z=>!z.OffLine).Count(),
|
||||||
IsSystemDoc = true,
|
IsSystemDoc = true,
|
||||||
CurrentStaffTrainDays=sysDoc.CurrentStaffTrainDays,
|
CurrentStaffTrainDays=sysDoc.CurrentStaffTrainDays,
|
||||||
NewStaffTrainDays = sysDoc.NewStaffTrainDays,
|
NewStaffTrainDays = sysDoc.NewStaffTrainDays,
|
||||||
Id = sysDoc.Id,
|
Id = sysDoc.Id,
|
||||||
UserCreateTime= user.CreateTime,
|
UserCreateTime= user.CreateTime,
|
||||||
CreateTime = sysDoc.CreateTime,
|
CreateTime = sysDoc.CreateTime,
|
||||||
|
|
Loading…
Reference in New Issue