У меня помутился рассудок

This commit is contained in:
GokaPek 2024-05-01 20:40:47 +04:00
parent 193a465a81
commit 117f273224
24 changed files with 388 additions and 30 deletions

View File

@ -0,0 +1,142 @@
using AbstractLawFirmContracts.ViewModels;
using System.Reflection;
using UniversityBusinessLogics.OfficePackage;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StorageContracts;
namespace UniversityBusinessLogics.BusinessLogics;
public class ReportLogic : IReportLogic
{
public List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model)
{
throw new NotImplementedException();
}
/*private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToPdf _saveToPdf;*/
private readonly ITeacherStorage _teacherStorage;
private readonly IDisciplineStorage _disciplineStorage;
private readonly IStudentStorage _studentStorage;
private readonly IStatementStorage _statementStorage;
private readonly IPlanOfStudyStorage _planOfStudyStorage;
public List<ReportTeacherViewModel> GetTeachers()
{
var teachers = _teacherStorage.GetFullList();
// Создаем список для результатов
var result = new List<ReportTeacherViewModel>();
foreach (var teacher in teachers)
{
// Получаем список дисциплин, связанных с учителем
var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel
{
TeacherId = teacher.Id,
});
// Получаем список студентов, связанных с дисциплинами
var students = new List<(string Student, string PhoneNumber)>();
foreach (var discipline in disciplines)
{
var studentDisciplines = _disciplineStorage.GetStudentsForDiscipline(new DisciplineSearchModel
{
Id = discipline.Id,
});
foreach (var studentDiscipline in studentDisciplines)
{
var studentList = _studentStorage.GetFilteredList(new StudentSearchModel
{
Id = studentDiscipline.Id,
});
foreach(var st in studentList){
students.Add((st.Name, st.PhoneNumber));
}
}
}
// Добавляем учителя и его студентов в результат
result.Add(new ReportTeacherViewModel
{
TeacherName = teacher.Name,
Students = students.Distinct().ToList() // Убираем дубликаты, если они есть
});
}
return result;
}
public List<ReportDisciplineViewModel> GetDisciplines(ReportDateRangeBindingModel model)
{
var disciplines = _disciplineStorage.GetFullList();
var reportDisciplineViewModels = new List<ReportDisciplineViewModel>();
foreach (var discipline in disciplines)
{
// Получаем список студентов, связанных с дисциплинами
var studentDisciplines = _disciplineStorage.GetStudentsForDiscipline(new DisciplineSearchModel
{
Id = discipline.Id,
});
var planOfStudys = new List<string>();
foreach (var studentDiscipline in studentDisciplines)
{
var student = _studentStorage.GetElement(new StudentSearchModel
{
Id = studentDiscipline.Id,
});
if (student != null)
{
var planOfStudy = _planOfStudyStorage.GetElement(new PlanOfStudySearchModel
{
Id = student.PlanOfStudyId,
});
if (planOfStudy != null)
{
planOfStudys.Add(planOfStudy.Profile);
}
}
}
// Получаем список заявлений преподавателя в указанном диапазоне дат
var statements = _statementStorage.GetFilteredList(new StatementSearchModel
{
TeacherId = discipline.TeacherId
});
// Создаем ReportDisciplineViewModel и добавляем его в список
reportDisciplineViewModels.Add(new ReportDisciplineViewModel
{
DisciplineName = discipline.Name,
PlanOfStudys = planOfStudys.Distinct().ToList(), // Убираем дубликаты, если они есть
Statements = statements.Select(s => s.Name).ToList()
});
}
return reportDisciplineViewModels;
}
public void SaveTeachersToExcel(ReportBindingModel option)
{
throw new NotImplementedException();
}
public void SaveTeachersToWord(ReportBindingModel option)
{
throw new NotImplementedException();
}
public void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,9 @@
namespace UniversityBusinessLogics.OfficePackage.HelperEnums
{
public enum ExcelStyleInfoType
{
Title,
Text,
TextWithBroder
}
}

View File

@ -0,0 +1,9 @@
namespace UniversityBusinessLogics.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Rigth
}
}

View File

@ -0,0 +1,8 @@
namespace UniversityBusinessLogics.OfficePackage.HelperEnums
{
public enum WordJustificationType
{
Center,
Both
}
}

View File

@ -0,0 +1,13 @@
using UniversityBusinessLogics.OfficePackage.HelperEnums;
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class ExcelCellParameters
{
public string ColumnName { get; set; } = string.Empty;
public uint RowIndex { get; set; }
public string Text { get; set; } = string.Empty;
public string CellReference => $"{ColumnName}{RowIndex}";
public ExcelStyleInfoType StyleInfo { get; set; }
}
}

View File

@ -0,0 +1,18 @@
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class ExcelInfo
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
public string Title { get; set; } = string.Empty;
public List<object> ReportObjects
{
get;
set;
} = new();
public List<string> Headers { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class ExcelMergeParameters
{
public string CellFromName { get; set; } = string.Empty;
public string CellToName { get; set; } = string.Empty;
public string Merge => $"{CellFromName}:{CellToName}";
}
}

View File

@ -0,0 +1,13 @@
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class PdfInfo
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
public string Title { get; set; } = string.Empty;
public DateOnly DateFrom { get; set; }
public DateOnly DateTo { get; set; }
public List<object> ReportObjects { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
using UniversityBusinessLogics.OfficePackage.HelperEnums;
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using UniversityBusinessLogics.OfficePackage.HelperEnums;
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,13 @@

namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class WordInfo
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
public string Title { get; set; } = string.Empty;
public List<object> ReportObjects { get; set; } = new();
}
}

View File

@ -0,0 +1,8 @@
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class WordParagraph
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using UniversityBusinessLogics.OfficePackage.HelperEnums;
namespace UniversityBusinessLogics.OfficePackage.HelperModels
{
public class WordTextProperties
{
public string Size { get; set; } = string.Empty;
public bool Bold { get; set; }
public WordJustificationType JustificationType { get; set; }
}
}

View File

@ -10,8 +10,9 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -1,15 +1,8 @@
namespace UniversityContracts.BindingModels;
/// <summary>
/// Опции для сохранения отчета, при сохранении указать одно из двух
/// </summary>
public class ReportBindingModel
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
/// <summary>
/// Массив айдишников по которым происходит выборка
/// </summary>
public int[]? Ids { get; set; }
}

View File

@ -1,4 +1,5 @@
using System;
using AbstractLawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -9,14 +10,16 @@ namespace UniversityContracts.BusinessLogicContracts
{
public interface IReportLogic
{
void SaveDisciplinesToWord(ReportBindingModel option);
/// <summary>
/// Часть кладовщика
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
List<ReportTeacherViewModel> GetTeachers();
List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model);
void SaveTeachersToWord(ReportBindingModel option);
void SaveDisciplinesToExcel(ReportBindingModel option);
void SendAccountsToEmail(ReportDateRangeBindingModel option, string email);
void SaveClientsToWord(ReportBindingModel option);
void SaveClientsToExcel(ReportBindingModel option);
void SaveTeachersToExcel(ReportBindingModel option);
void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email);
}

View File

@ -13,5 +13,7 @@ namespace UniversityContracts.SearchModels
public int? TeacherId { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public DateOnly? DateFrom { get; set; }
public DateOnly? DateTo { get; set; }
}
}

View File

@ -7,6 +7,5 @@ namespace UniversityContracts.SearchModels
public int? Id { get; set; }
public int UserId { get; set; }
public string? Name { get; set; }
}
}

View File

@ -17,5 +17,6 @@ namespace UniversityContracts.StorageContracts
DisciplineViewModel? Insert(DisciplineBindingModel model);
DisciplineViewModel? Update(DisciplineBindingModel model);
DisciplineViewModel? Delete(DisciplineBindingModel model);
List<StudentViewModel> GetStudentsForDiscipline(DisciplineSearchModel model);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractLawFirmContracts.ViewModels
{
public class ReportDisciplineViewModel
{
public string DisciplineName { get; set; } = string.Empty;
public List<string> PlanOfStudys { get; set; } = new();
public List<string> Statements { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractLawFirmContracts.ViewModels
{
public class ReportTeacherViewModel
{
public string TeacherName { get; set; } = string.Empty;
public List<(string Student, string PhoneNumber)> Students { get; set; } = new();
}
}

View File

@ -15,6 +15,25 @@ namespace UniversityDatabaseImplement.Implements
{
public class DisciplineStorage : IDisciplineStorage
{
public List<StudentViewModel> GetStudentsForDiscipline(DisciplineSearchModel model)
{
using var context = new UniversityDatabase();
var discipline = context.Disciplines
.Include(d => d.Students)
.ThenInclude(sd => sd.Student)
.FirstOrDefault(d => d.Id == model.Id);
if (discipline == null)
{
return new List<StudentViewModel>(); // Если дисциплина не найдена, возвращаем пустой список
}
return discipline.Students
.Select(sd => sd.Student.GetViewModel)
.ToList();
}
public DisciplineViewModel? Delete(DisciplineBindingModel model)
{
using var context = new UniversityDatabase();
@ -42,22 +61,48 @@ namespace UniversityDatabaseImplement.Implements
}
//ешьте котиков в них витамин с
public List<DisciplineViewModel> GetFilteredList(DisciplineSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Description))
{
return new();
}
CheckSearchModel(model);
using var context = new UniversityDatabase();
return context.Disciplines
.Include(x => x.Students)
.ThenInclude(x => x.Student)
.Where(x => x.Name.Contains(model.Name) || x.Description.Contains(model.Description) || x.Id == model.Id || x.TeacherId == model.TeacherId)
.Include(x => x.Teacher)
.Select(x => x.GetViewModel)
.ToList();
var query = context.Disciplines
.Include(x => x.Students)
.ThenInclude(x => x.Student)
.Include(x => x.Teacher)
.AsQueryable();
if (!string.IsNullOrEmpty(model.Name))
{
query = query.Where(x => x.Name.Contains(model.Name));
}
if (!string.IsNullOrEmpty(model.Description))
{
query = query.Where(x => x.Description.Contains(model.Description));
}
if (model.Id.HasValue)
{
query = query.Where(x => x.Id == model.Id.Value);
}
if (model.TeacherId.HasValue)
{
query = query.Where(x => x.TeacherId == model.TeacherId.Value);
}
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value);
}
return query.Select(x => x.GetViewModel).ToList();
}
public List<DisciplineViewModel> GetFullList()
{
using var context = new UniversityDatabase();
@ -105,5 +150,13 @@ namespace UniversityDatabaseImplement.Implements
throw;
}
}
private void CheckSearchModel(DisciplineSearchModel model)
{
if (model == null)
throw new ArgumentNullException("Передаваемая модель пуста", nameof(model));
if (model.DateFrom.HasValue != model.DateTo.HasValue)
throw new ArgumentException($"Не указано начало {model.DateFrom} или конец {model.DateTo} периода.");
}
}
}

View File

@ -9,6 +9,7 @@ using UniversityContracts.SearchModels;
using UniversityContracts.StorageContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace UniversityDatabaseImplement.Implements
{

View File

@ -23,6 +23,7 @@ namespace UniversityDatabaseImplement.Models
public string Name { get; private set; } = string.Empty;
[Required]
public string Description { get; private set; } = string.Empty;
public DateOnly Date { get; private set; }
public virtual User User { get; set; } = new();
public virtual Teacher Teacher { get; set; } = new();
private Dictionary<int, IStudentModel>? _studentDisciplines = null;