Compare commits
3 Commits
cdf1ca5e9f
...
66e5b05ee0
Author | SHA1 | Date | |
---|---|---|---|
66e5b05ee0 | |||
445da5c885 | |||
df55a3ea40 |
@ -100,9 +100,9 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
});
|
||||
|
||||
List<DefectViewModel> defectList = _defectStorage.GetFullList();
|
||||
List<(DefectViewModel, int)> defects = new();
|
||||
|
||||
|
||||
foreach(var techWork in techWorkList)
|
||||
foreach (var techWork in techWorkList)
|
||||
{
|
||||
foreach(var car in techWork.TechnicalWorkCars.Values)
|
||||
{
|
||||
@ -114,28 +114,43 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
TechnicalWorkDate = techWork.DateStartWork,
|
||||
TechnicalWorkPrice = techWork.WorkPrice,
|
||||
});
|
||||
List<DefectViewModel> defects = new();
|
||||
|
||||
foreach (var defect in defectList)
|
||||
{
|
||||
if (defect.DefectCars.ContainsKey(car.Id))
|
||||
{
|
||||
defects.Add(defect);
|
||||
int contains = 0;
|
||||
foreach (var defectt in defects)
|
||||
{
|
||||
if (defectt.Item2 == car.Id && defect.DefectType == defectt.Item1.DefectType)
|
||||
{
|
||||
contains++;
|
||||
}
|
||||
}
|
||||
if(contains == 0)
|
||||
{
|
||||
defects.Add(new(defect, car.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var defect in defects)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (var defect in defects)
|
||||
{
|
||||
if (defect.Item1.RepairId.HasValue)
|
||||
{
|
||||
var repair = _repairStorage.GetElement(new RepairSearchModel { Id = defect.Item1.RepairId });
|
||||
var car = _carStorage.GetElement(new CarSearchModel { Id = defect.Item2 });
|
||||
allList.Add(new ReportCarsViewModel
|
||||
{
|
||||
//if (defect.RepairId.HasValue)
|
||||
//{
|
||||
var repair = _repairStorage.GetElement(new RepairSearchModel { Id = 1 });
|
||||
allList.Add(new ReportCarsViewModel
|
||||
{
|
||||
RepairName = repair.RepairName,
|
||||
RepairStartDate = repair.RepairStartDate,
|
||||
RepairPrice = repair.RepairPrice,
|
||||
});
|
||||
//}
|
||||
}
|
||||
CarNumber = car.CarNumber,
|
||||
CarBrand = car.CarBrand,
|
||||
RepairName = repair.RepairName,
|
||||
RepairStartDate = repair.RepairStartDate,
|
||||
RepairPrice = repair.RepairPrice,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,61 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationBusinessLogic.MailWorker
|
||||
{
|
||||
public abstract class AbstractMailWorker
|
||||
{
|
||||
protected string _mailLogin = string.Empty;
|
||||
protected string _mailPassword = string.Empty;
|
||||
protected string _smtpClientHost = string.Empty;
|
||||
protected int _smtpClientPort;
|
||||
protected string _popHost = string.Empty;
|
||||
protected int _popPort;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void MailConfig(MailConfigBindingModel config)
|
||||
{
|
||||
_mailLogin = config.MailLogin;
|
||||
_mailPassword = config.MailPassword;
|
||||
_smtpClientHost = config.SmtpClientHost;
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||
}
|
||||
|
||||
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
if(string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
|
||||
|
||||
await SendMailAsync(info);
|
||||
}
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.BusinessLogicsContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger) : base(logger) { }
|
||||
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||
|
||||
try
|
||||
{
|
||||
objMailMessage.From = new MailAddress(_mailLogin);
|
||||
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||
objMailMessage.Subject = info.Subject;
|
||||
objMailMessage.Body = info.Text;
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
Attachment attachment = new Attachment(Directory.GetCurrentDirectory().Replace("ServiceStationRestApi", "ServiceStationExecutorApp") + "\\Reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
||||
objMailMessage.Attachments.Add(attachment);
|
||||
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace ServiceStationBusinessLogic.OfficePackage
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAligment = PdfParagraphAlignmentType.Center });
|
||||
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAligment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "3cm", "2cm", "2cm", "3cm", "2cm", "3cm", "2cm" });
|
||||
CreateTable(new List<string> { "3cm", "4cm", "2cm", "3cm", "2cm", "3cm", "2cm" });
|
||||
|
||||
CreateRow( new PdfRowParameters
|
||||
{
|
||||
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationContracts.BindingModels
|
||||
{
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string MailLogin { get; set; } = string.Empty;
|
||||
public string MailPassword { get; set; } = string.Empty;
|
||||
public string SmtpClientHost { get; set; } = string.Empty;
|
||||
public int SmtpClientPort { get; set; }
|
||||
public string PopHost { get; set; } = string.Empty;
|
||||
public int PopPort { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationContracts.BindingModels
|
||||
{
|
||||
public class MailSendInfoBindingModel
|
||||
{
|
||||
public string MailAddress { get; set; } = string.Empty;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -514,10 +514,10 @@ namespace ServiceStationExecutorApp.Controllers
|
||||
{
|
||||
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
}
|
||||
public IActionResult GetPdfFile()
|
||||
{
|
||||
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf", "application/pdf");
|
||||
}
|
||||
//public IActionResult GetPdfFile()
|
||||
//{
|
||||
// return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf", "application/pdf");
|
||||
//}
|
||||
public IActionResult ListCarsToPdf()
|
||||
{
|
||||
if (APIExecutor.Executor == null)
|
||||
@ -544,7 +544,13 @@ namespace ServiceStationExecutorApp.Controllers
|
||||
DateTo = dateTo,
|
||||
ExecutorId = APIExecutor.Executor.Id,
|
||||
});
|
||||
Response.Redirect("GetPdfFile");
|
||||
APIExecutor.PostRequest("api/report/sendpdftomail", new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = executorEmail,
|
||||
Subject = "Отчет по машинам",
|
||||
Text = "Отчет по машинам с " + dateFrom.ToShortDateString() + " по " + dateTo.ToShortDateString()
|
||||
});
|
||||
Response.Redirect("ListCarsToPdf");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceStationBusinessLogic.MailWorker;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.BusinessLogicsContracts;
|
||||
|
||||
@ -10,11 +11,13 @@ namespace ServiceStationRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IExecutorReportLogic _executorReportLogic;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
|
||||
public ReportController(ILogger<ReportController> logger, IExecutorReportLogic executorReportLogic)
|
||||
public ReportController(ILogger<ReportController> logger, IExecutorReportLogic executorReportLogic, AbstractMailWorker abstractMailWorker)
|
||||
{
|
||||
_logger = logger;
|
||||
_executorReportLogic = executorReportLogic;
|
||||
_mailWorker = abstractMailWorker;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -62,5 +65,18 @@ namespace ServiceStationRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void SendPdfToMail(MailSendInfoBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mailWorker.MailSendAsync(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отправки письма");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using ServiceStationBusinessLogic.BusinessLogics;
|
||||
using ServiceStationBusinessLogic.MailWorker;
|
||||
using ServiceStationBusinessLogic.OfficePackage;
|
||||
using ServiceStationBusinessLogic.OfficePackage.Implements;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.BusinessLogicsContracts;
|
||||
using ServiceStationContracts.StoragesContracts;
|
||||
using ServiceStationDatabaseImplement.Implements;
|
||||
@ -38,6 +40,8 @@ builder.Services.AddTransient<AbstractSaveToExcelExecutor, SaveToExcelExecutor>(
|
||||
builder.Services.AddTransient<AbstractSaveToWordExecutor, SaveToWordExecutor>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfExecutor, SaveToPdfExecutor>();
|
||||
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@ -52,6 +56,18 @@ builder.Services.AddSwaggerGen(c =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||
});
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
@ -5,5 +5,12 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"SmtpClientHost": "smtp.mail.ru",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.mail.ru",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "labwork7@mail.ru",
|
||||
"MailPassword": "i135ssgqi7jEzphpyVH9"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user