Сделал выгрузку списка животных

This commit is contained in:
gg12 darfren 2024-05-22 13:18:45 +04:00
parent dfe1c50ddc
commit 324781aa40
10 changed files with 171 additions and 37 deletions

View File

@ -4,6 +4,7 @@ using PharmacistApp.Models;
using System.Diagnostics;
using System.Text;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
@ -592,6 +593,57 @@ View(res);
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
[HttpPost]
public void AnimalListReport(List<int> services, string type)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (services.Count <= 0)
{
throw new Exception("Количество должно быть больше 0");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Неверный тип отчета");
}
if (type == "docx")
{
APIPharmacist.PostRequest("api/report/createanimallistwordfile", new ListAnimalsBindingModel
{
Services = services,
FileName = "C:\\ReportsCourseWork\\wordfile.docx"
});
Response.Redirect("GetWordFile");
}
else
{
APIPharmacist.PostRequest("api/report/createanimallistexcelfile", new ListAnimalsBindingModel
{
Services = services,
FileName = "C:\\ReportsCourseWork\\excelfile.xlsx"
});
Response.Redirect("GetExcelFile");
}
}
[HttpGet]
public IActionResult GetWordFile()
{
return new PhysicalFileResult("C:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetExcelFile()
{
return new PhysicalFileResult("C:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
[HttpGet]
public IActionResult Report()
{

View File

@ -19,9 +19,18 @@
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-2"><input type="submit" value="Word" class="btn btn-primary" /></div>
<div class="col-2"><input type="submit" value="Excel" class="btn btn-primary" /></div>
<div class="file-format">
<label class="form-label">Выберите формат файла:</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label class="form-check-label" for="docx">Word-файл</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label class="form-check-label" for="xlsx">Excel-файл</label>
</div>
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-block btn-outline-dark w-100">Создать</button>
</div>
</form>

View File

@ -10,6 +10,7 @@ using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Implements;
namespace VetClinicBusinessLogic.BusinessLogics
{
@ -19,13 +20,16 @@ namespace VetClinicBusinessLogic.BusinessLogics
private readonly IMedicineStorage _medicineStorage;
private readonly AbstractSaveToExcelPharmacist _saveToExcel;
private readonly AbstractSaveToWordPharmacist _saveToWord;
private readonly AbstractSaveToPdfPharmacist _saveToPdf;
public ReportLogicPharmacist(IServiceStorage serviceStorage, IMedicineStorage medicineStorage,
AbstractSaveToExcelPharmacist saveToExcel, AbstractSaveToWordPharmacist saveToWord)
AbstractSaveToExcelPharmacist saveToExcel, AbstractSaveToWordPharmacist saveToWord,
AbstractSaveToPdfPharmacist saveToPdf)
{
_serviceStorage = serviceStorage;
_medicineStorage = medicineStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ListAnimalsViewModel> GetServiceAnimals(List<int> services)
@ -86,42 +90,57 @@ namespace VetClinicBusinessLogic.BusinessLogics
});
}
public List<VisitGuidesSearchModel> GetMedicineVisitsAndGuidances(List<int> services)
public List<VisitsGuidesViewModel> GetMedicineVisitsAndGuidances(VisitsGuidesBindingModel model)
{
var medicines = model.Medicines;
List<VisitsGuidesViewModel> ans = new();
List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>> responseGuides =
_medicineStorage.GetGuidancesInfo(new VisitGuidesSearchModel { medicinesIds = medicines, DateFrom = model.DateFrom!, DateTo = model.DateTo!});
List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>> responseVisits =
_medicineStorage.GetVisitsInfo(new VisitGuidesSearchModel { medicinesIds = medicines, DateFrom = model.DateFrom!, DateTo = model.DateTo! });
Dictionary<int, VisitsGuidesViewModel> dict = new();
List<VisitGuidesSearchModel> ans = new();
List<Tuple<ServiceViewModel, List<Tuple<MedicineViewModel, List<AnimalViewModel>>>>> response =
_serviceStorage.GetReportInfo(new ListAnimalsSearchModel { servicesIds = services });
foreach (var service in response)
foreach(var medicine in responseGuides)
{
Dictionary<int, (AnimalViewModel, int)> counter = new();
foreach (var medicine in service.Item2)
dict.Add(medicine.Item1.Id, new());
dict[medicine.Item1.Id].MedicineName = medicine.Item1.MedicineName;
foreach(var service in medicine.Item2)
{
foreach (var animal in medicine.Item2)
foreach(var guidance in service.Item2)
{
if (!counter.ContainsKey(animal.Id))
counter.Add(animal.Id, (animal, 1));
else
{
counter[animal.Id] = (counter[animal.Id].Item1, counter[animal.Id].Item2 + 1);
}
dict[medicine.Item1.Id].Guidances.Add(guidance);
}
}
List<AnimalViewModel> res = new();
foreach (var cnt in counter)
}
foreach (var medicine in responseVisits)
{
HashSet<int> used = new();
foreach (var service in medicine.Item2)
{
if (cnt.Value.Item2 != service.Item2.Count)
continue;
res.Add(cnt.Value.Item1);
foreach (var visit in service.Item2)
{
if (used.Contains(visit.Id))
continue;
dict[medicine.Item1.Id].Visits.Add(visit);
}
}
ans.Add(new ListAnimalsViewModel
{
ServiceName = service.Item1.ServiceName,
Animals = res
});
ans.Add(dict[medicine.Item1.Id]);
}
return ans;
}
public void SaveMedicinesToPdfFile(VisitsGuidesBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список медикаментов",
DateFrom = model.DateFrom!,
DateTo = model.DateTo!,
Medicines = GetMedicineVisitsAndGuidances(model)
});
}
}
}

View File

@ -10,7 +10,7 @@ namespace VetClinicContracts.BindingModels
{
public string FileName { get; set; } = string.Empty;
public List<int> Medicines { get; set; } = new();
DateTime DateFrom { get; set; } = DateTime.Now;
DateTime DateTo { get; set; } = DateTime.Now;
public DateTime DateFrom { get; set; } = DateTime.Now;
public DateTime DateTo { get; set; } = DateTime.Now;
}
}

View File

@ -14,7 +14,7 @@ namespace VetClinicContracts.BusinessLogicsContracts
List<ListAnimalsViewModel> GetServiceAnimals(List<int> services);
void SaveAnimalsToWordFile(ListAnimalsBindingModel model);
void SaveAnimalsToExcelFile(ListAnimalsBindingModel model);
List<ListAnimalsViewModel> GetMedicineVisitsAndGuidances(List<int> services);
List<VisitsGuidesViewModel> GetMedicineVisitsAndGuidances(VisitsGuidesBindingModel services);
void SaveMedicinesToPdfFile(VisitsGuidesBindingModel model);
}
}

View File

@ -12,7 +12,5 @@ namespace VetClinicDataBaseImplement.Implements
public string MedicineName { get; set; } = string.Empty;
public List<VisitViewModel> Visits { get; set; } = new();
public List<GuidanceViewModel> Guidances { get; set; } = new();
public DateTime DateFrom { get; set; } = DateTime.Now;
public DateTime DateTo { get; set; } = DateTime.Now;
}
}

View File

@ -11,7 +11,7 @@ namespace VetClinicDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS02;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,46 @@
using Microsoft.AspNetCore.Mvc;
using VetClinicBusinessLogic.BusinessLogics;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
namespace VetClinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportController : Controller
{
private readonly IReportLogicPharmacist _reportPharmacist;
public ReportController(ILogger<ReportController> logger, IReportLogicPharmacist reportPharmacist)
{
_reportPharmacist = reportPharmacist;
}
public IActionResult Index(ReportLogicPharmacist reportPharmacist)
{
return View();
}
[HttpPost]
public void CreateAnimalListWordFile(ListAnimalsBindingModel model)
{
try
{
_reportPharmacist.SaveAnimalsToWordFile(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void CreateAnimalListExcelFile(ListAnimalsBindingModel model)
{
try
{
_reportPharmacist.SaveAnimalsToExcelFile(model);
}
catch (Exception ex)
{
throw;
}
}
}
}

View File

@ -4,6 +4,8 @@ using VetClinicContracts.StoragesContracts;
using VetClinicDataBaseImplement.Implements;
using Microsoft.OpenApi.Models;
using VetClinicBaseImplement.Implements;
using VetClinicBusinessLogic.OfficePackage;
using VetClinicBusinessLogic.OfficePackage.Implements;
var builder = WebApplication.CreateBuilder(args);
@ -30,6 +32,10 @@ builder.Services.AddTransient<IPharmacistLogic, PharmacistLogic>();
builder.Services.AddTransient<IServiceLogic, ServiceLogic>();
builder.Services.AddTransient<IMedicineLogic, MedicineLogic>();
builder.Services.AddTransient<IGuidanceLogic, GuidanceLogic>();
builder.Services.AddTransient<IReportLogicPharmacist, ReportLogicPharmacist>();
builder.Services.AddTransient<AbstractSaveToExcelPharmacist, SaveToExcelPharmacist>();
builder.Services.AddTransient<AbstractSaveToWordPharmacist, SaveToWordPharmacist>();
builder.Services.AddTransient<AbstractSaveToPdfPharmacist, SaveToPdfPharmacist>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@ -17,4 +17,8 @@
<ProjectReference Include="..\VetClinicDataBaseImplement\VetClinicDataBaseImplement.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Reports\" />
</ItemGroup>
</Project>