Работает list

This commit is contained in:
maxnes3 2023-05-20 00:24:04 +04:00
parent 8207be80a7
commit 3134b5f6e1
15 changed files with 299 additions and 79 deletions

View File

@ -1,4 +1,5 @@
using CaseAccountingContracts.BindingModels;
using CaseAccountingBusinessLogic.OfficePackage;
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.SearchModels;
using CaseAccountingContracts.StoragesContracts;
@ -17,32 +18,66 @@ namespace CaseAccountingBusinessLogic.BusinessLogics
private readonly ISpecializationStorage _specializationStorage;
private readonly IHearingStorage _hearingStorage;
private readonly ILawyerStorage _lawyerStorage;
private readonly WordBuilderProvider _wordBuilder;
private readonly ExcelBuilderProvider _excelBuilder;
/*private readonly PdfBuilderProvider _pdfBuilder;
private readonly MailSender _mailSender;*/
public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage)
public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder)
{
_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));
_wordBuilder = wordBuilder ?? throw new ArgumentNullException(nameof(wordBuilder));
_excelBuilder = excelBuilder ?? throw new ArgumentNullException(nameof(excelBuilder));
}
public List<ReportCaseSpecializationViewModel> GetCaseSpecialization(List<CaseViewModel> models)
{
var сases = new List<CaseViewModel>();
List<ReportCaseSpecializationViewModel> list = new();
foreach (var model in models)
сases.Add(_caseStorage.GetElement(new CaseSearchModel { Id = model.Id }));
return сases.Select(x => new ReportCaseSpecializationViewModel {
CaseName = x.Name,
Applicant = x.Applicant,
Defendant = x.Defendant,
Date = x.Date,
Specialization = x.Specialization,
}).ToList();
{
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;
}
public List<ReportHearingLawyerViewModel> GetHearingLawyer(ReportBindingModel model)
{
var hearings = _hearingStorage
/*var hearings = _hearingStorage
.GetFilteredList(new HearingSearchModel { UserId = model.UserId})
.Where(x => model.DateFrom <= x.Date && model.DateTo >= x.Date);
var list = new List<ReportHearingLawyerViewModel>();
@ -60,25 +95,50 @@ namespace CaseAccountingBusinessLogic.BusinessLogics
}
list.Add(record);
}
return list;
return list;*/
return new();
}
public void SaveCaseSpecializationToExcelFile(ReportBindingModel model)
public byte[] SaveListFile(CaseSpecializationListBindingModel model)
{
throw new NotImplementedException();
//TODO
byte[] file = Array.Empty<byte>();
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;
}
public void SaveCaseSpecializationToWordFile(ReportBindingModel model)
/*public void SendByMailStatusReport(ReportBindingModel reportModel)
{
throw new NotImplementedException();
//TODO
}
public void SaveHearingLawyerToPdfFile(ReportBindingModel model)
byte[] file = _pdfBuilder.GetEducationStatusReportFile(new()
{
throw new NotImplementedException();
//TODO
}
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
});
}*/
}
}

View File

@ -291,7 +291,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
});
}
public void CreateLawyersHearingsTable(List<ReportLawyerHearingViewModel> data)
/*public void CreateLawyersHearingsTable(List<ReportLawyerHearingViewModel> data)
{
if (worksheet == null || shareStringPart == null)
{
@ -357,6 +357,6 @@ namespace CaseAccountingBusinessLogic.OfficePackage
currentRow++;
}
}
}
}*/
}
}

View File

@ -1,5 +1,7 @@
using CaseAccountingBusinessLogic.OfficePackage;
using CaseAccountingBusinessLogic.OfficePackage.HelperModels;
using CaseAccountingContracts.ViewModels;
using ComputersShopBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
@ -285,7 +287,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
});
}
public void CreateStudentsDisciplineTable(List<ReportStudentsDisciplineViewModel> data)
public void CreateCaseSpecializationTable(List<ReportCaseSpecializationViewModel> data)
{
if (worksheet == null || shareStringPart == null)
{
@ -303,25 +305,25 @@ namespace CaseAccountingBusinessLogic.OfficePackage
{
ColumnName = "A",
RowIndex = 2,
Text = "Студент",
Text = "Специализация:",
StyleIndex = 2
});
InsertCellInWorksheet(new ExcelCellData
{
ColumnName = "B",
RowIndex = 2,
Text = исциплина",
Text = ела:",
StyleIndex = 2
});
uint currentRow = 3;
foreach (ReportStudentsDisciplineViewModel student in data)
foreach (ReportCaseSpecializationViewModel specialization in data)
{
InsertCellInWorksheet(new ExcelCellData
{
ColumnName = "A",
RowIndex = currentRow,
Text = student.Student,
Text = specialization.Specialization,
StyleIndex = 1
});
InsertCellInWorksheet(new ExcelCellData
@ -332,7 +334,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
StyleIndex = 1
});
currentRow++;
foreach (string discipline in student.Disciplines)
foreach (string caseName in specialization.Cases)
{
InsertCellInWorksheet(new ExcelCellData
{
@ -345,7 +347,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
{
ColumnName = "B",
RowIndex = currentRow,
Text = discipline,
Text = caseName,
StyleIndex = 1
});
currentRow++;

View File

@ -1,5 +1,5 @@
using UniversityBusinessLogic.OfficePackage.Models;
using UniversityContracts.ViewModels;
using CaseAccountingBusinessLogic.OfficePackage.HelperModels;
using CaseAccountingContracts.ViewModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
@ -141,26 +141,26 @@ namespace CaseAccountingBusinessLogic.OfficePackage
return file;
}
public void CreateStudentsDisciplineTable(List<ReportStudentsDisciplineViewModel> data)
public void CreateCaseSpecializationTable(List<ReportCaseSpecializationViewModel> data)
{
List<List<string>> rows = new();
foreach (ReportStudentsDisciplineViewModel student in data)
foreach (ReportCaseSpecializationViewModel specializationl in data)
{
List<string> studentCells = new() { student.Student, "" };
rows.Add(studentCells);
List<string> disciplineCells;
foreach (string discipline in student.Disciplines)
List<string> specializationlCells = new() { specializationl.Specialization, "" };
rows.Add(specializationlCells);
List<string> caseCells;
foreach (string caseString in specializationl.Cases)
{
disciplineCells = new() { "", discipline };
rows.Add(disciplineCells);
caseCells = new() { "", caseString };
rows.Add(caseCells);
}
}
WordTableData wordTable = new()
{
Columns = new List<(string, int)>()
{
("Студент", 3000),
(исциплина", 3000)
("Специализация", 3000),
(ела", 3000)
},
Rows = rows
};

View File

@ -0,0 +1,15 @@
using CaseAccountingContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.BindingModels
{
public class CaseSpecializationListBindingModel
{
public string FileType { get; set; } = string.Empty;
public List<CaseViewModel> Cases { get; set; } = new();
}
}

View File

@ -14,10 +14,6 @@ namespace CaseAccountingContracts.BusinessLogicContracts
List<ReportHearingLawyerViewModel> GetHearingLawyer(ReportBindingModel model);
void SaveCaseSpecializationToWordFile(ReportBindingModel model);
void SaveCaseSpecializationToExcelFile(ReportBindingModel model);
void SaveHearingLawyerToPdfFile(ReportBindingModel model);
byte[] SaveListFile(CaseSpecializationListBindingModel model);
}
}

View File

@ -8,10 +8,7 @@ namespace CaseAccountingContracts.ViewModels
{
public class ReportCaseSpecializationViewModel
{
public string CaseName { get; set; } = string.Empty;
public string Applicant { get; set; } = string.Empty;
public string Defendant { get; set; } = string.Empty;
public DateTime Date { get; set; }
public string Specialization { get; set; } = string.Empty;
public List<string> Cases { get; set; } = new();
}
}

View File

@ -18,8 +18,8 @@ namespace CaseAccountingDataBaseImplement
Host=localhost;
Port=5432;
Database=CaseAccountingDatabase;
Username=postgres;
Password=postgres");
Username=courseuser;
Password=courseuser");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -43,5 +43,25 @@ namespace CaseAccountingProviderView
throw new Exception(result);
}
}
public static O? PostRequestWithResult<I, O>(string requestUrl, I model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _user.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
var temp = JsonConvert.DeserializeObject<O>(result);
return temp;
}
else
{
return default;
}
}
}
}

View File

@ -35,6 +35,24 @@ namespace CaseAccountingProviderView.Controllers
return View();
}
public IActionResult SpecializationCaselist()
{
return View();
}
[HttpPost]
public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel)
{
if (APIUser.User == null)
{
return Array.Empty<int>();
}
byte[]? file = APIUser.PostRequestWithResult<CaseSpecializationListBindingModel, byte[]>
("api/reportprovider/specializationcaselist", listModel);
return file!.Select(b => (int)b).ToArray();
}
[HttpPost]
public void Login(string login, string password)
{
@ -73,15 +91,8 @@ namespace CaseAccountingProviderView.Controllers
{
return Redirect("~/Home/Enter");
}
/*if (page == 0)
{
page = 1;
}*/
ViewBag.Cases = APIUser.GetRequest<List<CaseViewModel>>
($"api/case/getallbyuser?userId={APIUser.User.Id}");
/*ViewBag.Page = page;
ViewBag.NumberOfPages = APIUser.GetRequest<int>
($"api/student/getnumberofpages?userId={APIUser.User.Id}");*/
return View();
}

View File

@ -10,16 +10,12 @@
</div>
</div>
<select id="file-type">
<select id="file-type" class="form-control mb-3">
<option>docx</option>
<option>xlsx</option>
</select>
<button id="create-button" type="button" class="button-primary text-button">
Показать итоговый вариант
</button>
<button id="save-button" type="button" class="button-primary text-button">
<button id="create-button" type="button" class="btn btn-success text-button">
Сохранить результат
</button>
@ -28,11 +24,12 @@
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Имя</th>
<th>Фамилия</th>
<th>Дата рождения</th>
<th>Номер студ. билета</th>
<th>Статус обучения</th>
<th>Номер дела:</th>
<th>Истец:</th>
<th>Ответчик:</th>
<th>Дата составления:</th>
<th>Примечание:</th>
<th>Специализация:</th>
</tr>
</thead>
<tbody id="scrollable-table__tbody">

View File

@ -21,7 +21,7 @@
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Cases">Дела</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Deals">Договора</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Hearings">Слушания</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Hearings">Получение список</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="SpecializationCaselist">Получение список</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Hearings">Получение отчёта</a>
</div>
</div>

View File

@ -0,0 +1,91 @@
const createBtn = document.getElementById("create-button")
const tbody = document.getElementById("scrollable-table__tbody")
const nameInput = document.getElementById("name-input")
var fileType = document.getElementById("file-type")
var cases = []
var dataArray = [];
const wordMIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
const excelMIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
window.addEventListener('load', async () => {
try {
await $.ajax({
url: `/case/getallbyuser`,
type: "GET",
contentType: "json"
}).done((result) => {
cases = result;
cases.forEach((caseModel) => {
const { id, name, applicant, defendant, annotation, date, specialization } = caseModel;
const row = tbody.insertRow();
row.setAttribute("data-id", id);
const cells = [name, applicant, defendant, annotation, date, specialization];
cells.forEach((value) => {
const cell = row.insertCell();
cell.textContent = value;
});
row.addEventListener('click', () => addAndRemoveFromList(row));
});
});
} catch (error) {
console.error(error);
}
})
createBtn.addEventListener('click', () => {
let listModel = {
"Cases": Array.from(dataArray),
"FileType": fileType.value
};
$.ajax({
url: "/home/specializationcaselist",
type: "POST",
contentType: "application/json",
data: JSON.stringify(listModel)
}).done((file) => {
let byteArray = new Uint8Array(file);
saveFile(byteArray, fileType);
});
})
const saveFile = async function (bytes, fileType) {
if (window.showSaveFilePicker) {
let type;
if (fileType.value == "docx") {
type = {
description: "Microsoft Word (OpenXML)",
accept: { [wordMIME]: [".docx"] }
};
} else if (fileType.value == "xlsx") {
type = {
description: "Microsoft Excel (OpenXML)",
accept: { [excelMIME]: [".xlsx"] }
};
}
const opts = {
suggestedName: `case-specialization-list.${fileType.value}`,
types: [type],
};
const handle = await showSaveFilePicker(opts);
const writable = await handle.createWritable();
await writable.write(bytes);
writable.close();
}
}
const addAndRemoveFromList = (row) => {
var id = parseInt(row.dataset.id);
console.log(cases.find(x => x.id === id))
var index = dataArray.indexOf(cases.find(x => x.id === id));
if (index === -1) {
dataArray.push(cases.find(x => x.id === id));
row.classList.add("bg-primary");
} else {
dataArray.splice(index, 1);
row.classList.remove("bg-primary");
}
console.log(dataArray);
}

View File

@ -0,0 +1,25 @@
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts;
using Microsoft.AspNetCore.Mvc;
namespace CaseAccountingRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportProviderController : Controller
{
private readonly IReportProviderLogic reportLogic;
public ReportProviderController(IReportProviderLogic reportLogic)
{
this.reportLogic = reportLogic;
}
[HttpPost]
public byte[] SpecializationCaselist(CaseSpecializationListBindingModel listModel)
{
byte[] file = reportLogic.SaveListFile(listModel);
return file;
}
}
}

View File

@ -1,4 +1,5 @@
using CaseAccountingBusinessLogic.BusinessLogics;
using CaseAccountingBusinessLogic.OfficePackage;
using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.StoragesContracts;
using CaseAccountingDataBaseImplement.Implements;
@ -26,6 +27,11 @@ builder.Services.AddTransient<ILawyerLogic, LawyerLogic>();
builder.Services.AddTransient<ISpecializationLogic, SpecializationLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IReportProviderLogic, ReportProviderLogic>();
builder.Services.AddTransient<WordBuilderProvider>();
builder.Services.AddTransient<ExcelBuilderProvider>();
builder.Services.AddControllers().AddNewtonsoftJson();
builder.Services.AddControllers();