2023-05-20 03:13:10 +04:00
|
|
|
|
using CaseAccountingBusinessLogic.BusinessLogic.OfficePackage;
|
|
|
|
|
using CaseAccountingBusinessLogic.OfficePackage;
|
2023-05-20 00:24:04 +04:00
|
|
|
|
using CaseAccountingContracts.BindingModels;
|
2023-04-08 19:01:51 +04:00
|
|
|
|
using CaseAccountingContracts.BusinessLogicContracts;
|
2023-04-09 01:01:14 +04:00
|
|
|
|
using CaseAccountingContracts.SearchModels;
|
2023-04-08 19:01:51 +04:00
|
|
|
|
using CaseAccountingContracts.StoragesContracts;
|
|
|
|
|
using CaseAccountingContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CaseAccountingBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportProviderLogic : IReportProviderLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ICaseStorage _caseStorage;
|
|
|
|
|
private readonly ISpecializationStorage _specializationStorage;
|
|
|
|
|
private readonly IHearingStorage _hearingStorage;
|
|
|
|
|
private readonly ILawyerStorage _lawyerStorage;
|
2023-05-20 00:24:04 +04:00
|
|
|
|
private readonly WordBuilderProvider _wordBuilder;
|
|
|
|
|
private readonly ExcelBuilderProvider _excelBuilder;
|
2023-05-20 03:13:10 +04:00
|
|
|
|
private readonly PdfBuilderProvider _pdfBuilder;
|
|
|
|
|
private readonly MailSender _mailSender;
|
2023-04-08 19:01:51 +04:00
|
|
|
|
|
2023-05-20 03:13:10 +04:00
|
|
|
|
public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage,
|
|
|
|
|
ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder,
|
|
|
|
|
PdfBuilderProvider pdfBuilder, MailSender mailSender)
|
2023-04-08 19:01:51 +04:00
|
|
|
|
{
|
|
|
|
|
_caseStorage = caseStorage ?? throw new ArgumentNullException(nameof(caseStorage));
|
|
|
|
|
_specializationStorage = specializationStorage ?? throw new ArgumentNullException(nameof(specializationStorage));
|
|
|
|
|
_hearingStorage = hearingStorage ?? throw new ArgumentNullException(nameof(hearingStorage));
|
|
|
|
|
_lawyerStorage = lawyerStorage ?? throw new ArgumentNullException(nameof(lawyerStorage));
|
2023-05-20 00:24:04 +04:00
|
|
|
|
_wordBuilder = wordBuilder ?? throw new ArgumentNullException(nameof(wordBuilder));
|
|
|
|
|
_excelBuilder = excelBuilder ?? throw new ArgumentNullException(nameof(excelBuilder));
|
2023-05-20 03:13:10 +04:00
|
|
|
|
_pdfBuilder = pdfBuilder ?? throw new ArgumentNullException(nameof(pdfBuilder));
|
|
|
|
|
_mailSender = mailSender ?? throw new ArgumentNullException(nameof(mailSender));
|
2023-04-08 19:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 01:01:14 +04:00
|
|
|
|
public List<ReportCaseSpecializationViewModel> GetCaseSpecialization(List<CaseViewModel> models)
|
2023-04-08 19:01:51 +04:00
|
|
|
|
{
|
2023-05-20 00:24:04 +04:00
|
|
|
|
List<ReportCaseSpecializationViewModel> list = new();
|
2023-04-09 01:01:14 +04:00
|
|
|
|
foreach (var model in models)
|
2023-05-20 00:24:04 +04:00
|
|
|
|
{
|
|
|
|
|
var specialization = _specializationStorage.GetElement(new SpecializationSearchModel { Id = model.SpecializationId });
|
|
|
|
|
var caseModel = _caseStorage.GetElement(new CaseSearchModel { Id = model.Id });
|
|
|
|
|
if (specialization == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Некоректные данные по специализации");
|
|
|
|
|
}
|
|
|
|
|
if (caseModel == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Некоректные данные по делу");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasSpec = false;
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var report in list)
|
|
|
|
|
{
|
|
|
|
|
if (hasSpec = report.Specialization.Equals(specialization.Name))
|
|
|
|
|
{
|
|
|
|
|
report.Cases.Add("Дело #" + caseModel.Id.ToString());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hasSpec)
|
|
|
|
|
{
|
|
|
|
|
var newElement = new ReportCaseSpecializationViewModel
|
|
|
|
|
{
|
|
|
|
|
Specialization = specialization.Name,
|
|
|
|
|
Cases = new()
|
|
|
|
|
};
|
|
|
|
|
newElement.Cases.Add("Дело #" + caseModel.Id.ToString());
|
|
|
|
|
list.Add(newElement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
2023-04-08 19:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReportHearingLawyerViewModel> GetHearingLawyer(ReportBindingModel model)
|
|
|
|
|
{
|
2023-05-20 03:13:10 +04:00
|
|
|
|
var hearings = _hearingStorage
|
|
|
|
|
.GetFilteredList(new HearingSearchModel { UserId = model.UserId })
|
2023-04-09 01:01:14 +04:00
|
|
|
|
.Where(x => model.DateFrom <= x.Date && model.DateTo >= x.Date);
|
2023-04-08 19:01:51 +04:00
|
|
|
|
var list = new List<ReportHearingLawyerViewModel>();
|
2023-04-09 01:01:14 +04:00
|
|
|
|
foreach (var hearing in hearings)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportHearingLawyerViewModel
|
|
|
|
|
{
|
2023-05-20 03:13:10 +04:00
|
|
|
|
Hearing = "Номер слушания #" + hearing.Id.ToString(),
|
|
|
|
|
CaseLawyers = new()
|
2023-04-09 01:01:14 +04:00
|
|
|
|
};
|
2023-05-20 03:13:10 +04:00
|
|
|
|
var caseId = _caseStorage.GetElement(new CaseSearchModel { Id = hearing.CaseId }).Id;
|
|
|
|
|
foreach (var lawyer in _lawyerStorage.GetLawyerMTM(caseId))
|
2023-04-09 01:01:14 +04:00
|
|
|
|
{
|
2023-05-20 03:13:10 +04:00
|
|
|
|
record.CaseLawyers.Add(new CaseLawyerViewModel
|
|
|
|
|
{
|
|
|
|
|
Case = "Дело #" + caseId.ToString(),
|
|
|
|
|
Date = hearing.Date,
|
|
|
|
|
Lawyer = lawyer.Surname + " " + lawyer.Name + " " + lawyer.Patronymic
|
|
|
|
|
});
|
2023-04-09 01:01:14 +04:00
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
2023-05-20 03:13:10 +04:00
|
|
|
|
return list;
|
2023-04-08 19:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-20 00:24:04 +04:00
|
|
|
|
public byte[] SaveListFile(CaseSpecializationListBindingModel model)
|
2023-04-08 19:01:51 +04:00
|
|
|
|
{
|
2023-05-20 00:24:04 +04:00
|
|
|
|
byte[] file = Array.Empty<byte>();
|
2023-04-08 19:01:51 +04:00
|
|
|
|
|
2023-05-20 03:13:10 +04:00
|
|
|
|
string title = "Список специализаций по выбраным делам";
|
2023-05-20 00:24:04 +04:00
|
|
|
|
|
|
|
|
|
if (model.FileType == "docx")
|
|
|
|
|
{
|
|
|
|
|
_wordBuilder.CreateDocument();
|
|
|
|
|
_wordBuilder.CreateTitle(title);
|
|
|
|
|
_wordBuilder.CreateCaseSpecializationTable(GetCaseSpecialization(model.Cases));
|
|
|
|
|
file = _wordBuilder.GetFile();
|
|
|
|
|
}
|
|
|
|
|
else if (model.FileType == "xlsx")
|
|
|
|
|
{
|
|
|
|
|
_excelBuilder.CreateDocument();
|
|
|
|
|
_excelBuilder.CreateTitle(title);
|
|
|
|
|
_excelBuilder.CreateCaseSpecializationTable(GetCaseSpecialization(model.Cases));
|
|
|
|
|
file = _excelBuilder.GetFile();
|
|
|
|
|
}
|
|
|
|
|
return file;
|
2023-04-08 19:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-20 03:13:10 +04:00
|
|
|
|
public void SendByMailStatusReport(ReportBindingModel reportModel)
|
2023-04-08 19:01:51 +04:00
|
|
|
|
{
|
2023-05-20 03:13:10 +04:00
|
|
|
|
byte[] file = _pdfBuilder.GetHearingLawyerReportFile(new()
|
2023-05-20 00:24:04 +04:00
|
|
|
|
{
|
2023-05-20 03:13:10 +04:00
|
|
|
|
Title = "Отчет по слушаниям",
|
2023-05-20 00:24:04 +04:00
|
|
|
|
DateFrom = reportModel.DateFrom,
|
|
|
|
|
DateTo = reportModel.DateTo,
|
2023-05-20 03:13:10 +04:00
|
|
|
|
Records = GetHearingLawyer(reportModel)
|
2023-05-20 00:24:04 +04:00
|
|
|
|
});
|
|
|
|
|
_mailSender.SendMailAsync(new()
|
|
|
|
|
{
|
|
|
|
|
MailAddress = reportModel.UserEmail,
|
2023-05-20 03:13:10 +04:00
|
|
|
|
Subject = "Отчет по слушаниям",
|
2023-05-20 00:24:04 +04:00
|
|
|
|
Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " +
|
|
|
|
|
$"по {reportModel.DateTo.ToShortDateString()}.",
|
|
|
|
|
File = file
|
|
|
|
|
});
|
2023-05-20 03:13:10 +04:00
|
|
|
|
}
|
2023-04-08 19:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|