2024-05-28 20:27:58 +04:00
|
|
|
|
using UniversityBusinessLogic.OfficePackage;
|
2024-05-02 17:22:43 +04:00
|
|
|
|
using University.ViewModels;
|
2024-05-01 20:40:47 +04:00
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.BusinessLogicContracts;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.StorageContracts;
|
2024-05-02 17:22:43 +04:00
|
|
|
|
using UniversityContracts.ViewModels;
|
2024-05-28 21:41:10 +04:00
|
|
|
|
using DocumentFormat.OpenXml.EMMA;
|
|
|
|
|
using UniversityBusinessLogic.OfficePackage.HelperModels;
|
2024-05-01 20:40:47 +04:00
|
|
|
|
|
|
|
|
|
namespace UniversityBusinessLogics.BusinessLogics;
|
|
|
|
|
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
public List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*private readonly AbstractSaveToWord _saveToWord;
|
2024-05-28 17:08:06 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;*/
|
2024-05-01 20:40:47 +04:00
|
|
|
|
|
|
|
|
|
private readonly ITeacherStorage _teacherStorage;
|
|
|
|
|
private readonly IDisciplineStorage _disciplineStorage;
|
|
|
|
|
private readonly IStudentStorage _studentStorage;
|
|
|
|
|
private readonly IStatementStorage _statementStorage;
|
|
|
|
|
private readonly IPlanOfStudyStorage _planOfStudyStorage;
|
2024-05-28 20:09:01 +04:00
|
|
|
|
|
|
|
|
|
private readonly AbstractSaveToExcelWorker _saveToExcelWorker;
|
|
|
|
|
private readonly AbstractSaveToWordWorker _saveToWordWorker;
|
2024-05-29 19:29:42 +04:00
|
|
|
|
private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
|
2024-05-28 21:41:10 +04:00
|
|
|
|
|
2024-05-29 18:51:07 +04:00
|
|
|
|
private readonly AbstractSaveToExcelStorekeeper _saveToExcelStorekeeper;
|
2024-05-29 11:30:39 +04:00
|
|
|
|
//private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
|
2024-05-28 21:41:10 +04:00
|
|
|
|
private readonly AbstractSaveToWordStorekeeper _saveToWordStorekeeper;
|
|
|
|
|
public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage
|
2024-05-28 20:09:01 +04:00
|
|
|
|
disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage,
|
2024-05-28 21:47:51 +04:00
|
|
|
|
IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker
|
2024-05-29 19:29:42 +04:00
|
|
|
|
,AbstractSaveToPdfWorker saveToPdfWorker, AbstractSaveToWordStorekeeper saveToWordStorekeeper,
|
|
|
|
|
AbstractSaveToExcelStorekeeper saveToExcelStorekeeper)
|
2024-05-28 20:09:01 +04:00
|
|
|
|
{
|
|
|
|
|
_teacherStorage = teacherStorage;
|
|
|
|
|
_disciplineStorage = disciplineStorage;
|
|
|
|
|
_studentStorage = studentStorage;
|
|
|
|
|
_statementStorage = statementStorage;
|
|
|
|
|
_planOfStudyStorage = planOfStudyStorage;
|
|
|
|
|
|
|
|
|
|
_saveToExcelWorker = saveToExcelWorker;
|
|
|
|
|
_saveToWordWorker = saveToWordWorker;
|
2024-05-29 19:26:11 +04:00
|
|
|
|
_saveToPdfWorker = saveToPdfWorker;
|
2024-05-29 11:30:39 +04:00
|
|
|
|
|
2024-05-29 18:51:07 +04:00
|
|
|
|
_saveToWordStorekeeper = saveToWordStorekeeper;
|
|
|
|
|
_saveToExcelStorekeeper = saveToExcelStorekeeper;
|
2024-05-28 20:09:01 +04:00
|
|
|
|
}
|
2024-05-29 11:30:39 +04:00
|
|
|
|
public List<ReportTeacherViewModel> GetTeachers(int userId)
|
2024-05-01 20:40:47 +04:00
|
|
|
|
{
|
2024-05-29 11:30:39 +04:00
|
|
|
|
var teachers = _teacherStorage.GetFilteredList(new TeacherSearchModel
|
|
|
|
|
{
|
|
|
|
|
UserId = userId
|
|
|
|
|
});
|
2024-05-01 20:40:47 +04:00
|
|
|
|
|
|
|
|
|
// Создаем список для результатов
|
|
|
|
|
var result = new List<ReportTeacherViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var teacher in teachers)
|
|
|
|
|
{
|
|
|
|
|
// Получаем список дисциплин, связанных с учителем
|
|
|
|
|
var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel
|
|
|
|
|
{
|
|
|
|
|
TeacherId = teacher.Id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Получаем список студентов, связанных с дисциплинами
|
2024-05-29 17:55:47 +04:00
|
|
|
|
var students = new List<string>();
|
2024-05-01 20:40:47 +04:00
|
|
|
|
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){
|
2024-05-29 17:55:47 +04:00
|
|
|
|
students.Add(st.Name + " " + st.PhoneNumber);
|
2024-05-01 20:40:47 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Добавляем учителя и его студентов в результат
|
|
|
|
|
result.Add(new ReportTeacherViewModel
|
|
|
|
|
{
|
2024-05-28 22:09:51 +04:00
|
|
|
|
TeacherId = teacher.Id,
|
2024-05-01 20:40:47 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 02:49:07 +04:00
|
|
|
|
public List<ReportPlanOfStudyViewModel> GetPlanOfStudyAndDisciplines(int userId)
|
2024-05-02 17:22:43 +04:00
|
|
|
|
{
|
|
|
|
|
var planOfStudies = _planOfStudyStorage.GetFullList();
|
|
|
|
|
var reportPlanOfStudyViewModels = new List<ReportPlanOfStudyViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var planOfStudy in planOfStudies)
|
|
|
|
|
{
|
|
|
|
|
// Получаем список дисциплин для текущего плана обучения
|
2024-05-29 02:49:07 +04:00
|
|
|
|
var disciplines = _planOfStudyStorage.GetDisciplineFromStudentsFromPlanOfStudys(new PlanOfStudySearchModel { Id = planOfStudy.Id, UserId = userId });
|
2024-05-02 17:22:43 +04:00
|
|
|
|
|
|
|
|
|
// Создаем ReportPlanOfStudyViewModel и добавляем его в список
|
|
|
|
|
reportPlanOfStudyViewModels.Add(new ReportPlanOfStudyViewModel
|
|
|
|
|
{
|
2024-05-29 02:49:07 +04:00
|
|
|
|
Id = planOfStudy.Id,
|
2024-05-02 17:22:43 +04:00
|
|
|
|
PlanOfStudyName = planOfStudy.Profile,
|
2024-05-28 20:27:58 +04:00
|
|
|
|
FormOfStudy = planOfStudy.FormOfStudy,
|
2024-05-02 17:22:43 +04:00
|
|
|
|
Disciplines = disciplines.Select(d => d.Name).ToList() // Получаем только имена дисциплин
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reportPlanOfStudyViewModels;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 19:26:11 +04:00
|
|
|
|
public List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents()
|
2024-05-02 17:22:43 +04:00
|
|
|
|
{
|
|
|
|
|
var planOfStudies = _planOfStudyStorage.GetFullList();
|
|
|
|
|
var reportPlanOfStudyAndStudentViewModels = new List<ReportPlanOfStudyAndStudentViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var planOfStudy in planOfStudies)
|
|
|
|
|
{
|
|
|
|
|
// Получаем список студентов для текущего плана обучения
|
|
|
|
|
var students = _studentStorage.GetFilteredList(new StudentSearchModel { Id = planOfStudy.Id });
|
|
|
|
|
|
2024-05-29 19:26:11 +04:00
|
|
|
|
// Создаем списки имен студентов и дисциплин
|
|
|
|
|
var studentNames = students.Select(student => student.Name).ToList();
|
|
|
|
|
var disciplineNames = new List<string>();
|
2024-05-02 17:22:43 +04:00
|
|
|
|
|
|
|
|
|
foreach (var student in students)
|
|
|
|
|
{
|
|
|
|
|
// Получаем список дисциплин для текущего студента
|
|
|
|
|
var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel { Id = student.Id });
|
|
|
|
|
|
2024-05-29 19:26:11 +04:00
|
|
|
|
// Добавляем имена дисциплин в общий список
|
|
|
|
|
disciplineNames.AddRange(disciplines.Select(discipline => discipline.Name));
|
2024-05-02 17:22:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Создаем ReportPlanOfStudyAndStudentViewModel и добавляем его в список
|
|
|
|
|
reportPlanOfStudyAndStudentViewModels.Add(new ReportPlanOfStudyAndStudentViewModel
|
|
|
|
|
{
|
2024-05-29 19:26:11 +04:00
|
|
|
|
Id = planOfStudy.Id, // Добавляем идентификатор плана обучения
|
2024-05-02 17:22:43 +04:00
|
|
|
|
PlanOfStudyName = planOfStudy.Profile,
|
2024-05-29 19:26:11 +04:00
|
|
|
|
StudentName = studentNames,
|
|
|
|
|
DisciplineName = disciplineNames
|
2024-05-02 17:22:43 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reportPlanOfStudyAndStudentViewModels;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 20:40:47 +04:00
|
|
|
|
public void SaveTeachersToExcel(ReportBindingModel option)
|
|
|
|
|
{
|
2024-05-29 18:51:07 +04:00
|
|
|
|
_saveToExcelStorekeeper.CreateReport(new ExcelInfoStorekeeper
|
|
|
|
|
{
|
|
|
|
|
FileName = option.FileName,
|
|
|
|
|
Title = "Список преподователей и студентов",
|
|
|
|
|
Teachers = GetTeachers(0)
|
|
|
|
|
});
|
2024-05-01 20:40:47 +04:00
|
|
|
|
}
|
2024-05-02 17:22:43 +04:00
|
|
|
|
public void SavePlanOfStudyToExcel(ReportBindingModel option)
|
|
|
|
|
{
|
2024-05-29 02:49:07 +04:00
|
|
|
|
_saveToExcelWorker.CreateReport(new ExcelInfoWorker
|
2024-05-28 21:40:18 +04:00
|
|
|
|
{
|
2024-05-29 02:49:07 +04:00
|
|
|
|
FileName = option.FileName,
|
|
|
|
|
Title = "Список дисциплин и планов обучения",
|
|
|
|
|
PlanOfStudys = GetPlanOfStudyAndDisciplines(0)
|
|
|
|
|
});
|
2024-05-02 17:22:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SavePlanOfStudyToWord(ReportBindingModel option)
|
|
|
|
|
{
|
2024-05-28 21:40:18 +04:00
|
|
|
|
_saveToWordWorker.CreateDoc(new WordInfoWorker
|
|
|
|
|
{
|
|
|
|
|
FileName = option.FileName,
|
2024-05-29 02:49:07 +04:00
|
|
|
|
Title = "Список дисциплин и планов обучения",
|
|
|
|
|
PlanOfStudys = GetPlanOfStudyAndDisciplines(0)
|
2024-05-28 21:40:18 +04:00
|
|
|
|
});
|
2024-05-02 17:22:43 +04:00
|
|
|
|
}
|
2024-05-01 20:40:47 +04:00
|
|
|
|
|
|
|
|
|
public void SaveTeachersToWord(ReportBindingModel option)
|
|
|
|
|
{
|
2024-05-28 21:41:10 +04:00
|
|
|
|
_saveToWordStorekeeper.CreateDoc(new WordInfoStorekeeper
|
|
|
|
|
{
|
|
|
|
|
FileName = option.FileName,
|
2024-05-29 18:51:07 +04:00
|
|
|
|
Title = "Список преподавателей и студентов",
|
2024-05-29 11:30:39 +04:00
|
|
|
|
TeacherInfo = GetTeachers(0)
|
2024-05-28 21:41:10 +04:00
|
|
|
|
});
|
2024-05-01 20:40:47 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2024-05-02 17:22:43 +04:00
|
|
|
|
|
2024-05-29 19:26:11 +04:00
|
|
|
|
public void SendPlanOfStudyToEmail(ReportBindingModel option)
|
2024-05-02 17:22:43 +04:00
|
|
|
|
{
|
2024-05-29 19:26:11 +04:00
|
|
|
|
_saveToPdfWorker.CreateDoc(new PdfInfoWorker
|
2024-05-28 21:40:18 +04:00
|
|
|
|
{
|
2024-05-29 19:26:11 +04:00
|
|
|
|
FileName = option.FileName,
|
|
|
|
|
Title = "Отчёт по заказам за период",
|
|
|
|
|
PlanOfStudyAndStudent = GetPlanOfStudyAndStudents()
|
|
|
|
|
});
|
2024-05-02 17:22:43 +04:00
|
|
|
|
}
|
2024-05-01 20:40:47 +04:00
|
|
|
|
}
|