添加发送邮件功能
This commit is contained in:
@@ -365,6 +365,11 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
public List<Guid> Ids { get; set; }
|
||||
}
|
||||
|
||||
public class PublishTrialDocumentInDto
|
||||
{
|
||||
public List<Guid> Ids { get; set; }
|
||||
}
|
||||
|
||||
public class AddOrEditSystemDocument : SystemDocumentAddOrEdit
|
||||
{
|
||||
|
||||
|
||||
@@ -60,6 +60,24 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
|
||||
public int SignViewMinimumMinutes { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 现有员工培训天数
|
||||
/// </summary>
|
||||
public int? CurrentStaffTrainDays { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新员工培训天数
|
||||
/// </summary>
|
||||
public int? NewStaffTrainDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否发布
|
||||
/// </summary>
|
||||
|
||||
public bool IsPublish { get; set; } = true;
|
||||
|
||||
}
|
||||
|
||||
public class AddOrEditTrialDocument : TrialDocumentAddOrEdit
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using IRaCIS.Core.Application.MassTransit.Consumer;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using MassTransit.Mediator;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic.Core;
|
||||
@@ -28,6 +31,7 @@ namespace IRaCIS.Core.Application.Services
|
||||
IRepository<SystemDocNeedConfirmedUserType> _systemDocNeedConfirmedUserTypeRepository,
|
||||
IRepository<TrialDocNeedConfirmedUserType> _trialDocNeedConfirmedUserTypeRepository,
|
||||
IRepository<SystemDocument> _systemDocumentRepository,
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
IRepository<TrialIdentityUser> _trialIdentityUserRepository,
|
||||
IRepository<TrialUserRole> _trialUserRoleRepository,
|
||||
IRepository<IdentityUser> _identityUserRepository,
|
||||
@@ -35,7 +39,34 @@ namespace IRaCIS.Core.Application.Services
|
||||
IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, ITrialDocumentService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 发布项目文档
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> PublishTrialDocument(PublishTrialDocumentInDto inDto)
|
||||
{
|
||||
await _trialDocumentRepository.BatchUpdateNoTrackingAsync(x => inDto.Ids.Contains(x.Id), x => new TrialDocument()
|
||||
{
|
||||
IsPublish = true,
|
||||
IsDeleted = false,
|
||||
});
|
||||
Console.WriteLine("开始 发布项目文档");
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// 创建独立作用域
|
||||
using (var scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
// 从新作用域解析服务
|
||||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||
await mediator.Publish(new SystemDocumentPublishEvent { Ids = inDto.Ids });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return ResponseOutput.Result(true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -74,6 +105,8 @@ namespace IRaCIS.Core.Application.Services
|
||||
TrialCode = trialDoc.Trial.TrialCode,
|
||||
ResearchProgramNo = trialDoc.Trial.ResearchProgramNo,
|
||||
ExperimentName = trialDoc.Trial.ExperimentName,
|
||||
CurrentStaffTrainDays = trialDoc.CurrentStaffTrainDays,
|
||||
NewStaffTrainDays= trialDoc.NewStaffTrainDays,
|
||||
Id = trialDoc.Id,
|
||||
IsSystemDoc = false,
|
||||
CreateTime = trialDoc.CreateTime,
|
||||
@@ -944,7 +977,9 @@ namespace IRaCIS.Core.Application.Services
|
||||
|
||||
var document = (await _trialDocumentRepository.Where(t => t.Id == addOrEditTrialDocument.Id, true).Include(t => t.NeedConfirmedUserTypeList).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
|
||||
bool beforeIsPublish = document.IsPublish;
|
||||
bool beforeIsDeleted = document.IsDeleted;
|
||||
var beforeUserTypeIds = document.NeedConfirmedUserTypeList.Select(x => x.NeedConfirmUserTypeId).ToList();
|
||||
|
||||
_mapper.Map(addOrEditTrialDocument, document);
|
||||
|
||||
@@ -973,7 +1008,37 @@ namespace IRaCIS.Core.Application.Services
|
||||
|
||||
|
||||
var success = await _trialDocumentRepository.SaveChangesAsync();
|
||||
// 检查是否需要发送邮件给新增的角色
|
||||
if (beforeIsPublish && document.IsPublish && !beforeIsDeleted && !document.IsDeleted)
|
||||
{
|
||||
// 找出新增的用户角色ID
|
||||
var newUserTypeIds = addOrEditTrialDocument.NeedConfirmedUserTypeIdList
|
||||
.Where(id => !beforeUserTypeIds.Contains(id))
|
||||
.ToList();
|
||||
|
||||
if (newUserTypeIds.Any() && newUserTypeIds.Count() > 0)
|
||||
{
|
||||
// 发送邮件给新增的角色
|
||||
Console.WriteLine("开始 发送项目文档更新邮件给新增角色");
|
||||
Console.WriteLine(string.Join(",", newUserTypeIds));
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// 创建独立作用域
|
||||
using (var scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
// 从新作用域解析服务
|
||||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||
// 只发送给新增的角色
|
||||
await mediator.Publish(new TrialDocumentPublishEvent
|
||||
{
|
||||
Ids = new List<Guid> { document.Id },
|
||||
NewUserTypeIds = newUserTypeIds
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return ResponseOutput.Ok(document.Id.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user