2022-05-04 15:02:12 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure
|
|
|
|
|
{
|
|
|
|
|
class MailBodyFactory
|
|
|
|
|
{
|
2022-05-18 11:07:39 +05:00
|
|
|
|
private readonly string platformName;
|
2022-05-04 15:02:12 +05:00
|
|
|
|
private readonly string platformUrl;
|
2022-05-18 11:07:39 +05:00
|
|
|
|
private readonly string companyName;
|
|
|
|
|
private readonly string supportMail;
|
2022-05-04 15:02:12 +05:00
|
|
|
|
|
|
|
|
|
public MailBodyFactory(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
platformName = configuration.GetValue("email:platformName", "Цифровое бурение");
|
|
|
|
|
platformUrl = configuration.GetValue("email:platformUrl", "");
|
|
|
|
|
companyName = configuration.GetValue("email:companyName", "ООО \"Цифровое бурение\"");
|
|
|
|
|
supportMail = configuration.GetValue("email:supportMail", "support@digitaldrilling.ru");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string MakeSubject(WellDto well, string action)
|
|
|
|
|
{
|
|
|
|
|
var subj = $"{well.Deposit}, {well.Cluster}, {well.Caption}. Программа бурения. {action}";
|
|
|
|
|
return subj;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
public string MakeMailBodyForNewPublisher(WellDto well, string publisherName, string documentCategory)
|
2022-05-04 15:02:12 +05:00
|
|
|
|
{
|
|
|
|
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
var body = $"<html><body><h2>Здравствуйте, {publisherName}.</h2>" +
|
2022-05-04 15:02:12 +05:00
|
|
|
|
$"На портале {platformName} началось создание программы бурения скважины {drillingProgramHref}," +
|
|
|
|
|
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
|
|
|
|
$"<br><br>От вас ожидается загрузка на портал документа «{documentCategory}» в формате excel (*.xlsx)." +
|
|
|
|
|
MakeSignatue() +
|
|
|
|
|
$"</body></html>";
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
public string MakeMailBodyForApproverNewFile(WellDto well, string approverName, int idFile, string fileName)
|
2022-05-04 15:02:12 +05:00
|
|
|
|
{
|
|
|
|
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
var body = $"<html><body><h2>Здравствуйте, {approverName}.</h2>" +
|
|
|
|
|
$"На портал {platformName} загружен документ {fileName}" +
|
2022-05-04 15:02:12 +05:00
|
|
|
|
$" для согласования при создании программы бурения скважины {drillingProgramHref}, куст ({well.Cluster})" +
|
|
|
|
|
$", месторождение ({well.Deposit}).<br>" +
|
|
|
|
|
MakeSignatue() +
|
|
|
|
|
$"</body></html>";
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
public string MakeMailBodyForPublisherOnReject(WellDto well, string publisherName, int idFile, string fileName, FileMarkDto fileMark)
|
2022-05-04 15:02:12 +05:00
|
|
|
|
{
|
|
|
|
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
var body = $"<html><body><h2>Здравствуйте, {publisherName}.</h2>" +
|
|
|
|
|
$"На портале {platformName} отклонен загруженный вами документ {fileName} " +
|
2022-05-04 15:02:12 +05:00
|
|
|
|
$" по программе бурения скважины {drillingProgramHref}," +
|
|
|
|
|
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
2022-05-18 11:07:39 +05:00
|
|
|
|
$" Комментарий согласующего ({fileMark.User?.Name} {fileMark.User?.Surname}):<br>{fileMark.Comment}" +
|
2022-05-04 15:02:12 +05:00
|
|
|
|
MakeSignatue() +
|
|
|
|
|
$"</body></html>";
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
public string MakeMailBodyForPublisherOnFullAccept(WellDto well, string publisherName, int idFile, string fileName)
|
2022-05-04 15:02:12 +05:00
|
|
|
|
{
|
|
|
|
|
var drillingProgramHref = MakeDrillingProgramHref(well);
|
|
|
|
|
|
2022-05-18 11:07:39 +05:00
|
|
|
|
var body = $"<html><body><h2>Здравствуйте, {publisherName}.</h2>" +
|
|
|
|
|
$"На портале {platformName} полностью согласован документ {fileName} " +
|
2022-05-04 15:02:12 +05:00
|
|
|
|
$" по программе бурения скважины {drillingProgramHref}," +
|
|
|
|
|
$" куст {well.Cluster}, месторождение {well.Deposit}." +
|
|
|
|
|
MakeSignatue() +
|
|
|
|
|
$"</body></html>";
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string MakeDrillingProgramHref(WellDto well)
|
|
|
|
|
{
|
2022-05-18 11:07:39 +05:00
|
|
|
|
var drillingProgramUrl = $"{platformUrl}/well/{well.Id}/drillingProgram";
|
2022-05-04 15:02:12 +05:00
|
|
|
|
var drillingProgramHref = MakeHref(drillingProgramUrl, well.Caption);
|
|
|
|
|
return drillingProgramHref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string MakeHref(string url, string text)
|
|
|
|
|
=> $"<a href=\"{url}\">{text}</a>";
|
|
|
|
|
|
|
|
|
|
protected string MakeSignatue()
|
|
|
|
|
{
|
|
|
|
|
var logo = GetImageBase64("logo_32.png");
|
2022-05-05 13:28:48 +05:00
|
|
|
|
var sign = $"<br><br>---<br><img src=\"{logo}\"/><br>" +
|
|
|
|
|
$"{companyName}<br>" +
|
|
|
|
|
$"Это письмо сформировано автоматически.<br>" +
|
|
|
|
|
$"Для получения помощи по работе на портале {platformName}" +
|
|
|
|
|
$"обращайтесь по адресу {supportMail}";
|
2022-05-04 15:02:12 +05:00
|
|
|
|
return sign;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetImageBase64(string resourceFileName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(resourceFileName))
|
|
|
|
|
return null;
|
|
|
|
|
|
2022-05-05 13:28:48 +05:00
|
|
|
|
var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
var resoursesDir = "Res";
|
|
|
|
|
|
|
|
|
|
var logoFilePath = Path.Combine(baseDir, resoursesDir, resourceFileName);
|
|
|
|
|
|
|
|
|
|
var imageBytes = File.ReadAllBytes(logoFilePath);
|
|
|
|
|
var format = Path.GetExtension(resourceFileName).Trim('.');
|
|
|
|
|
return "data:image/" + format + ";base64," + Convert.ToBase64String(imageBytes);
|
2022-05-04 15:02:12 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|