forked from ddrilling/AsbCloudServer
fix emails triggers and bodies
This commit is contained in:
parent
00cfb0909c
commit
24ccc2a128
@ -53,7 +53,8 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
DatabaseFacade Database { get; }
|
DatabaseFacade Database { get; }
|
||||||
|
|
||||||
Task<int> RefreshMaterializedViewAsync<TEntity>(string? mwName = null, CancellationToken token = default) where TEntity : class;
|
Task<int> RefreshMaterializedViewAsync(string? mwName = null, CancellationToken token = default);
|
||||||
|
Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token = default) where TEntity : class;
|
||||||
int SaveChanges();
|
int SaveChanges();
|
||||||
int SaveChanges(bool acceptAllChangesOnSuccess);
|
int SaveChanges(bool acceptAllChangesOnSuccess);
|
||||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||||
|
@ -57,7 +57,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Trace.TraceError(ex.Message);
|
Trace.TraceError(ex.Message);
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
}
|
}
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
@ -8,58 +8,8 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
{
|
{
|
||||||
internal class DrillingProgramMaker
|
internal class DrillingProgramMaker
|
||||||
{
|
{
|
||||||
|
|
||||||
private const int maxAllowedColumns = 256;
|
private const int maxAllowedColumns = 256;
|
||||||
|
|
||||||
//public async Task<FileInfoDto> GetOrCreateAsync(int idWell, int idUser, CancellationToken token = default)
|
|
||||||
//{
|
|
||||||
// var programParts = (await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgramItems, token)
|
|
||||||
// .ConfigureAwait(false))
|
|
||||||
// .Where(f => f.FileMarks?.Any(m => m.IdMarkType == 1 && !m.IsDeleted) ?? false);
|
|
||||||
|
|
||||||
// var well = await wellService.GetAsync(idWell, token)
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
|
|
||||||
// var programs = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
|
|
||||||
// if (programs is not null && programs.Any() && programParts.Any())
|
|
||||||
// {
|
|
||||||
// programs = programs.OrderByDescending(f => f.UploadDate);
|
|
||||||
// var matchFilesIterator = programs.GetEnumerator();
|
|
||||||
// matchFilesIterator.MoveNext();
|
|
||||||
// var matchFile = matchFilesIterator.Current;
|
|
||||||
|
|
||||||
// if (programParts.All(pp => matchFile.UploadDate > pp.UploadDate) &&
|
|
||||||
// File.Exists(fileService.GetUrl(matchFile)))
|
|
||||||
// return matchFile;
|
|
||||||
// else
|
|
||||||
// await fileService.DeleteAsync(matchFile.Id, token)
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
|
|
||||||
// while (matchFilesIterator.MoveNext())
|
|
||||||
// await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
|
|
||||||
// .ConfigureAwait(false);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!programParts.Any())
|
|
||||||
// throw new FileNotFoundException("Нет частей для формирования программы бурения");
|
|
||||||
|
|
||||||
// var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
|
||||||
|
|
||||||
// var filteredFilePaths = programParts
|
|
||||||
// .Select(file => fileService.GetUrl(file));
|
|
||||||
|
|
||||||
// var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
|
||||||
|
|
||||||
// UniteExcelFiles(filteredFilePaths, tempResultFilePath);
|
|
||||||
|
|
||||||
// var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
|
|
||||||
// resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// return fileInfo;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static void UniteExcelFiles(IEnumerable<string> excelFilesNames, string resultExcelPath)
|
public static void UniteExcelFiles(IEnumerable<string> excelFilesNames, string resultExcelPath)
|
||||||
{
|
{
|
||||||
var resultExcelFile = new XLWorkbook(XLEventTracking.Disabled);
|
var resultExcelFile = new XLWorkbook(XLEventTracking.Disabled);
|
||||||
|
@ -254,7 +254,8 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
if (idUserRole == idUserRoleApprover)
|
if (idUserRole == idUserRoleApprover)
|
||||||
await RemoveDrillingProgramAsync(part.IdWell, token);
|
await RemoveDrillingProgramAsync(part.IdWell, token);
|
||||||
|
|
||||||
await NotifyNewPublisherAsync(idWell, user, part.FileCategory.Name, token);
|
if (idUserRole == idUserRolePublisher)
|
||||||
|
await NotifyNewPublisherAsync(idWell, user, part.FileCategory.Name, token);
|
||||||
|
|
||||||
return await context.SaveChangesAsync(token);
|
return await context.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
@ -291,11 +292,16 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
|
|
||||||
var part = await context.DrillingProgramParts
|
var part = await context.DrillingProgramParts
|
||||||
.Include(p => p.RelatedUsers)
|
.Include(p => p.RelatedUsers)
|
||||||
|
.ThenInclude(r => r.User)
|
||||||
|
.AsNoTracking()
|
||||||
.FirstOrDefaultAsync(p => p.IdWell == fileInfo.IdWell && p.IdFileCategory == fileInfo.IdCategory, token);
|
.FirstOrDefaultAsync(p => p.IdWell == fileInfo.IdWell && p.IdFileCategory == fileInfo.IdCategory, token);
|
||||||
|
|
||||||
if (!part.RelatedUsers.Any(r => r.IdUser == idUser && r.IdUserRole == idUserRoleApprover))
|
var user = part.RelatedUsers.FirstOrDefault(r => r.IdUser == idUser && r.IdUserRole == idUserRoleApprover)?.User;
|
||||||
|
if (user is null)
|
||||||
throw new ForbidException($"User {idUser} is not in the approvers list.");
|
throw new ForbidException($"User {idUser} is not in the approvers list.");
|
||||||
|
|
||||||
|
fileMarkDto.User = user.Adapt<UserDto>();
|
||||||
|
|
||||||
var oldMarksIds = fileInfo.FileMarks
|
var oldMarksIds = fileInfo.FileMarks
|
||||||
?.Where(m => m.User.Id == idUser)
|
?.Where(m => m.User.Id == idUser)
|
||||||
.Select(m => m.Id);
|
.Select(m => m.Id);
|
||||||
@ -311,16 +317,22 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
await RemoveDrillingProgramAsync(fileInfo.IdWell, token);
|
await RemoveDrillingProgramAsync(fileInfo.IdWell, token);
|
||||||
await NotifyPublisherOnRejectAsync(fileMarkDto, token);
|
await NotifyPublisherOnRejectAsync(fileMarkDto, token);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// если все согласованты согласовали - оповещаем публикатора
|
|
||||||
if (part.RelatedUsers
|
|
||||||
.Where(u => u.IdUserRole == idUserRoleApprover)
|
|
||||||
.All(user => fileInfo.FileMarks
|
|
||||||
.Any(mark => mark.IdMarkType == idMarkTypeApprove && mark.User.Id == user.IdUser)))
|
|
||||||
{
|
{
|
||||||
await NotifyPublisherOnFullAccepAsync(fileMarkDto, token);
|
// если все согласованты согласовали - оповещаем публикатора
|
||||||
|
var approvers = part.RelatedUsers
|
||||||
|
.Where(u => u.IdUserRole == idUserRoleApprover);
|
||||||
|
if (approvers
|
||||||
|
.All(user => fileInfo.FileMarks
|
||||||
|
.Any(mark => (mark.IdMarkType == idMarkTypeApprove && mark.User.Id == user.IdUser && !mark.IsDeleted)) ||
|
||||||
|
(fileMarkDto.IdMarkType == idMarkTypeApprove && user.IdUser == idUser)))
|
||||||
|
{
|
||||||
|
await NotifyPublisherOnFullAccepAsync(fileMarkDto, token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@ namespace AsbCloudInfrastructure
|
|||||||
{
|
{
|
||||||
class MailBodyFactory
|
class MailBodyFactory
|
||||||
{
|
{
|
||||||
protected readonly string platformName;
|
private readonly string platformName;
|
||||||
private readonly string platformUrl;
|
private readonly string platformUrl;
|
||||||
protected readonly string companyName;
|
private readonly string companyName;
|
||||||
protected readonly string supportMail;
|
private readonly string supportMail;
|
||||||
|
|
||||||
public MailBodyFactory(IConfiguration configuration)
|
public MailBodyFactory(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
@ -26,11 +26,11 @@ namespace AsbCloudInfrastructure
|
|||||||
return subj;
|
return subj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MakeMailBodyForNewPublisher(WellDto well, string userName, string documentCategory)
|
public string MakeMailBodyForNewPublisher(WellDto well, string publisherName, string documentCategory)
|
||||||
{
|
{
|
||||||
var drillingProgramHref = MakeDrillingProgramHref(well);
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
||||||
|
|
||||||
var body = $"<html><body><h2>Здравствуйте, {userName}.</h2>" +
|
var body = $"<html><body><h2>Здравствуйте, {publisherName}.</h2>" +
|
||||||
$"На портале {platformName} началось создание программы бурения скважины {drillingProgramHref}," +
|
$"На портале {platformName} началось создание программы бурения скважины {drillingProgramHref}," +
|
||||||
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
||||||
$"<br><br>От вас ожидается загрузка на портал документа «{documentCategory}» в формате excel (*.xlsx)." +
|
$"<br><br>От вас ожидается загрузка на портал документа «{documentCategory}» в формате excel (*.xlsx)." +
|
||||||
@ -39,13 +39,12 @@ namespace AsbCloudInfrastructure
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MakeMailBodyForApproverNewFile(WellDto well, string userName, int idFile, string fileName)
|
public string MakeMailBodyForApproverNewFile(WellDto well, string approverName, int idFile, string fileName)
|
||||||
{
|
{
|
||||||
var fileDownloadHref = MakeFileDownloadHref(well.Id, idFile, fileName);
|
|
||||||
var drillingProgramHref = MakeDrillingProgramHref(well);
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
||||||
|
|
||||||
var body = $"<html><body><h2>Здравствуйте, {userName}.</h2>" +
|
var body = $"<html><body><h2>Здравствуйте, {approverName}.</h2>" +
|
||||||
$"На портал {platformName} загружен документ {fileDownloadHref}" +
|
$"На портал {platformName} загружен документ {fileName}" +
|
||||||
$" для согласования при создании программы бурения скважины {drillingProgramHref}, куст ({well.Cluster})" +
|
$" для согласования при создании программы бурения скважины {drillingProgramHref}, куст ({well.Cluster})" +
|
||||||
$", месторождение ({well.Deposit}).<br>" +
|
$", месторождение ({well.Deposit}).<br>" +
|
||||||
MakeSignatue() +
|
MakeSignatue() +
|
||||||
@ -53,28 +52,26 @@ namespace AsbCloudInfrastructure
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MakeMailBodyForPublisherOnReject(WellDto well, string userName, int idFile, string fileName, FileMarkDto fileMark)
|
public string MakeMailBodyForPublisherOnReject(WellDto well, string publisherName, int idFile, string fileName, FileMarkDto fileMark)
|
||||||
{
|
{
|
||||||
var fileDownloadHref = MakeFileDownloadHref(well.Id, idFile, fileName);
|
|
||||||
var drillingProgramHref = MakeDrillingProgramHref(well);
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
||||||
|
|
||||||
var body = $"<html><body><h2>Здравствуйте, {userName}.</h2>" +
|
var body = $"<html><body><h2>Здравствуйте, {publisherName}.</h2>" +
|
||||||
$"На портале {platformName} отклонен загруженный вами документ {fileDownloadHref} " +
|
$"На портале {platformName} отклонен загруженный вами документ {fileName} " +
|
||||||
$" по программе бурения скважины {drillingProgramHref}," +
|
$" по программе бурения скважины {drillingProgramHref}," +
|
||||||
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
||||||
$" Комментарий согласующего ({fileMark.User.Name} {fileMark.User.Surname}):<br>{fileMark.Comment}" +
|
$" Комментарий согласующего ({fileMark.User?.Name} {fileMark.User?.Surname}):<br>{fileMark.Comment}" +
|
||||||
MakeSignatue() +
|
MakeSignatue() +
|
||||||
$"</body></html>";
|
$"</body></html>";
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MakeMailBodyForPublisherOnFullAccept(WellDto well, string userName, int idFile, string fileName)
|
public string MakeMailBodyForPublisherOnFullAccept(WellDto well, string publisherName, int idFile, string fileName)
|
||||||
{
|
{
|
||||||
var fileDownloadHref = MakeFileDownloadHref(well.Id, idFile, fileName);
|
|
||||||
var drillingProgramHref = MakeDrillingProgramHref(well);
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
||||||
|
|
||||||
var body = $"<html><body><h2>Здравствуйте, {userName}.</h2>" +
|
var body = $"<html><body><h2>Здравствуйте, {publisherName}.</h2>" +
|
||||||
$"На портале {platformName} полностью согласован документ {fileDownloadHref} " +
|
$"На портале {platformName} полностью согласован документ {fileName} " +
|
||||||
$" по программе бурения скважины {drillingProgramHref}," +
|
$" по программе бурения скважины {drillingProgramHref}," +
|
||||||
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
||||||
MakeSignatue() +
|
MakeSignatue() +
|
||||||
@ -82,16 +79,9 @@ namespace AsbCloudInfrastructure
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string MakeFileDownloadHref(int idWell, int idFile, string fileName)
|
|
||||||
{
|
|
||||||
var fileDownloadUrl = $"{platformUrl}/api/well/{idWell}/files/{idFile}";
|
|
||||||
var fileDownloadHref = MakeHref(fileDownloadUrl, fileName);
|
|
||||||
return fileDownloadHref;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string MakeDrillingProgramHref(WellDto well)
|
private string MakeDrillingProgramHref(WellDto well)
|
||||||
{
|
{
|
||||||
var drillingProgramUrl = $"{platformUrl}/api/well/{well.Id}/drillingProgram";
|
var drillingProgramUrl = $"{platformUrl}/well/{well.Id}/drillingProgram";
|
||||||
var drillingProgramHref = MakeHref(drillingProgramUrl, well.Caption);
|
var drillingProgramHref = MakeHref(drillingProgramUrl, well.Caption);
|
||||||
return drillingProgramHref;
|
return drillingProgramHref;
|
||||||
}
|
}
|
||||||
|
@ -337,6 +337,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
newFileMark.Id = default;
|
newFileMark.Id = default;
|
||||||
newFileMark.DateCreated = DateTime.UtcNow;
|
newFileMark.DateCreated = DateTime.UtcNow;
|
||||||
newFileMark.IdUser = idUser;
|
newFileMark.IdUser = idUser;
|
||||||
|
newFileMark.User = null;
|
||||||
|
|
||||||
db.FileMarks.Add(newFileMark);
|
db.FileMarks.Add(newFileMark);
|
||||||
return await db.SaveChangesAsync(token);
|
return await db.SaveChangesAsync(token);
|
||||||
|
@ -16,7 +16,12 @@
|
|||||||
"email": {
|
"email": {
|
||||||
"smtpServer": "smtp.timeweb.ru",
|
"smtpServer": "smtp.timeweb.ru",
|
||||||
"sender": "bot@autodrilling.ru",
|
"sender": "bot@autodrilling.ru",
|
||||||
"password": "xHhgwZ4D"
|
"password": "xHhgwZ4D",
|
||||||
|
|
||||||
|
"platformName": "Цифровое бурение",
|
||||||
|
"platformUrl": "cloud.digitaldrilling.ru",
|
||||||
|
"companyName": "ООО \"Цифровое бурение\"",
|
||||||
|
"supportMail": "support@digitaldrilling.ru"
|
||||||
},
|
},
|
||||||
"Urls": "http://0.0.0.0:5000" //;https://0.0.0.0:5001" //,
|
"Urls": "http://0.0.0.0:5000" //;https://0.0.0.0:5001" //,
|
||||||
// See https man: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0
|
// See https man: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0
|
||||||
|
Loading…
Reference in New Issue
Block a user