2023-05-20 00:24:04 +04:00
|
|
|
|
using CaseAccountingBusinessLogic.OfficePackage;
|
|
|
|
|
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;
|
|
|
|
|
/*private readonly PdfBuilderProvider _pdfBuilder;
|
|
|
|
|
private readonly MailSender _mailSender;*/
|
2023-04-08 19:01:51 +04:00
|
|
|
|
|
2023-05-20 00:24:04 +04:00
|
|
|
|
public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder)
|
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-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 00:24:04 +04:00
|
|
|
|
/*var hearings = _hearingStorage
|
2023-04-09 01:01:14 +04:00
|
|
|
|
.GetFilteredList(new HearingSearchModel { UserId = model.UserId})
|
|
|
|
|
.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
|
|
|
|
|
{
|
|
|
|
|
Information = hearing.Information,
|
|
|
|
|
Date = hearing.Date,
|
|
|
|
|
Lawyers = new List<(string Surname, string Name, string Patronymic)>()
|
|
|
|
|
};
|
|
|
|
|
foreach (var lawyer in _caseStorage.GetElement(new CaseSearchModel { Id = hearing.CaseId }).Lawyers.Values)
|
|
|
|
|
{
|
|
|
|
|
record.Lawyers.Add((lawyer.Surname, lawyer.Name, lawyer.Patronymic));
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
2023-05-20 00:24:04 +04:00
|
|
|
|
return list;*/
|
|
|
|
|
return new();
|
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 00:24:04 +04:00
|
|
|
|
string title = "Список дисциплин по выбранным студентам";
|
|
|
|
|
|
|
|
|
|
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 00:24:04 +04:00
|
|
|
|
/*public void SendByMailStatusReport(ReportBindingModel reportModel)
|
2023-04-08 19:01:51 +04:00
|
|
|
|
{
|
2023-05-20 00:24:04 +04:00
|
|
|
|
byte[] file = _pdfBuilder.GetEducationStatusReportFile(new()
|
|
|
|
|
{
|
|
|
|
|
Title = "Отчет по статусам обучения",
|
|
|
|
|
DateFrom = reportModel.DateFrom,
|
|
|
|
|
DateTo = reportModel.DateTo,
|
|
|
|
|
Records = GetStreamStudentEdStatPeriod(reportModel)
|
|
|
|
|
});
|
|
|
|
|
_mailSender.SendMailAsync(new()
|
|
|
|
|
{
|
|
|
|
|
MailAddress = reportModel.UserEmail,
|
|
|
|
|
Subject = "Отчет по статусам обучения",
|
|
|
|
|
Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " +
|
|
|
|
|
$"по {reportModel.DateTo.ToShortDateString()}.",
|
|
|
|
|
File = file
|
|
|
|
|
});
|
|
|
|
|
}*/
|
2023-04-08 19:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|